Clear trusted cache in rolify callback (#19275)

This commit is contained in:
Joshua Wehner 2023-04-03 14:45:00 +02:00 committed by GitHub
parent 197b7f7128
commit ca89fbcec3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 8 deletions

View file

@ -1,6 +1,6 @@
class User < ApplicationRecord
resourcify
rolify
rolify after_add: :update_user_roles_cache, after_remove: :update_user_roles_cache
include CloudinaryHelper
@ -633,4 +633,10 @@ class User < ApplicationRecord
def confirmation_required?
ForemInstance.smtp_enabled?
end
def update_user_roles_cache(...)
authorizer.clear_cache
Rails.cache.delete("user-#{id}/has_trusted_role")
trusted?
end
end

View file

@ -165,6 +165,10 @@ module Authorizer
has_any_role?(:workshop_pass)
end
def clear_cache
remove_instance_variable(:@trusted) if defined? @trusted
end
private
def has_role?(*args)

View file

@ -133,14 +133,8 @@ module Moderator
user.remove_role(:comment_suspended) if user.comment_suspended?
end
def update_trusted_cache
Rails.cache.delete("user-#{@user.id}/has_trusted_role")
@user.trusted?
end
def update_roles
handle_user_status(user_params[:user_status], user_params[:note_for_current_role])
update_trusted_cache
end
end
end

View file

@ -5,7 +5,6 @@ module TagModerators
user.add_role(:trusted)
user.notification_setting.update(email_community_mod_newsletter: true)
Rails.cache.delete("user-#{user.id}/has_trusted_role")
NotifyMailer.with(user: user).trusted_role_email.deliver_now
return unless community_mod_newsletter_enabled?