Remove unsafe params from antenna old edit page
This commit is contained in:
parent
258a29ffde
commit
22774276e8
3 changed files with 3 additions and 197 deletions
|
@ -92,142 +92,6 @@ class Antenna < ApplicationRecord
|
|||
context
|
||||
end
|
||||
|
||||
def list=(list_id)
|
||||
list_id = list_id.to_i if list_id.is_a?(String)
|
||||
if list_id.is_a?(Numeric)
|
||||
self[:list_id] = list_id
|
||||
else
|
||||
self[:list] = list_id
|
||||
end
|
||||
end
|
||||
|
||||
def keywords_raw
|
||||
return '' if keywords.blank?
|
||||
|
||||
keywords.join("\n")
|
||||
end
|
||||
|
||||
def keywords_raw=(raw)
|
||||
keywords = raw.split(/\R/).filter { |r| r.present? && r.length >= 2 }.uniq
|
||||
self[:keywords] = keywords
|
||||
self[:any_keywords] = keywords.none?
|
||||
end
|
||||
|
||||
def exclude_keywords_raw
|
||||
return '' if exclude_keywords.blank?
|
||||
|
||||
exclude_keywords.join("\n")
|
||||
end
|
||||
|
||||
def exclude_keywords_raw=(raw)
|
||||
exclude_keywords = raw.split(/\R/).filter(&:present?).uniq
|
||||
self[:exclude_keywords] = exclude_keywords
|
||||
end
|
||||
|
||||
def tags_raw
|
||||
antenna_tags.where(exclude: false).map { |tag| tag.tag.name }.join("\n")
|
||||
end
|
||||
|
||||
def tags_raw=(raw)
|
||||
return if tags_raw == raw
|
||||
|
||||
tag_names = raw.split(/\R/).filter(&:present?).map { |r| r.start_with?('#') ? r[1..] : r }.uniq
|
||||
|
||||
antenna_tags.where(exclude: false).destroy_all
|
||||
Tag.find_or_create_by_names(tag_names).each do |tag|
|
||||
antenna_tags.create!(tag: tag, exclude: false)
|
||||
end
|
||||
self[:any_tags] = tag_names.none?
|
||||
end
|
||||
|
||||
def exclude_tags_raw
|
||||
return '' if exclude_tags.blank?
|
||||
|
||||
Tag.where(id: exclude_tags).map(&:name).join("\n")
|
||||
end
|
||||
|
||||
def exclude_tags_raw=(raw)
|
||||
return if exclude_tags_raw == raw
|
||||
|
||||
tags = []
|
||||
tag_names = raw.split(/\R/).filter(&:present?).map { |r| r.start_with?('#') ? r[1..] : r }.uniq
|
||||
Tag.find_or_create_by_names(tag_names).each do |tag|
|
||||
tags << tag.id
|
||||
end
|
||||
self[:exclude_tags] = tags
|
||||
end
|
||||
|
||||
def domains_raw
|
||||
antenna_domains.where(exclude: false).map(&:name).join("\n")
|
||||
end
|
||||
|
||||
def domains_raw=(raw)
|
||||
return if domains_raw == raw
|
||||
|
||||
domain_names = raw.split(/\R/).filter(&:present?).uniq
|
||||
|
||||
antenna_domains.where(exclude: false).destroy_all
|
||||
domain_names.each do |domain|
|
||||
antenna_domains.create!(name: domain, exclude: false)
|
||||
end
|
||||
self[:any_domains] = domain_names.none?
|
||||
end
|
||||
|
||||
def exclude_domains_raw
|
||||
return '' if exclude_domains.blank?
|
||||
|
||||
exclude_domains.join("\n")
|
||||
end
|
||||
|
||||
def exclude_domains_raw=(raw)
|
||||
return if exclude_domains_raw == raw
|
||||
|
||||
domain_names = raw.split(/\R/).filter(&:present?).uniq
|
||||
self[:exclude_domains] = domain_names
|
||||
end
|
||||
|
||||
def accounts_raw
|
||||
antenna_accounts.where(exclude: false).map(&:account).map { |account| account.domain ? "@#{account.username}@#{account.domain}" : "@#{account.username}" }.join("\n")
|
||||
end
|
||||
|
||||
def accounts_raw=(raw)
|
||||
return if accounts_raw == raw
|
||||
|
||||
account_names = raw.split(/\R/).filter(&:present?).map { |r| r.start_with?('@') ? r[1..] : r }.uniq
|
||||
|
||||
hit = false
|
||||
antenna_accounts.where(exclude: false).destroy_all
|
||||
account_names.each do |name|
|
||||
username, domain = name.split('@')
|
||||
account = Account.find_by(username: username, domain: domain)
|
||||
if account.present?
|
||||
antenna_accounts.create!(account: account, exclude: false)
|
||||
hit = true
|
||||
end
|
||||
end
|
||||
self[:any_accounts] = !hit
|
||||
end
|
||||
|
||||
def exclude_accounts_raw
|
||||
return '' if exclude_accounts.blank?
|
||||
|
||||
Account.where(id: exclude_accounts).map { |account| account.domain ? "@#{account.username}@#{account.domain}" : "@#{account.username}" }.join("\n")
|
||||
end
|
||||
|
||||
def exclude_accounts_raw=(raw)
|
||||
return if exclude_accounts_raw == raw
|
||||
|
||||
account_names = raw.split(/\R/).filter(&:present?).map { |r| r.start_with?('@') ? r[1..] : r }.uniq
|
||||
|
||||
accounts = []
|
||||
account_names.each do |name|
|
||||
username, domain = name.split('@')
|
||||
account = Account.find_by(username: username, domain: domain)
|
||||
accounts << account.id if account.present?
|
||||
end
|
||||
self[:exclude_accounts] = accounts
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_limit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue