function updateGroupUri($group)
{
    if (!have_option('q', 'quiet')) {
        print "Updating URI for group '" . $group->nickname . "' (" . $group->id . ")...";
    }
    if (empty($group->uri)) {
        // Using clone here was screwing up the group->find() iteration
        $orig = User_group::staticGet('id', $group->id);
        $group->uri = $group->getUri();
        if (have_option('dry_run')) {
            echo " would have set {$group->uri} ";
        } else {
            if (!$group->update($orig)) {
                throw new Exception("Can't update uri for group " . $group->nickname . ".");
            }
            echo " set {$group->uri} ";
        }
    } else {
        print " already set, keeping {$group->uri} ";
    }
    if (have_option('v', 'verbose')) {
        print "DONE.";
    }
    if (!have_option('q', 'quiet') || have_option('v', 'verbose')) {
        print "\n";
    }
}
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_('Must be logged in.'), 403);
     }
     if (!$this->user->hasRight(Right::NEWMESSAGE)) {
         throw new Exception(sprintf(_('User %s not allowed to send private messages.'), $this->user->nickname));
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('newgroupmessage', array('nickname' => $nickname));
         common_redirect($url, 301);
         return false;
     }
     $localGroup = Local_group::staticGet('nickname', $nickname);
     if (empty($localGroup)) {
         throw new ClientException(_('No such group'), 404);
     }
     $this->group = User_group::staticGet('id', $localGroup->group_id);
     if (empty($this->group)) {
         throw new ClientException(_('No such group'), 404);
     }
     // This throws an exception on error
     Group_privacy_settings::ensurePost($this->user, $this->group);
     // If we're posted to, check session token and get text
     if ($this->isPost()) {
         $this->checkSessionToken();
         $this->text = $this->trimmed('content');
     }
     return true;
 }
Example #3
0
 /**
  * Handle input, produce output
  *
  * Switches based on GET or POST method. On GET, shows a form
  * for posting a notice. On POST, saves the results of that form.
  *
  * Results may be a full page, or just a single notice list item,
  * depending on whether AJAX was requested.
  *
  * @param array $args $_REQUEST contents
  *
  * @return void
  */
 function handle($args)
 {
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             // check for this before token since all POST and FILES data
             // is losts when size is exceeded
             if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) {
                 // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
                 // TRANS: %s is the number of bytes of the CONTENT_LENGTH.
                 $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH']));
                 $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
             }
             parent::handle($args);
             $user = common_current_user();
             $group = User_group::staticGet('id', $this->trimmed('groupid'));
             $taskid = $this->trimmed('taskid');
             try {
                 $this->saveNewNotice();
                 Task::completeTask($user->id, $taskid);
             } catch (Exception $e) {
                 $this->ajaxErrorMsg($e->getMessage(), $taskid, $group);
                 return;
             }
         }
     }
 }
Example #4
0
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('groupmembers', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed when trying to view group members without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         // TRANS: Client error displayed when trying to view group members for a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when trying to view group members for an object that is not a group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     return true;
 }
Example #5
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     if (empty($nickname_arg)) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $this->nickname) {
         common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301);
         return false;
     }
     $local = Local_group::staticGet('nickname', $this->nickname);
     if (!$local) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
Example #6
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         // TRANS: Client exception thrown when trying to view group private messages without being logged in.
         throw new ClientException(_m('Only logged-in users can view private messages.'), 403);
     }
     $id = $this->trimmed('id');
     $this->gm = Group_message::staticGet('id', $id);
     if (empty($this->gm)) {
         // TRANS: Client exception thrown when trying to view a non-existing group private message.
         throw new ClientException(_m('No such message.'), 404);
     }
     $this->group = User_group::staticGet('id', $this->gm->to_group);
     if (empty($this->group)) {
         // TRANS: Server exception thrown when trying to view group private messages for a non-exsting group.
         throw new ServerException(_m('Group not found.'));
     }
     if (!$this->user->isMember($this->group)) {
         // TRANS: Client exception thrown when trying to view a group private message without being a group member.
         throw new ClientException(_m('Cannot read message.'), 403);
     }
     $this->sender = Profile::staticGet('id', $this->gm->from_profile);
     if (empty($this->sender)) {
         // TRANS: Server exception thrown when trying to view a group private message without a sender.
         throw new ServerException(_m('No sender found.'));
     }
     return true;
 }
