Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email Notification Not Always Being Sent To Users After Admin Permissions Update #836

Closed
aaronskiba opened this issue Jul 31, 2024 · 1 comment

Comments

@aaronskiba
Copy link
Collaborator

Please complete the following fields as applicable:

What version of the DMPRoadmap code are you running? (e.g. v2.2.0)
4.1.1+portage-4.1.2

Expected behaviour:
An email should be sent out whenever admin permissions are granted, updated, or revoked for a user.

Actual behaviour:

  • Email notifications appear to be sending whenever one or more permissions are removed. However, with respect to adding perms, Perm.use_api is the only one which triggers the email notification.

Relevant Code:

# app/controllers/users_controller.rb
    perms_ids = permission_params[:perm_ids].blank? ? [] : permission_params[:perm_ids].map(&:to_i)
    perms = Perm.where(id: perms_ids)
    privileges_changed = false
    current_user.perms.each do |perm|
      if @user.perms.include? perm
        unless perms.include? perm
          @user.perms.delete(perm)
          @user.remove_token! if perm.id == Perm.use_api.id
          privileges_changed = true
        end
      elsif perms.include? perm
        @user.perms << perm
        if perm.id == Perm.use_api.id
          @user.keep_or_generate_token!
          privileges_changed = true
        end
      end
    end

    if @user.save
      if privileges_changed
        deliver_if(recipients: @user, key: 'users.admin_privileges') do |r|
          UserMailer.admin_privileges(r).deliver_now
        end
      end
@lagoan
Copy link
Collaborator

lagoan commented Aug 19, 2024

Related to #835

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants