2022-02-24 23:34:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-05 00:41:40 +00:00
|
|
|
class Api::V1::Admin::Trends::StatusesController < Api::V1::Trends::StatusesController
|
2023-04-18 09:33:30 +00:00
|
|
|
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
|
2022-02-24 23:34:14 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-07-05 00:41:40 +00:00
|
|
|
def enabled?
|
|
|
|
super || current_user&.can?(:manage_taxonomies)
|
|
|
|
end
|
|
|
|
|
|
|
|
def statuses_from_trends
|
|
|
|
if current_user&.can?(:manage_taxonomies)
|
|
|
|
Trends.statuses.query
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
2022-02-24 23:34:14 +00:00
|
|
|
end
|
|
|
|
end
|