Example #7
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $cur = common_current_user();
     if (empty($cur)) {
         throw new ClientException(_('Only for logged-in users'), 403);
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('groupinbox', array('nickname' => $nickname));
         common_redirect($url);
         return false;
     }
     $localGroup = Local_group::staticGet('nickname', $nickname);
     if (empty($localGroup)) {
         throw new ClientException(_('No such group'), 404);
     }
     $this->group = User_group::staticGet('id', $localGroup->group_id);
     if (empty($this->group)) {
         throw new ClientException(_('No such group'), 404);
     }
     if (!$cur->isMember($this->group)) {
         throw new ClientException(_('Only for members'), 403);
     }
     $this->page = $this->trimmed('page');
     if (!$this->page) {
         $this->page = 1;
     }
     $this->gm = Group_message::forGroup($this->group, ($this->page - 1) * MESSAGES_PER_PAGE, MESSAGES_PER_PAGE + 1);
     return true;
 }
Example #8
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     if (empty($nickname_arg)) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a group nickname.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $this->nickname) {
         common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301);
         return false;
     }
     $local = Local_group::staticGet('nickname', $this->nickname);
     if (!$local) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed for a non-local group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed for a nickname that is not a group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_('Only logged-in users can view private messages.'), 403);
     }
     $id = $this->trimmed('id');
     $this->gm = Group_message::staticGet('id', $id);
     if (empty($this->gm)) {
         throw new ClientException(_('No such message'), 404);
     }
     $this->group = User_group::staticGet('id', $this->gm->to_group);
     if (empty($this->group)) {
         throw new ServerException(_('Group not found.'));
     }
     if (!$this->user->isMember($this->group)) {
         throw new ClientException(_('Cannot read message.'), 403);
     }
     $this->sender = Profile::staticGet('id', $this->gm->from_profile);
     if (empty($this->sender)) {
         throw new ServerException(_('No sender found.'));
     }
     return true;
 }
