summaryrefslogtreecommitdiff
path: root/app/services/members/update_service.rb
blob: 5c6e51201c2d482e6be76ddda00131fe4bfaf7b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

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)

      old_access_level = member.human_access
      old_expiry = member.expires_at

      if member.update(params)
        after_execute(action: permission, old_access_level: old_access_level, old_expiry: old_expiry, member: member)

        # Deletes only confidential issues todos for guests
        enqueue_delete_todos(member) if downgrading_to_guest?
      end

      if member.errors.any?
        error(member.errors.full_messages.to_sentence, pass_back: { member: member })
      else
        success(member: member)
      end
    end

    private

    def downgrading_to_guest?
      params[:access_level] == Gitlab::Access::GUEST
    end
  end
end

Members::UpdateService.prepend_if_ee('EE::Members::UpdateService')