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
private
organization 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
searchProjectTopics
query
2. Testing changes to 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 Topic
andSave 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-org
anyways:
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-org
user and navigate tohttp://gdk.test:3000/admin/users
. Impersonate any member who doesn't belong toprivate-org
that'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-org
topics:
{
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-org
topics:
{
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-org
are 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-org
are 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
Merge request reports
Activity
assigned to @l.rosa
added pipelinetier-1 label
- A deleted user
added backend documentation frontend labels
- Resolved by Leonardo da Rosa
- Resolved by Leonardo da Rosa
- Resolved by Leonardo da Rosa
2 Warnings This MR changes code in ee/
, but its Changelog commit is missing theEE: true
trailer. Consider adding it to your Changelog commits.This merge request does not refer to an existing milestone. 1 Message This merge request adds or changes documentation files. A review from the Technical Writing team before you merge is recommended. Reviews can happen after you merge. Documentation review
The following files require a review from a technical writer:
-
doc/api/graphql/reference/index.md
(Link to current live version)
The review does not need to block merging this merge request. See the:
-
Metadata for the
*.md
files that you've changed. The first few lines of each*.md
file identify the stage and group most closely associated with your docs change. - The Technical Writer assigned for that stage and group.
- Documentation workflows for information on when to assign a merge request for review.
Multiversion compatibility
This merge request updates GraphQL backend and frontend code.
To prevent an incident, ensure the updated frontend code is backwards compatible.
For more information, see the multiversion compatibility documentation.
Reviewer roulette
Category Reviewer Maintainer backend @qzhaogitlab
(UTC+11, 14 hours ahead of author)
@reprazent
(UTC+1, 4 hours ahead of author)
frontend @leetickett-gitlab
(UTC+0, 3 hours ahead of author)
@mfluharty
(UTC+0, 3 hours ahead of author)
groupauthentication Reviewer review is optional for groupauthentication @atevans
(UTC-8, 5 hours behind author)
Please refer to documentation page for guidance on how you can benefit from the Reviewer Roulette, or use the GitLab Review Workload Dashboard to find other available reviewers.
If needed, you can retry the
danger-review
job that generated this comment.Generated by
DangerEdited by Ghost User-
- Resolved by 🤖 GitLab Bot 🤖
Proper labels assigned to this merge request. Please ignore me.
@l.rosa
- please see the following guidance and update this merge request.1 Error Please add typebug typefeature, or typemaintenance label to this merge request. Edited by 🤖 GitLab Bot 🤖
added groupdatabase label
added Category:Database devopsdata_access labels
added typemaintenance label
@fernanda.toledo, can you take the initial frontend review?
@rutgerwessels can you take the initial backend review?
/cc follow-up from !165066 (merged)
requested review from @fernanda.toledo
requested review from @rutgerwessels