From 7076cda746049c468e3ad656c58653e9fcb7d822 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Jan 2009 09:06:40 -0500 Subject: add edit group action --- actions/editgroup.php | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 actions/editgroup.php (limited to 'actions/editgroup.php') diff --git a/actions/editgroup.php b/actions/editgroup.php new file mode 100644 index 000000000..5f853a089 --- /dev/null +++ b/actions/editgroup.php @@ -0,0 +1,212 @@ +. + * + * @category Group + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Add a new group + * + * This is the form for adding a new group + * + * @category Group + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class EditgroupAction extends Action +{ + var $msg; + var $group = null; + + function title() + { + return sprintf(_('Edit %s group'), $this->group->nickname); + } + + /** + * Prepare to run + */ + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + if (!common_logged_in()) { + $this->clientError(_('You must be logged in to create a group.')); + return false; + } + + return true; + + $nickname_arg = $this->arg('nickname'); + $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('editgroup', $args), 301); + return false; + } + + if (!$nickname) { + $this->clientError(_('No nickname'), 404); + return false; + } + + $this->group = User_group::staticGet('nickname', $nickname); + + if (!$this->group) { + $this->clientError(_('No such group'), 404); + return false; + } + } + + /** + * Handle the request + * + * On GET, show the form. On POST, try to save the group. + * + * @param array $args unused + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->trySave(); + } else { + $this->showForm(); + } + } + + function showForm($msg=null) + { + $this->msg = $msg; + $this->showPage(); + } + + function showContent() + { + $form = new GroupEditForm($this, $this->group); + $form->show(); + } + + function showPageNotice() + { + if ($this->msg) { + $this->element('p', 'error', $this->msg); + } else { + $this->element('p', 'instructions', + _('Use this form to edit the group.')); + } + } + + function trySave() + { + $nickname = common_canonical_nickname($this->trimmed('nickname')); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $description = $this->trimmed('description'); + $location = $this->trimmed('location'); + + if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { + $this->showForm(_('Nickname must have only lowercase letters '. + 'and numbers and no spaces.')); + return; + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + return; + } else if (!User_group::allowedNickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($description) && strlen($description) > 140) { + $this->showForm(_('description is too long (max 140 chars).')); + return; + } else if (!is_null($location) && strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } + + $orig = clone($this->group); + + $this->group->nickname = $nickname; + $this->group->fullname = $fullname; + $this->group->homepage = $homepage; + $this->group->description = $description; + $this->group->location = $location; + $this->group->created = common_sql_now(); + + $result = $this->group->update($orig); + + if (!$result) { + common_log_db_error($this->group, 'UPDATE', __FILE__); + $this->serverError(_('Could not update group.')); + } + + if ($this->group->nickname != $orig->nickname) { + common_redirect(common_local_url('editgroup', + array('nickname' => $nickname)), + 307); + } else { + $this->showForm(_('Options saved.')); + } + } + + function nicknameExists($nickname) + { + $group = User_group::staticGet('nickname', $nickname); + return (!is_null($group) && + $group != false && + $group->id != $this->group->id); + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 1499a5e048ac64c8a51c67ba6e612d72652c30c8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Jan 2009 09:55:44 -0500 Subject: Add tabset to group and admin tabs --- actions/editgroup.php | 8 ++++++++ actions/showgroup.php | 6 ++++++ lib/groupnav.php | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'actions/editgroup.php') diff --git a/actions/editgroup.php b/actions/editgroup.php index 5f853a089..e0d4c0d03 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -96,6 +96,8 @@ class EditgroupAction extends Action $this->clientError(_('No such group'), 404); return false; } + + return true; } /** @@ -124,6 +126,12 @@ class EditgroupAction extends Action $this->showPage(); } + function showLocalNav() + { + $nav = new GroupNav($this, $this->group); + $nav->show(); + } + function showContent() { $form = new GroupEditForm($this, $this->group); diff --git a/actions/showgroup.php b/actions/showgroup.php index f404c648d..5c72996bf 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -144,6 +144,12 @@ class ShowgroupAction extends Action $this->showPage(); } + function showLocalNav() + { + $nav = new GroupNav($this, $this->group); + $nav->show(); + } + /** * Show the page content * diff --git a/lib/groupnav.php b/lib/groupnav.php index 2762949ad..c499d6bff 100644 --- a/lib/groupnav.php +++ b/lib/groupnav.php @@ -83,7 +83,7 @@ class GroupNav extends Widget $nickname)), _('Group'), sprintf(_('%s group'), $nickname), - $action_name == 'all', + $action_name == 'group', 'nav_group_group'); $this->out->menuItem(common_local_url('groupmembers', array('nickname' => $nickname)), -- cgit v1.2.3-54-g00ecf From dcf973ab46f8e56ffbcf2b8112d9290b71c3c0d5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Jan 2009 10:20:13 -0500 Subject: fix edit group prepare, check for admin --- actions/editgroup.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'actions/editgroup.php') diff --git a/actions/editgroup.php b/actions/editgroup.php index e0d4c0d03..82b78cc5c 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -72,9 +72,7 @@ class EditgroupAction extends Action return false; } - return true; - - $nickname_arg = $this->arg('nickname'); + $nickname_arg = $this->trimmed('nickname'); $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname @@ -97,6 +95,13 @@ class EditgroupAction extends Action return false; } + $cur = common_current_user(); + + if (!$cur->isAdmin($group)) { + $this->clientError(_('You must be an admin to edit the group'), 403); + return false; + } + return true; } -- cgit v1.2.3-54-g00ecf From e272adb321fb72043ac7f9a16848ef9386e56571 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Thu, 22 Jan 2009 08:01:40 +0000 Subject: fixed a few bugs and logic problems in groups --- actions/editgroup.php | 19 ++++++++++++++++--- actions/leavegroup.php | 20 +++++++++++++------- actions/newgroup.php | 3 ++- actions/showgroup.php | 6 ++++-- lib/groupeditform.php | 1 + 5 files changed, 36 insertions(+), 13 deletions(-) (limited to 'actions/editgroup.php') diff --git a/actions/editgroup.php b/actions/editgroup.php index 82b78cc5c..98ebcb87a 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -88,7 +88,12 @@ class EditgroupAction extends Action return false; } - $this->group = User_group::staticGet('nickname', $nickname); + $groupid = $this->trimmed('groupid'); + if ($groupid) { + $this->group = User_group::staticGet('id', $groupid); + } else { + $this->group = User_group::staticGet('nickname', $nickname); + } if (!$this->group) { $this->clientError(_('No such group'), 404); @@ -97,7 +102,7 @@ class EditgroupAction extends Action $cur = common_current_user(); - if (!$cur->isAdmin($group)) { + if (!$cur->isAdmin($this->group)) { $this->clientError(_('You must be an admin to edit the group'), 403); return false; } @@ -155,6 +160,13 @@ class EditgroupAction extends Action function trySave() { + $cur = common_current_user(); + if (!$cur->isAdmin($this->group)) { + $this->clientError(_('You must be an admin to edit the group'), 403); + return; + } + + $nickname = common_canonical_nickname($this->trimmed('nickname')); $fullname = $this->trimmed('fullname'); $homepage = $this->trimmed('homepage'); @@ -222,4 +234,5 @@ class EditgroupAction extends Action $group != false && $group->id != $this->group->id); } -} \ No newline at end of file +} + diff --git a/actions/leavegroup.php b/actions/leavegroup.php index 587208b36..c7152e3c0 100644 --- a/actions/leavegroup.php +++ b/actions/leavegroup.php @@ -57,12 +57,12 @@ class LeavegroupAction extends Action parent::prepare($args); if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); + $this->serverError(_('Inboxes must be enabled for groups to work.')); return false; } if (!common_logged_in()) { - $this->clientError(_('You must be logged in to join a group.')); + $this->clientError(_('You must be logged in to leave a group.')); return false; } @@ -78,24 +78,30 @@ class LeavegroupAction extends Action } if (!$nickname) { - $this->clientError(_('No nickname'), 404); + $this->clientError(_('No nickname.'), 404); return false; } $this->group = User_group::staticGet('nickname', $nickname); if (!$this->group) { - $this->clientError(_('No such group'), 404); + $this->clientError(_('No such group.'), 404); return false; } $cur = common_current_user(); - if (!$cur->isMember($group)) { - $this->clientError(_('You are not a member of that group'), 403); + if (!$cur->isMember($this->group)) { + $this->clientError(_('You are not a member of that group.'), 403); return false; } + if ($cur->isAdmin($this->group)) { + $this->clientError(_('You may not leave a group while you are its administrator.'), 403); + return false; + + } + return true; } @@ -150,4 +156,4 @@ class LeavegroupAction extends Action $this->group->nickname))); } } -} \ No newline at end of file +} diff --git a/actions/newgroup.php b/actions/newgroup.php index 41c095ec0..42fd380df 100644 --- a/actions/newgroup.php +++ b/actions/newgroup.php @@ -201,4 +201,5 @@ class NewgroupAction extends Action $group = User_group::staticGet('nickname', $nickname); return (!is_null($group) && $group != false); } -} \ No newline at end of file +} + diff --git a/actions/showgroup.php b/actions/showgroup.php index 1af080c7e..0a499aff9 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -267,8 +267,10 @@ class ShowgroupAction extends Action $cur = common_current_user(); if ($cur) { if ($cur->isMember($this->group)) { - $lf = new LeaveForm($this, $this->group); - $lf->show(); + if (!$cur->isAdmin($this->group)) { + $lf = new LeaveForm($this, $this->group); + $lf->show(); + } } else { $jf = new JoinForm($this, $this->group); $jf->show(); diff --git a/lib/groupeditform.php b/lib/groupeditform.php index fe53918d1..ca674f3c8 100644 --- a/lib/groupeditform.php +++ b/lib/groupeditform.php @@ -133,6 +133,7 @@ class GroupEditForm extends Form { $this->out->elementStart('ul', 'form_data'); $this->out->elementStart('li'); + $this->out->hidden('groupid', $this->group->id); $this->out->input('nickname', _('Nickname'), ($this->out->arg('nickname')) ? $this->out->arg('nickname') : $this->group->nickname, _('1-64 lowercase letters or numbers, no punctuation or spaces')); -- cgit v1.2.3-54-g00ecf