leonardo
(Leonardo Mosquera)
October 11, 2022, 6:12pm
5
There’s only one user field present in that output, with ID 1, so you would set the User Custom Field Name field to user_field_1 instead of 1 as you currently have it.
As of today, I’m afraid the trigger explicitly checks for demotions and avoids firing - it only works for promotions:
cooked
end
def handle_user_promoted(user_id, new_trust_level, old_trust_level)
trigger = DiscourseAutomation::Triggerable::USER_PROMOTED
user = User.find_by(id: user_id)
return if user.blank?
# don't want to do anything if the user is demoted. this should probably
# be a separate event in core
return if new_trust_level < old_trust_level
DiscourseAutomation::Automation.where(trigger: trigger, enabled: true).find_each do |automation|
trust_level_code_all = DiscourseAutomation::Triggerable::USER_PROMOTED_TRUST_LEVEL_CHOICES.first[:id]
restricted_group_id = automation.trigger_field('restricted_group')['value']
trust_level_transition = automation.trigger_field('trust_level_transition')['value']
trust_level_transition = trust_level_transition || trust_level_code_all
next if restricted_group_id.present? && !GroupUser.exists?(user_id: user_id, group_id: restricted_group_id)