-
Notifications
You must be signed in to change notification settings - Fork 0
module configs #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
module configs #989
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fe43d1b
feat: created module configuration table
raphael-goetz a41c4be
feat: added module configuration service
raphael-goetz 01155ef
fix: adjusted for code review
raphael-goetz 3bd1698
Apply suggestions from code review
raphael-goetz 3de0c6c
feat: requested changes from code review
raphael-goetz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...graphql/mutations/namespaces/projects/runtime_assignments/update_module_configurations.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mutations | ||
| module Namespaces | ||
| module Projects | ||
| module RuntimeAssignments | ||
| class UpdateModuleConfigurations < BaseMutation | ||
| description 'Updates the saved module configurations for a project runtime assignment.' | ||
|
|
||
| argument :module_configurations, [Types::Input::ModuleConfigurationInputType], | ||
| required: true, | ||
| description: 'The full set of saved module configurations for this assignment.' | ||
| argument :namespace_project_runtime_assignment_id, | ||
| Types::GlobalIdType[::NamespaceProjectRuntimeAssignment], | ||
| required: true, | ||
| description: 'The project runtime assignment to update.' | ||
|
|
||
| field :namespace_project_runtime_assignment, Types::NamespaceProjectRuntimeAssignmentType, | ||
| null: true, | ||
| description: 'The updated project runtime assignment.' | ||
|
|
||
| def resolve(namespace_project_runtime_assignment_id:, module_configurations:) | ||
| runtime_assignment = SagittariusSchema.object_from_id(namespace_project_runtime_assignment_id) | ||
|
|
||
| if runtime_assignment.nil? | ||
| return { | ||
| namespace_project_runtime_assignment: nil, | ||
| errors: [create_error(:runtime_not_assigned, 'Invalid project runtime assignment')], | ||
| } | ||
| end | ||
|
|
||
| ::Namespaces::Projects::RuntimeAssignments::UpdateModuleConfigurationsService.new( | ||
| current_authentication, | ||
| runtime_assignment, | ||
| module_configurations | ||
| ).execute.to_mutation_response(success_key: :namespace_project_runtime_assignment) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
16 changes: 16 additions & 0 deletions
16
app/graphql/types/input/module_configuration_input_type.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Types | ||
| module Input | ||
| class ModuleConfigurationInputType < Types::BaseInputObject | ||
| description 'Input type for saving a module configuration value.' | ||
|
|
||
| argument :module_configuration_definition_id, Types::GlobalIdType[::ModuleConfigurationDefinition], | ||
| required: true, | ||
| description: 'The configuration definition to save a value for.' | ||
| argument :value, GraphQL::Types::JSON, | ||
| required: false, | ||
| description: 'The saved configuration value.' | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Types | ||
| class ModuleConfigurationType < Types::BaseObject | ||
| description 'Represents a saved module configuration value for a project runtime assignment.' | ||
|
|
||
| authorize :read_module_configuration | ||
|
|
||
| field :definition, Types::ModuleConfigurationDefinitionType, | ||
| null: false, | ||
| method: :module_configuration_definition, | ||
| description: 'The configuration definition this saved value belongs to.' | ||
| field :value, GraphQL::Types::JSON, | ||
| null: true, | ||
| description: 'The saved configuration value.' | ||
|
|
||
| id_field ModuleConfiguration | ||
| timestamps | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/graphql/types/namespace_project_runtime_assignment_type.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Types | ||
| class NamespaceProjectRuntimeAssignmentType < Types::BaseObject | ||
| description 'Represents a runtime assignment for a project.' | ||
|
|
||
| authorize :read_namespace_project_runtime_assignment | ||
|
|
||
| field :compatible, Boolean, null: false, description: 'Whether the assigned runtime is compatible.' | ||
| field :module_configurations, Types::ModuleConfigurationType.connection_type, | ||
| null: false, | ||
| description: 'Saved module configuration values for this project runtime assignment.' | ||
| field :runtime, Types::RuntimeType, null: false, description: 'The assigned runtime.' | ||
|
|
||
| id_field NamespaceProjectRuntimeAssignment | ||
| timestamps | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class ModuleConfiguration < ApplicationRecord | ||
| belongs_to :namespace_project_runtime_assignment, inverse_of: :module_configurations | ||
| belongs_to :module_configuration_definition, inverse_of: :module_configurations | ||
|
|
||
| validates :module_configuration_definition_id, | ||
| uniqueness: { scope: :namespace_project_runtime_assignment_id } | ||
| validate :validate_runtime | ||
|
|
||
| def to_grpc | ||
| Tucana::Shared::ModuleConfiguration.new( | ||
| identifier: module_configuration_definition.identifier, | ||
| value: Tucana::Shared::Value.from_ruby(value) | ||
| ) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def validate_runtime | ||
| return if namespace_project_runtime_assignment.nil? || module_configuration_definition.nil? | ||
|
|
||
| definition_runtime_id = module_configuration_definition.runtime_module.runtime_id | ||
| assignment_runtime_id = namespace_project_runtime_assignment.runtime_id | ||
| return if definition_runtime_id == assignment_runtime_id | ||
|
|
||
| errors.add(:module_configuration_definition, 'must belong to the assigned runtime') | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class ModuleConfigurationPolicy < BasePolicy | ||
| delegate { subject.namespace_project_runtime_assignment } | ||
|
|
||
| rule { can?(:read_namespace_project_runtime_assignment) }.enable :read_module_configuration | ||
| end |
12 changes: 12 additions & 0 deletions
12
app/policies/namespace_project_runtime_assignment_policy.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class NamespaceProjectRuntimeAssignmentPolicy < BasePolicy | ||
| include CustomizablePermission | ||
|
|
||
| delegate { subject.namespace_project } | ||
|
|
||
| namespace_resolver { |runtime_assignment| runtime_assignment.namespace_project.namespace } | ||
|
|
||
| rule { can?(:read_namespace_project) }.enable :read_namespace_project_runtime_assignment | ||
| customizable_permission :update_module_configurations | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.