-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move project_controller (meta and save_meta) to its own controller
- Loading branch information
Showing
43 changed files
with
3,491 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,71 @@ | ||
module Webui | ||
module Projects | ||
class MetaController < WebuiController | ||
require_dependency 'opensuse/validator' | ||
before_action :set_project, only: [:show] | ||
before_action :set_project_by_name, only: [:update] | ||
before_action :validate_meta, only: [:update], unless: -> { !params[:meta] } | ||
after_action :verify_authorized, only: [:update] | ||
|
||
def show | ||
@meta = @project.render_xml | ||
switch_to_webui2 | ||
end | ||
|
||
def update | ||
authorize @project, :update? | ||
errors = [] | ||
errors = validate_request_and_set_error(errors) | ||
errors = run_update(errors) if errors.empty? | ||
status = if errors.empty? | ||
flash.now[:success] = 'Config successfully saved!' | ||
200 | ||
else | ||
flash.now[:error] = errors.compact.join("\n") | ||
400 | ||
end | ||
switch_to_webui2 | ||
render layout: false, status: status, partial: "layouts/#{view_namespace}/flash", object: flash | ||
end | ||
|
||
private | ||
|
||
def validate_meta | ||
Suse::Validator.validate('project', params[:meta]) | ||
@request_data = Xmlhash.parse(params[:meta]) | ||
rescue Suse::ValidationError => exception | ||
flash.now[:error] = exception.message | ||
render layout: false, status: 400, partial: "layouts/#{view_namespace}/flash", object: flash | ||
end | ||
|
||
def view_namespace | ||
switch_to_webui2? ? 'webui2' : 'webui' | ||
end | ||
|
||
def validate_request_and_set_error(errors) | ||
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 run_update(errors) | ||
Project.transaction do | ||
errors << @project.update_from_xml(@request_data)[:error] | ||
errors = errors.compact | ||
@project.store if errors.empty? | ||
end | ||
errors.compact | ||
end | ||
|
||
def set_project_by_name | ||
@project = Project.get_by_name(params[:project]) | ||
rescue Project::UnknownObjectError | ||
@project = nil | ||
end | ||
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
157 changes: 157 additions & 0 deletions
157
src/api/spec/cassettes/Webui_ProjectController/GET_add_maintained_project_dialog/1_44_1.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.