Skip to content

Draft: Add On Call Rotation creation to GraphQL

Sean Arnold requested to merge 262857-create-rotation-model into master

What does this MR do?

This adds the ability to create On-Call rotations via the GraphQL API.

To dot his we add two models:

  • IncidentManagement::OncallRotation - The oncall rotation itself, which belongs to a IncidentManagement::Schedule
  • IncidentManagement::OncallParticipant - The participants of the oncall rotation.

Database Migrations

UP:

== 20201124030537 CreateIncidentManagementOnCallRotations: migrating ==========
-- table_exists?(:incident_management_oncall_rotations)
   -> 0.0005s
-- create_table(:incident_management_oncall_rotations)
   -> 0.0101s
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_rotations\nADD CONSTRAINT check_5209fb5d02\nCHECK ( char_length(name) <= 200 )\nNOT VALID;\n")
   -> 0.0005s
-- current_schema()
   -> 0.0002s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_rotations VALIDATE CONSTRAINT check_5209fb5d02;")
   -> 0.0006s
-- execute("RESET ALL")
   -> 0.0002s
== 20201124030537 CreateIncidentManagementOnCallRotations: migrated (0.0223s) =

== 20201125233219 AddIncidentManagementOnCallParticipants: migrating ==========
-- table_exists?(:incident_management_oncall_participants)
   -> 0.0005s
-- create_table(:incident_management_oncall_participants)
   -> 0.0073s
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_participants\nADD CONSTRAINT check_961cd02646\nCHECK ( char_length(color_palette) <= 10 )\nNOT VALID;\n")
   -> 0.0004s
-- current_schema()
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_participants VALIDATE CONSTRAINT check_961cd02646;")
   -> 0.0004s
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_participants\nADD CONSTRAINT check_48e3872c49\nCHECK ( char_length(color_weight) <= 4 )\nNOT VALID;\n")
   -> 0.0003s
-- current_schema()
   -> 0.0001s
-- execute("ALTER TABLE incident_management_oncall_participants VALIDATE CONSTRAINT check_48e3872c49;")
   -> 0.0005s
== 20201125233219 AddIncidentManagementOnCallParticipants: migrated (0.0164s) =

DOWN:

== 20201125233219 AddIncidentManagementOnCallParticipants: reverting ==========
-- drop_table(:incident_management_oncall_participants)
   -> 0.0130s
== 20201125233219 AddIncidentManagementOnCallParticipants: reverted (0.0131s) =

== 20201124030537 CreateIncidentManagementOnCallRotations: reverting ==========
-- drop_table(:incident_management_oncall_rotations)
   -> 0.0016s
== 20201124030537 CreateIncidentManagementOnCallRotations: reverted (0.0124s) =

GraphQL Mutation example:

Mutation:
mutation newRotation($input: OncallRotationCreateInput!) {
  oncallRotationCreate(input: $input) {
    oncallRotation {
      id
      name
      startsAt
      rotationLength
      rotationLengthUnit
      participants {
        nodes {
          user {
            id
            username
          }
          colorWeight
          colorPalette
        }
      }
    }
    errors
  }
}
Query variables:
{
  "input": {
    "projectPath": "root/autodevops-deploy-test",
    "scheduleIid": "1",
    "name": "Rotation 33345455",
    "startsAt": {
      "date": "2020-09-19",
      "time": "09:00"
    },
    "rotationLength": {
      "length": 1,
      "unit": "WEEKS"
    },
    "participantUsernames": [
      {
        "username": "root",
        "colorWeight": "500",
        "colorPalette": "black"
      },
      {
        "username": "another",
        "colorWeight": "500",
        "colorPalette": "black"
      }
    ]
  }
}

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #262857 (closed)

Edited by Sean Arnold

Merge request reports