2016-09-06 01:05:34 -04:00
|
|
|
# The protected branches 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 ApiCreateService < BaseService
|
|
|
|
def execute
|
2016-09-22 11:08:05 -04:00
|
|
|
push_access_level =
|
2016-10-24 02:02:09 -04:00
|
|
|
if params.delete(:developers_can_push)
|
2016-09-22 11:08:05 -04:00
|
|
|
Gitlab::Access::DEVELOPER
|
|
|
|
else
|
|
|
|
Gitlab::Access::MASTER
|
|
|
|
end
|
2016-09-06 01:05:34 -04:00
|
|
|
|
2016-09-22 11:08:05 -04:00
|
|
|
merge_access_level =
|
2016-10-24 02:02:09 -04:00
|
|
|
if params.delete(:developers_can_merge)
|
2016-09-22 11:08:05 -04:00
|
|
|
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 }])
|
2016-09-06 01:05:34 -04:00
|
|
|
|
|
|
|
service = ProtectedBranches::CreateService.new(@project, @current_user, @params)
|
|
|
|
service.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|