/**
* Handle the request
*
- * Save the new message
+ * Join the authenticated user to the group
*
* @return void
*/
{
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);
}
$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) {
return true;
}
- function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
}
}
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
$this->showPage();
}
* Prepare to run
*/
- function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
*
* 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 {
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;
}
/**
* Prepare to run
*/
- function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
return true;
}
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->handlePost();
} else {
return true;
}
- function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
}
}
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
$this->showPage();
}
}
// @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;
}
}
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
$this->showPage();
}
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
*
* @return void
*/
- function handle($args)
+ protected function handle()
{
+ parent::handle();
$this->showPage();
}
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()) {
return false;
}
- function isAdmin($group)
+ function isAdmin(User_group $group)
{
$gm = Group_member::pkeyGet(array('profile_id' => $this->id,
'group_id' => $group->id));
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);
}
{
protected $group;
- function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
}
} 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.