From 942887ca8ce29f2cbb487d884a328d7fbbba2566 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 21 Mar 2011 17:17:18 -0700 Subject: [PATCH] Split up some list/form classes, and get the 'approve' and 'cancel' links on group member queue working. --- actions/approvegroup.php | 168 ++++++++++++++++ actions/cancelgroup.php | 17 +- actions/groupmembers.php | 373 ------------------------------------ actions/groupqueue.php | 372 ++--------------------------------- classes/Profile.php | 22 +++ lib/approvegroupform.php | 122 ++++++++++++ lib/cancelgroupform.php | 10 +- lib/groupblockform.php | 130 +++++++++++++ lib/groupmemberlist.php | 18 ++ lib/groupmemberlistitem.php | 105 ++++++++++ lib/makeadminform.php | 125 ++++++++++++ lib/router.php | 2 +- 12 files changed, 735 insertions(+), 729 deletions(-) create mode 100644 actions/approvegroup.php create mode 100644 lib/approvegroupform.php create mode 100644 lib/groupblockform.php create mode 100644 lib/groupmemberlist.php create mode 100644 lib/groupmemberlistitem.php create mode 100644 lib/makeadminform.php diff --git a/actions/approvegroup.php b/actions/approvegroup.php new file mode 100644 index 0000000000..c52e0e3c46 --- /dev/null +++ b/actions/approvegroup.php @@ -0,0 +1,168 @@ +. + * + * @category Group + * @package StatusNet + * @author Evan Prodromou + * @copyright 2008-2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +/** + * Leave a group + * + * This is the action for leaving a group. It works more or less like the subscribe action + * for users. + * + * @category Group + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ +class ApprovegroupAction extends Action +{ + var $group = null; + + /** + * Prepare to run + */ + function prepare($args) + { + parent::prepare($args); + + if (!common_logged_in()) { + // TRANS: Client error displayed when trying to leave a group while not logged in. + $this->clientError(_('You must be logged in to leave 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 displayed when trying to leave 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 displayed when trying to leave a group without providing a group name or group ID. + $this->clientError(_('No nickname or ID.'), 404); + return false; + } + + if (!$this->group) { + // TRANS: Client error displayed when trying to leave a non-existing group. + $this->clientError(_('No such group.'), 404); + return false; + } + + $cur = common_current_user(); + if (empty($cur)) { + $this->clientError(_('Must be logged in.'), 403); + return false; + } + if ($this->arg('profile_id')) { + if ($cur->isAdmin($this->group)) { + $this->profile = Profile::staticGet('id', $this->arg('profile_id')); + } else { + $this->clientError(_('Only group admin can approve or cancel join requests.'), 403); + return false; + } + } else { + $this->clientError(_('Must specify a profile.')); + return false; + } + + $this->request = Group_join_queue::pkeyGet(array('profile_id' => $this->profile->id, + 'group_id' => $this->group->id)); + + if (empty($this->request)) { + $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403); + } + return true; + } + + /** + * Handle the request + * + * On POST, add the current user to the group + * + * @param array $args unused + * + * @return void + */ + function handle($args) + { + parent::handle($args); + + try { + $this->profile->completeJoinGroup($this->group); + } catch (Exception $e) { + common_log(LOG_ERROR, "Exception canceling group sub: " . $e->getMessage()); + // TRANS: Server error displayed when cancelling a queued group join request fails. + // TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed. + $this->serverError(sprintf(_('Could not cancel request for user %1$s to join group %2$s.'), + $this->profile->nickname, $this->group->nickname)); + return; + } + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + // TRANS: Title for leave group page after leaving. + $this->element('title', null, sprintf(_m('TITLE','%1$s left group %2$s'), + $this->profile->nickname, + $this->group->nickname)); + $this->elementEnd('head'); + $this->elementStart('body'); + $jf = new JoinForm($this, $this->group); + $jf->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + common_redirect(common_local_url('groupmembers', array('nickname' => + $this->group->nickname)), + 303); + } + } +} diff --git a/actions/cancelgroup.php b/actions/cancelgroup.php index 089b4d751e..68d7f39139 100644 --- a/actions/cancelgroup.php +++ b/actions/cancelgroup.php @@ -97,13 +97,26 @@ class CancelgroupAction extends Action } $cur = common_current_user(); - $this->profile = $cur->getProfile(); + if (empty($cur)) { + $this->clientError(_('Must be logged in.'), 403); + return false; + } + if ($this->arg('profile_id')) { + if ($cur->isAdmin($this->group)) { + $this->profile = Profile::staticGet('id', $this->arg('profile_id')); + } else { + $this->clientError(_('Only group admin can approve or cancel join requests.'), 403); + return false; + } + } else { + $this->profile = $cur->getProfile(); + } $this->request = Group_join_queue::pkeyGet(array('profile_id' => $this->profile->id, 'group_id' => $this->group->id)); if (empty($this->request)) { - $this->clientError(_('You are not in the moderation queue for this group.'), 403); + $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403); } return true; } diff --git a/actions/groupmembers.php b/actions/groupmembers.php index e280fd1fd1..2bb35ceddc 100644 --- a/actions/groupmembers.php +++ b/actions/groupmembers.php @@ -152,376 +152,3 @@ class GroupmembersAction extends GroupDesignAction array('nickname' => $this->group->nickname)); } } - -class GroupMemberList extends ProfileList -{ - var $group = null; - - function __construct($profile, $group, $action) - { - parent::__construct($profile, $action); - - $this->group = $group; - } - - function newListItem($profile) - { - return new GroupMemberListItem($profile, $this->group, $this->action); - } -} - -class GroupMemberListItem extends ProfileListItem -{ - var $group = null; - - function __construct($profile, $group, $action) - { - parent::__construct($profile, $action); - - $this->group = $group; - } - - function showFullName() - { - parent::showFullName(); - if ($this->profile->isAdmin($this->group)) { - $this->out->text(' '); // for separating the classes. - // TRANS: Indicator in group members list that this user is a group administrator. - $this->out->element('span', 'role', _('Admin')); - } - } - - function showActions() - { - $this->startActions(); - if (Event::handle('StartProfileListItemActionElements', array($this))) { - $this->showSubscribeButton(); - $this->showMakeAdminForm(); - $this->showGroupBlockForm(); - Event::handle('EndProfileListItemActionElements', array($this)); - } - $this->endActions(); - } - - function showMakeAdminForm() - { - $user = common_current_user(); - - if (!empty($user) && - $user->id != $this->profile->id && - ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) && - !$this->profile->isAdmin($this->group)) { - $this->out->elementStart('li', 'entity_make_admin'); - $maf = new MakeAdminForm($this->out, $this->profile, $this->group, - $this->returnToArgs()); - $maf->show(); - $this->out->elementEnd('li'); - } - - } - - function showGroupBlockForm() - { - $user = common_current_user(); - - if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) { - $this->out->elementStart('li', 'entity_block'); - $bf = new GroupBlockForm($this->out, $this->profile, $this->group, - $this->returnToArgs()); - $bf->show(); - $this->out->elementEnd('li'); - } - } - - function linkAttributes() - { - $aAttrs = parent::linkAttributes(); - - if (common_config('nofollow', 'members')) { - $aAttrs['rel'] .= ' nofollow'; - } - - return $aAttrs; - } - - function homepageAttributes() - { - $aAttrs = parent::linkAttributes(); - - if (common_config('nofollow', 'members')) { - $aAttrs['rel'] = 'nofollow'; - } - - return $aAttrs; - } - - /** - * Fetch necessary return-to arguments for the profile forms - * to return to this list when they're done. - * - * @return array - */ - protected function returnToArgs() - { - $args = array('action' => 'groupmembers', - 'nickname' => $this->group->nickname); - $page = $this->out->arg('page'); - if ($page) { - $args['param-page'] = $page; - } - return $args; - } -} - -/** - * Form for blocking a user from a group - * - * @category Form - * @package StatusNet - * @author Evan Prodromou - * @author Sarven Capadisli - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - * - * @see BlockForm - */ -class GroupBlockForm extends Form -{ - /** - * Profile of user to block - */ - - var $profile = null; - - /** - * Group to block the user from - */ - - var $group = null; - - /** - * Return-to args - */ - - var $args = null; - - /** - * Constructor - * - * @param HTMLOutputter $out output channel - * @param Profile $profile profile of user to block - * @param User_group $group group to block user from - * @param array $args return-to args - */ - function __construct($out=null, $profile=null, $group=null, $args=null) - { - parent::__construct($out); - - $this->profile = $profile; - $this->group = $group; - $this->args = $args; - } - - /** - * ID of the form - * - * @return int ID of the form - */ - function id() - { - // This should be unique for the page. - return 'block-' . $this->profile->id; - } - - /** - * class of the form - * - * @return string class of the form - */ - function formClass() - { - return 'form_group_block'; - } - - /** - * Action of the form - * - * @return string URL of the action - */ - function action() - { - return common_local_url('groupblock'); - } - - /** - * Legend of the Form - * - * @return void - */ - function formLegend() - { - // TRANS: Form legend for form to block user from a group. - $this->out->element('legend', null, _('Block user from group')); - } - - /** - * Data elements of the form - * - * @return void - */ - function formData() - { - $this->out->hidden('blockto-' . $this->profile->id, - $this->profile->id, - 'blockto'); - $this->out->hidden('blockgroup-' . $this->group->id, - $this->group->id, - 'blockgroup'); - if ($this->args) { - foreach ($this->args as $k => $v) { - $this->out->hidden('returnto-' . $k, $v); - } - } - } - - /** - * Action elements - * - * @return void - */ - function formActions() - { - $this->out->submit( - 'submit', - // TRANS: Button text for the form that will block a user from a group. - _m('BUTTON','Block'), - 'submit', - null, - // TRANS: Submit button title. - _m('TOOLTIP', 'Block this user')); - } -} - -/** - * Form for making a user an admin for a group - * - * @category Form - * @package StatusNet - * @author Evan Prodromou - * @author Sarven Capadisli - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - */ -class MakeAdminForm extends Form -{ - /** - * Profile of user to block - */ - var $profile = null; - - /** - * Group to block the user from - */ - var $group = null; - - /** - * Return-to args - */ - var $args = null; - - /** - * Constructor - * - * @param HTMLOutputter $out output channel - * @param Profile $profile profile of user to block - * @param User_group $group group to block user from - * @param array $args return-to args - */ - function __construct($out=null, $profile=null, $group=null, $args=null) - { - parent::__construct($out); - - $this->profile = $profile; - $this->group = $group; - $this->args = $args; - } - - /** - * ID of the form - * - * @return int ID of the form - */ - function id() - { - // This should be unique for the page. - return 'makeadmin-' . $this->profile->id; - } - - /** - * class of the form - * - * @return string class of the form - */ - function formClass() - { - return 'form_make_admin'; - } - - /** - * Action of the form - * - * @return string URL of the action - */ - function action() - { - return common_local_url('makeadmin', array('nickname' => $this->group->nickname)); - } - - /** - * Legend of the Form - * - * @return void - */ - function formLegend() - { - // TRANS: Form legend for form to make a user a group admin. - $this->out->element('legend', null, _('Make user an admin of the group')); - } - - /** - * Data elements of the form - * - * @return void - */ - function formData() - { - $this->out->hidden('profileid-' . $this->profile->id, - $this->profile->id, - 'profileid'); - $this->out->hidden('groupid-' . $this->group->id, - $this->group->id, - 'groupid'); - if ($this->args) { - foreach ($this->args as $k => $v) { - $this->out->hidden('returnto-' . $k, $v); - } - } - } - - /** - * Action elements - * - * @return void - */ - function formActions() - { - $this->out->submit( - 'submit', - // TRANS: Button text for the form that will make a user administrator. - _m('BUTTON','Make Admin'), - 'submit', - null, - // TRANS: Submit button title. - _m('TOOLTIP','Make this user an admin')); - } -} diff --git a/actions/groupqueue.php b/actions/groupqueue.php index aa745f7384..687fa0b973 100644 --- a/actions/groupqueue.php +++ b/actions/groupqueue.php @@ -94,6 +94,11 @@ class GroupqueueAction extends GroupDesignAction return false; } + $cur = common_current_user(); + if (!$cur || !$cur->isAdmin($this->group)) { + $this->clientError(_('Only the group admin may approve users.')); + return false; + } return true; } @@ -143,7 +148,7 @@ class GroupqueueAction extends GroupDesignAction if ($members) { // @fixme change! - $member_list = new GroupMemberList($members, $this->group, $this); + $member_list = new GroupQueueList($members, $this->group, $this); $cnt = $member_list->show(); } @@ -155,375 +160,40 @@ class GroupqueueAction extends GroupDesignAction } } -class GroupMemberList extends ProfileList +class GroupQueueList extends GroupMemberList { - var $group = null; - - function __construct($profile, $group, $action) - { - parent::__construct($profile, $action); - - $this->group = $group; - } - function newListItem($profile) { - return new GroupMemberListItem($profile, $this->group, $this->action); + return new GroupQueueListItem($profile, $this->group, $this->action); } } -class GroupMemberListItem extends ProfileListItem +class GroupQueueListItem extends GroupMemberListItem { - var $group = null; - - function __construct($profile, $group, $action) - { - parent::__construct($profile, $action); - - $this->group = $group; - } - - function showFullName() - { - parent::showFullName(); - if ($this->profile->isAdmin($this->group)) { - $this->out->text(' '); // for separating the classes. - // TRANS: Indicator in group members list that this user is a group administrator. - $this->out->element('span', 'role', _('Admin')); - } - } - function showActions() { $this->startActions(); if (Event::handle('StartProfileListItemActionElements', array($this))) { - $this->showSubscribeButton(); - $this->showMakeAdminForm(); - $this->showGroupBlockForm(); + $this->showApproveButton(); + $this->showCancelButton(); Event::handle('EndProfileListItemActionElements', array($this)); } $this->endActions(); } - function showMakeAdminForm() - { - $user = common_current_user(); - - if (!empty($user) && - $user->id != $this->profile->id && - ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) && - !$this->profile->isAdmin($this->group)) { - $this->out->elementStart('li', 'entity_make_admin'); - $maf = new MakeAdminForm($this->out, $this->profile, $this->group, - $this->returnToArgs()); - $maf->show(); - $this->out->elementEnd('li'); - } - - } - - function showGroupBlockForm() + function showApproveButton() { - $user = common_current_user(); - - if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) { - $this->out->elementStart('li', 'entity_block'); - $bf = new GroupBlockForm($this->out, $this->profile, $this->group, - $this->returnToArgs()); - $bf->show(); - $this->out->elementEnd('li'); - } - } - - function linkAttributes() - { - $aAttrs = parent::linkAttributes(); - - if (common_config('nofollow', 'members')) { - $aAttrs['rel'] .= ' nofollow'; - } - - return $aAttrs; - } - - function homepageAttributes() - { - $aAttrs = parent::linkAttributes(); - - if (common_config('nofollow', 'members')) { - $aAttrs['rel'] = 'nofollow'; - } - - return $aAttrs; - } - - /** - * Fetch necessary return-to arguments for the profile forms - * to return to this list when they're done. - * - * @return array - */ - protected function returnToArgs() - { - $args = array('action' => 'groupmembers', - 'nickname' => $this->group->nickname); - $page = $this->out->arg('page'); - if ($page) { - $args['param-page'] = $page; - } - return $args; - } -} - -/** - * Form for blocking a user from a group - * - * @category Form - * @package StatusNet - * @author Evan Prodromou - * @author Sarven Capadisli - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - * - * @see BlockForm - */ -class GroupBlockForm extends Form -{ - /** - * Profile of user to block - */ - - var $profile = null; - - /** - * Group to block the user from - */ - - var $group = null; - - /** - * Return-to args - */ - - var $args = null; - - /** - * Constructor - * - * @param HTMLOutputter $out output channel - * @param Profile $profile profile of user to block - * @param User_group $group group to block user from - * @param array $args return-to args - */ - function __construct($out=null, $profile=null, $group=null, $args=null) - { - parent::__construct($out); - - $this->profile = $profile; - $this->group = $group; - $this->args = $args; - } - - /** - * ID of the form - * - * @return int ID of the form - */ - function id() - { - // This should be unique for the page. - return 'block-' . $this->profile->id; - } - - /** - * class of the form - * - * @return string class of the form - */ - function formClass() - { - return 'form_group_block'; - } - - /** - * Action of the form - * - * @return string URL of the action - */ - function action() - { - return common_local_url('groupblock'); - } - - /** - * Legend of the Form - * - * @return void - */ - function formLegend() - { - // TRANS: Form legend for form to block user from a group. - $this->out->element('legend', null, _('Block user from group')); - } - - /** - * Data elements of the form - * - * @return void - */ - function formData() - { - $this->out->hidden('blockto-' . $this->profile->id, - $this->profile->id, - 'blockto'); - $this->out->hidden('blockgroup-' . $this->group->id, - $this->group->id, - 'blockgroup'); - if ($this->args) { - foreach ($this->args as $k => $v) { - $this->out->hidden('returnto-' . $k, $v); - } - } - } - - /** - * Action elements - * - * @return void - */ - function formActions() - { - $this->out->submit( - 'submit', - // TRANS: Button text for the form that will block a user from a group. - _m('BUTTON','Block'), - 'submit', - null, - // TRANS: Submit button title. - _m('TOOLTIP', 'Block this user')); - } -} - -/** - * Form for making a user an admin for a group - * - * @category Form - * @package StatusNet - * @author Evan Prodromou - * @author Sarven Capadisli - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - */ -class MakeAdminForm extends Form -{ - /** - * Profile of user to block - */ - var $profile = null; - - /** - * Group to block the user from - */ - var $group = null; - - /** - * Return-to args - */ - var $args = null; - - /** - * Constructor - * - * @param HTMLOutputter $out output channel - * @param Profile $profile profile of user to block - * @param User_group $group group to block user from - * @param array $args return-to args - */ - function __construct($out=null, $profile=null, $group=null, $args=null) - { - parent::__construct($out); - - $this->profile = $profile; - $this->group = $group; - $this->args = $args; - } - - /** - * ID of the form - * - * @return int ID of the form - */ - function id() - { - // This should be unique for the page. - return 'makeadmin-' . $this->profile->id; - } - - /** - * class of the form - * - * @return string class of the form - */ - function formClass() - { - return 'form_make_admin'; - } - - /** - * Action of the form - * - * @return string URL of the action - */ - function action() - { - return common_local_url('makeadmin', array('nickname' => $this->group->nickname)); - } - - /** - * Legend of the Form - * - * @return void - */ - function formLegend() - { - // TRANS: Form legend for form to make a user a group admin. - $this->out->element('legend', null, _('Make user an admin of the group')); - } - - /** - * Data elements of the form - * - * @return void - */ - function formData() - { - $this->out->hidden('profileid-' . $this->profile->id, - $this->profile->id, - 'profileid'); - $this->out->hidden('groupid-' . $this->group->id, - $this->group->id, - 'groupid'); - if ($this->args) { - foreach ($this->args as $k => $v) { - $this->out->hidden('returnto-' . $k, $v); - } - } + $this->out->elementStart('li', 'entity_join'); + $form = new ApproveGroupForm($this->out, $this->group, $this->profile); + $form->show(); + $this->out->elementEnd('li'); } - /** - * Action elements - * - * @return void - */ - function formActions() + function showCancelButton() { - $this->out->submit( - 'submit', - // TRANS: Button text for the form that will make a user administrator. - _m('BUTTON','Make Admin'), - 'submit', - null, - // TRANS: Submit button title. - _m('TOOLTIP','Make this user an admin')); + $this->out->elementStart('li', 'entity_leave'); + $bf = new CancelGroupForm($this->out, $this->group, $this->profile); + $bf->show(); + $this->out->elementEnd('li'); } } diff --git a/classes/Profile.php b/classes/Profile.php index 57522d28dc..126bc25a66 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -384,6 +384,28 @@ class Profile extends Memcached_DataObject } } + /** + * Complete a pending group join on our end... + * + * @param User_group $group + */ + function completeJoinGroup(User_group $group) + { + $ok = null; + $request = Group_join_queue::pkeyGet(array('profile_id' => $this->id, + 'group_id' => $group->id)); + if ($request) { + if (Event::handle('StartJoinGroup', array($group, $this))) { + $ok = Group_member::join($group->id, $this->id); + $request->delete(); + Event::handle('EndJoinGroup', array($group, $this)); + } + } else { + throw new Exception(_m('Invalid group join approval: not pending.')); + } + return $ok; + } + /** * Leave a group that this profile is a member of. * diff --git a/lib/approvegroupform.php b/lib/approvegroupform.php new file mode 100644 index 0000000000..265dc9ba71 --- /dev/null +++ b/lib/approvegroupform.php @@ -0,0 +1,122 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for leaving a group + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @see UnsubscribeForm + */ + +class ApproveGroupForm extends Form +{ + /** + * group for user to leave + */ + + var $group = null; + var $profile = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param group $group group to leave + */ + + function __construct($out=null, $group=null, $profile=null) + { + parent::__construct($out); + + $this->group = $group; + $this->profile = $profile; + } + + /** + * ID of the form + * + * @return string ID of the form + */ + + function id() + { + return 'group-cancel-' . $this->group->id; + } + + /** + * class of the form + * + * @return string of the form class + */ + + function formClass() + { + return 'form_group_join ajax'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + $params = array(); + if ($this->profile) { + $params['profile_id'] = $this->profile->id; + } + return common_local_url('approvegroup', + array('id' => $this->group->id), $params); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Approve')); + } +} diff --git a/lib/cancelgroupform.php b/lib/cancelgroupform.php index e71144f0ed..f945a847f7 100644 --- a/lib/cancelgroupform.php +++ b/lib/cancelgroupform.php @@ -54,6 +54,7 @@ class CancelGroupForm extends Form */ var $group = null; + var $profile = null; /** * Constructor @@ -62,11 +63,12 @@ class CancelGroupForm extends Form * @param group $group group to leave */ - function __construct($out=null, $group=null) + function __construct($out=null, $group=null, $profile=null) { parent::__construct($out); $this->group = $group; + $this->profile = $profile; } /** @@ -99,8 +101,12 @@ class CancelGroupForm extends Form function action() { + $params = array(); + if ($this->profile) { + $params['profile_id'] = $this->profile->id; + } return common_local_url('cancelgroup', - array('id' => $this->group->id)); + array('id' => $this->group->id), $params); } /** diff --git a/lib/groupblockform.php b/lib/groupblockform.php new file mode 100644 index 0000000000..279ddf66fb --- /dev/null +++ b/lib/groupblockform.php @@ -0,0 +1,130 @@ + + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + * + * @see BlockForm + */ +class GroupBlockForm extends Form +{ + /** + * Profile of user to block + */ + + var $profile = null; + + /** + * Group to block the user from + */ + + var $group = null; + + /** + * Return-to args + */ + + var $args = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Profile $profile profile of user to block + * @param User_group $group group to block user from + * @param array $args return-to args + */ + function __construct($out=null, $profile=null, $group=null, $args=null) + { + parent::__construct($out); + + $this->profile = $profile; + $this->group = $group; + $this->args = $args; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + function id() + { + // This should be unique for the page. + return 'block-' . $this->profile->id; + } + + /** + * class of the form + * + * @return string class of the form + */ + function formClass() + { + return 'form_group_block'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + function action() + { + return common_local_url('groupblock'); + } + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + // TRANS: Form legend for form to block user from a group. + $this->out->element('legend', null, _('Block user from group')); + } + + /** + * Data elements of the form + * + * @return void + */ + function formData() + { + $this->out->hidden('blockto-' . $this->profile->id, + $this->profile->id, + 'blockto'); + $this->out->hidden('blockgroup-' . $this->group->id, + $this->group->id, + 'blockgroup'); + if ($this->args) { + foreach ($this->args as $k => $v) { + $this->out->hidden('returnto-' . $k, $v); + } + } + } + + /** + * Action elements + * + * @return void + */ + function formActions() + { + $this->out->submit( + 'submit', + // TRANS: Button text for the form that will block a user from a group. + _m('BUTTON','Block'), + 'submit', + null, + // TRANS: Submit button title. + _m('TOOLTIP', 'Block this user')); + } +} diff --git a/lib/groupmemberlist.php b/lib/groupmemberlist.php new file mode 100644 index 0000000000..92dc4029c6 --- /dev/null +++ b/lib/groupmemberlist.php @@ -0,0 +1,18 @@ +group = $group; + } + + function newListItem($profile) + { + return new GroupMemberListItem($profile, $this->group, $this->action); + } +} diff --git a/lib/groupmemberlistitem.php b/lib/groupmemberlistitem.php new file mode 100644 index 0000000000..82fdc4ef2f --- /dev/null +++ b/lib/groupmemberlistitem.php @@ -0,0 +1,105 @@ +group = $group; + } + + function showFullName() + { + parent::showFullName(); + if ($this->profile->isAdmin($this->group)) { + $this->out->text(' '); // for separating the classes. + // TRANS: Indicator in group members list that this user is a group administrator. + $this->out->element('span', 'role', _('Admin')); + } + } + + function showActions() + { + $this->startActions(); + if (Event::handle('StartProfileListItemActionElements', array($this))) { + $this->showSubscribeButton(); + $this->showMakeAdminForm(); + $this->showGroupBlockForm(); + Event::handle('EndProfileListItemActionElements', array($this)); + } + $this->endActions(); + } + + function showMakeAdminForm() + { + $user = common_current_user(); + + if (!empty($user) && + $user->id != $this->profile->id && + ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) && + !$this->profile->isAdmin($this->group)) { + $this->out->elementStart('li', 'entity_make_admin'); + $maf = new MakeAdminForm($this->out, $this->profile, $this->group, + $this->returnToArgs()); + $maf->show(); + $this->out->elementEnd('li'); + } + + } + + function showGroupBlockForm() + { + $user = common_current_user(); + + if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) { + $this->out->elementStart('li', 'entity_block'); + $bf = new GroupBlockForm($this->out, $this->profile, $this->group, + $this->returnToArgs()); + $bf->show(); + $this->out->elementEnd('li'); + } + } + + function linkAttributes() + { + $aAttrs = parent::linkAttributes(); + + if (common_config('nofollow', 'members')) { + $aAttrs['rel'] .= ' nofollow'; + } + + return $aAttrs; + } + + function homepageAttributes() + { + $aAttrs = parent::linkAttributes(); + + if (common_config('nofollow', 'members')) { + $aAttrs['rel'] = 'nofollow'; + } + + return $aAttrs; + } + + /** + * Fetch necessary return-to arguments for the profile forms + * to return to this list when they're done. + * + * @return array + */ + protected function returnToArgs() + { + $args = array('action' => 'groupmembers', + 'nickname' => $this->group->nickname); + $page = $this->out->arg('page'); + if ($page) { + $args['param-page'] = $page; + } + return $args; + } +} + diff --git a/lib/makeadminform.php b/lib/makeadminform.php new file mode 100644 index 0000000000..de245f3d66 --- /dev/null +++ b/lib/makeadminform.php @@ -0,0 +1,125 @@ + + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ +class MakeAdminForm extends Form +{ + /** + * Profile of user to block + */ + var $profile = null; + + /** + * Group to block the user from + */ + var $group = null; + + /** + * Return-to args + */ + var $args = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Profile $profile profile of user to block + * @param User_group $group group to block user from + * @param array $args return-to args + */ + function __construct($out=null, $profile=null, $group=null, $args=null) + { + parent::__construct($out); + + $this->profile = $profile; + $this->group = $group; + $this->args = $args; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + function id() + { + // This should be unique for the page. + return 'makeadmin-' . $this->profile->id; + } + + /** + * class of the form + * + * @return string class of the form + */ + function formClass() + { + return 'form_make_admin'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + function action() + { + return common_local_url('makeadmin', array('nickname' => $this->group->nickname)); + } + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + // TRANS: Form legend for form to make a user a group admin. + $this->out->element('legend', null, _('Make user an admin of the group')); + } + + /** + * Data elements of the form + * + * @return void + */ + function formData() + { + $this->out->hidden('profileid-' . $this->profile->id, + $this->profile->id, + 'profileid'); + $this->out->hidden('groupid-' . $this->group->id, + $this->group->id, + 'groupid'); + if ($this->args) { + foreach ($this->args as $k => $v) { + $this->out->hidden('returnto-' . $k, $v); + } + } + } + + /** + * Action elements + * + * @return void + */ + function formActions() + { + $this->out->submit( + 'submit', + // TRANS: Button text for the form that will make a user administrator. + _m('BUTTON','Make Admin'), + 'submit', + null, + // TRANS: Submit button title. + _m('TOOLTIP','Make this user an admin')); + } +} diff --git a/lib/router.php b/lib/router.php index fcc915b107..fa9fe9aee1 100644 --- a/lib/router.php +++ b/lib/router.php @@ -366,7 +366,7 @@ class Router $m->connect('group/new', array('action' => 'newgroup')); - foreach (array('edit', 'join', 'leave', 'delete', 'cancel') as $v) { + foreach (array('edit', 'join', 'leave', 'delete', 'cancel', 'approve') as $v) { $m->connect('group/:nickname/'.$v, array('action' => $v.'group'), array('nickname' => Nickname::DISPLAY_FMT)); -- 2.39.5