2020-05-25 09:04:54 -07:00
|
|
|
class Ajax::ListController < AjaxController
|
2015-01-17 09:24:36 -08:00
|
|
|
def create
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :err
|
2015-01-17 09:24:36 -08:00
|
|
|
|
|
|
|
unless user_signed_in?
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :noauth
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".noauth")
|
2015-01-17 09:24:36 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-01-17 10:53:34 -08:00
|
|
|
begin
|
|
|
|
params.require :name
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue ActionController::ParameterMissing => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :toolong
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".noname")
|
2015-01-17 10:53:34 -08:00
|
|
|
return
|
|
|
|
end
|
2015-01-17 09:24:36 -08:00
|
|
|
params.require :user
|
|
|
|
|
|
|
|
begin
|
2020-04-30 15:05:41 -07:00
|
|
|
target_user = User.find_by_screen_name!(params[:user])
|
2020-05-25 09:04:54 -07:00
|
|
|
list = List.create! user: current_user, display_name: params[:name]
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :toolong
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".toolong")
|
2015-01-17 09:24:36 -08:00
|
|
|
return
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue ActiveRecord::RecordNotFound => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :notfound
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".notfound")
|
2015-01-17 09:24:36 -08:00
|
|
|
return
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue ActiveRecord::RecordNotUnique => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :exists
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".exists")
|
2015-01-17 09:24:36 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
|
|
|
@response[:success] = true
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".success")
|
2020-05-25 09:04:54 -07:00
|
|
|
@response[:render] = render_to_string(partial: 'modal/list/item', locals: { list: list, user: target_user })
|
2015-01-17 09:24:36 -08:00
|
|
|
end
|
|
|
|
|
2015-01-17 09:57:23 -08:00
|
|
|
def destroy
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :err
|
2015-01-17 09:57:23 -08:00
|
|
|
|
|
|
|
unless user_signed_in?
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :noauth
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".noauth")
|
2015-01-17 09:57:23 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-05-25 09:04:54 -07:00
|
|
|
params.require :list
|
2015-01-17 09:57:23 -08:00
|
|
|
|
|
|
|
begin
|
2020-05-25 09:04:54 -07:00
|
|
|
List.where(user: current_user, name: params[:list]).first.destroy!
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue ActiveRecord::RecordNotFound => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :notfound
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".notfound")
|
2015-01-17 09:57:23 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
|
|
|
@response[:success] = true
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".success")
|
2015-01-17 09:57:23 -08:00
|
|
|
end
|
|
|
|
|
2015-01-17 08:50:25 -08:00
|
|
|
def membership
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :err
|
2015-01-17 08:50:25 -08:00
|
|
|
|
|
|
|
unless user_signed_in?
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :noauth
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".noauth")
|
2015-01-17 08:50:25 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
params.require :user
|
2020-05-25 09:04:54 -07:00
|
|
|
params.require :list
|
2015-01-17 08:50:25 -08:00
|
|
|
params.require :add
|
|
|
|
|
|
|
|
add = params[:add] == 'true'
|
|
|
|
|
|
|
|
begin
|
2020-05-25 09:04:54 -07:00
|
|
|
list = current_user.lists.find_by_name!(params[:list])
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue ActiveRecord::RecordNotFound => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :notfound
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".notfound")
|
2015-01-17 08:50:25 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-30 15:05:41 -07:00
|
|
|
target_user = User.find_by_screen_name!(params[:user])
|
2015-01-17 08:50:25 -08:00
|
|
|
|
2022-06-09 10:55:56 -07:00
|
|
|
raise Errors::ListingSelfBlockedOther if current_user.blocking?(target_user)
|
|
|
|
raise Errors::ListingOtherBlockedSelf if target_user.blocking?(current_user)
|
|
|
|
|
2015-01-17 08:50:25 -08:00
|
|
|
if add
|
2020-05-25 09:04:54 -07:00
|
|
|
list.add_member target_user if list.members.find_by_user_id(target_user.id).nil?
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:checked] = true
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".success.add")
|
2015-01-17 08:50:25 -08:00
|
|
|
else
|
2020-05-25 09:04:54 -07:00
|
|
|
list.remove_member target_user unless list.members.find_by_user_id(target_user.id).nil?
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:checked] = false
|
2022-07-06 01:41:34 -07:00
|
|
|
@response[:message] = t(".success.remove")
|
2015-01-17 08:50:25 -08:00
|
|
|
end
|
2015-05-08 16:31:31 -07:00
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
|
|
|
@response[:success] = true
|
2015-01-17 08:50:25 -08:00
|
|
|
end
|
|
|
|
end
|