Appease the dog overlords

This commit is contained in:
Andreas Nedbal 2022-07-09 19:16:18 +02:00 committed by Karina Kwiatek
parent 0555279cd2
commit 47120e8d24
3 changed files with 28 additions and 26 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Ajax::ListController < AjaxController
before_action :authenticate_user!
@ -6,13 +8,13 @@ class Ajax::ListController < AjaxController
@response[:status] = :err
target_user = User.find_by_screen_name!(params[:user])
target_user = User.find_by!(screen_name: params[:user])
list = List.create! user: current_user, display_name: params[:name]
@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 })
@response[:render] = render_to_string(partial: "modal/list/item", locals: { list: list, user: target_user })
end
def destroy
@ -34,20 +36,20 @@ class Ajax::ListController < AjaxController
@response[:status] = :err
add = params[:add] == 'true'
add = params[:add] == "true"
target_user = User.find_by_screen_name!(params[:user])
list = current_user.lists.find_by_name!(params[:list])
target_user = User.find_by!(screen_name: params[:user])
list = current_user.lists.find_by!(name: params[:list])
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?
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?
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

View File

@ -12,9 +12,9 @@ class List < ApplicationRecord
validates :display_name, length: { maximum: 30 }
before_validation do
self.display_name.strip!
self.name = self.display_name.parameterize
self.name = '-followers-' if self.name == 'followers'
display_name.strip!
self.name = display_name.parameterize
self.name = "-followers-" if name == "followers"
end
alias members list_members