Commit f037897f054263f135c3fc68b7c32f0422c5cc87
1 parent
2e9bff75
Exists in
master
and in
22 other branches
Fix: add/remove admin with CustomFormsPLugin enabled
(ActionItem2494)
Showing
1 changed file
with
17 additions
and
13 deletions
Show diff stats
plugins/custom_forms/lib/ext/role_assignment_trigger.rb
| ... | ... | @@ -2,24 +2,28 @@ module RoleAssignmentTrigger |
| 2 | 2 | def self.included(base) |
| 3 | 3 | base.class_eval do |
| 4 | 4 | before_create do |ra| |
| 5 | - profile = ra.resource | |
| 6 | - person = ra.accessor | |
| 7 | - ok = !profile.nil? && !person.nil? && profile.environment.present? | |
| 8 | - if ok && profile.environment.plugin_enabled?(CustomFormsPlugin) && !person.is_member_of?(profile) | |
| 9 | - CustomFormsPlugin::Form.from(profile).on_memberships.each do |form| | |
| 10 | - CustomFormsPlugin::MembershipSurvey.create!(:requestor => profile, :target => person, :form_id => form.id) | |
| 5 | + if ra.resource.kind_of?(Profile) | |
| 6 | + profile = ra.resource | |
| 7 | + person = ra.accessor | |
| 8 | + ok = !profile.nil? && !person.nil? && profile.environment.present? | |
| 9 | + if ok && profile.environment.plugin_enabled?(CustomFormsPlugin) && !person.is_member_of?(profile) | |
| 10 | + CustomFormsPlugin::Form.from(profile).on_memberships.each do |form| | |
| 11 | + CustomFormsPlugin::MembershipSurvey.create!(:requestor => profile, :target => person, :form_id => form.id) | |
| 12 | + end | |
| 11 | 13 | end |
| 12 | 14 | end |
| 13 | 15 | end |
| 14 | 16 | |
| 15 | 17 | after_destroy do |ra| |
| 16 | - profile = ra.resource | |
| 17 | - person = ra.accessor | |
| 18 | - ok = !profile.nil? && !person.nil? && profile.environment.present? | |
| 19 | - if ok && profile.environment.plugin_enabled?(CustomFormsPlugin) && !person.is_member_of?(profile) | |
| 20 | - CustomFormsPlugin::Form.from(profile).on_memberships.each do |form| | |
| 21 | - task = person.tasks.pending.select {|task| task.kind_of?(CustomFormsPlugin::MembershipSurvey) && task.form_id == form.id}.first | |
| 22 | - task.cancel if task | |
| 18 | + if ra.resource.kind_of?(Profile) | |
| 19 | + profile = ra.resource | |
| 20 | + person = ra.accessor | |
| 21 | + ok = !profile.nil? && !person.nil? && profile.environment.present? | |
| 22 | + if ok && profile.environment.plugin_enabled?(CustomFormsPlugin) && !person.is_member_of?(profile) | |
| 23 | + CustomFormsPlugin::Form.from(profile).on_memberships.each do |form| | |
| 24 | + task = person.tasks.pending.select {|task| task.kind_of?(CustomFormsPlugin::MembershipSurvey) && task.form_id == form.id}.first | |
| 25 | + task.cancel if task | |
| 26 | + end | |
| 23 | 27 | end |
| 24 | 28 | end |
| 25 | 29 | end | ... | ... |