/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $this->checkSessionToken(); if (!common_logged_in()) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { // TRANS: Error message displayed when trying to perform an action that requires a logged in user. $this->clientError(_('Not logged in.')); } else { // Redirect to login. common_set_returnto($this->selfUrl()); $user = common_current_user(); if (Event::handle('RedirectToLogin', array($this, $user))) { common_redirect(common_local_url('login'), 303); } } return false; } $id = $this->trimmed('profileid'); if (!$id) { // TRANS: Client error displayed when trying to change user options without specifying a user to work on. $this->clientError(_('No profile specified.')); return false; } $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { // TRANS: Client error displayed when trying to change user options without specifying an existing user to work on. $this->clientError(_('No profile with that ID.')); return false; } return true; }
/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $this->checkSessionToken(); if (!common_logged_in()) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->clientError(_('Not logged in.')); } else { // Redirect to login. common_set_returnto($this->selfUrl()); $user = common_current_user(); if (Event::handle('RedirectToLogin', array($this, $user))) { common_redirect(common_local_url('login'), 303); } } return false; } $id = $this->trimmed('profileid'); if (!$id) { $this->clientError(_('No profile specified.')); return false; } $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { $this->clientError(_('No profile with that ID.')); return false; } 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()) { // 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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) && !$user->hasRight(Right::MAKEGROUPADMIN)) { $this->clientError(_('Only an admin can make another user an admin.'), 401); return false; } if ($this->profile->isAdmin($this->group)) { $this->clientError(sprintf(_('%1$s is already an admin for group "%2$s".'), $this->profile->getBestName(), $this->group->getBestName()), 401); return false; } return true; }
/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $this->checkSessionToken(); if (!common_logged_in()) { $this->clientError(_('Not logged in.')); return false; } $id = $this->trimmed('profileid'); if (!$id) { $this->clientError(_('No profile specified.')); return false; } $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { $this->clientError(_('No profile with that ID.')); return false; } return true; }
function prepare($args) { parent::prepare($args); if (!common_logged_in()) { $this->clientError(_('Not logged in.')); return false; } $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) && !$user->hasRole('grader')) { $this->clientError(_('Only an admin and grader can make another user a grader.'), 401); return false; } if ($this->profile->hasRole('grader')) { $this->clientError(sprintf(_('%1$s is already a grader for group "%2$s".'), $this->profile->getBestName(), $this->group->getBestName()), 401); return false; } return true; }