]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Split up some list/form classes, and get the 'approve' and 'cancel' links on group...
authorBrion Vibber <brion@pobox.com>
Tue, 22 Mar 2011 00:17:18 +0000 (17:17 -0700)
committerBrion Vibber <brion@pobox.com>
Tue, 22 Mar 2011 00:17:18 +0000 (17:17 -0700)
12 files changed:
actions/approvegroup.php [new file with mode: 0644]
actions/cancelgroup.php
actions/groupmembers.php
actions/groupqueue.php
classes/Profile.php
lib/approvegroupform.php [new file with mode: 0644]
lib/cancelgroupform.php
lib/groupblockform.php [new file with mode: 0644]
lib/groupmemberlist.php [new file with mode: 0644]
lib/groupmemberlistitem.php [new file with mode: 0644]
lib/makeadminform.php [new file with mode: 0644]
lib/router.php

diff --git a/actions/approvegroup.php b/actions/approvegroup.php
new file mode 100644 (file)
index 0000000..c52e0e3
--- /dev/null
@@ -0,0 +1,168 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Leave a group
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Group
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @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 <evan@status.net>
+ * @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);
+        }
+    }
+}
index 089b4d751e7f2ac7ea48d4403b2a0d1cf6f91881..68d7f39139db1e83fcc13a6573008243fc1de32f 100644 (file)
@@ -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;
     }
index e280fd1fd136a9fb02df003fee08305a90a628cb..2bb35ceddc7eada48df9c5573895a0c135f029b2 100644 (file)
@@ -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 <evan@status.net>
- * @author   Sarven Capadisli <csarven@status.net>
- * @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 <evan@status.net>
- * @author   Sarven Capadisli <csarven@status.net>
- * @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'));
-    }
-}
index aa745f73840569c19bf202629a0fbeff30fbda5f..687fa0b9732a20616639478e6372c20f2d78970d 100644 (file)
@@ -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 <evan@status.net>
- * @author   Sarven Capadisli <csarven@status.net>
- * @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 <evan@status.net>
- * @author   Sarven Capadisli <csarven@status.net>
- * @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');
     }
 }
index 57522d28dc98f4cab849385c0fa35173550f4a22..126bc25a662caf2987b5c235538742492a5f7dce 100644 (file)
@@ -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 (file)
index 0000000..265dc9b
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Form for leaving a group
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Form
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @author    Sarven Capadisli <csarven@status.net>
+ * @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 <evan@status.net>
+ * @author   Sarven Capadisli <csarven@status.net>
+ * @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'));
+    }
+}
index e71144f0edfcf9d9e06c5922ce7a758e5232b763..f945a847f79b58ea5dcafe9fe522b14009fbb8bc 100644 (file)
@@ -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 (file)
index 0000000..279ddf6
--- /dev/null
@@ -0,0 +1,130 @@
+<?php
+
+/**
+ * Form for blocking a user from a group
+ *
+ * @category Form
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Sarven Capadisli <csarven@status.net>
+ * @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 (file)
index 0000000..92dc402
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+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);
+    }
+}
diff --git a/lib/groupmemberlistitem.php b/lib/groupmemberlistitem.php
new file mode 100644 (file)
index 0000000..82fdc4e
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+
+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;
+    }
+}
+
diff --git a/lib/makeadminform.php b/lib/makeadminform.php
new file mode 100644 (file)
index 0000000..de245f3
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+
+/**
+ * Form for making a user an admin for a group
+ *
+ * @category Form
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Sarven Capadisli <csarven@status.net>
+ * @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'));
+    }
+}
index fcc915b107cce4302c6c1b57e1b4c3935cd37826..fa9fe9aee16e3b0a978d6133251a807f6faa0398 100644 (file)
@@ -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));