debian-mirror-gitlab/app/services/members/update_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.9 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
module Members
class UpdateService < Members::BaseService
# returns the updated member
def execute(member, permission: :update)
raise Gitlab::Access::AccessDeniedError unless can?(current_user, action_member_permission(permission, member), member)
2022-07-23 23:45:48 +05:30
raise Gitlab::Access::AccessDeniedError if prevent_upgrade_to_owner?(member) || prevent_downgrade_from_owner?(member)
2018-03-27 19:54:05 +05:30
2022-10-11 01:57:18 +05:30
return success(member: member) if update_results_in_no_change?(member)
2018-03-27 19:54:05 +05:30
old_access_level = member.human_access
2020-03-13 15:44:24 +05:30
old_expiry = member.expires_at
2018-03-27 19:54:05 +05:30
2018-11-18 11:00:15 +05:30
if member.update(params)
2020-03-13 15:44:24 +05:30
after_execute(action: permission, old_access_level: old_access_level, old_expiry: old_expiry, member: member)
2019-01-03 12:48:30 +05:30
# Deletes only confidential issues todos for guests
enqueue_delete_todos(member) if downgrading_to_guest?
2018-03-27 19:54:05 +05:30
end
2021-03-11 19:13:27 +05:30
if member.errors.any?
error(member.errors.full_messages.to_sentence, pass_back: { member: member })
else
success(member: member)
end
2018-03-27 19:54:05 +05:30
end
2019-01-03 12:48:30 +05:30
private
2022-10-11 01:57:18 +05:30
def update_results_in_no_change?(member)
return false if params[:expires_at]&.to_date != member.expires_at
return false if params[:access_level] != member.access_level
true
end
2019-01-03 12:48:30 +05:30
def downgrading_to_guest?
params[:access_level] == Gitlab::Access::GUEST
end
2022-07-23 23:45:48 +05:30
def upgrading_to_owner?
params[:access_level] == Gitlab::Access::OWNER
end
def downgrading_from_owner?(member)
member.owner?
end
def prevent_upgrade_to_owner?(member)
upgrading_to_owner? && cannot_assign_owner_responsibilities_to_member_in_project?(member)
end
def prevent_downgrade_from_owner?(member)
downgrading_from_owner?(member) && cannot_revoke_owner_responsibilities_from_member_in_project?(member)
end
2018-03-27 19:54:05 +05:30
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Members::UpdateService.prepend_mod_with('Members::UpdateService')