Commit 41f99dc6 authored by Alex Kalderimis's avatar Alex Kalderimis

Wrap instance metadata in a model so that it can have a policy

This avoids needing to special case policy checks against a hash, and
is part of a larger MR that requires GraphQL objects to respond to
authorization checks more uniformly.

See: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40088)
parent 2df95811
...@@ -5,7 +5,7 @@ module Resolvers ...@@ -5,7 +5,7 @@ module Resolvers
type Types::MetadataType, null: false type Types::MetadataType, null: false
def resolve(**args) def resolve(**args)
{ version: Gitlab::VERSION, revision: Gitlab.revision } ::InstanceMetadata.new
end end
end end
end end
# frozen_string_literal: true
class InstanceMetadata
attr_reader :version, :revision
def initialize(version: Gitlab::VERSION, revision: Gitlab.revision)
@version = version
@revision = revision
end
end
# frozen_string_literal: true
class InstanceMetadataPolicy < BasePolicy
delegate { :global }
end
...@@ -7,7 +7,7 @@ RSpec.describe Resolvers::MetadataResolver do ...@@ -7,7 +7,7 @@ RSpec.describe Resolvers::MetadataResolver do
describe '#resolve' do describe '#resolve' do
it 'returns version and revision' do it 'returns version and revision' do
expect(resolve(described_class)).to eq(version: Gitlab::VERSION, revision: Gitlab.revision) expect(resolve(described_class)).to have_attributes(version: Gitlab::VERSION, revision: Gitlab.revision)
end end
end end
end end
# frozen_string_literal: true
require 'fast_spec_helper'
RSpec.describe InstanceMetadata do
it 'has the correct properties' do
expect(subject).to have_attributes(
version: Gitlab::VERSION,
revision: Gitlab.revision
)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe InstanceMetadataPolicy do
subject { described_class.new(user, InstanceMetadata.new) }
context 'for any logged-in user' do
let(:user) { create(:user) }
specify { expect_allowed(:read_instance_metadata) }
end
context 'for anonymous users' do
let(:user) { nil }
specify { expect_disallowed(:read_instance_metadata) }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment