Welcome to mirror list, hosted at ThFree Co, Russian Federation.

legacy_api_create_service.rb « protected_branches « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e358fd0374e679e078c83f436226f6c3e8ecb96c (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
# The branches#protect API still uses the `developers_can_push` and `developers_can_merge`
# flags for backward compatibility, and so performs translation between that format and the
# internal data model (separate access levels). The translation code is non-trivial, and so
# lives in this service.
module ProtectedBranches
  class LegacyApiCreateService < BaseService
    def execute
      push_access_level =
        if params.delete(:developers_can_push)
          Gitlab::Access::DEVELOPER
        else
          Gitlab::Access::MASTER
        end

      merge_access_level =
        if params.delete(:developers_can_merge)
          Gitlab::Access::DEVELOPER
        else
          Gitlab::Access::MASTER
        end

      @params.merge!(push_access_levels_attributes: [{ access_level: push_access_level }],
                     merge_access_levels_attributes: [{ access_level: merge_access_level }])

      service = ProtectedBranches::CreateService.new(@project, @current_user, @params)
      service.execute
    end
  end
end