Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash when a GraphQL-requested workspace (with the random argument) doesn't exist #2213

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/graph/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/controllers/graphql_controller_11_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading