mirror of
https://github.com/discourse/discourse.git
synced 2025-03-04 10:19:40 +00:00
FIX: creating watched words...
... wasn't working because it wasn't storing the proper "action" value. Issue was that we were using the "action" parameter which is being used by Rails to determine which controller action to call. We need to use the "action_key" parameter instead.
This commit is contained in:
parent
0e44072b2b
commit
e7d0083dbe
@ -14,7 +14,7 @@ class Admin::WatchedWordsController < Admin::StaffController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
opts = watched_words_params
|
opts = watched_words_params
|
||||||
action = opts[:action] || self.class.actions[opts[:action_key].to_sym]
|
action = WatchedWord.actions[opts[:action_key].to_sym]
|
||||||
words = opts.delete(:words)
|
words = opts.delete(:words)
|
||||||
|
|
||||||
watched_word_group = WatchedWordGroup.new(action: action)
|
watched_word_group = WatchedWordGroup.new(action: action)
|
||||||
@ -118,6 +118,6 @@ class Admin::WatchedWordsController < Admin::StaffController
|
|||||||
|
|
||||||
def watched_words_params
|
def watched_words_params
|
||||||
@watched_words_params ||=
|
@watched_words_params ||=
|
||||||
params.permit(:id, :replacement, :action, :action_key, :case_sensitive, words: [])
|
params.permit(:id, :replacement, :action_key, :case_sensitive, words: [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,14 +5,9 @@ class WatchedWordGroup < ActiveRecord::Base
|
|||||||
|
|
||||||
has_many :watched_words, dependent: :destroy
|
has_many :watched_words, dependent: :destroy
|
||||||
|
|
||||||
def self.actions
|
|
||||||
WatchedWord.actions
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_or_update_members(words, params)
|
def create_or_update_members(words, params)
|
||||||
WatchedWordGroup.transaction do
|
WatchedWordGroup.transaction do
|
||||||
self.action_key = params[:action_key] if params[:action_key]
|
self.action = WatchedWord.actions[params[:action_key].to_sym]
|
||||||
self.action = params[:action] if params[:action]
|
|
||||||
self.save! if self.changed?
|
self.save! if self.changed?
|
||||||
|
|
||||||
words.each do |word|
|
words.each do |word|
|
||||||
@ -21,22 +16,16 @@ class WatchedWordGroup < ActiveRecord::Base
|
|||||||
params.merge(word: word, watched_word_group_id: self.id),
|
params.merge(word: word, watched_word_group_id: self.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
unless watched_word.valid?
|
if !watched_word.valid?
|
||||||
self.errors.merge!(watched_word.errors)
|
self.errors.merge!(watched_word.errors)
|
||||||
|
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def action_key=(arg)
|
|
||||||
self.action = WatchedWordGroup.actions[arg.to_sym]
|
|
||||||
end
|
|
||||||
|
|
||||||
def action_log_details
|
def action_log_details
|
||||||
action_key = WatchedWord.actions.key(self.action)
|
"#{WatchedWord.actions.key(self.action)} → #{watched_words.pluck(:word).join(", ")}"
|
||||||
"#{action_key} → #{watched_words.pluck(:word).join(", ")}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user