]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
fixed a few bugs and logic problems in groups
authorRobin Millette <millette@controlyourself.ca>
Thu, 22 Jan 2009 08:01:40 +0000 (08:01 +0000)
committerRobin Millette <millette@plantard.controlezvous.ca>
Thu, 22 Jan 2009 08:01:40 +0000 (08:01 +0000)
actions/editgroup.php
actions/leavegroup.php
actions/newgroup.php
actions/showgroup.php
lib/groupeditform.php

index 82b78cc5c7ac596b75fcb9ef48b1f663fa9b5b48..98ebcb87acf541b90b7c44006a191af3a509afc4 100644 (file)
@@ -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
+}
+
index 587208b36a1768e4268296a8f47db96477c94c58..c7152e3c0e32cc9db0b46855c28b3140570a8218 100644 (file)
@@ -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
+}
index 41c095ec0b27d84a170e3ac54cfcf53c984015e4..42fd380dfe51ce2a2670474f8c5d9953739aa832 100644 (file)
@@ -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
+}
+
index 1af080c7ed001cbf4048f41cefc675fe2d239228..0a499aff9941cff63e0c6a90f5ebd811002485eb 100644 (file)
@@ -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();
index fe53918d19ef239760a145c1cbda31fe12b51c29..ca674f3c8e24a925c93b194c0866ce5748fc0663 100644 (file)
@@ -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'));