retrospring/app/controllers/ajax/list_controller.rb

59 lines
1.6 KiB
Ruby
Raw Normal View History

class Ajax::ListController < AjaxController
before_action :authenticate_user!
2015-01-17 18:24:36 +01:00
def create
params.require :name
2015-01-17 18:24:36 +01:00
@response[:status] = :err
2015-01-17 18:24:36 +01:00
target_user = User.find_by_screen_name!(params[:user])
list = List.create! user: current_user, display_name: params[:name]
2015-01-17 18:24:36 +01:00
@response[:status] = :okay
@response[:success] = true
@response[:message] = t(".success")
@response[:render] = render_to_string(partial: 'modal/list/item', locals: { list: list, user: target_user })
2015-01-17 18:24:36 +01:00
end
2015-01-17 18:57:23 +01:00
def destroy
params.require :list
2015-01-17 18:57:23 +01:00
@response[:status] = :err
List.where(user: current_user, name: params[:list]).first.destroy!
2015-01-17 18:57:23 +01:00
@response[:status] = :okay
@response[:success] = true
@response[:message] = t(".success")
2015-01-17 18:57:23 +01:00
end
def membership
params.require :user
params.require :list
params.require :add
@response[:status] = :err
add = params[:add] == 'true'
2020-05-01 00:05:41 +02:00
target_user = User.find_by_screen_name!(params[:user])
list = current_user.lists.find_by_name!(params[:list])
2022-06-09 19:55:56 +02:00
raise Errors::ListingSelfBlockedOther if current_user.blocking?(target_user)
raise Errors::ListingOtherBlockedSelf if target_user.blocking?(current_user)
if add
list.add_member target_user if list.members.find_by_user_id(target_user.id).nil?
@response[:checked] = true
@response[:message] = t(".success.add")
else
list.remove_member target_user unless list.members.find_by_user_id(target_user.id).nil?
@response[:checked] = false
@response[:message] = t(".success.remove")
end
2015-05-09 01:31:31 +02:00
@response[:status] = :okay
@response[:success] = true
end
end