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
*
* 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) {

View File

@ -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();
}

View File

@ -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 {

View File

@ -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;
}

View File

@ -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 {

View File

@ -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();
}

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?
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();
}

View File

@ -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();
}

View File

@ -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));

View File

@ -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);
}

View File

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

View File

@ -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.