debian-mirror-gitlab/lib/gitlab/graphql/authorize/instrumentation.rb

22 lines
539 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
module Gitlab
module Graphql
module Authorize
class Instrumentation
# Replace the resolver for the field with one that will only return the
# resolved object if the permissions check is successful.
def instrument(_type, field)
2019-07-07 11:18:12 +05:30
service = AuthorizeFieldService.new(field)
2018-11-08 19:23:39 +05:30
2019-07-07 11:18:12 +05:30
if service.authorizations?
field.redefine { resolve(service.authorized_resolve) }
else
field
2018-11-08 19:23:39 +05:30
end
end
end
end
end
end