2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
module Types
|
|
|
|
module PermissionTypes
|
|
|
|
class MergeRequest < BasePermissionType
|
2020-06-23 00:09:42 +05:30
|
|
|
PERMISSION_FIELDS = %i[push_to_source_branch
|
|
|
|
remove_source_branch
|
|
|
|
cherry_pick_on_current_merge_request
|
|
|
|
revert_on_current_merge_request].freeze
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
present_using MergeRequestPresenter
|
|
|
|
description 'Check permissions for the current user on a merge request'
|
|
|
|
graphql_name 'MergeRequestPermissions'
|
|
|
|
|
|
|
|
abilities :read_merge_request, :admin_merge_request,
|
|
|
|
:update_merge_request, :create_note
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
PERMISSION_FIELDS.each do |field_name|
|
|
|
|
permission_field field_name, method: :"can_#{field_name}?", calls_gitaly: true
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
permission_field :can_merge, calls_gitaly: true, resolve: -> (object, args, context) do
|
|
|
|
object.can_be_merged_by?(context[:current_user])
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|