debian-mirror-gitlab/app/services/protected_branches/legacy_api_create_service.rb

32 lines
1 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
# The branches#protect API still uses the `developers_can_push` and `developers_can_merge`
2016-11-03 12:29:30 +05:30
# 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
2018-03-17 18:26:18 +05:30
class LegacyApiCreateService < BaseService
2016-11-03 12:29:30 +05:30
def execute
push_access_level =
if params.delete(:developers_can_push)
Gitlab::Access::DEVELOPER
else
2018-11-18 11:00:15 +05:30
Gitlab::Access::MAINTAINER
2016-11-03 12:29:30 +05:30
end
merge_access_level =
if params.delete(:developers_can_merge)
Gitlab::Access::DEVELOPER
else
2018-11-18 11:00:15 +05:30
Gitlab::Access::MAINTAINER
2016-11-03 12:29:30 +05:30
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