Skip to content

Add GraphQL endpoints to fetch abuse report and abuse report labels

Eugie Limpin requested to merge el-abuse-report-labels-graphql-endpoint into master

What does this MR do and why?

Partially resolves https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/167

This MR introduces GraphQL endpoints to fetch an abuse report record and abuse report labels. These endpoints are used to implement showing of abuse report labels and adding/removing labels to an abuse report.

Related MRs

  1. Add GraphQL endpoints that will be used to display abuse report labels 👈🏼 You are here
  2. Implement show abuse report labels and adding/removing labels to an abuse report
  3. Implement create abuse report labels (MR yet to be created)

Database changes

Admin::AbuseReportLabelsFinder.new(...).execute

Without search_term param

Explained: https://console.postgres.ai/shared/76f80919-da32-499e-aa02-2362e6770e16

Raw query
SELECT
    "labels".*
FROM
    "labels"
WHERE
    "labels"."type" = 'Admin::AbuseReportLabel'
ORDER BY
    "labels"."title" ASC,
    "labels"."id" DESC
LIMIT 101

With search_term param

Explained: https://console.postgres.ai/shared/53144c6f-27bb-4c54-b7ca-2d0ab2110306

Raw query
SELECT
    "labels".*
FROM
    "labels"
WHERE
    "labels"."type" = 'Admin::AbuseReportLabel'
    AND ("labels"."title" ILIKE '%400%'
        OR "labels"."description" ILIKE '%400%')
ORDER BY
    "labels"."title" ASC,
    "labels"."id" DESC
LIMIT 101

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Fetch an abuse report Fetch abuse report labels
Screenshot_2023-08-03_at_4.17.51_PM Screenshot_2023-08-03_at_4.16.54_PM

How to set up and validate locally

Validate abuse report labels GraphQL endpoint

  1. Login with an admin user (root)
  2. Create abuse report label records
    $ rails console
    > Admin::AbuseReportLabel.create("Label One")
    > Admin::AbuseReportLabel.create("Label Two")
  3. Go to localhost:3000/-/graphql-explorer and run the following query:
    {
      abuseReportLabels(searchTerm: "") {
        nodes {
          id
          title
          description
          color
          textColor
        }
      }
    }
  4. Validate that the output looks like:
    {
      "data": {
        "abuseReportLabels": {
          "nodes": [
            {
              "id": "gid://gitlab/Admin::AbuseReportLabel/124",
              "title": "Label One",
              "description": null,
              "color": "#6699cc",
              "textColor": "#FFFFFF"
            },
            {
              "id": "gid://gitlab/Admin::AbuseReportLabel/126",
              "title": "Label Three",
              "description": null,
              "color": "#6699cc",
              "textColor": "#FFFFFF"
            },
            {
              "id": "gid://gitlab/Admin::AbuseReportLabel/125",
              "title": "Label Two",
              "description": null,
              "color": "#6699cc",
              "textColor": "#FFFFFF"
            }
          ]
        }
      }
    }

Validate abuse report GraphQL endpoint

  1. Get a Global ID of an existing abuse report
    $ rails console
    > Gitlab::GlobalId.build(AbuseReport.last, id: AbuseReport.last.id).to_s
    => "gid://gitlab/AbuseReport/76"
  2. Go to localhost:3000/-/graphql-explorer and run the following query:
    {
      # Replace gid://gitlab/AbuseReport/76 with the ID you got from the previous step
      abuseReport(id: "gid://gitlab/AbuseReport/76") {
        labels {
          nodes {
            id
            title
            description
            color
            textColor
          }
        }
      }
    }
  3. Validate that you get an output that looks like:
    {
      "data": {
        "abuseReport": {
          "labels": {
            "nodes": [
              {
                "id": "gid://gitlab/Admin::AbuseReportLabel/124",
                "title": "Label One",
                "description": null,
                "color": "#6699cc",
                "textColor": "#FFFFFF"
              },
              {
                "id": "gid://gitlab/Admin::AbuseReportLabel/125",
                "title": "Label Two",
                "description": null,
                "color": "#6699cc",
                "textColor": "#FFFFFF"
              }
            ]
          }
        }
      }
    }

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugie Limpin

Merge request reports