From 2ae566376a5e9da3b06eb07ebde7ec64067816b4 Mon Sep 17 00:00:00 2001 From: Caio <117518+caiosba@users.noreply.github.com> Date: Tue, 11 Feb 2025 12:15:01 -0300 Subject: [PATCH] Don't crash when a GraphQL-requested workspace with the `random` argument doesn't exist. Reported by Sentry. Fixes: CV2-6151. --- app/graph/types/query_type.rb | 3 ++- .../controllers/graphql_controller_11_test.rb | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/graph/types/query_type.rb b/app/graph/types/query_type.rb index 62265a522..d9fc2cc06 100644 --- a/app/graph/types/query_type.rb +++ b/app/graph/types/query_type.rb @@ -82,11 +82,12 @@ def me def team(id: nil, slug: nil, random: nil) tid = id.to_i + team = nil unless slug.blank? team = Team.where(slug: slug).first tid = team.id unless team.nil? end - team.reload if random + team.reload if team && random tid = Team.current&.id || User.current&.teams&.first&.id if tid === 0 GraphqlCrudOperations.load_if_can(Team, tid.to_i, context) end diff --git a/test/controllers/graphql_controller_11_test.rb b/test/controllers/graphql_controller_11_test.rb index c0ad9877a..1d1c0f204 100644 --- a/test/controllers/graphql_controller_11_test.rb +++ b/test/controllers/graphql_controller_11_test.rb @@ -377,4 +377,24 @@ def teardown assert_equal pm1.created_at.to_i, response['media_cluster_origin_timestamp'] assert_equal CheckMediaClusterOrigins::OriginCodes::USER_ADDED, response['media_cluster_origin'] end + + test "should not crash if workspace doesn't exist" do + t = create_team + u = create_user + create_team_user team: t, user: u, role: 'admin' + authenticate_with_user(u) + t.delete + + query = <<~GRAPHQL + query { + team(slug: "#{t.slug}", random: "123456") { + name + } + } + GRAPHQL + + post :create, params: { query: query, team: t.slug } + assert_response :success + assert_match /ActiveRecord::RecordNotFound/, @response.body + end end