Commit 47c247d3 authored by Max Woolf's avatar Max Woolf

Refactor Compliance Framework graphql parameters

Moves name, description and color
in to a separate InputType and nests those
parameters within a params object for
inputs to Update or Create mutations.
parent 226c1b96
......@@ -3370,6 +3370,23 @@ type ComplianceFrameworkEdge {
node: ComplianceFramework
}
input ComplianceFrameworkInput {
"""
New color representation of the compliance framework in hex format. e.g. #FCA121.
"""
color: String
"""
New description for the compliance framework.
"""
description: String
"""
New name for the compliance framework.
"""
name: String
}
"""
Identifier of ComplianceManagement::Framework
"""
......@@ -4161,24 +4178,14 @@ input CreateComplianceFrameworkInput {
clientMutationId: String
"""
Color to represent the compliance framework as a hexadecimal value. e.g. #ABC123.
"""
color: String!
"""
Description of the compliance framework.
"""
description: String!
"""
Name of the compliance framework.
Full path of the namespace to add the compliance framework to.
"""
name: String!
namespacePath: ID!
"""
Full path of the namespace to add the compliance framework to.
Parameters to update the compliance framework with.
"""
namespacePath: ID!
params: ComplianceFrameworkInput!
}
"""
......@@ -23655,24 +23662,14 @@ input UpdateComplianceFrameworkInput {
clientMutationId: String
"""
New color representation of the compliance framework in hex format. e.g. #FCA121
"""
color: String
"""
New description for the compliance framework
"""
description: String
"""
The global ID of the compliance framework to update
The global ID of the compliance framework to update.
"""
id: ComplianceManagementFrameworkID!
"""
New name for the compliance framework
Parameters to update the compliance framework with.
"""
name: String
params: ComplianceFrameworkInput!
}
"""
......@@ -23685,7 +23682,7 @@ type UpdateComplianceFrameworkPayload {
clientMutationId: String
"""
The compliance framework after mutation
The compliance framework after mutation.
"""
complianceFramework: ComplianceFramework
......
......@@ -9252,6 +9252,47 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "ComplianceFrameworkInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "name",
"description": "New name for the compliance framework.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "description",
"description": "New description for the compliance framework.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "color",
"description": "New color representation of the compliance framework in hex format. e.g. #FCA121.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "ComplianceManagementFrameworkID",
......@@ -11413,42 +11454,14 @@
"defaultValue": null
},
{
"name": "name",
"description": "Name of the compliance framework.",
"name": "params",
"description": "Parameters to update the compliance framework with.",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "description",
"description": "Description of the compliance framework.",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "color",
"description": "Color to represent the compliance framework as a hexadecimal value. e.g. #ABC123.",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"kind": "INPUT_OBJECT",
"name": "ComplianceFrameworkInput",
"ofType": null
}
},
......@@ -69219,7 +69232,7 @@
"inputFields": [
{
"name": "id",
"description": "The global ID of the compliance framework to update",
"description": "The global ID of the compliance framework to update.",
"type": {
"kind": "NON_NULL",
"name": null,
......@@ -69232,32 +69245,16 @@
"defaultValue": null
},
{
"name": "name",
"description": "New name for the compliance framework",
"name": "params",
"description": "Parameters to update the compliance framework with.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "description",
"description": "New description for the compliance framework",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "color",
"description": "New color representation of the compliance framework in hex format. e.g. #FCA121",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "ComplianceFrameworkInput",
"ofType": null
}
},
"defaultValue": null
},
......@@ -69297,7 +69294,7 @@
},
{
"name": "complianceFramework",
"description": "The compliance framework after mutation",
"description": "The compliance framework after mutation.",
"args": [
],
......@@ -3610,7 +3610,7 @@ Autogenerated return type of UpdateComplianceFramework.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `clientMutationId` | String | A unique identifier for the client performing the mutation. |
| `complianceFramework` | ComplianceFramework | The compliance framework after mutation |
| `complianceFramework` | ComplianceFramework | The compliance framework after mutation. |
| `errors` | String! => Array | Errors encountered during execution of the mutation. |
### UpdateContainerExpirationPolicyPayload
......
......@@ -15,21 +15,13 @@ module Mutations
required: true,
description: 'Full path of the namespace to add the compliance framework to.'
argument :name, GraphQL::STRING_TYPE,
argument :params, Types::ComplianceManagement::ComplianceFrameworkInputType,
required: true,
description: 'Name of the compliance framework.'
argument :description, GraphQL::STRING_TYPE,
required: true,
description: 'Description of the compliance framework.'
argument :color, GraphQL::STRING_TYPE,
required: true,
description: 'Color to represent the compliance framework as a hexadecimal value. e.g. #ABC123.'
description: 'Parameters to update the compliance framework with.'
def resolve(**args)
service = ::ComplianceManagement::Frameworks::CreateService.new(namespace: namespace(args[:namespace_path]),
params: args,
params: args[:params].to_h,
current_user: current_user).execute
service.success? ? success(service) : error(service)
......
......@@ -11,33 +11,22 @@ module Mutations
argument :id,
::Types::GlobalIDType[::ComplianceManagement::Framework],
required: true,
description: 'The global ID of the compliance framework to update'
description: 'The global ID of the compliance framework to update.'
argument :name,
GraphQL::STRING_TYPE,
required: false,
description: 'New name for the compliance framework'
argument :description,
GraphQL::STRING_TYPE,
required: false,
description: 'New description for the compliance framework'
argument :color,
GraphQL::STRING_TYPE,
required: false,
description: 'New color representation of the compliance framework in hex format. e.g. #FCA121'
argument :params, Types::ComplianceManagement::ComplianceFrameworkInputType,
required: true,
description: 'Parameters to update the compliance framework with.'
field :compliance_framework,
Types::ComplianceManagement::ComplianceFrameworkType,
null: true,
description: "The compliance framework after mutation"
description: "The compliance framework after mutation."
def resolve(id:, **args)
framework = authorized_find!(id: id)
::ComplianceManagement::Frameworks::UpdateService.new(framework: framework,
current_user: current_user,
params: args).execute
params: args[:params].to_h).execute
{ compliance_framework: framework, errors: errors_on_object(framework) }
end
......
# frozen_string_literal: true
module Types
module ComplianceManagement
# rubocop: disable Graphql/AuthorizeTypes
class ComplianceFrameworkInputType < BaseInputObject
graphql_name 'ComplianceFrameworkInput'
argument :name,
GraphQL::STRING_TYPE,
required: false,
description: 'New name for the compliance framework.'
argument :description,
GraphQL::STRING_TYPE,
required: false,
description: 'New description for the compliance framework.'
argument :color,
GraphQL::STRING_TYPE,
required: false,
description: 'New color representation of the compliance framework in hex format. e.g. #FCA121.'
end
end
end
......@@ -84,7 +84,7 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do
end
context 'framework parameters are invalid' do
let(:params) { valid_params.merge(color: 'notacolor') }
subject { mutation.resolve(invalid_color_params) }
it 'does not create a new compliance framework' do
expect { subject }.not_to change { namespace.compliance_management_frameworks.count }
......@@ -103,9 +103,22 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do
def valid_params
{
namespace_path: namespace.full_path,
name: 'GDPR',
description: 'Example description',
color: '#abc123'
params: {
name: 'GDPR',
description: 'Example description',
color: '#abc123'
}
}
end
def invalid_color_params
{
namespace_path: namespace.full_path,
params: {
name: 'GDPR',
description: 'Example description',
color: '#notacolor'
}
}
end
end
......@@ -16,7 +16,7 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Update do
}
end
subject { mutation.resolve(id: global_id_of(framework), **params) }
subject { mutation.resolve(id: global_id_of(framework), params: params) }
context 'feature is enabled and licensed' do
before do
......
......@@ -12,9 +12,11 @@ RSpec.describe 'Create a Compliance Framework' do
graphql_mutation(
:create_compliance_framework,
namespace_path: namespace.full_path,
name: 'GDPR',
description: 'Example Description',
color: '#ABC123'
params: {
name: 'GDPR',
description: 'Example Description',
color: '#ABC123'
}
)
end
......
......@@ -10,9 +10,11 @@ RSpec.describe 'Update a compliance framework' do
let(:current_user) { framework.namespace.owner }
let(:params) do
{
name: 'New Name',
description: 'New Description',
color: '#AAC112'
params: {
name: 'New Name',
description: 'New Description',
color: '#AAC112'
}
}
end
......@@ -72,9 +74,11 @@ RSpec.describe 'Update a compliance framework' do
context 'with invalid params' do
let(:params) do
{
name: '',
description: '',
color: 'NOTACOLOR'
params: {
name: '',
description: '',
color: 'NOTACOLOR'
}
}
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment