Skip to content

Commit 98643e5

Browse files
committed
feat: added authorization to velorum query object
1 parent c917836 commit 98643e5

6 files changed

Lines changed: 10 additions & 4 deletions

File tree

app/graphql/types/query_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class QueryType < Types::BaseObject
4343
field :users, Types::UserType.connection_type, null: false, description: 'Find users'
4444

4545
field :global_runtimes, Types::RuntimeType.connection_type, null: false, description: 'Find runtimes'
46-
field :velorum, Types::VelorumType, null: false, description: 'Get Velorum information'
46+
field :velorum, Types::VelorumType, null: true, description: 'Get Velorum information'
4747

4848
def application
4949
{}

app/graphql/types/velorum_type.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module Types
44
class VelorumType < Types::BaseObject
55
description 'Represents Velorum integration information'
66

7+
authorize :read_velorum_config
8+
declarative_policy_subject { :global }
9+
710
field :enabled, Boolean, null: false, description: 'Whether Velorum is enabled'
811
field :models, [Types::VelorumModelType], null: false, description: 'Find models available through Velorum'
912

app/policies/global_policy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class GlobalPolicy < BasePolicy
1212
enable :read_flow_type
1313
enable :read_flow_type_setting
1414
enable :read_metadata
15+
enable :read_velorum_config
1516
end
1617

1718
rule { admin }.policy do

docs/graphql/object/query.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Root Query type
1414
| `globalRuntimes` | [`RuntimeConnection!`](../object/runtimeconnection.md) | Find runtimes |
1515
| `organizations` | [`OrganizationConnection!`](../object/organizationconnection.md) | Find organizations |
1616
| `users` | [`UserConnection!`](../object/userconnection.md) | Find users |
17-
| `velorum` | [`Velorum!`](../object/velorum.md) | Get Velorum information |
17+
| `velorum` | [`Velorum`](../object/velorum.md) | Get Velorum information |
1818

1919
## Fields with arguments
2020

spec/graphql/types/velorum_type_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212

1313
it { expect(described_class.graphql_name).to eq('Velorum') }
1414
it { expect(described_class).to have_graphql_fields(fields) }
15+
it { expect(described_class).to require_graphql_authorizations(:read_velorum_config) }
1516
end

spec/requests/graphql/query/velorum_query_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
QUERY
2222
end
2323

24+
let(:current_user) { create(:user) }
2425
let(:client) { instance_double(Sagittarius::Velorum::Client) }
2526
let(:models_response) do
2627
Tucana::Velorum::ModelsResponse.new(
@@ -49,7 +50,7 @@
4950
end
5051

5152
it 'proxies models from Velorum through gRPC' do
52-
post_graphql(query)
53+
post_graphql(query, current_user: current_user)
5354

5455
expect(graphql_data_at(:velorum, :enabled)).to be(true)
5556
expect(graphql_data_at(:velorum, :models)).to contain_exactly(
@@ -76,7 +77,7 @@
7677
end
7778

7879
it 'returns disabled state and an empty model list without creating a Velorum client' do
79-
post_graphql(query)
80+
post_graphql(query, current_user: current_user)
8081

8182
expect(graphql_data_at(:velorum, :enabled)).to be(false)
8283
expect(graphql_data_at(:velorum, :models)).to eq([])

0 commit comments

Comments
 (0)