2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-23 03:55:14 -04:00
|
|
|
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-03-03 21:30:32 -05:00
|
|
|
service = AuthorizeFieldService.new(field)
|
2018-05-23 03:55:14 -04:00
|
|
|
|
2019-11-15 07:06:12 -05:00
|
|
|
if service.authorizations? && !resolver_skips_authorizations?(field)
|
2019-03-03 21:30:32 -05:00
|
|
|
field.redefine { resolve(service.authorized_resolve) }
|
|
|
|
else
|
|
|
|
field
|
2018-05-23 03:55:14 -04:00
|
|
|
end
|
|
|
|
end
|
2019-11-15 07:06:12 -05:00
|
|
|
|
|
|
|
def resolver_skips_authorizations?(field)
|
|
|
|
field.metadata[:resolver].try(:skip_authorizations?)
|
|
|
|
end
|
2018-05-23 03:55:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|