]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
authorBrion Vibber <brion@pobox.com>
Tue, 29 Mar 2011 23:26:20 +0000 (16:26 -0700)
committerBrion Vibber <brion@pobox.com>
Tue, 29 Mar 2011 23:26:20 +0000 (16:26 -0700)
Conflicts:
actions/apistatusesretweet.php
actions/repeat.php
classes/Notice.php
lib/command.php

actions/apistatusesretweet.php
actions/repeat.php
classes/Group_join_queue.php
classes/Notice.php
lib/command.php

index 6e6ebb038f8c83d6b8aa755fc4f6b738a4512aed..4832da1823d6243d49a1122a144d4ad9607c5af1 100644 (file)
@@ -78,44 +78,6 @@ class ApiStatusesRetweetAction extends ApiAuthAction
 
         $this->user = $this->auth_user;
 
-        if ($this->user->id == $this->original->profile_id) {
-            // TRANS: Client error displayed trying to repeat an own notice through the API.
-            $this->clientError(_('Cannot repeat your own notice.'),
-                               400, $this->format);
-            return false;
-        }
-
-        // Is it OK to repeat that notice (general enough scope)?
-
-        if ($this->original->scope != Notice::SITE_SCOPE &&
-            $this->original->scope != Notice::PUBLIC_SCOPE) {
-            // TRANS: Client error displayed when trying to repeat a private notice.
-            $this->clientError(_('You may not repeat a private notice.'),
-                               403,
-                               $this->format);
-            return false;
-        }
-
-        $profile = $this->user->getProfile();
-
-        // Can the profile actually see that notice?
-
-        if (!$this->original->inScope($profile)) {
-            // TRANS: Client error displayed when trying to repeat a notice the user has no access to.
-            $this->clientError(_('No access to that notice.'),
-                               403,
-                               $this->format);
-            return false;
-        }
-
-        if ($profile->hasRepeated($id)) {
-            // TRANS: Client error displayed trying to re-repeat a notice through the API.
-            $this->clientError(_('Already repeated that notice.'),
-                               400, $this->format);
-            return false;
-        }
-
-
         return true;
     }
 
index 3c5ced1129013058971bef7f02b27e32824b4a8d..44c57456fa3cb6f5ead2b24d0016ee778aba9e4a 100644 (file)
@@ -73,21 +73,6 @@ class RepeatAction extends Action
             return false;
         }
 
-        // Is it OK to repeat that notice (general enough scope)?
-
-        if ($this->notice->scope != Notice::SITE_SCOPE &&
-            $this->notice->scope != Notice::PUBLIC_SCOPE) {
-            // TRANS: Client error displayed when trying to repeat a private notice.
-            $this->clientError(_('You may not repeat a private notice.'),
-                               403);
-        }
-
-        if ($this->user->id == $this->notice->profile_id) {
-            // TRANS: Client error displayed when trying to repeat an own notice.
-            $this->clientError(_('You cannot repeat your own notice.'));
-            return false;
-        }
-
         $token  = $this->trimmed('token-'.$id);
 
         if (empty($token) || $token != common_session_token()) {
@@ -95,22 +80,6 @@ class RepeatAction extends Action
             return false;
         }
 
-        $profile = $this->user->getProfile();
-
-        // Can the profile actually see that notice?
-
-        if (!$this->notice->inScope($profile)) {
-            // TRANS: Client error displayed when trying to repeat a notice the user has no access to.
-            $this->clientError(_('No access to that notice.'), 403);
-        }
-
-
-        if ($profile->hasRepeated($id)) {
-            // TRANS: Client error displayed when trying to repeat an already repeated notice.
-            $this->clientError(_('You already repeated that notice.'));
-            return false;
-        }
-
         return true;
     }
 
index 38473c9b7cb9cbb77b8d055be0302dd83a9049b6..7df71ed0420cf12f824700928b947c2dd03e0b70 100644 (file)
@@ -104,7 +104,7 @@ class Group_join_queue extends Managed_DataObject
      *
      * @return Group_member object on success
      */
