diff options
Diffstat (limited to 'app/services/users/update_highest_member_role_service.rb')
-rw-r--r-- | app/services/users/update_highest_member_role_service.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/services/users/update_highest_member_role_service.rb b/app/services/users/update_highest_member_role_service.rb new file mode 100644 index 00000000000..00f0af89e8d --- /dev/null +++ b/app/services/users/update_highest_member_role_service.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Users + class UpdateHighestMemberRoleService < BaseService + attr_reader :user, :identity_params + + def initialize(user) + @user = user + end + + def execute + return true if user_highest_role.persisted? && highest_access_level == user_highest_role.highest_access_level + + user_highest_role.update!(highest_access_level: highest_access_level) + end + + private + + def user_highest_role + @user_highest_role ||= begin + @user.user_highest_role || @user.build_user_highest_role + end + end + + def highest_access_level + @highest_access_level ||= @user.current_highest_access_level + end + end +end |