FIX: Only show "Approve" button for the admin user if reviewable

FIX: Only show “Approve” button for the admin user if reviewable

diff --git a/app/serializers/admin_user_list_serializer.rb b/app/serializers/admin_user_list_serializer.rb
index eaa2793..6c09e63 100644
--- a/app/serializers/admin_user_list_serializer.rb
+++ b/app/serializers/admin_user_list_serializer.rb
@@ -18,7 +18,6 @@ class AdminUserListSerializer < BasicUserSerializer
              :username,
              :title,
              :avatar_template,
-             :can_approve,
              :approved,
              :suspended_at,
              :suspended_till,
@@ -106,14 +105,6 @@ class AdminUserListSerializer < BasicUserSerializer
     Time.now - object.created_at
   end
 
-  def can_approve
-    scope.can_approve?(object)
-  end
-
-  def include_can_approve?
-    SiteSetting.must_approve_users
-  end
-
   def include_approved?
     SiteSetting.must_approve_users
   end
diff --git a/app/serializers/admin_user_serializer.rb b/app/serializers/admin_user_serializer.rb
index df7f279..2ed6825 100644
--- a/app/serializers/admin_user_serializer.rb
+++ b/app/serializers/admin_user_serializer.rb
@@ -7,11 +7,21 @@ class AdminUserSerializer < AdminUserListSerializer
              :can_send_activation_email,
              :can_activate,
              :can_deactivate,
+             :can_approve,
              :ip_address,
              :registration_ip_address
 
   has_one :single_sign_on_record, serializer: SingleSignOnRecordSerializer, embed: :objects
 
+  def can_approve
+    reviewable = ReviewableUser.find_by(target: object)
+    reviewable.present? && reviewable.actions_for(scope).has?(:approve)
+  end
+
+  def include_can_approve?
+    SiteSetting.must_approve_users
+  end
+
   def can_send_activation_email
     scope.can_send_activation_email?(object)
   end

GitHub sha: 692e09d8

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: