Commit 87b61455 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '292477-compliance-framework-graphql-base-input-object' into 'master'

Refactor Compliance Framework graphql parameters

See merge request gitlab-org/gitlab!50154
parents 4d9b9c2d 47c247d3
...@@ -3595,6 +3595,23 @@ type ComplianceFrameworkEdge { ...@@ -3595,6 +3595,23 @@ type ComplianceFrameworkEdge {
node: ComplianceFramework 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 Identifier of ComplianceManagement::Framework
""" """
...@@ -4386,24 +4403,14 @@ input CreateComplianceFrameworkInput { ...@@ -4386,24 +4403,14 @@ input CreateComplianceFrameworkInput {
clientMutationId: String clientMutationId: String
""" """
Color to represent the compliance framework as a hexadecimal value. e.g. #ABC123. Full path of the namespace to add the compliance framework to.
"""
color: String!
"""
Description of the compliance framework.
"""
description: String!
"""
Name of the compliance framework.
""" """
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!
} }
""" """
...@@ -24295,24 +24302,14 @@ input UpdateComplianceFrameworkInput { ...@@ -24295,24 +24302,14 @@ input UpdateComplianceFrameworkInput {
clientMutationId: String clientMutationId: String
""" """
New color representation of the compliance framework in hex format. e.g. #FCA121 The global ID of the compliance framework to update.
"""
color: String
"""
New description for the compliance framework
"""
description: String
"""
The global ID of the compliance framework to update
""" """
id: ComplianceManagementFrameworkID! id: ComplianceManagementFrameworkID!
""" """
New name for the compliance framework Parameters to update the compliance framework with.
""" """
name: String params: ComplianceFrameworkInput!
} }
""" """
...@@ -24325,7 +24322,7 @@ type UpdateComplianceFrameworkPayload { ...@@ -24325,7 +24322,7 @@ type UpdateComplianceFrameworkPayload {
clientMutationId: String clientMutationId: String
""" """
The compliance framework after mutation The compliance framework after mutation.
""" """
complianceFramework: ComplianceFramework complianceFramework: ComplianceFramework
......
...@@ -9834,6 +9834,47 @@ ...@@ -9834,6 +9834,47 @@
"enumValues": null, "enumValues": null,
"possibleTypes": 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", "kind": "SCALAR",
"name": "ComplianceManagementFrameworkID", "name": "ComplianceManagementFrameworkID",
...@@ -11975,42 +12016,14 @@ ...@@ -11975,42 +12016,14 @@
"defaultValue": null "defaultValue": null
}, },
{ {
"name": "name", "name": "params",
"description": "Name of the compliance framework.", "description": "Parameters to update the compliance framework with.",
"type": { "type": {
"kind": "NON_NULL", "kind": "NON_NULL",
"name": null, "name": null,
"ofType": { "ofType": {
"kind": "SCALAR", "kind": "INPUT_OBJECT",
"name": "String", "name": "ComplianceFrameworkInput",
"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",
"ofType": null "ofType": null
} }
}, },
...@@ -70788,7 +70801,7 @@ ...@@ -70788,7 +70801,7 @@
"inputFields": [ "inputFields": [
{ {
"name": "id", "name": "id",
"description": "The global ID of the compliance framework to update", "description": "The global ID of the compliance framework to update.",
"type": { "type": {
"kind": "NON_NULL", "kind": "NON_NULL",
"name": null, "name": null,
...@@ -70801,32 +70814,16 @@ ...@@ -70801,32 +70814,16 @@
"defaultValue": null "defaultValue": null
}, },
{ {
"name": "name", "name": "params",
"description": "New name for the compliance framework", "description": "Parameters to update the compliance framework with.",
"type": { "type": {
"kind": "SCALAR", "kind": "NON_NULL",
"name": "String", "name": null,
"ofType": null "ofType": {
}, "kind": "INPUT_OBJECT",
"defaultValue": null "name": "ComplianceFrameworkInput",
}, "ofType": 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 "defaultValue": null
}, },
...@@ -70866,7 +70863,7 @@ ...@@ -70866,7 +70863,7 @@
}, },
{ {
"name": "complianceFramework", "name": "complianceFramework",
"description": "The compliance framework after mutation", "description": "The compliance framework after mutation.",
"args": [ "args": [
], ],
...@@ -3645,7 +3645,7 @@ Autogenerated return type of UpdateComplianceFramework. ...@@ -3645,7 +3645,7 @@ Autogenerated return type of UpdateComplianceFramework.
| Field | Type | Description | | Field | Type | Description |
| ----- | ---- | ----------- | | ----- | ---- | ----------- |
| `clientMutationId` | String | A unique identifier for the client performing the mutation. | | `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. | | `errors` | String! => Array | Errors encountered during execution of the mutation. |
### UpdateContainerExpirationPolicyPayload ### UpdateContainerExpirationPolicyPayload
......
...@@ -15,21 +15,13 @@ module Mutations ...@@ -15,21 +15,13 @@ module Mutations
required: true, required: true,
description: 'Full path of the namespace to add the compliance framework to.' description: 'Full path of the namespace to add the compliance framework to.'
argument :name, GraphQL::STRING_TYPE, argument :params, Types::ComplianceManagement::ComplianceFrameworkInputType,
required: true, required: true,
description: 'Name of the compliance framework.' description: 'Parameters to update the compliance framework with.'
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.'
def resolve(**args) def resolve(**args)
service = ::ComplianceManagement::Frameworks::CreateService.new(namespace: namespace(args[:namespace_path]), service = ::ComplianceManagement::Frameworks::CreateService.new(namespace: namespace(args[:namespace_path]),
params: args, params: args[:params].to_h,
current_user: current_user).execute current_user: current_user).execute
service.success? ? success(service) : error(service) service.success? ? success(service) : error(service)
......
...@@ -11,33 +11,22 @@ module Mutations ...@@ -11,33 +11,22 @@ module Mutations
argument :id, argument :id,
::Types::GlobalIDType[::ComplianceManagement::Framework], ::Types::GlobalIDType[::ComplianceManagement::Framework],
required: true, required: true,
description: 'The global ID of the compliance framework to update' description: 'The global ID of the compliance framework to update.'
argument :name, argument :params, Types::ComplianceManagement::ComplianceFrameworkInputType,
GraphQL::STRING_TYPE, required: true,
required: false, description: 'Parameters to update the compliance framework with.'
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'
field :compliance_framework, field :compliance_framework,
Types::ComplianceManagement::ComplianceFrameworkType, Types::ComplianceManagement::ComplianceFrameworkType,
null: true, null: true,
description: "The compliance framework after mutation" description: "The compliance framework after mutation."
def resolve(id:, **args) def resolve(id:, **args)
framework = authorized_find!(id: id) framework = authorized_find!(id: id)
::ComplianceManagement::Frameworks::UpdateService.new(framework: framework, ::ComplianceManagement::Frameworks::UpdateService.new(framework: framework,
current_user: current_user, current_user: current_user,
params: args).execute params: args[:params].to_h).execute
{ compliance_framework: framework, errors: errors_on_object(framework) } { compliance_framework: framework, errors: errors_on_object(framework) }
end 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 ...@@ -84,7 +84,7 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do
end end
context 'framework parameters are invalid' do 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 it 'does not create a new compliance framework' do
expect { subject }.not_to change { namespace.compliance_management_frameworks.count } expect { subject }.not_to change { namespace.compliance_management_frameworks.count }
...@@ -103,9 +103,22 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do ...@@ -103,9 +103,22 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do
def valid_params def valid_params
{ {
namespace_path: namespace.full_path, namespace_path: namespace.full_path,
name: 'GDPR', params: {
description: 'Example description', name: 'GDPR',
color: '#abc123' 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
end end
...@@ -16,7 +16,7 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Update do ...@@ -16,7 +16,7 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Update do
} }
end 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 context 'feature is enabled and licensed' do
before do before do
......
...@@ -12,9 +12,11 @@ RSpec.describe 'Create a Compliance Framework' do ...@@ -12,9 +12,11 @@ RSpec.describe 'Create a Compliance Framework' do
graphql_mutation( graphql_mutation(
:create_compliance_framework, :create_compliance_framework,
namespace_path: namespace.full_path, namespace_path: namespace.full_path,
name: 'GDPR', params: {
description: 'Example Description', name: 'GDPR',
color: '#ABC123' description: 'Example Description',
color: '#ABC123'
}
) )
end end
......
...@@ -10,9 +10,11 @@ RSpec.describe 'Update a compliance framework' do ...@@ -10,9 +10,11 @@ RSpec.describe 'Update a compliance framework' do
let(:current_user) { framework.namespace.owner } let(:current_user) { framework.namespace.owner }
let(:params) do let(:params) do
{ {
name: 'New Name', params: {
description: 'New Description', name: 'New Name',
color: '#AAC112' description: 'New Description',
color: '#AAC112'
}
} }
end end
...@@ -72,9 +74,11 @@ RSpec.describe 'Update a compliance framework' do ...@@ -72,9 +74,11 @@ RSpec.describe 'Update a compliance framework' do
context 'with invalid params' do context 'with invalid params' do
let(:params) do let(:params) do
{ {
name: '', params: {
description: '', name: '',
color: 'NOTACOLOR' description: '',
color: 'NOTACOLOR'
}
} }
end 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