diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 12:07:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 12:07:52 +0300 |
commit | 7e019504f5ac6decde690565857238e7e59aa034 (patch) | |
tree | fab8832b40e25fc9bc1ae54b9303b95ea146b5d5 /app/services | |
parent | 116d4e56e83a1f408afe710ce070e699ba206475 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/members/update_highest_role_service.rb | 38 | ||||
-rw-r--r-- | app/services/users/update_highest_member_role_service.rb | 29 |
2 files changed, 67 insertions, 0 deletions
diff --git a/app/services/members/update_highest_role_service.rb b/app/services/members/update_highest_role_service.rb new file mode 100644 index 00000000000..ce1707c13ec --- /dev/null +++ b/app/services/members/update_highest_role_service.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Members + class UpdateHighestRoleService < ::BaseService + include ExclusiveLeaseGuard + + LEASE_TIMEOUT = 30.minutes.to_i + + attr_reader :user_id + + def initialize(user_id) + @user_id = user_id + end + + def execute + try_obtain_lease do + UpdateHighestRoleWorker.perform_async(user_id) + end + end + + private + + def lease_key + "update_highest_role:#{user_id}" + end + + def lease_timeout + LEASE_TIMEOUT + end + + # Do not release the lease before the timeout to + # prevent multiple jobs being executed during the + # defined timeout + def lease_release? + false + end + end +end 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 |