123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class Group_privacy_settings extends Managed_DataObject
- {
- public $__table = 'group_privacy_settings';
-
- public $group_id;
-
- public $allow_privacy;
-
- public $allow_sender;
-
- public $created;
-
- public $modified;
-
- const SOMETIMES = -1;
- const NEVER = 0;
- const ALWAYS = 1;
-
- const EVERYONE = 1;
- const MEMBER = 2;
- const ADMIN = 4;
- public static function schemaDef()
- {
- return array(
- 'fields' => array(
- 'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group_privacy_settings'),
- 'allow_privacy' => array('type' => 'int', 'not null' => true, 'description' => 'sometimes=-1, never=0, always=1'),
- 'allow_sender' => array('type' => 'int', 'not null' => true, 'description' => 'list of bit-mappy values in source code'),
- 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
- 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
- ),
- 'primary key' => array('group_id'),
- 'foreign keys' => array(
- 'group_privacy_settings_group_id_fkey' => array('user_group', array('group_id' => 'id')),
- ),
- );
- }
- function forGroup($group)
- {
- $gps = Group_privacy_settings::getKV('group_id', $group->id);
- if (empty($gps)) {
-
- $gps = new Group_privacy_settings();
- $gps->allow_privacy = Group_privacy_settings::SOMETIMES;
- $gps->allow_sender = Group_privacy_settings::MEMBER;
- }
- return $gps;
- }
- function ensurePost($user, $group)
- {
- $gps = self::forGroup($group);
- if ($gps->allow_privacy == Group_privacy_settings::NEVER) {
-
- throw new Exception(sprintf(_m('Group %s does not allow private messages.'),
- $group->nickname));
- }
- switch ($gps->allow_sender) {
- case Group_privacy_settings::EVERYONE:
- $profile = $user->getProfile();
- if (Group_block::isBlocked($group, $profile)) {
-
-
- throw new Exception(sprintf(_m('User %1$s is blocked from group %2$s.'),
- $user->nickname,
- $group->nickname));
- }
- break;
- case Group_privacy_settings::MEMBER:
- if (!$user->isMember($group)) {
-
-
- throw new Exception(sprintf(_m('User %1$s is not a member of group %2$s.'),
- $user->nickname,
- $group->nickname));
- }
- break;
- case Group_privacy_settings::ADMIN:
- if (!$user->isAdmin($group)) {
-
-
- throw new Exception(sprintf(_m('User %1$s is not an administrator of group %2$s.'),
- $user->nickname,
- $group->nickname));
- }
- break;
- default:
-
-
- throw new Exception(sprintf(_m('Unknown privacy settings for group %s.'),
- $group->nickname));
- }
- return true;
- }
- }
|