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