Class: ProtectedBranches::LegacyApiUpdateService

Inherits:
BaseService show all
Defined in:
app/services/protected_branches/legacy_api_update_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseService

#project_or_group

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#after_execute, #initialize, #refresh_cache

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from ProtectedBranches::BaseService

Instance Attribute Details

#developers_can_mergeObject (readonly)

Returns the value of attribute developers_can_merge.



9
10
11
# File 'app/services/protected_branches/legacy_api_update_service.rb', line 9

def developers_can_merge
  @developers_can_merge
end

#developers_can_pushObject (readonly)

Returns the value of attribute developers_can_push.



9
10
11
# File 'app/services/protected_branches/legacy_api_update_service.rb', line 9

def developers_can_push
  @developers_can_push
end

#protected_branchObject (readonly)

Returns the value of attribute protected_branch.



9
10
11
# File 'app/services/protected_branches/legacy_api_update_service.rb', line 9

def protected_branch
  @protected_branch
end

Instance Method Details

#execute(protected_branch) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/protected_branches/legacy_api_update_service.rb', line 11

def execute(protected_branch)
  @protected_branch = protected_branch
  @developers_can_push = params.delete(:developers_can_push)
  @developers_can_merge = params.delete(:developers_can_merge)

  protected_branch.transaction do
    delete_redundant_access_levels

    case developers_can_push
    when true
      params[:push_access_levels_attributes] = [{ access_level: Gitlab::Access::DEVELOPER }]
    when false
      params[:push_access_levels_attributes] = [{ access_level: Gitlab::Access::MAINTAINER }]
    end

    case developers_can_merge
    when true
      params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::DEVELOPER }]
    when false
      params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::MAINTAINER }]
    end

    service = ProtectedBranches::UpdateService.new(project_or_group, current_user, params)
    service.execute(protected_branch)
  end
end