Skip to content

Commit 2440999

Browse files
committed
validate topic and post archetype before updating fields
1 parent ec0b782 commit 2440999

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plugin.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,21 @@ module ::CommunityCustomFields
3737
object.topic.custom_fields.slice(*CommunityCustomFields::CUSTOM_FIELDS.keys)
3838
end
3939

40-
on(:topic_created) do |topic, _opts, _user|
40+
on(:topic_created) do |topic, _opts, user|
41+
return unless topic.archetype == "regular" && user.id > 0
42+
4143
topic.custom_fields[:assignee_id] = 0
4244
topic.custom_fields[:status] = "new"
4345
topic.custom_fields[:waiting_since] = Time.now.utc
4446
topic.save_custom_fields
4547
end
4648

4749
on(:post_created) do |post, _opts, user|
50+
return unless post.archetype == "regular" && user.id > 0
51+
4852
topic = post.topic
4953

50-
if user.admin && user.id > 0
54+
if user.admin
5155
# check if user is an admin and update the `waiting_since` field, if so
5256
topic.custom_fields[:waiting_since] = Time.now.utc
5357
topic.save_custom_fields

0 commit comments

Comments
 (0)