Initial user role controls on profile pages, for owner to add/remove administrator and moderator options.
Buttons need to be themed.
This commit is contained in:
parent
06db00d303
commit
4a2511139e
99
actions/grantrole.php
Normal file
99
actions/grantrole.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Action class to sandbox an abusive user
|
||||
*
|
||||
* 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 Action
|
||||
* @package StatusNet
|
||||
* @author Evan Prodromou <evan@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')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sandbox a user.
|
||||
*
|
||||
* @category Action
|
||||
* @package StatusNet
|
||||
* @author Evan Prodromou <evan@status.net>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
||||
* @link http://status.net/
|
||||
*/
|
||||
|
||||
class GrantRoleAction extends ProfileFormAction
|
||||
{
|
||||
/**
|
||||
* Check parameters
|
||||
*
|
||||
* @param array $args action arguments (URL, GET, POST)
|
||||
*
|
||||
* @return boolean success flag
|
||||
*/
|
||||
|
||||
function prepare($args)
|
||||
{
|
||||
if (!parent::prepare($args)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->role = $this->arg('role');
|
||||
if (!Profile_role::isValid($this->role)) {
|
||||
$this->clientError(_("Invalid role."));
|
||||
return false;
|
||||
}
|
||||
if (!Profile_role::isSettable($this->role)) {
|
||||
$this->clientError(_("This role is reserved and cannot be set."));
|
||||
return false;
|
||||
}
|
||||
|
||||
$cur = common_current_user();
|
||||
|
||||
assert(!empty($cur)); // checked by parent
|
||||
|
||||
if (!$cur->hasRight(Right::GRANTROLE)) {
|
||||
$this->clientError(_("You cannot grant user roles on this site."));
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(!empty($this->profile)); // checked by parent
|
||||
|
||||
if ($this->profile->hasRole($this->role)) {
|
||||
$this->clientError(_("User already has this role."));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sandbox a user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function handlePost()
|
||||
{
|
||||
$this->profile->grantRole($this->role);
|
||||
}
|
||||
}
|
99
actions/revokerole.php
Normal file
99
actions/revokerole.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Action class to sandbox an abusive user
|
||||
*
|
||||
* 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 Action
|
||||
* @package StatusNet
|
||||
* @author Evan Prodromou <evan@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')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sandbox a user.
|
||||
*
|
||||
* @category Action
|
||||
* @package StatusNet
|
||||
* @author Evan Prodromou <evan@status.net>
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
||||
* @link http://status.net/
|
||||
*/
|
||||
|
||||
class RevokeRoleAction extends ProfileFormAction
|
||||
{
|
||||
/**
|
||||
* Check parameters
|
||||
*
|
||||
* @param array $args action arguments (URL, GET, POST)
|
||||
*
|
||||
* @return boolean success flag
|
||||
*/
|
||||
|
||||
function prepare($args)
|
||||
{
|
||||
if (!parent::prepare($args)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->role = $this->arg('role');
|
||||
if (!Profile_role::isValid($this->role)) {
|
||||
$this->clientError(_("Invalid role."));
|
||||
return false;
|
||||
}
|
||||
if (!Profile_role::isSettable($this->role)) {
|
||||
$this->clientError(_("This role is reserved and cannot be set."));
|
||||
return false;
|
||||
}
|
||||
|
||||
$cur = common_current_user();
|
||||
|
||||
assert(!empty($cur)); // checked by parent
|
||||
|
||||
if (!$cur->hasRight(Right::REVOKEROLE)) {
|
||||
$this->clientError(_("You cannot revoke user roles on this site."));
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(!empty($this->profile)); // checked by parent
|
||||
|
||||
if (!$this->profile->hasRole($this->role)) {
|
||||
$this->clientError(_("User doesn't have this role."));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sandbox a user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function handlePost()
|
||||
{
|
||||
$this->profile->revokeRole($this->role);
|
||||
}
|
||||
}
|
|
@ -743,6 +743,10 @@ class Profile extends Memcached_DataObject
|
|||
case Right::CONFIGURESITE:
|
||||
$result = $this->hasRole(Profile_role::ADMINISTRATOR);
|
||||
break;
|
||||
case Right::GRANTROLE:
|
||||
case Right::REVOKEROLE:
|
||||
$result = $this->hasRole(Profile_role::OWNER);
|
||||
break;
|
||||
case Right::NEWNOTICE:
|
||||
case Right::NEWMESSAGE:
|
||||
case Right::SUBSCRIBE:
|
||||
|
|
|
@ -53,4 +53,21 @@ class Profile_role extends Memcached_DataObject
|
|||
const ADMINISTRATOR = 'administrator';
|
||||
const SANDBOXED = 'sandboxed';
|
||||
const SILENCED = 'silenced';
|
||||
|
||||
public static function isValid($role)
|
||||
{
|
||||
// @fixme could probably pull this from class constants
|
||||
$known = array(self::OWNER,
|
||||
self::MODERATOR,
|
||||
self::ADMINISTRATOR,
|
||||
self::SANDBOXED,
|
||||
self::SILENCED);
|
||||
return in_array($role, $known);
|
||||
}
|
||||
|
||||
public static function isSettable($role)
|
||||
{
|
||||
$allowedRoles = array('administrator', 'moderator');
|
||||
return self::isValid($role) && in_array($role, $allowedRoles);
|
||||
}
|
||||
}
|
||||
|
|
93
lib/grantroleform.php
Normal file
93
lib/grantroleform.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Form for granting a role
|
||||
*
|
||||
* 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>, Brion Vibber <brion@status.net>
|
||||
* @copyright 2009-2010 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')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form for sandboxing a user
|
||||
*
|
||||
* @category Form
|
||||
* @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/
|
||||
*
|
||||
* @see UnSandboxForm
|
||||
*/
|
||||
|
||||
class GrantRoleForm extends ProfileActionForm
|
||||
{
|
||||
function __construct($role, $label, $writer, $profile, $r2args)
|
||||
{
|
||||
parent::__construct($writer, $profile, $r2args);
|
||||
$this->role = $role;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action this form provides
|
||||
*
|
||||
* @return string Name of the action, lowercased.
|
||||
*/
|
||||
|
||||
function target()
|
||||
{
|
||||
return 'grantrole';
|
||||
}
|
||||
|
||||
/**
|
||||
* Title of the form
|
||||
*
|
||||
* @return string Title of the form, internationalized
|
||||
*/
|
||||
|
||||
function title()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
function formData()
|
||||
{
|
||||
parent::formData();
|
||||
$this->out->hidden('role', $this->role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the form
|
||||
*
|
||||
* @return string description of the form, internationalized
|
||||
*/
|
||||
|
||||
function description()
|
||||
{
|
||||
return sprintf(_('Grant this user the "%s" role'), $this->label);
|
||||
}
|
||||
}
|
93
lib/revokeroleform.php
Normal file
93
lib/revokeroleform.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Form for revoking a role
|
||||
*
|
||||
* 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>, Brion Vibber <brion@status.net>
|
||||
* @copyright 2009-2010 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')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form for sandboxing a user
|
||||
*
|
||||
* @category Form
|
||||
* @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/
|
||||
*
|
||||
* @see UnSandboxForm
|
||||
*/
|
||||
|
||||
class RevokeRoleForm extends ProfileActionForm
|
||||
{
|
||||
function __construct($role, $label, $writer, $profile, $r2args)
|
||||
{
|
||||
parent::__construct($writer, $profile, $r2args);
|
||||
$this->role = $role;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action this form provides
|
||||
*
|
||||
* @return string Name of the action, lowercased.
|
||||
*/
|
||||
|
||||
function target()
|
||||
{
|
||||
return 'revokerole';
|
||||
}
|
||||
|
||||
/**
|
||||
* Title of the form
|
||||
*
|
||||
* @return string Title of the form, internationalized
|
||||
*/
|
||||
|
||||
function title()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
function formData()
|
||||
{
|
||||
parent::formData();
|
||||
$this->out->hidden('role', $this->role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the form
|
||||
*
|
||||
* @return string description of the form, internationalized
|
||||
*/
|
||||
|
||||
function description()
|
||||
{
|
||||
return sprintf(_('Revoke the "%s" role from this user'), $this->label);
|
||||
}
|
||||
}
|
|
@ -58,5 +58,7 @@ class Right
|
|||
const EMAILONSUBSCRIBE = 'emailonsubscribe';
|
||||
const EMAILONFAVE = 'emailonfave';
|
||||
const MAKEGROUPADMIN = 'makegroupadmin';
|
||||
const GRANTROLE = 'grantrole';
|
||||
const REVOKEROLE = 'revokerole';
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ class Router
|
|||
'groupblock', 'groupunblock',
|
||||
'sandbox', 'unsandbox',
|
||||
'silence', 'unsilence',
|
||||
'grantrole', 'revokerole',
|
||||
'repeat',
|
||||
'deleteuser',
|
||||
'geocode',
|
||||
|
|
|
@ -346,6 +346,16 @@ class UserProfile extends Widget
|
|||
$this->out->elementEnd('ul');
|
||||
$this->out->elementEnd('li');
|
||||
}
|
||||
|
||||
if ($cur->hasRight(Right::GRANTROLE)) {
|
||||
$this->out->elementStart('li', 'entity_role');
|
||||
$this->out->element('p', null, _('User role'));
|
||||
$this->out->elementStart('ul');
|
||||
$this->roleButton('administrator', _m('role', 'Administrator'));
|
||||
$this->roleButton('moderator', _m('role', 'Moderator'));
|
||||
$this->out->elementEnd('ul');
|
||||
$this->out->elementEnd('li');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,6 +369,22 @@ class UserProfile extends Widget
|
|||
}
|
||||
}
|
||||
|
||||
function roleButton($role, $label)
|
||||
{
|
||||
list($action, $r2args) = $this->out->returnToArgs();
|
||||
$r2args['action'] = $action;
|
||||
|
||||
$this->out->elementStart('li', "entity_role_$role");
|
||||
if ($this->user->hasRole($role)) {
|
||||
$rf = new RevokeRoleForm($role, $label, $this->out, $this->profile, $r2args);
|
||||
$rf->show();
|
||||
} else {
|
||||
$rf = new GrantRoleForm($role, $label, $this->out, $this->profile, $r2args);
|
||||
$rf->show();
|
||||
}
|
||||
$this->out->elementEnd('li');
|
||||
}
|
||||
|
||||
function showRemoteSubscribeLink()
|
||||
{
|
||||
$url = common_local_url('remotesubscribe',
|
||||
|
|
Loading…
Reference in New Issue
Block a user