mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-15 06:38:51 +00:00
bacb674921
Co-authored-by: Liam Cooke <liam@liamcooke.com> Co-authored-by: John Holdun <john@johnholdun.com> Co-authored-by: Effy Elden <effy@effy.space> Co-authored-by: Lina Reyne <git@lina.pizza> Co-authored-by: Lina <20880695+necropolina@users.noreply.github.com> Co-authored-by: Claire <claire.github-309c@sitedethib.com>
48 lines
1.1 KiB
Ruby
48 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1::ListsController < Api::BaseController
|
|
before_action -> { doorkeeper_authorize! :read, :'read:lists' }, only: [:index, :show]
|
|
before_action -> { doorkeeper_authorize! :write, :'write:lists' }, except: [:index, :show]
|
|
|
|
before_action :require_user!
|
|
before_action :set_list, except: [:index, :create]
|
|
|
|
rescue_from ArgumentError do |e|
|
|
render json: { error: e.to_s }, status: 422
|
|
end
|
|
|
|
def index
|
|
@lists = List.where(account: current_account).all
|
|
render json: @lists, each_serializer: REST::ListSerializer
|
|
end
|
|
|
|
def show
|
|
render json: @list, serializer: REST::ListSerializer
|
|
end
|
|
|
|
def create
|
|
@list = List.create!(list_params.merge(account: current_account))
|
|
render json: @list, serializer: REST::ListSerializer
|
|
end
|
|
|
|
def update
|
|
@list.update!(list_params)
|
|
render json: @list, serializer: REST::ListSerializer
|
|
end
|
|
|
|
def destroy
|
|
@list.destroy!
|
|
render_empty
|
|
end
|
|
|
|
private
|
|
|
|
def set_list
|
|
@list = List.where(account: current_account).find(params[:id])
|
|
end
|
|
|
|
def list_params
|
|
params.permit(:title, :replies_policy, :exclusive)
|
|
end
|
|
end
|