From 05e4210d2e2f36eb9c40249fb26112b1142fd90b Mon Sep 17 00:00:00 2001 From: Vasilii Iakliushin Date: Fri, 1 Aug 2025 11:15:23 +0200 Subject: [PATCH] Fix NoMethodError for OrganizationClusterAgentsFinder Sentry error: https://new-sentry.gitlab.net/organizations/gitlab/issues/1754306 **Problem** User object can be nil when GraphQL endpoint is used without an authentication. **Solution** Use `Ability.allowed?` that can handle empty users. Changelog: fixed EE: true --- .../organization_cluster_agents_finder.rb | 4 ++-- .../organization_cluster_agents_finder_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ee/app/finders/remote_development/organization_cluster_agents_finder.rb b/ee/app/finders/remote_development/organization_cluster_agents_finder.rb index 60487e6a927583..9945a7f036bfe3 100644 --- a/ee/app/finders/remote_development/organization_cluster_agents_finder.rb +++ b/ee/app/finders/remote_development/organization_cluster_agents_finder.rb @@ -7,8 +7,8 @@ class OrganizationClusterAgentsFinder # @param [User] user # @return [ActiveRecord::Relation] def self.execute(organization:, filter:, user:) - return Clusters::Agent.none unless organization && user.can?(:read_organization_cluster_agent_mapping, - organization) + return Clusters::Agent.none unless organization && + Ability.allowed?(user, :read_organization_cluster_agent_mapping, organization) fetch_agents(filter: filter, organization: organization).ordered_by_name end diff --git a/ee/spec/finders/remote_development/organization_cluster_agents_finder_spec.rb b/ee/spec/finders/remote_development/organization_cluster_agents_finder_spec.rb index bb3038e727c5f0..32bd2d3d409ca1 100644 --- a/ee/spec/finders/remote_development/organization_cluster_agents_finder_spec.rb +++ b/ee/spec/finders/remote_development/organization_cluster_agents_finder_spec.rb @@ -53,6 +53,14 @@ end end + context 'when user is empty' do + let(:user) { nil } + + it 'returns an empty response' do + expect(response).to eq([]) + end + end + context 'with filter_type set to all' do let(:filter) { :all } -- GitLab