From: Mikael Nordfeldth Date: Sun, 28 Aug 2016 07:34:31 +0000 (+0200) Subject: Make Group actions ManagedAction so groupbyid works X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=af6a3aa456c239e5dfc03b5cd34f0192fd4117ac;p=quix0rs-gnu-social.git Make Group actions ManagedAction so groupbyid works --- diff --git a/actions/groupbyid.php b/actions/groupbyid.php index de87ec5c67..ed4ec979a9 100644 --- a/actions/groupbyid.php +++ b/actions/groupbyid.php @@ -42,7 +42,7 @@ if (!defined('GNUSOCIAL')) { exit(1); } * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class GroupbyidAction extends ManagedAction +class GroupbyidAction extends ShowgroupAction { /** group we're viewing. */ protected $group = null; @@ -55,10 +55,10 @@ class GroupbyidAction extends ManagedAction protected function doPreparation() { $this->group = User_group::getByID($this->arg('id')); - } + $this->target = $this->group->getProfile(); - public function showPage() - { - common_redirect($this->group->homeUrl(), 303); + if ($this->target->isLocal()) { + common_redirect($this->target->getUrl()); + } } } diff --git a/actions/groupmembers.php b/actions/groupmembers.php index 44c4dd6f99..1d2171b27f 100644 --- a/actions/groupmembers.php +++ b/actions/groupmembers.php @@ -27,12 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once(INSTALLDIR.'/lib/profilelist.php'); -require_once INSTALLDIR.'/lib/publicgroupnav.php'; +if (!defined('GNUSOCIAL)') { exit(1); } /** * List of group members @@ -52,15 +47,6 @@ class GroupmembersAction extends GroupAction return true; } - protected function prepare(array $args=array()) - { - parent::prepare($args); - - $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - - return true; - } - function title() { if ($this->page == 1) { diff --git a/actions/showgroup.php b/actions/showgroup.php index 8770e6cc8b..8cc65aa906 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -76,79 +76,15 @@ class ShowgroupAction extends GroupAction } } - /** - * Prepare the action - * - * Reads and validates arguments and instantiates the attributes. - * - * @param array $args $_REQUEST args - * - * @return boolean success flag - */ - protected function prepare(array $args=array()) + public function getStream() { - parent::prepare($args); - - $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) { $stream = new GroupNoticeStream($this->group, $this->scoped); } else { $stream = new ThreadingGroupNoticeStream($this->group, $this->scoped); } - $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1); - - common_set_returnto($this->selfUrl()); - - return true; - } - - /** - * Handle the request - * - * Shows a profile for the group, some controls, and a list of - * group notices. - * - * @return void - */ - protected function handle() - { - parent::handle(); - $this->showPage(); - } - - /** - * Show the page content - * - * Shows a group profile and a list of group notices - */ - function showContent() - { - $this->showGroupNotices(); - } - - /** - * Show the group notices - * - * @return void - */ - function showGroupNotices() - { - if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) { - $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE)); - } else { - $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped); - } - - $cnt = $nl->show(); - - $this->pagination($this->page > 1, - $cnt > NOTICES_PER_PAGE, - $this->page, - 'showgroup', - array('nickname' => $this->group->nickname)); + return $stream; } /** diff --git a/lib/groupaction.php b/lib/groupaction.php index 31a0b8bc34..2fcec360bc 100644 --- a/lib/groupaction.php +++ b/lib/groupaction.php @@ -40,25 +40,23 @@ define('MEMBERS_PER_SECTION', 27); * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class GroupAction extends Action +class GroupAction extends ShowstreamAction { protected $group; - protected function prepare(array $args=array()) + protected function doPreparation() { - parent::prepare($args); - $nickname_arg = $this->arg('nickname'); $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname - if ($nickname_arg != $nickname) { + if ($nickname_arg !== $nickname) { $args = array('nickname' => $nickname); if ($this->page != 1) { $args['page'] = $this->page; } - common_redirect(common_local_url('showgroup', $args), 301); + common_redirect(common_local_url($this->getActionName(), $args), 301); } if (!$nickname) { @@ -79,15 +77,16 @@ class GroupAction extends Action } else { common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'"); // TRANS: Client error displayed if no remote group with a given name was found requesting group page. - $this->clientError(_('No such group.'), 404); + throw new ClientException(_('No such group.'), 404); } } $this->group = User_group::getKV('id', $local->group_id); + $this->target = $this->group->getProfile(); if (!$this->group instanceof User_group) { // TRANS: Client error displayed if no local group with a given name was found requesting group page. - $this->clientError(_('No such group.'), 404); + throw new ClientException(_('No such group.'), 404); } } @@ -105,8 +104,7 @@ class GroupAction extends Action function showSections() { $this->showMembers(); - $cur = common_current_user(); - if ($cur && $cur->isAdmin($this->group)) { + if ($this->scoped instanceof Profile && $this->scoped->isAdmin($this->group)) { $this->showPending(); $this->showBlocked(); } diff --git a/lib/profileaction.php b/lib/profileaction.php index 22c960406a..64087cf312 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -55,7 +55,7 @@ abstract class ProfileAction extends ManagedAction $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname - if ($nickname_arg != $nickname) { + if ($nickname_arg !== $nickname) { $args = array('nickname' => $nickname); if ($this->arg('page') && $this->arg('page') != 1) { $args['page'] = $this->arg['page']; @@ -83,7 +83,7 @@ abstract class ProfileAction extends ManagedAction // this will call ->doPreparation() which child classes use to set $this->target parent::prepare($args); - if ($this->target->hasRole(Profile_role::SILENCED) + if ($this->target->isPerson() && $this->target->hasRole(Profile_role::SILENCED) && (!$this->scoped instanceof Profile || !$this->scoped->hasRight(Right::SILENCEUSER))) { throw new ClientException(_('This profile has been silenced by site moderators'), 403); }