Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6422 from vpereira/new_project_meta
Move meta related actions from ProjectController to its own CRUD controller
- Loading branch information
Showing
46 changed files
with
3,544 additions
and
130 deletions.
There are no files selected for viewing
This file contains 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 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,47 @@ | ||
module Webui | ||
module Projects | ||
class MetaController < WebuiController | ||
before_action :set_project | ||
before_action :validate_meta, only: [:update], if: -> { params[:meta] } | ||
after_action :verify_authorized, only: [:update] | ||
|
||
def show | ||
@meta = @project.render_xml | ||
switch_to_webui2 | ||
end | ||
|
||
def update | ||
authorize @project, :update? | ||
updater = ::MetaControllerService::ProjectUpdater.new(project: @project, request_data: @request_data) | ||
updater.call | ||
|
||
status = if updater.valid? | ||
flash.now[:success] = 'Config successfully saved!' | ||
200 | ||
else | ||
flash.now[:error] = updater.errors | ||
400 | ||
end | ||
switch_to_webui2 | ||
render layout: false, status: status, partial: "layouts/#{view_namespace}/flash", object: flash | ||
end | ||
|
||
private | ||
|
||
def validate_meta | ||
meta_validator = ::MetaControllerService::MetaXMLValidator.new(params) | ||
meta_validator.call | ||
if meta_validator.errors? | ||
flash.now[:error] = meta_validator.errors | ||
render layout: false, status: 400, partial: "layouts/#{view_namespace}/flash", object: flash | ||
else | ||
@request_data = meta_validator.request_data | ||
end | ||
end | ||
|
||
def view_namespace | ||
switch_to_webui2? ? 'webui2' : 'webui' | ||
end | ||
end | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
src/api/app/services/meta_controller_service/meta_validator.rb
This file contains 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,25 @@ | ||
module MetaControllerService | ||
class MetaValidator | ||
attr_reader :project, :request_data, :errors | ||
|
||
def initialize(params = {}) | ||
@project = params[:project] | ||
@request_data = params[:request_data] | ||
@errors = [] | ||
end | ||
|
||
def call | ||
remove_repositories = @project.get_removed_repositories(@request_data) | ||
@errors << Project.check_repositories(remove_repositories)[:error] | ||
@errors << Project.validate_remote_permissions(@request_data)[:error] | ||
@errors << Project.validate_link_xml_attribute(@request_data, @project.name)[:error] | ||
@errors << Project.validate_maintenance_xml_attribute(@request_data)[:error] | ||
@errors << Project.validate_repository_xml_attribute(@request_data, @project.name)[:error] | ||
@errors.compact! | ||
end | ||
|
||
def valid? | ||
@errors.empty? | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
src/api/app/services/meta_controller_service/meta_xml_validator.rb
This file contains 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,22 @@ | ||
module MetaControllerService | ||
class MetaXMLValidator | ||
require_dependency 'opensuse/validator' | ||
|
||
attr_reader :meta, :request_data, :errors | ||
|
||
def initialize(params = {}) | ||
@meta = params[:meta] | ||
end | ||
|
||
def call | ||
Suse::Validator.validate('project', @meta) | ||
@request_data = Xmlhash.parse(@meta) | ||
rescue Suse::ValidationError => exception | ||
@errors = exception.message | ||
end | ||
|
||
def errors? | ||
@errors.present? | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
src/api/app/services/meta_controller_service/project_updater.rb
This file contains 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,30 @@ | ||
module MetaControllerService | ||
class ProjectUpdater | ||
def initialize(project: nil, request_data: {}, validator_klass: ::MetaControllerService::MetaValidator) | ||
@project = project | ||
@request_data = request_data | ||
@validator = validator_klass.new(project: project, request_data: request_data) | ||
end | ||
|
||
def call | ||
@validator.call | ||
unless @validator.valid? | ||
@errors = @validator.errors | ||
return | ||
end | ||
|
||
Project.transaction do | ||
@errors = @project.update_from_xml(@request_data)[:error] | ||
@project.store if valid? | ||
end | ||
end | ||
|
||
def errors | ||
@errors.is_a?(Array) ? @errors.join("\n") : @errors | ||
end | ||
|
||
def valid? | ||
@validator.valid? && @errors.blank? | ||
end | ||
end | ||
end |
This file contains 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 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 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 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
3 changes: 3 additions & 0 deletions
3
src/api/app/views/webui2/webui/projects/meta/_breadcrumb_items.html.haml
This file contains 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,3 @@ | ||
= render partial: 'webui/project/breadcrumb_items' | ||
%li.breadcrumb-item.active{ 'aria-current' => 'page' } | ||
Meta |
File renamed without changes.
This file contains 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.