about summary refs log tree commit diff
path: root/app/controllers/api/v1/admin/trends/statuses_controller.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-04-22 19:13:02 +0200
committerGitHub <noreply@github.com>2023-04-22 19:13:02 +0200
commit2ebbfebfe9c7c967e3bcc9da0eec4628f9188233 (patch)
treeed3fa3f23d520e99fdd8b19597992b59a47aaa7d /app/controllers/api/v1/admin/trends/statuses_controller.rb
parentf30c5e7f15f967019245d2c78f3c2e89800eb838 (diff)
parent9ef32ea570fd0db63bd75714cd847abad6833345 (diff)
Merge pull request #2192 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers/api/v1/admin/trends/statuses_controller.rb')
-rw-r--r--app/controllers/api/v1/admin/trends/statuses_controller.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/app/controllers/api/v1/admin/trends/statuses_controller.rb b/app/controllers/api/v1/admin/trends/statuses_controller.rb
index c39f77363..34b6580df 100644
--- a/app/controllers/api/v1/admin/trends/statuses_controller.rb
+++ b/app/controllers/api/v1/admin/trends/statuses_controller.rb
@@ -1,7 +1,36 @@
 # frozen_string_literal: true
 
 class Api::V1::Admin::Trends::StatusesController < Api::V1::Trends::StatusesController
-  before_action -> { authorize_if_got_token! :'admin:read' }
+  include Authorization
+
+  before_action -> { authorize_if_got_token! :'admin:read' }, only: :index
+  before_action -> { authorize_if_got_token! :'admin:write' }, except: :index
+
+  after_action :verify_authorized, except: :index
+
+  def index
+    if current_user&.can?(:manage_taxonomies)
+      render json: @statuses, each_serializer: REST::Admin::Trends::StatusSerializer
+    else
+      super
+    end
+  end
+
+  def approve
+    authorize [:admin, :status], :review?
+
+    status = Status.find(params[:id])
+    status.update(trendable: true)
+    render json: status, serializer: REST::Admin::Trends::StatusSerializer
+  end
+
+  def reject
+    authorize [:admin, :status], :review?
+
+    status = Status.find(params[:id])
+    status.update(trendable: false)
+    render json: status, serializer: REST::Admin::Trends::StatusSerializer
+  end
 
   private