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
This commit is contained in:
Mikael Nordfeldth 2014-03-01 11:55:06 +01:00
parent 9a03ec98e7
commit fc047bd6e6
12 changed files with 30 additions and 40 deletions

View File

@ -72,7 +72,7 @@ class ApiGroupJoinAction extends ApiAuthAction
/** /**
* Handle the request * Handle the request
* *
* Save the new message * Join the authenticated user to the group
* *
* @return void * @return void
*/ */
@ -80,7 +80,7 @@ class ApiGroupJoinAction extends ApiAuthAction
{ {
parent::handle(); 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. // TRANS: Client error displayed when trying to have a non-existing user join a group.
$this->clientError(_('No such user.'), 404); $this->clientError(_('No such user.'), 404);
} }
@ -90,23 +90,23 @@ class ApiGroupJoinAction extends ApiAuthAction
$this->clientError(_('Group not found.'), 404); $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. // 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); $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. // 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); $this->clientError(_('You have been blocked from that group by the admin.'), 403);
} }
try { try {
$this->user->joinGroup($this->group); $this->scoped->joinGroup($this->group);
} catch (Exception $e) { } catch (Exception $e) {
// TRANS: Server error displayed when joining a group failed in the database. // 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. // 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.'), $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) { switch($this->format) {

View File

@ -49,7 +49,7 @@ class BlockedfromgroupAction extends GroupAction
return true; return true;
} }
function prepare($args) protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; $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(); $this->showPage();
} }

View File

@ -59,7 +59,7 @@ class EditgroupAction extends GroupAction
* Prepare to run * Prepare to run
*/ */
function prepare($args) protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);
@ -119,13 +119,11 @@ class EditgroupAction extends GroupAction
* *
* On GET, show the form. On POST, try to save the group. * On GET, show the form. On POST, try to save the group.
* *
* @param array $args unused
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->trySave(); $this->trySave();
} else { } else {

View File

@ -58,54 +58,45 @@ class GroupblockAction extends RedirectingAction
if (!common_logged_in()) { if (!common_logged_in()) {
// TRANS: Error message displayed when trying to perform an action that requires a logged in user. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
$this->clientError(_('Not logged in.')); $this->clientError(_('Not logged in.'));
return false;
} }
$token = $this->trimmed('token'); $token = $this->trimmed('token');
if (empty($token) || $token != common_session_token()) { if (empty($token) || $token != common_session_token()) {
// TRANS: Client error displayed when the session token does not match or is not given. // 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.')); $this->clientError(_('There was a problem with your session token. Try again, please.'));
return;
} }
$id = $this->trimmed('blockto'); $id = $this->trimmed('blockto');
if (empty($id)) { if (empty($id)) {
// TRANS: Client error displayed trying to block a user from a group while not specifying a to be blocked user profile. // 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.')); $this->clientError(_('No profile specified.'));
return false;
} }
$this->profile = Profile::getKV('id', $id); $this->profile = Profile::getKV('id', $id);
if (empty($this->profile)) { if (empty($this->profile)) {
// TRANS: Client error displayed trying to block a user from a group while specifying a non-existing 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.')); $this->clientError(_('No profile with that ID.'));
return false;
} }
$group_id = $this->trimmed('blockgroup'); $group_id = $this->trimmed('blockgroup');
if (empty($group_id)) { 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. // 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.')); $this->clientError(_('No group specified.'));
return false;
} }
$this->group = User_group::getKV('id', $group_id); $this->group = User_group::getKV('id', $group_id);
if (empty($this->group)) { if (empty($this->group)) {
// TRANS: Client error displayed trying to block a user from a group while specifying a non-existing group. // TRANS: Client error displayed trying to block a user from a group while specifying a non-existing group.
$this->clientError(_('No such group.')); $this->clientError(_('No such group.'));
return false;
} }
$user = common_current_user(); $user = common_current_user();
if (!$user->isAdmin($this->group)) { if (!$user->isAdmin($this->group)) {
// TRANS: Client error displayed trying to block a user from a group while not being an admin user. // 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); $this->clientError(_('Only an admin can block group members.'), 401);
return false;
} }
if (Group_block::isBlocked($this->group, $this->profile)) { 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. // 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.')); $this->clientError(_('User is already blocked from group.'));
return false;
} }
// XXX: could have proactive blocks, but we don't have UI for it. // XXX: could have proactive blocks, but we don't have UI for it.
if (!$this->profile->isMember($this->group)) { 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. // 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.')); $this->clientError(_('User is not a member of group.'));
return false;
} }
return true; return true;
} }

View File

@ -60,7 +60,7 @@ class GrouplogoAction extends GroupAction
/** /**
* Prepare to run * Prepare to run
*/ */
function prepare($args) protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);
@ -115,9 +115,9 @@ class GrouplogoAction extends GroupAction
return true; return true;
} }
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->handlePost(); $this->handlePost();
} else { } else {

View File

@ -52,7 +52,7 @@ class GroupmembersAction extends GroupAction
return true; return true;
} }
function prepare($args) protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);
@ -77,9 +77,9 @@ class GroupmembersAction extends GroupAction
} }
} }
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
$this->showPage(); $this->showPage();
} }

View File

@ -53,7 +53,7 @@ class GroupqueueAction extends GroupAction
} }
// @todo FIXME: most of this belongs in a base class, sounds common to most group actions? // @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); parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; $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(); $this->showPage();
} }

View File

@ -91,7 +91,7 @@ class ShowgroupAction extends GroupAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);
@ -123,8 +123,9 @@ class ShowgroupAction extends GroupAction
* *
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle();
$this->showPage(); $this->showPage();
} }

View File

@ -256,7 +256,7 @@ class Profile extends Managed_DataObject
return $stream->getNotices($offset, $limit, $since_id, $max_id); return $stream->getNotices($offset, $limit, $since_id, $max_id);
} }
function isMember($group) function isMember(User_group $group)
{ {
$groups = $this->getGroups(0, null); $groups = $this->getGroups(0, null);
while ($groups instanceof User_group && $groups->fetch()) { while ($groups instanceof User_group && $groups->fetch()) {
@ -267,7 +267,7 @@ class Profile extends Managed_DataObject
return false; return false;
} }
function isAdmin($group) function isAdmin(User_group $group)
{ {
$gm = Group_member::pkeyGet(array('profile_id' => $this->id, $gm = Group_member::pkeyGet(array('profile_id' => $this->id,
'group_id' => $group->id)); 'group_id' => $group->id));

View File

@ -616,12 +616,12 @@ class User extends Managed_DataObject
return true; return true;
} }
function isMember($group) function isMember(User_group $group)
{ {
return $this->getProfile()->isMember($group); return $this->getProfile()->isMember($group);
} }
function isAdmin($group) function isAdmin(User_group $group)
{ {
return $this->getProfile()->isAdmin($group); return $this->getProfile()->isAdmin($group);
} }

View File

@ -46,7 +46,7 @@ class GroupAction extends Action
{ {
protected $group; protected $group;
function prepare($args) protected function prepare(array $args=array())
{ {
parent::prepare($args); parent::prepare($args);

View File

@ -218,7 +218,7 @@ class OStatusInitAction extends Action
} }
} else if ($this->group) { } else if ($this->group) {
$group = Local_group::getKV('nickname', $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)); return common_local_url('groupbyid', array('id' => $group->group_id));
} else { } else {
// TRANS: Client error. // TRANS: Client error.