Example #10
0
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_config('inboxes', 'enabled')) {
         $this->serverError(_('Inboxes must be enabled for groups to work.'));
         return false;
     }
     if (!common_logged_in()) {
         $this->clientError(_('You must be logged in to leave a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('leavegroup', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('nickname', $nickname);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isMember($this->group)) {
         $this->clientError(_('You are not a member of that group.'), 403);
         return false;
     }
     return true;
 }
Example #11
0
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('groupmembers', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     return true;
 }
function updateGroupAvatars($group)
{
    if (!have_option('q', 'quiet')) {
        print "Updating avatars for group '" . $group->nickname . "' (" . $group->id . ")...";
    }
    if (empty($group->original_logo)) {
        print "(none found)...";
    } else {
        // Using clone here was screwing up the group->find() iteration
        $orig = User_group::staticGet('id', $group->id);
        $group->original_logo = Avatar::url(basename($group->original_logo));
        $group->homepage_logo = Avatar::url(basename($group->homepage_logo));
        $group->stream_logo = Avatar::url(basename($group->stream_logo));
        $group->mini_logo = Avatar::url(basename($group->mini_logo));
        if (!$group->update($orig)) {
            throw new Exception("Can't update avatars for group " . $group->nickname . ".");
        }
    }
    if (have_option('v', 'verbose')) {
        print "DONE.";
    }
    if (!have_option('q', 'quiet') || have_option('v', 'verbose')) {
        print "\n";
    }
}
Example #13
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('blockto');
     if (empty($id)) {
         // TRANS: Client error displayed trying to block a user from a group while not specifying a to be blocked user profile.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         // TRANS: Client error displayed trying to block a user from a group while specifying a non-existing profile.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('blockgroup');
     if (empty($group_id)) {
         // TRANS: Client error displayed trying to block a user from a group while not specifying a group to block a profile from.
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while specifying a non-existing group.
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while not being an admin user.
         $this->clientError(_('Only an admin can block group members.'), 401);
         return false;
     }
     if (Group_block::isBlocked($this->group, $this->profile)) {
         // TRANS: Client error displayed trying to block a user from a group while user is already blocked from the given group.
         $this->clientError(_('User is already blocked from group.'));
         return false;
     }
     // XXX: could have proactive blocks, but we don't have UI for it.
     if (!$this->profile->isMember($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while user is not a member of given group.
         $this->clientError(_('User is not a member of group.'));
         return false;
     }
     return true;
 }
Example #14
0
 function getGroup()
 {
     $group = User_group::staticGet('id', $this->group_id);
     if (empty($group)) {
         // TRANS: Exception thrown providing an invalid group ID.
         // TRANS: %s is the invalid group ID.
         throw new Exception(sprintf(_("Group ID %s is invalid."), $this->group_id));
     }
     return $group;
 }
Example #15
0
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed when trying to join a group while not logged in.
         $this->clientError(_('You must be logged in to join a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::staticGet('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
                 return false;
             }
             $local = Local_group::staticGet('nickname', $nickname);
             if (!$local) {
                 // TRANS: Client error displayed when trying to join a non-local group.
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
             $this->group = User_group::staticGet('id', $local->group_id);
         } else {
             // TRANS: Client error displayed when trying to join a group without providing a group name or group ID.
             $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
     }
     if (!$this->group) {
         // TRANS: Client error displayed when trying to join a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if ($cur->isMember($this->group)) {
         // TRANS: Client error displayed when trying to join a group while already a member.
         $this->clientError(_('You are already a member of that group.'), 403);
         return false;
     }
     if (Group_block::isBlocked($this->group, $cur->getProfile())) {
         // TRANS: Client error displayed when trying to join a group while being blocked form joining it.
         $this->clientError(_('You have been blocked from that group by the admin.'), 403);
         return false;
     }
     return true;
 }
Example #16
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('profileid');
     if (empty($id)) {
         // TRANS: Client error displayed when not providing a profile ID on the Make Admin page.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         // TRANS: Client error displayed when specifying an invalid profile ID on the Make Admin page.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('groupid');
     if (empty($group_id)) {
         // TRANS: Client error displayed when not providing a group ID on the Make Admin page.
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         // TRANS: Client error displayed when providing an invalid group ID on the Make Admin page.
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group) && !$user->hasRight(Right::MAKEGROUPADMIN)) {
         // TRANS: Client error displayed when trying to make another user admin on the Make Admin page while not an admin.
         $this->clientError(_('Only an admin can make another user an admin.'), 401);
         return false;
     }
     if ($this->profile->isAdmin($this->group)) {
         // TRANS: Client error displayed when trying to make another user admin on the Make Admin page who already is admin.
         // TRANS: %1$s is the user that is already admin, %2$s is the group user is already admin for.
         $this->clientError(sprintf(_('%1$s is already an admin for group "%2$s".'), $this->profile->getBestName(), $this->group->getBestName()), 401);
         return false;
     }
     return true;
 }
Example #17
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('unblockto');
     if (empty($id)) {
         // TRANS: Client error displayed when trying to unblock a user from a group without providing a profile.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         // TRANS: Client error displayed when trying to unblock a user from a group without providing an existing profile.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('unblockgroup');
     if (empty($group_id)) {
         // TRANS: Client error displayed when trying to unblock a user from a group without providing a group.
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         // TRANS: Client error displayed when trying to unblock a user from a non-existing group.
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group)) {
         // TRANS: Client error displayed when trying to unblock a user from a group without being an administrator for the group.
         $this->clientError(_('Only an admin can unblock group members.'), 401);
         return false;
     }
     if (!Group_block::isBlocked($this->group, $this->profile)) {
         // TRANS: Client error displayed when trying to unblock a non-blocked user from a group.
         $this->clientError(_('User is not blocked from group.'));
         return false;
     }
     return true;
 }
