2022-02-25 08:34:14 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-05 09:41:40 +09:00
|
|
|
class Api::V1::Admin::Trends::LinksController < Api::V1::Trends::LinksController
|
2023-04-18 18:33:30 +09: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: @links, each_serializer: REST::Admin::Trends::LinkSerializer
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def approve
|
|
|
|
authorize :preview_card, :review?
|
|
|
|
|
|
|
|
link = PreviewCard.find(params[:id])
|
|
|
|
link.update(trendable: true)
|
|
|
|
render json: link, serializer: REST::Admin::Trends::LinkSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def reject
|
|
|
|
authorize :preview_card, :review?
|
|
|
|
|
|
|
|
link = PreviewCard.find(params[:id])
|
|
|
|
link.update(trendable: false)
|
|
|
|
render json: link, serializer: REST::Admin::Trends::LinkSerializer
|
|
|
|
end
|
2022-02-25 08:34:14 +09:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-07-05 09:41:40 +09:00
|
|
|
def enabled?
|
|
|
|
super || current_user&.can?(:manage_taxonomies)
|
|
|
|
end
|
|
|
|
|
|
|
|
def links_from_trends
|
|
|
|
if current_user&.can?(:manage_taxonomies)
|
|
|
|
Trends.links.query
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
2022-02-25 08:34:14 +09:00
|
|
|
end
|
|
|
|
end
|