From 04ad0838bee46ad9b2cd8520d13d8287e86aec93 Mon Sep 17 00:00:00 2001
From: Evan Prodromou <evan@status.net>
Date: Sun, 25 Mar 2012 13:16:23 -0400
Subject: [PATCH] Add spam-training, spam-reviewing rights

Replaced the check for a moderator role in certain spam-training and
-reviewing points. Make sure modhelpers can check, too.
---
 classes/Notice.php                    | 2 +-
 classes/Profile.php                   | 2 ++
 lib/profilenoticestream.php           | 2 +-
 lib/right.php                         | 2 ++
 plugins/ModHelper/ModHelperPlugin.php | 4 +++-
 5 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/classes/Notice.php b/classes/Notice.php
index a84dcf6ed3..a813db99b3 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -2472,7 +2472,7 @@ class Notice extends Managed_DataObject
             $author = $this->getProfile();
 
             if ($author->hasRole(Profile_role::SILENCED)) {
-                if (empty($profile) || !$profile->hasRole(Profile_role::MODERATOR)) {
+                if (empty($profile) || !$profile->hasRight(Right::REVIEWSPAM)) {
                     return true;
                 }
             }
diff --git a/classes/Profile.php b/classes/Profile.php
index e07d37139b..cefcaf90b5 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -1190,6 +1190,8 @@ class Profile extends Managed_DataObject
             case Right::SILENCEUSER:
             case Right::DELETEUSER:
             case Right::DELETEGROUP:
+            case Right::TRAINSPAM:
+            case Right::REVIEWSPAM:
                 $result = $this->hasRole(Profile_role::MODERATOR);
                 break;
             case Right::CONFIGURESITE:
diff --git a/lib/profilenoticestream.php b/lib/profilenoticestream.php
index 1fde1c6025..5b02bc7b3f 100644
--- a/lib/profilenoticestream.php
+++ b/lib/profilenoticestream.php
@@ -95,7 +95,7 @@ class ProfileNoticeStream extends ScopingNoticeStream
 
         if (common_config('notice', 'hidespam')) {
             if ($this->streamProfile->hasRole(Profile_role::SILENCED) &&
-                (empty($this->userProfile) || !$this->userProfile->hasRole(Profile_role::MODERATOR))) {
+                (empty($this->userProfile) || !$this->userProfile->hasRight(Right::REVIEWSPAM))) {
                 return true;
             }
         }
diff --git a/lib/right.php b/lib/right.php
index baa18d3c13..f00f590278 100644
--- a/lib/right.php
+++ b/lib/right.php
@@ -68,5 +68,7 @@ class Right
     const CREATEGROUP        = 'creategroup';
     const WEBLOGIN           = 'weblogin';
     const API                = 'api';
+    const REVIEWSPAM         = 'reviewspam';
+    const TRAINSPAM          = 'trainspam';
 }
 
diff --git a/plugins/ModHelper/ModHelperPlugin.php b/plugins/ModHelper/ModHelperPlugin.php
index c2757bbeae..bed0d8d49e 100644
--- a/plugins/ModHelper/ModHelperPlugin.php
+++ b/plugins/ModHelper/ModHelperPlugin.php
@@ -27,6 +27,8 @@ if (!defined('STATUSNET')) {
  */
 class ModHelperPlugin extends Plugin
 {
+    static $rights = array(Right::SILENCEUSER, Right::TRAINSPAM, Right::REVIEWSPAM);
+
     function onPluginVersion(&$versions)
     {
         $versions[] = array('name' => 'ModHelper',
@@ -42,7 +44,7 @@ class ModHelperPlugin extends Plugin
 
     function onUserRightsCheck($profile, $right, &$result)
     {
-        if ($right == Right::SILENCEUSER) {
+        if (in_array($right, self::$rights)) {
             // Hrm.... really we should confirm that the *other* user isn't privleged. :)
             if ($profile->hasRole('modhelper')) {
                 $result = true;
-- 
2.39.5