Example #18
0
 /**
  * Take arguments for running
  *
  * This method is called first, and it lets the action class get
  * all its arguments and validate them. It's also the time
  * to fetch any relevant data from the database.
  *
  * Action classes should run parent::prepare($args) as the first
  * line of this method to make sure the default argument-processing
  * happens.
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $alumno = $this->trimmed('nickname');
     $group = $this->trimmed('nickgroup');
     $this->group = User_group::staticGet('nickname', $group);
     $this->alumno = Profile::staticGet('nickname', $alumno);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $ids = Grades::getNoticeFromUserInGroup($this->alumno->id, $this->group->id);
     $this->generarEstadisticas($ids);
     $this->notice = $this->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, $ids);
     common_set_returnto($this->selfUrl());
     return true;
 }
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('blockto');
     if (empty($id)) {
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('blockgroup');
     if (empty($group_id)) {
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group)) {
         $this->clientError(_('Only an admin can block group members.'), 401);
         return false;
     }
     if (Group_block::isBlocked($this->group, $this->profile)) {
         $this->clientError(_('User is already blocked from group.'));
         return false;
     }
     // XXX: could have proactive blocks, but we don't have UI for it.
     if (!$this->profile->isMember($this->group)) {
         $this->clientError(_('User is not a member of group.'));
         return false;
     }
     return true;
 }
Example #20
0
 function prepare($args)
 {
     parent::prepare($args);
     $id = $this->arg('id');
     if (!$id) {
         $this->clientError(_('No ID.'));
         return false;
     }
     common_debug("Got ID {$id}");
     $this->group = User_group::staticGet('id', $id);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     return true;
 }
Example #21
0
 /**
  * Prepare to run
  *
  * @fixme merge common setup code with other group actions
  * @fixme allow group admins to delete their own groups
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error when trying to delete group while not logged in.
         $this->clientError(_('You must be logged in to delete a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::staticGet('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
                 return false;
             }
             $local = Local_group::staticGet('nickname', $nickname);
             if (!$local) {
                 // TRANS: Client error when trying to delete a non-local group.
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
             $this->group = User_group::staticGet('id', $local->group_id);
         } else {
             // TRANS: Client error when trying to delete a group without providing a nickname or ID for the group.
             $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
     }
     if (!$this->group) {
         // TRANS: Client error when trying to delete a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->hasRight(Right::DELETEGROUP)) {
         // TRANS: Client error when trying to delete a group without having the rights to delete it.
         $this->clientError(_('You are not allowed to delete this group.'), 403);
         return false;
     }
     return true;
 }
Example #22
0
 function prepare($args)
 {
     parent::prepare($args);
     $id = $this->trimmed('id');
     if (!$id) {
         $this->clientError(_('No ID.'));
     }
     $this->group = User_group::staticGet('id', $id);
     if (empty($this->group)) {
         $this->clientError(_('No such group.'));
     }
     $oprofile = Ostatus_profile::staticGet('group_id', $id);
     if ($oprofile) {
         $this->clientError(_m("Can't accept remote posts for a remote group."));
     }
     return true;
 }
Example #23
0
 function prepare($args)
 {
     parent::prepare($args);
     $id = $this->arg('id');
     if (!$id) {
         // TRANS: Client error displayed referring to a group's permalink without providing a group ID.
         $this->clientError(_('No ID.'));
         return false;
     }
     common_debug("Got ID {$id}");
     $this->group = User_group::staticGet('id', $id);
     if (!$this->group) {
         // TRANS: Client error displayed referring to a group's permalink for a non-existing group ID.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     return true;
 }
 /**
  * Sets the right action for the form, and passes request args into
  * the base action
  *
  * @param array $args misc. arguments
  *
  * @return boolean true
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed trying to change group design settings while not logged in.
         $this->clientError(_('You must be logged in to edit a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('groupdesignsettings', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed trying to change group design settings without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $groupid = $this->trimmed('groupid');
     if ($groupid) {
         $this->group = User_group::staticGet('id', $groupid);
     } else {
         $local = Local_group::staticGet('nickname', $nickname);
         if ($local) {
             $this->group = User_group::staticGet('id', $local->group_id);
         }
     }
     if (!$this->group) {
         // TRANS: Client error displayed trying to change group design settings while providing a nickname for a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         // TRANS: Client error displayed trying to change group design settings without being a (group) admin.
         $this->clientError(_('You must be an admin to edit the group.'), 403);
         return false;
     }
     $this->submitaction = common_local_url('groupdesignsettings', array('nickname' => $this->group->nickname));
     return true;
 }
Example #25
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('profileid');
     if (empty($id)) {
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('groupid');
     if (empty($group_id)) {
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group)) {
         $this->clientError(_('Only an admin can make another user an admin.'), 401);
         return false;
     }
     if ($this->profile->isAdmin($this->group)) {
         $this->clientError(sprintf(_('%s is already an admin for group "%s".'), $this->profile->getBestName(), $this->group->getBestName()), 401);
         return false;
     }
     return true;
 }
Example #26
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('showgroup', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed if no nickname argument was given requesting a group page.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         $alias = Group_alias::staticGet('alias', $nickname);
         if ($alias) {
             $args = array('id' => $alias->group_id);
             if ($this->page != 1) {
                 $args['page'] = $this->page;
             }
             common_redirect(common_local_url('groupbyid', $args), 301);
             return false;
         } else {
             common_log(LOG_NOTICE, "Couldn't find local group for nickname '{$nickname}'");
             // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
             $this->clientError(_('No such group.'), 404);
             return false;
         }
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed if no local group with a given name was found requesting group page.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
 }
Example #27
0
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         $this->clientError(_('You must be logged in to leave a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::staticGet('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
                 return false;
             }
             $local = Local_group::staticGet('nickname', $nickname);
             if (!$local) {
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
             $this->group = User_group::staticGet('id', $local->group_id);
         } else {
             $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
     }
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isMember($this->group)) {
         $this->clientError(_('You are not a member of that group.'), 403);
         return false;
     }
     return true;
 }
Example #28
0
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_config('inboxes', 'enabled')) {
         $this->serverError(_('Inboxes must be enabled for groups to work'));
         return false;
     }
     $id = $this->arg('id');
     if (!$id) {
         $this->clientError(_('No ID'));
         return false;
     }
     common_debug("Got ID {$id}");
     $this->group = User_group::staticGet('id', $id);
     if (!$this->group) {
         $this->clientError(_('No such group'), 404);
         return false;
     }
     return true;
 }
Example #29
0
 /**
  * Sets the right action for the form, and passes request args into
  * the base action
  *
  * @param array $args misc. arguments
  *
  * @return boolean true
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_config('inboxes', 'enabled')) {
         $this->serverError(_('Inboxes must be enabled for groups to work'));
         return false;
     }
     if (!common_logged_in()) {
         $this->clientError(_('You must be logged in to edit a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('groupdesignsettings', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname'), 404);
         return false;
     }
     $groupid = $this->trimmed('groupid');
     if ($groupid) {
         $this->group = User_group::staticGet('id', $groupid);
     } else {
         $this->group = User_group::staticGet('nickname', $nickname);
     }
     if (!$this->group) {
         $this->clientError(_('No such group'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         $this->clientError(_('You must be an admin to edit the group'), 403);
         return false;
     }
     $this->submitaction = common_local_url('groupdesignsettings', array('nickname' => $this->group->nickname));
     return true;
 }
Example #30
0
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         $this->clientError(_('You must be logged in to create a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('editgroup', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $groupid = $this->trimmed('groupid');
     if ($groupid) {
         $this->group = User_group::staticGet('id', $groupid);
     } else {
         $local = Local_group::staticGet('nickname', $nickname);
         if ($local) {
             $this->group = User_group::staticGet('id', $local->group_id);
         }
     }
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         $this->clientError(_('You must be an admin to edit the group.'), 403);
         return false;
     }
     return true;
 }