-    function complete(User_group $group)
+    function complete()
     {
         $join = null;
         $profile = $this->getMember();
index 33b54b0cc758c9e7e176f416e72c6c03835070f1..86954e3678538e8e2e9c0fd5c9d5d299c54c1bb7 100644 (file)
@@ -350,14 +350,31 @@ class Notice extends Memcached_DataObject
 
             $repeat = Notice::staticGet('id', $repeat_of);
 
-            if (!empty($repeat) &&
-                $repeat->scope != Notice::SITE_SCOPE &&
+            if (empty($repeat)) {
+                throw new ClientException(_('Cannot repeat; original notice is missing or deleted.'));
+            }
+
+            if ($profile->id == $repeat->profile_id) {
+                // TRANS: Client error displayed when trying to repeat an own notice.
+                throw new ClientException(_('You cannot repeat your own notice.'));
+            }
+
+            if ($repeat->scope != Notice::SITE_SCOPE &&
                 $repeat->scope != Notice::PUBLIC_SCOPE) {
-                // TRANS: Client exception thrown when trying to repeat a private notice.
+                // TRANS: Client error displayed when trying to repeat a non-public notice.
                 throw new ClientException(_('Cannot repeat a private notice.'), 403);
             }
 
-            // XXX: Check for access...?
+            if (!$repeat->inScope($profile)) {
+                // The generic checks above should cover this, but let's be sure!
+                // TRANS: Client error displayed when trying to repeat a notice you cannot access.
+                throw new ClientException(_('Cannot repeat a notice you cannot read.'), 403);
+            }
+
+            if ($profile->hasRepeated($repeat->id)) {
+                // TRANS: Client error displayed when trying to repeat an already repeated notice.
+                throw new ClientException(_('You already repeated that notice.'));
+            }
 
             $notice->repeat_of = $repeat_of;
         } else {
@@ -1570,6 +1587,15 @@ class Notice extends Memcached_DataObject
         return $location;
     }
 
+    /**
+     * Convenience function for posting a repeat of an existing message.
+     *
+     * @param int $repeater_id: profile ID of user doing the repeat
+     * @param string $source: posting source key, eg 'web', 'api', etc
+     * @return Notice
+     *
+     * @throws Exception on failure or permission problems
+     */
     function repeat($repeater_id, $source)
     {
         $author = Profile::staticGet('id', $this->profile_id);
index acb3ac0038d29dc71efd8ee15edfb818f2cea09e..aaad57776176a8e4cf43c072b211be22bd6681f1 100644 (file)
@@ -537,46 +537,15 @@ class RepeatCommand extends Command
     {
         $notice = $this->getNotice($this->other);
 
-        if($this->user->id == $notice->profile_id)
-        {
-            // TRANS: Error text shown when trying to repeat an own notice.
-            $channel->error($this->user, _('Cannot repeat your own notice.'));
-            return;
-        }
-
-        // Is it OK to repeat that notice (general enough scope)?
-
-        if ($notice->scope != Notice::SITE_SCOPE &&
-            $notice->scope != Notice::PUBLIC_SCOPE) {
-            // TRANS: Client error displayed when trying to repeat a private notice.
-            $channel->error($this->user, _('You may not repeat a private notice.'));
-        }
-
-        $profile = $this->user->getProfile();
-
-        // Can the profile actually see that notice?
-
-        if (!$notice->inScope($profile)) {
-            // TRANS: Client error displayed when trying to repeat a notice the user has no access to.
-            $channel->error($this->user, _('You have no access to that notice.'));
-        }
-
-        if ($profile->hasRepeated($notice->id)) {
-            // TRANS: Error text shown when trying to repeat an notice that was already repeated by the user.
-            $channel->error($this->user, _('Already repeated that notice.'));
-            return;
-        }
-
-        $repeat = $notice->repeat($this->user->id, $channel->source);
-
-        if ($repeat) {
+        try {
+            $repeat = $notice->repeat($this->user->id, $channel->source());
+            $recipient = $notice->getProfile();
 
             // TRANS: Message given having repeated a notice from another user.
             // TRANS: %s is the name of the user for which the notice was repeated.
             $channel->output($this->user, sprintf(_('Notice from %s repeated.'), $recipient->nickname));
-        } else {
-            // TRANS: Error text shown when repeating a notice fails with an unknown reason.
-            $channel->error($this->user, _('Error repeating notice.'));
+        } catch (Exception $e) {
+            $channel->error($this->user, $e->getMessage());
         }
     }
 }