Skip to content
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

Few fixes for global issue template editing #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions app/controllers/global_issue_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

# noinspection RubocopInspection
class GlobalIssueTemplatesController < ApplicationController
layout 'base'
layout 'admin'
self.main_menu = false
menu_item :redmine_issue_templates

helper :issues
helper :issue_templates
include IssueTemplatesHelper
include IssueTemplatesCommon
menu_item :issues
before_action :find_object, only: %i[show edit update destroy]
before_action :find_project, only: %i[edit update]
before_action :require_admin, only: %i[index new show], excep: [:preview]
before_action :find_object, only: %i[show update destroy]
before_action :find_project, only: :update
before_action :require_admin

#
# Action for global template : Admin right is required.
Expand Down Expand Up @@ -62,21 +64,6 @@ def update
save_and_flash(:notice_successful_update, :show)
end

def edit
# Change from request.post to request.patch for Rails4.
return unless request.patch? || request.put?

begin
@global_issue_template.safe_attributes = valid_params
rescue ActiveRecord::SerializationTypeMismatch
flash[:error] = I18n.t(:builtin_fields_should_be_valid_json, default: 'Please enter a valid JSON fotmat string.')
render render_form_params.merge(action: :show)
return
end

save_and_flash(:notice_successful_update, :show)
end

def destroy
unless @global_issue_template.destroy
flash[:error] = l(:enabled_template_cannot_destroy)
Expand Down
2 changes: 1 addition & 1 deletion app/views/global_issue_templates/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<h2 class='global_issue_template'><%=h "#{l(:global_issue_templates)}" %></h2>
<%= render partial: 'common/nodata', locals: { trackers: trackers } %>
<div class='contextual issue_templates'>
<%= link_to(l(:label_new_templates),
Expand All @@ -10,6 +9,7 @@
{ controller: 'settings', action: 'plugin', id: 'redmine_issue_templates' },
class: 'issue_template icon plugins') %>
</div>
<h2 class='global_issue_template'><%=h "#{l(:global_issue_templates)}" %></h2>
<div style='clear: both;'></div>

<% if template_map.blank? %>
Expand Down
27 changes: 27 additions & 0 deletions test/functional/global_issue_templates_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ def test_get_index
assert_response :success
end

def test_should_require_admin
@request.session[:user_id] = 2 # Non-admin

get :index
assert_response 403

get :new
assert_response 403

get :orphaned_templates
assert_response 403

get :show, params: { id: 2 }
assert_response 403

post :preview, params: { global_issue_template: { description: 'Test' } }
assert_response 403

post :create, params: { global_issue_template: { title: 'Global Template title', description: 'test'}}
assert_response 403

assert_no_difference 'GlobalIssueTemplate.count' do
delete :destroy, params: { id: 2 }
assert_response 403
end
end

def test_get_index_should_sort_trackers_in_position_order
[
['Feature request', 1],
Expand Down