]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Prevent group creation by silenced users.
authorBrion Vibber <brion@pobox.com>
Tue, 28 Dec 2010 19:34:02 +0000 (11:34 -0800)
committerBrion Vibber <brion@pobox.com>
Tue, 28 Dec 2010 19:34:02 +0000 (11:34 -0800)
* adds Right::CREATEGROUP
* logic in Profile::hasRight() checks for silencing
* NewgroupAction checks for the permission before letting you see or process the form in the UI
* User_group::register() logic does a low-level check on the specified initial group admin, and rejects creation if that user doesn't have the right; guaranteeing that API methods etc will also have this restriction applied sensibly.

actions/newgroup.php
classes/Profile.php
classes/User_group.php
lib/right.php

index 05520223c0f7c6fb5b64e77545547503f8ffeaae..04441e71c64952c3d42f5096e51984568c0b7a8f 100644 (file)
@@ -66,6 +66,13 @@ class NewgroupAction extends Action
             return false;
         }
 
+        $user = common_current_user();
+        $profile = $user->getProfile();
+        if (!$profile->hasRight(Right::CREATEGROUP)) {
+            // TRANS: Client exception thrown when a user tries to create a group while banned.
+            throw new ClientException(_('You are not allowed to create groups on this site.'), 403);
+        }
+
         return true;
     }
 
index 2e88f17ad3d787b665750359a7d5726464a5e4b2..00e076a624744a677650177134401bd3aca322a3 100644 (file)
@@ -909,6 +909,7 @@ class Profile extends Memcached_DataObject
             case Right::NEWNOTICE:
             case Right::NEWMESSAGE:
             case Right::SUBSCRIBE:
+            case Right::CREATEGROUP:
                 $result = !$this->isSilenced();
                 break;
             case Right::PUBLICNOTICE:
index 7d6e219148374f49545d1937ba469b961c7ce97b..f223164d04f25004df852a114611803ff65b2482 100644 (file)
@@ -465,6 +465,16 @@ class User_group extends Memcached_DataObject
     }
 
     static function register($fields) {
+        if (!empty($fields['userid'])) {
+            $profile = Profile::staticGet('id', $fields['userid']);
+            if ($profile && !$profile->hasRight(Right::CREATEGROUP)) {
+                common_log(LOG_WARNING, "Attempted group creation from banned user: " . $profile->nickname);
+
+                // TRANS: Client exception thrown when a user tries to create a group while banned.
+                throw new ClientException(_('You are not allowed to create groups on this site.'), 403);
+            }
+        }
+
         // MAGICALLY put fields into current scope
 
         extract($fields);
index bacbea5f2966dc6afd20d1708f92f57b58225e8a..ccabd00c92061925a36d427a80b9988eeb19aef3 100644 (file)
@@ -61,5 +61,6 @@ class Right
     const GRANTROLE          = 'grantrole';
     const REVOKEROLE         = 'revokerole';
     const DELETEGROUP        = 'deletegroup';
+    const CREATEGROUP        = 'creategroup';
 }