Skip to content

Commit

Permalink
Merge pull request #6537 from vpereira/move_prjconf_project_configura…
Browse files Browse the repository at this point in the history
…tion_controller

Move prjconf actions from project_controller to its own controller
  • Loading branch information
vpereira committed Dec 11, 2018
2 parents 71a9688 + b6e1147 commit 0b58b87
Show file tree
Hide file tree
Showing 34 changed files with 1,322 additions and 450 deletions.
16 changes: 16 additions & 0 deletions src/api/app/assets/javascripts/webui2/cm2/show-prjconf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is a manifest file that'll be compiled into codemirror, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require codemirror
//= require webui2/cm2/toolbars
//= require webui2/cm2/mode/prjconf
//= require webui2/cm2/use-codemirror
39 changes: 2 additions & 37 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ class Webui::ProjectController < Webui::WebuiController
:show, :linking_projects, :add_person, :add_group, :buildresult, :delete_dialog,
:destroy, :remove_path_from_target, :rebuild_time, :packages_simple,
:requests, :save, :monitor, :toggle_watch,
:prjconf, :edit, :edit_comment,
:edit, :edit_comment,
:status, :maintained_projects,
:add_maintained_project_dialog, :add_maintained_project, :remove_maintained_project,
:maintenance_incidents, :unlock_dialog, :unlock, :save_person, :save_group, :remove_role,
:move_path, :save_prjconf, :clear_failed_comment, :pulse, :update_pulse]

# TODO: check if get_by_name or set_by_name is used for save_prjconf
before_action :set_project_by_name, only: [:save_prjconf]
:move_path, :clear_failed_comment, :pulse, :update_pulse]

before_action :set_project_by_id, only: [:update]

Expand Down Expand Up @@ -500,38 +497,6 @@ def toggle_watch
end
end

def prjconf
sliced_params = params.slice(:rev)
sliced_params.permit!

@content = @project.config.content(sliced_params.to_h)
switch_to_webui2
return if @content
flash[:error] = @project.config.errors.full_messages.to_sentence
redirect_to controller: 'project', nextstatus: 404
end

def save_prjconf
authorize @project, :update?

params[:user] = User.current.login
sliced_params = params.slice(:user, :comment)
sliced_params.permit!

content = @project.config.save(sliced_params.to_h, params[:config])

if content
flash.now[:success] = 'Config successfully saved!'
status = 200
else
flash.now[:error] = @project.config.errors.full_messages.to_sentence
status = 400
end
switch_to_webui2
namespace = switch_to_webui2? ? 'webui2' : 'webui'
render layout: false, status: status, partial: "layouts/#{namespace}/flash", object: flash
end

def clear_failed_comment
authorize @project, :update?

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Webui
module Projects
class ProjectConfigurationController < WebuiController
before_action :set_project
after_action :verify_authorized, only: :update

def show
sliced_params = params.slice(:rev).permit!
@content = @project.config.content(sliced_params.to_h)
switch_to_webui2
return if @content
flash[:error] = @project.config.errors.full_messages.to_sentence
redirect_to projects_path(nextstatus: 404)
end

def update
authorize @project, :update?
result = ::ProjectConfigurationService::ProjectConfigurationUpdater.new(@project, User.current, params).call
status = if result.saved?
flash.now[:success] = 'Config successfully saved!'
200
else
flash.now[:error] = result.errors
400
end
switch_to_webui2
render layout: false, status: status, partial: "layouts/#{view_namespace}/flash", object: flash
end

private

def view_namespace
switch_to_webui2? ? 'webui2' : 'webui'
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module ProjectConfigurationService
class ProjectConfigurationUpdater
def initialize(project, user, params)
@user = user
@project = project
@params = params
end

def call
@config = @project.config.save(sliced_params, @params[:config])
self
end

def saved?
@config.present? || false
end

def errors
@project.config.errors.full_messages.to_sentence
end

private

def sliced_params
@params[:user] = @user.login
sliced_params = @params.slice(:user, :comment)
sliced_params.permit!
sliced_params
end
end
end
2 changes: 1 addition & 1 deletion src/api/app/views/webui/project/_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</ul>
<div id="advanced_tabs" class="hidden">
<ul>
<%= tab 'projectconfig', 'Project Config', :controller => '/webui/project', :action => :prjconf unless @project.defines_remote_instance? || @is_maintenance_project %>
<%= tab 'projectconfig', 'Project Config', :controller => '/webui/projects/project_configuration', :action => :show unless @project.defines_remote_instance? || @is_maintenance_project %>
<% unless @spider_bot -%>
<%= tab 'attribute', 'Attributes', :controller => '/webui/attribute', :project => @project, :action => 'index' %>
<%= tab 'meta', "Meta", :controller => '/webui/projects/meta', :action => :show %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% content_for(:content_for_head, javascript_include_tag('webui/application/cm2/index-prjconf')) %>
<% @pagetitle = "Project Configuration of #{@project}" %>
<% @metarobots = 'noindex' %>
<% project_bread_crumb 'Project Configuration' %>
<%= render :partial => 'webui/project/tabs' %>

<h3><%= @pagetitle %></h3>
<div style="margin-left: 15px; margin-right: 15px;">
<% if User.current.can_modify?(@project) %>
<%= render partial: "shared/editor", locals: {text: @content, mode: 'prjconf', save: {url: save_project_config_path, method: 'POST', data: {project: @project.name, submit: 'config'}}} %>
<% else %>
<%= render partial: "shared/editor", locals: {text: @content, mode: 'prjconf', style: {read_only: true}} %>
<% end %>
</div>
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' }
Project Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
:ruby
content_for(:content_for_head, javascript_include_tag('webui2/cm2/show-prjconf'))
@pagetitle = "Project Configuration of #{@project}"
@metarobots = 'noindex'

.card
= render(partial: 'webui/project/tabs', locals: { project: @project })

.card-body
%h3= @pagetitle
- if User.current.can_modify?(@project)
= render partial: 'shared/editor', locals: { text: @content, mode: 'prjconf',
save: { url: save_project_config_path, method: :post,
data: { project: @project.name, submit: 'config' } } }
- else
= render partial: 'shared/editor', locals: { text: @content, mode: 'prjconf', style: { read_only: true } }
7 changes: 5 additions & 2 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ def self.public_or_about_path?(request)
post 'project/save_meta/:project' => :update, constraints: cons, as: :project_save_meta
end

controller 'webui/projects/project_configuration' do
get 'project/prjconf/:project' => :show, constraints: cons, as: :project_config
post 'project/save_prjconf/:project' => :update, constraints: cons, as: :save_project_config
end

controller 'webui/project' do
get 'project/' => :index, as: 'projects'
get 'project/list_public' => :index
Expand Down Expand Up @@ -286,8 +291,6 @@ def self.public_or_about_path?(request)
get 'project/package_buildresult/:project' => :package_buildresult, constraints: cons
# TODO: this should be POST (and the link AJAX)
get 'project/toggle_watch/:project' => :toggle_watch, constraints: cons, as: 'project_toggle_watch'
get 'project/prjconf/:project' => :prjconf, constraints: cons, as: :project_config
post 'project/save_prjconf/:project' => :save_prjconf, constraints: cons, as: :save_project_config
get 'project/clear_failed_comment/:project' => :clear_failed_comment, constraints: cons, as: :clear_failed_comment
get 'project/edit/:project' => :edit, constraints: cons
get 'project/edit_comment_form/:project' => :edit_comment_form, constraints: cons, as: :edit_comment_form
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

0 comments on commit 0b58b87

Please sign in to comment.