#37 Fixing notice delete form

Merged
diogo merged 1 commits from tenma/master into diogo/master 5 years ago
3 changed files with 23 additions and 9 deletions
  1. 4 3
      actions/deletenotice.php
  2. 1 0
      lib/noticelistitem.php
  3. 18 6
      plugins/ActivityVerb/ActivityVerbPlugin.php

+ 4 - 3
actions/deletenotice.php

@@ -39,9 +39,10 @@ class DeletenoticeAction extends FormAction
     {
         $this->notice = Notice::getByID($this->trimmed('notice'));
 
-        if (!$this->scoped->sameAs($this->notice->getProfile()) &&
-                   !$this->scoped->hasRight(Right::DELETEOTHERSNOTICE)) {
-            // TRANS: Error message displayed trying to delete a notice that was not made by the current user.
+        if ($this->notice->isVerb([ActivityVerb::DELETE]) ||
+            (!$this->scoped->sameAs($this->notice->getProfile()) &&
+              !$this->scoped->hasRight(Right::DELETEOTHERSNOTICE))) {
+            // TRANS: Error message displayed when trying to delete a notice that was not made by the current user.
             $this->clientError(_('Cannot delete this notice.'));
         }
 

+ 1 - 0
lib/noticelistitem.php

@@ -618,6 +618,7 @@ class NoticeListItem extends Widget
         $todel = (empty($this->repeat)) ? $this->notice : $this->repeat;
 
         if (!empty($user) &&
+            !$this->notice->isVerb([ActivityVerb::DELETE]) &&
             ($todel->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) {
             $this->out->text(' ');
             $deleteurl = common_local_url('deletenotice',

+ 18 - 6
plugins/ActivityVerb/ActivityVerbPlugin.php

@@ -35,14 +35,26 @@ class ActivityVerbPlugin extends Plugin
 
     public function onRouterInitialized(URLMapper $m)
     {
+        $unsupported = ['delete', 'share'];
+
+        foreach ($unsupported as $idx => $verb) {
+            $unsupported[$idx] = "(?!".$verb.")";
+        }
+
+        // not all verbs are currently handled by ActivityVerb Plugins,
+        // so we need a strong regexp to prevent route replacement in
+        // the URLMapper
+        $verb_regexp = implode("", $unsupported) . '[a-z]+';
+
         $m->connect('notice/:id/:verb',
-                    array('action' => 'activityverb'),
-                    array('id'     => '[0-9]+',
-                          'verb'   => '[a-z]+'));
+                    ['action' => 'activityverb'],
+                    ['id'     => '[0-9]+',
+                     'verb'   => $verb_regexp]);
+
         $m->connect('activity/:id/:verb',
-                    array('action' => 'activityverb'),
-                    array('id'     => '[0-9]+',
-                          'verb'   => '[a-z]+'));
+                    ['action' => 'activityverb'],
+                    ['id'     => '[0-9]+',
+                     'verb'   => $verb_regexp]);
     }
 
     public function onPluginVersion(array &$versions)