Uses organization id on Topics GraphQL
What does this MR do and why?
Uses organization to query Topics through GraphQL.
Related MRs:
How to test
1. Setup
Click to expand
- Enable Organizations FF
Feature.enable(:ui_for_organizations)
- Create a new
privateorganization in the console
Organizations::Organization.create!(name: 'Private Organization', path: 'private-org', visibility_level: 0)
- Navigate to the organization page
http://gdk.test:3000/-/organizations/private-org
- Create a new group for the private organization. Name it my-private-org-group
http://gdk.test:3000/-/organizations/private-org/groups/new
- Create a new project. Select the group you created above (my-private-org-group) and name it project-from-private-org.
http://gdk.test:3000/projects/new#blank_project
- Create a user called private-org-user
http://gdk.test:3000/admin/users/new
- Navigate to my-private-org-group page and invite the user you created above. Give a maintainer role to the user
http://gdk.test:3000/groups/my-private-org-group/-/group_members
- Check the organization page. You must see 1 group, 1 Project and 2 Users (Admin and the newly created one)
http://gdk.test:3000/-/organizations/private-org
2. Testing changes to searchProjectTopics query
This query is used by http://gdk.test:3000/<group>/<project>/edit page.
As Admin
Click to expand
Note: Make sure you're logged in as Administrator
-
After the setup visit the project you created for the private organization at http://gdk.test:3000/my-private-org-group/project-from-private-org/edit
-
Search for
Project Topics. As there's no topic for the current org, the search will be empty. Let's create some topics in the console:
organization = Organizations::Organization.find_by_path('private-org')
Projects::Topic.create!(name: 'private-org-first-topic', title: 'Private Organization First Topic', organization: organization)
Try to assign the topic to the project, by searching Private Organization First Topic in the search box.
-
In the search box, add a new topic called
Private Org Second TopicandSave Changes. -
Check the console. The organization should have two topics, as also the project:
organization.topics
[
#<Projects::Topic:0x0000000154d9e248 name: "private-org-first-topic", >,
#<Projects::Topic:0x0000000154d9e108 name: "Private Org Second Topic", >
]
organization.projects.map(&:topic_list)
=> [["private-org-first-topic", "Private Org Second Topic"]]
- Test the query using
http://gdk.test:3000/-/graphql-explorer. As admin, you'll be able to query this organization topics:
# Get the private-org global id to use in GraphQL
organization.to_global_id.to_s
{
topics(organizationId: "gid://gitlab/Organizations::Organization/1000") {
nodes {
id
name
title
}
}
}
{
"data": {
"topics": {
"nodes": [
{
"id": "gid://gitlab/Projects::Topic/1",
"name": "private-org-first-topic",
"title": "Private Organization First Topic"
},
{
"id": "gid://gitlab/Projects::Topic/2",
"name": "Private Org Second Topic",
"title": "Private Org Second Topic"
}
]
}
},
"correlationId": "01JEP9AMZG78GRRD1P8FYNFJJ9"
}
- If you don't specify the
organizationPath, the topics from the default org will be shown:
{
topics {
nodes {
id
name
title
}
}
}
{
"data": {
"topics": {
"nodes": [
{
"id": "gid://gitlab/Projects::Topic/3",
"name": "ruby",
"title": "ruby"
},
{
"id": "gid://gitlab/Projects::Topic/4",
"name": "postgres",
"title": "postgres"
},
{
"id": "gid://gitlab/Projects::Topic/5",
"name": "rspec",
"title": "rspec"
},
{
"id": "gid://gitlab/Projects::Topic/6",
"name": "shell",
"title": "shell"
}
]
}
},
"correlationId": "01JEP9EV0AVSJ9MJ5CQECTWPD0"
}
As member of the private organization (impersonating private org user)
Click to expand
-
Navigate to http://gdk.test:3000/admin/users/private-org-user and impersonate the user.
-
Navigate to http://gdk.test:3000/my-private-org-group/project-from-private-org/edit to edit the project. In the search box, try to search or create topics for the private organization.
-
Test the query using
http://gdk.test:3000/-/graphql-explorer. As member of private org, you'll be able to query this organization topics:
{
topics(organizationId: "gid://gitlab/Organizations::Organization/1000") {
nodes {
id
name
title
}
}
}
{
"data": {
"topics": {
"nodes": [
{
"id": "gid://gitlab/Projects::Topic/1",
"name": "private-org-first-topic",
"title": "Private Organization First Topic"
},
{
"id": "gid://gitlab/Projects::Topic/2",
"name": "Private Org Second Topic",
"title": "Private Org Second Topic"
},
{
"id": "gid://gitlab/Projects::Topic/7",
"name": "Private Org Third Topic",
"title": "Private Org Third Topic"
}
]
}
},
"correlationId": "01JEP9JB0T9VP96C3KH6QS9R5S"
}
- As the user belongs to only one org (
private-org), if you don't specify theorganizationPath, the topics will be fetched fromprivate-organyways:
NOTE: We're setting the current org per request on https://gitlab.com/gitlab-org/gitlab/blob/a58ac8fba89b62635d6fb8e7f7e1a7879bb72adc/app/controllers/application_controller.rb#L564-564
{
topics {
nodes {
id
name
title
}
}
}
{
"data": {
"topics": {
"nodes": [
{
"id": "gid://gitlab/Projects::Topic/1",
"name": "private-org-first-topic",
"title": "Private Organization First Topic"
},
{
"id": "gid://gitlab/Projects::Topic/2",
"name": "Private Org Second Topic",
"title": "Private Org Second Topic"
},
{
"id": "gid://gitlab/Projects::Topic/7",
"name": "Private Org Third Topic",
"title": "Private Org Third Topic"
}
]
}
},
"correlationId": "01JEPBM9CNXD6ZYTE9N0RZF3A8"
}
- As we also have a default public org, the user can fetch topics from this org as well:
NOTE: In case of an unauthenticated request - the request will use the fallback organization
{
topics(organizationId: "gid://gitlab/Organizations::Organization/1000") {
nodes {
id
name
title
}
}
}
{
"data": {
"topics": {
"nodes": [
{
"id": "gid://gitlab/Projects::Topic/3",
"name": "ruby",
"title": "ruby"
},
{
"id": "gid://gitlab/Projects::Topic/4",
"name": "postgres",
"title": "postgres"
},
{
"id": "gid://gitlab/Projects::Topic/5",
"name": "rspec",
"title": "rspec"
},
{
"id": "gid://gitlab/Projects::Topic/6",
"name": "shell",
"title": "shell"
}
]
}
},
"correlationId": "01JEPBXEGJ1JK968BAACW30BNR"
}
As member of the public organization only
Click to expand
-
Stop impersonating the
private-orguser and navigate tohttp://gdk.test:3000/admin/users. Impersonate any member who doesn't belong toprivate-orgthat's not an admin. -
Test the query using
http://gdk.test:3000/-/graphql-explorer. As this is not a member of the private org, you'll not be able to queryprivate-orgtopics:
{
topics(organizationPath: "private-org") {
nodes {
id
name
title
}
}
}
{
"errors": [
{
"graphQLErrors": [
{
"message": "The resource that you are attempting to access does not exist or you don't have permission to perform this action",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"topics"
]
}
],
"clientErrors": [],
"networkError": null,
"message": "The resource that you are attempting to access does not exist or you don't have permission to perform this action",
"stack": ".."
}
]
}
- Only topics from public org can be searched:
{
topics {
nodes {
id
name
title
}
}
}
OR
{
topics(organizationId: "gid://gitlab/Organizations::Organization/1") {
nodes {
id
name
title
}
}
}
{
"data": {
"topics": {
"nodes": [
{
"id": "gid://gitlab/Projects::Topic/3",
"name": "ruby",
"title": "ruby"
},
{
"id": "gid://gitlab/Projects::Topic/4",
"name": "postgres",
"title": "postgres"
},
{
"id": "gid://gitlab/Projects::Topic/5",
"name": "rspec",
"title": "rspec"
},
{
"id": "gid://gitlab/Projects::Topic/6",
"name": "shell",
"title": "shell"
}
]
}
},
"correlationId": "01JEPC9NC6B8DGWXJVHC9YD4TJ"
}
Querying without an unauthenticated user
Click to expand
-
In a new private browser window, go to
http://gdk.test:3000/-/graphql-explorer -
Try to query
private-orgtopics:
{
topics(organizationId: "gid://gitlab/Organizations::Organization/1000") {
nodes {
id
name
title
}
}
}
{
"errors": [
{
"graphQLErrors": [
{
"message": "The resource that you are attempting to access does not exist or you don't have permission to perform this action",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"topics"
]
}
],
"clientErrors": [],
"networkError": null,
"message": "The resource that you are attempting to access does not exist or you don't have permission to perform this action",
"stack": ".."
}
]
}
- Only topics from public org can be searched:
{
topics {
nodes {
id
name
title
}
}
}
OR
{
topics(organizationId: "gid://gitlab/Organizations::Organization/1") {
nodes {
id
name
title
}
}
}
{
"data": {
"topics": {
"nodes": [
{
"id": "gid://gitlab/Projects::Topic/3",
"name": "ruby",
"title": "ruby"
},
{
"id": "gid://gitlab/Projects::Topic/4",
"name": "postgres",
"title": "postgres"
},
{
"id": "gid://gitlab/Projects::Topic/5",
"name": "rspec",
"title": "rspec"
},
{
"id": "gid://gitlab/Projects::Topic/6",
"name": "shell",
"title": "shell"
}
]
}
},
"correlationId": "01JEPCD9AKTWD6MMYVTE7DEE1M"
}
- You can test the same using CURL
curl "http://gdk.test:3000/api/graphql" --header "Content-Type: application/json" --request POST --data "{\"query\": \"{ topics { nodes { id name title } } }\"}"
{"data":{"topics":{"nodes":[{"id":"gid://gitlab/Projects::Topic/3","name":"ruby","title":"ruby"},{"id":"gid://gitlab/Projects::Topic/4","name":"postgres","title":"postgres"},{"id":"gid://gitlab/Projects::Topic/5","name":"rspec","title":"rspec"},{"id":"gid://gitlab/Projects::Topic/6","name":"shell","title":"shell"}]}}}%
3. Testing Explore topics
As we can't switch organizations in the dashboard, topics from http://gdk.test:3000/explore/projects/topics will use the default organization.
Click to expand
- Go to
http://gdk.test:3000/explore/projects/topics - Check that no topics from the
private-orgare shown. The search only shows topics from the default org.
4. Testing Admin topics
As we can't switch organizations in the dashboard, topics shown, created or merged at http://gdk.test:3000/admin/topics will use the default organization.
Click to expand
- Make sure you're logged in as Admin
- Go to
http://gdk.test:3000/admin/topics - Check that no topics from the
private-orgare shown. The search only shows topics from the default org. - Try to merge two topics. Only topics belonging to the same organization can be merged. The merge search-boxes should also show only topics from the default organization
- Try to create a new topic. The topic will be associated with the default organization. You can check in the console through
Projects::Topic