function isPendingMember($group) { $request = Group_join_queue::pkeyGet(array('profile_id' => $this->id, 'group_id' => $group->id)); return !empty($request); }
/** * Prepare to run */ function prepare($args) { parent::prepare($args); if (!common_logged_in()) { // TRANS: Client error displayed when trying to leave a group while not logged in. $this->clientError(_('You must be logged in to leave a group.')); } $nickname_arg = $this->trimmed('nickname'); $id = intval($this->arg('id')); if ($id) { $this->group = User_group::getKV('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); } $local = Local_group::getKV('nickname', $nickname); if (!$local) { // TRANS: Client error displayed when trying to leave a non-local group. $this->clientError(_('No such group.'), 404); } $this->group = User_group::getKV('id', $local->group_id); } else { // TRANS: Client error displayed when trying to leave a group without providing a group name or group ID. $this->clientError(_('No nickname or ID.'), 404); } } if (!$this->group) { // TRANS: Client error displayed when trying to leave a non-existing group. $this->clientError(_('No such group.'), 404); } $cur = common_current_user(); if (empty($cur)) { // TRANS: Client error displayed trying to approve group membership while not logged in. $this->clientError(_('Must be logged in.'), 403); } if ($this->arg('profile_id')) { if ($cur->isAdmin($this->group)) { $this->profile = Profile::getKV('id', $this->arg('profile_id')); } else { // TRANS: Client error displayed trying to approve group membership while not a group administrator. $this->clientError(_('Only group admin can approve or cancel join requests.'), 403); } } else { // TRANS: Client error displayed trying to approve group membership without specifying a profile to approve. $this->clientError(_('Must specify a profile.')); } $this->request = Group_join_queue::pkeyGet(array('profile_id' => $this->profile->id, 'group_id' => $this->group->id)); if (empty($this->request)) { // TRANS: Client error displayed trying to approve group membership for a non-existing request. // TRANS: %s is a nickname. $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403); } $this->approve = (bool) $this->arg('approve'); $this->cancel = (bool) $this->arg('cancel'); if (!$this->approve && !$this->cancel) { // TRANS: Client error displayed trying to approve/deny group membership. $this->clientError(_('Internal error: received neither cancel nor abort.')); } if ($this->approve && $this->cancel) { // TRANS: Client error displayed trying to approve/deny group membership. $this->clientError(_('Internal error: received both cancel and abort.')); } return true; }
/** * Prepare to run */ function prepare($args) { parent::prepare($args); if (!common_logged_in()) { // TRANS: Client error displayed when trying to leave a group while not 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) { // TRANS: Client error displayed when trying to leave 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 leave 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 leave a non-existing group. $this->clientError(_('No such group.'), 404); return false; } $cur = common_current_user(); if (empty($cur)) { // TRANS: Client error displayed when trying to leave a group while not logged in. $this->clientError(_('Must be logged in.'), 403); return false; } if ($this->arg('profile_id')) { if ($cur->isAdmin($this->group)) { $this->profile = Profile::staticGet('id', $this->arg('profile_id')); } else { // TRANS: Client error displayed when trying to approve or cancel a group join request without // TRANS: being a group administrator. $this->clientError(_('Only group admin can approve or cancel join requests.'), 403); return false; } } else { $this->profile = $cur->getProfile(); } $this->request = Group_join_queue::pkeyGet(array('profile_id' => $this->profile->id, 'group_id' => $this->group->id)); if (empty($this->request)) { // TRANS: Client error displayed when trying to approve a non-existing group join request. // TRANS: %s is a user nickname. $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403); } return true; }