Make rubocop happy and use defined? when checking for reviewable_api_enabled
This commit is contained in:
parent
c882b097f8
commit
8ca446eeed
17
plugin.rb
17
plugin.rb
|
@ -35,19 +35,12 @@ after_initialize do
|
||||||
- flagged-* connectors
|
- flagged-* connectors
|
||||||
- flagged queue code inside the JS initializer
|
- flagged queue code inside the JS initializer
|
||||||
=end
|
=end
|
||||||
reviewable_api_enabled = begin
|
reviewable_api_enabled = defined?(Reviewable)
|
||||||
'Reviewable'.constantize
|
|
||||||
true
|
|
||||||
rescue NameError
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
# Raise an invalid access error if a user tries to act on something
|
# Raise an invalid access error if a user tries to act on something
|
||||||
# not assigned to them
|
# not assigned to them
|
||||||
DiscourseEvent.on(:before_staff_flag_action) do |args|
|
DiscourseEvent.on(:before_staff_flag_action) do |args|
|
||||||
return if reviewable_api_enabled
|
if !reviewable_api_enabled && SiteSetting.assign_locks_flags?
|
||||||
|
|
||||||
if SiteSetting.assign_locks_flags?
|
|
||||||
|
|
||||||
if custom_fields = args[:post].topic&.custom_fields
|
if custom_fields = args[:post].topic&.custom_fields
|
||||||
if assigned_to_id = custom_fields[TopicAssigner::ASSIGNED_TO_ID]
|
if assigned_to_id = custom_fields[TopicAssigner::ASSIGNED_TO_ID]
|
||||||
|
@ -261,12 +254,12 @@ after_initialize do
|
||||||
|
|
||||||
# Unassign if there are no more flags in the topic
|
# Unassign if there are no more flags in the topic
|
||||||
on(:flag_reviewed) do |post|
|
on(:flag_reviewed) do |post|
|
||||||
if !reviewable_api_enabled &&
|
if !reviewable_api_enabled &&
|
||||||
SiteSetting.assign_locks_flags? &&
|
SiteSetting.assign_locks_flags? &&
|
||||||
post.topic &&
|
post.topic &&
|
||||||
FlagQuery.flagged_post_actions(topic_id: post.topic_id, filter: "old").count > 0 &&
|
FlagQuery.flagged_post_actions(topic_id: post.topic_id, filter: "old").count > 0 &&
|
||||||
FlagQuery.flagged_post_actions(topic_id: post.topic_id).count == 0
|
FlagQuery.flagged_post_actions(topic_id: post.topic_id).count == 0
|
||||||
|
|
||||||
::TopicAssigner.new(post.topic, Discourse.system_user).unassign
|
::TopicAssigner.new(post.topic, Discourse.system_user).unassign
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue