summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-03-03 15:43:49 -0800
committerBrion Vibber <brion@pobox.com>2010-03-03 15:43:49 -0800
commit4a2511139eaafcbe93a2e720e0c6f170ecb00d77 (patch)
tree1b9abf6fcd9db6a4d785871352dd7eb20ae35b82 /actions
parent06db00d303bda500eec578b490c12d2bf389c853 (diff)
Initial user role controls on profile pages, for owner to add/remove administrator and moderator options.
Buttons need to be themed.
Diffstat (limited to 'actions')
-rw-r--r--actions/grantrole.php99
-rw-r--r--actions/revokerole.php99
2 files changed, 198 insertions, 0 deletions
diff --git a/actions/grantrole.php b/actions/grantrole.php
new file mode 100644
index 000000000..cd6bd4d79
--- /dev/null
+++ b/actions/grantrole.php
@@ -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);
+ }
+}
diff --git a/actions/revokerole.php b/actions/revokerole.php
new file mode 100644
index 000000000..b78c1c25a
--- /dev/null
+++ b/actions/revokerole.php
@@ -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);
+ }
+}