From fc047bd6e6208be5832c9855b4054c25b189776c Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 1 Mar 2014 11:55:06 +0100 Subject: [PATCH] Minor code cleanup with group related actions (thanks brw12) Originated from brw12 who noticed an incorrect variable name used in an error message in actions/apigroupjoin.php:109 --- actions/apigroupjoin.php | 12 ++++++------ actions/blockedfromgroup.php | 6 +++--- actions/editgroup.php | 8 +++----- actions/groupblock.php | 9 --------- actions/grouplogo.php | 6 +++--- actions/groupmembers.php | 6 +++--- actions/groupqueue.php | 6 +++--- actions/showgroup.php | 5 +++-- classes/Profile.php | 4 ++-- classes/User.php | 4 ++-- lib/groupaction.php | 2 +- plugins/OStatus/actions/ostatusinit.php | 2 +- 12 files changed, 30 insertions(+), 40 deletions(-) diff --git a/actions/apigroupjoin.php b/actions/apigroupjoin.php index 10081ae1b5..3e571801f2 100644 --- a/actions/apigroupjoin.php +++ b/actions/apigroupjoin.php @@ -72,7 +72,7 @@ class ApiGroupJoinAction extends ApiAuthAction /** * Handle the request * - * Save the new message + * Join the authenticated user to the group * * @return void */ @@ -80,7 +80,7 @@ class ApiGroupJoinAction extends ApiAuthAction { parent::handle(); - if (empty($this->user)) { + if (empty($this->scoped)) { // TRANS: Client error displayed when trying to have a non-existing user join a group. $this->clientError(_('No such user.'), 404); } @@ -90,23 +90,23 @@ class ApiGroupJoinAction extends ApiAuthAction $this->clientError(_('Group not found.'), 404); } - if ($this->user->isMember($this->group)) { + if ($this->scoped->isMember($this->group)) { // TRANS: Server error displayed when trying to join a group the user is already a member of. $this->clientError(_('You are already a member of that group.'), 403); } - if (Group_block::isBlocked($this->group, $this->user->getProfile())) { + if (Group_block::isBlocked($this->group, $this->scoped)) { // TRANS: Server error displayed when trying to join a group the user is blocked from joining. $this->clientError(_('You have been blocked from that group by the admin.'), 403); } try { - $this->user->joinGroup($this->group); + $this->scoped->joinGroup($this->group); } catch (Exception $e) { // TRANS: Server error displayed when joining a group failed in the database. // TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed. $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), - $cur->nickname, $this->group->nickname)); + $this->scoped->nickname, $this->group->nickname)); } switch($this->format) { diff --git a/actions/blockedfromgroup.php b/actions/blockedfromgroup.php index 685d6dd068..a00c12ef58 100644 --- a/actions/blockedfromgroup.php +++ b/actions/blockedfromgroup.php @@ -49,7 +49,7 @@ class BlockedfromgroupAction extends GroupAction return true; } - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; @@ -109,9 +109,9 @@ class BlockedfromgroupAction extends GroupAction } } - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); $this->showPage(); } diff --git a/actions/editgroup.php b/actions/editgroup.php index ee1f5b86ff..befbd55992 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -59,7 +59,7 @@ class EditgroupAction extends GroupAction * Prepare to run */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -119,13 +119,11 @@ class EditgroupAction extends GroupAction * * On GET, show the form. On POST, try to save the group. * - * @param array $args unused - * * @return void */ - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->trySave(); } else { diff --git a/actions/groupblock.php b/actions/groupblock.php index 2dbb897514..1c6ccb9e59 100644 --- a/actions/groupblock.php +++ b/actions/groupblock.php @@ -58,54 +58,45 @@ class GroupblockAction extends RedirectingAction 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::getKV('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::getKV('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; } diff --git a/actions/grouplogo.php b/actions/grouplogo.php index 1e62514312..adffe63c38 100644 --- a/actions/grouplogo.php +++ b/actions/grouplogo.php @@ -60,7 +60,7 @@ class GrouplogoAction extends GroupAction /** * Prepare to run */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -115,9 +115,9 @@ class GrouplogoAction extends GroupAction return true; } - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->handlePost(); } else { diff --git a/actions/groupmembers.php b/actions/groupmembers.php index 52979101fd..44c4dd6f99 100644 --- a/actions/groupmembers.php +++ b/actions/groupmembers.php @@ -52,7 +52,7 @@ class GroupmembersAction extends GroupAction return true; } - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -77,9 +77,9 @@ class GroupmembersAction extends GroupAction } } - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); $this->showPage(); } diff --git a/actions/groupqueue.php b/actions/groupqueue.php index 1d5a3cd134..7227b11090 100644 --- a/actions/groupqueue.php +++ b/actions/groupqueue.php @@ -53,7 +53,7 @@ class GroupqueueAction extends GroupAction } // @todo FIXME: most of this belongs in a base class, sounds common to most group actions? - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; @@ -119,9 +119,9 @@ class GroupqueueAction extends GroupAction } } - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); $this->showPage(); } diff --git a/actions/showgroup.php b/actions/showgroup.php index 10601e58b4..e2b5e8d547 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -91,7 +91,7 @@ class ShowgroupAction extends GroupAction * * @return boolean success flag */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -123,8 +123,9 @@ class ShowgroupAction extends GroupAction * * @return void */ - function handle($args) + protected function handle() { + parent::handle(); $this->showPage(); } diff --git a/classes/Profile.php b/classes/Profile.php index 76b2ac28d0..ea87d217ab 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -256,7 +256,7 @@ class Profile extends Managed_DataObject return $stream->getNotices($offset, $limit, $since_id, $max_id); } - function isMember($group) + function isMember(User_group $group) { $groups = $this->getGroups(0, null); while ($groups instanceof User_group && $groups->fetch()) { @@ -267,7 +267,7 @@ class Profile extends Managed_DataObject return false; } - function isAdmin($group) + function isAdmin(User_group $group) { $gm = Group_member::pkeyGet(array('profile_id' => $this->id, 'group_id' => $group->id)); diff --git a/classes/User.php b/classes/User.php index 24a03b62fd..a6b04d5905 100644 --- a/classes/User.php +++ b/classes/User.php @@ -616,12 +616,12 @@ class User extends Managed_DataObject return true; } - function isMember($group) + function isMember(User_group $group) { return $this->getProfile()->isMember($group); } - function isAdmin($group) + function isAdmin(User_group $group) { return $this->getProfile()->isAdmin($group); } diff --git a/lib/groupaction.php b/lib/groupaction.php index ede0e3100f..0e2867fba8 100644 --- a/lib/groupaction.php +++ b/lib/groupaction.php @@ -46,7 +46,7 @@ class GroupAction extends Action { protected $group; - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); diff --git a/plugins/OStatus/actions/ostatusinit.php b/plugins/OStatus/actions/ostatusinit.php index 4edaafaa4e..5666c898af 100644 --- a/plugins/OStatus/actions/ostatusinit.php +++ b/plugins/OStatus/actions/ostatusinit.php @@ -218,7 +218,7 @@ class OStatusInitAction extends Action } } else if ($this->group) { $group = Local_group::getKV('nickname', $this->group); - if ($group) { + if ($group instanceof Local_group) { return common_local_url('groupbyid', array('id' => $group->group_id)); } else { // TRANS: Client error.