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 LegacyApiUpdateService < BaseService
|
2016-10-24 02:02:09 -04:00
|
|
|
def execute(protected_branch)
|
2016-09-30 03:44:46 -04:00
|
|
|
@developers_can_push = params.delete(:developers_can_push)
|
2016-10-24 02:02:09 -04:00
|
|
|
@developers_can_merge = params.delete(:developers_can_merge)
|
2016-09-06 01:05:34 -04:00
|
|
|
|
|
|
|
@protected_branch = protected_branch
|
|
|
|
|
|
|
|
protected_branch.transaction do
|
2016-09-13 22:34:29 -04:00
|
|
|
delete_redundant_access_levels
|
2016-09-06 01:05:34 -04:00
|
|
|
|
2016-09-13 22:34:29 -04:00
|
|
|
case @developers_can_push
|
|
|
|
when true
|
2017-02-21 18:50:22 -05:00
|
|
|
params[:push_access_levels_attributes] = [{ access_level: Gitlab::Access::DEVELOPER }]
|
2016-09-13 22:34:29 -04:00
|
|
|
when false
|
2017-02-21 18:50:22 -05:00
|
|
|
params[:push_access_levels_attributes] = [{ access_level: Gitlab::Access::MASTER }]
|
2016-09-06 01:05:34 -04:00
|
|
|
end
|
|
|
|
|
2016-09-13 22:34:29 -04:00
|
|
|
case @developers_can_merge
|
|
|
|
when true
|
2017-02-21 18:50:22 -05:00
|
|
|
params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::DEVELOPER }]
|
2016-09-13 22:34:29 -04:00
|
|
|
when false
|
2017-02-21 18:50:22 -05:00
|
|
|
params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::MASTER }]
|
2016-09-06 01:05:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
service = ProtectedBranches::UpdateService.new(@project, @current_user, @params)
|
|
|
|
service.execute(protected_branch)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-09-13 22:34:29 -04:00
|
|
|
def delete_redundant_access_levels
|
2016-09-30 03:44:46 -04:00
|
|
|
unless @developers_can_merge.nil?
|
2016-09-06 01:05:34 -04:00
|
|
|
@protected_branch.merge_access_levels.destroy_all
|
|
|
|
end
|
|
|
|
|
2016-09-30 03:44:46 -04:00
|
|
|
unless @developers_can_push.nil?
|
2016-09-06 01:05:34 -04:00
|
|
|
@protected_branch.push_access_levels.destroy_all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|