2018-07-18 12:03:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-22 10:16:08 -05:00
|
|
|
# The branches#protect API still uses the `developers_can_push` and `developers_can_merge`
|
2016-09-06 01:05:34 -04:00
|
|
|
# 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
|
2017-11-22 10:16:08 -05:00
|
|
|
class LegacyApiCreateService < BaseService
|
2016-09-06 01:05:34 -04:00
|
|
|
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
|
2018-07-11 10:36:08 -04:00
|
|
|
Gitlab::Access::MAINTAINER
|
2016-09-22 11:08:05 -04:00
|
|
|
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
|
2018-07-11 10:36:08 -04:00
|
|
|
Gitlab::Access::MAINTAINER
|
2016-09-22 11:08:05 -04:00
|
|
|
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
|