forked from agileware-jp/redmine_issue_templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix project bound global note template deletion (agileware-jp#65)
* fix: enabling global note template deletion * test: add test case for global note template * chore: fix spell * fix: use Migration version 5.2 * fix: remove unnecessary `!` * Update spec/models/global_note_template_spec.rb Co-authored-by: Yuya.Nishida. <[email protected]> * Update spec/models/global_note_template_spec.rb Co-authored-by: Yuya.Nishida. <[email protected]> * fix: display accurate strings * fix: hide disabled note templates * fix: switch the display depending on whether the user has editing permissions for the note template * feat: add tests for template edit form visibility * feat: display appropriate validation attribute names * fix tests --------- Co-authored-by: Yuya.Nishida. <[email protected]>
- Loading branch information
1 parent
51d278c
commit 10f2cc6
Showing
15 changed files
with
221 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# A mixin to display the appropriate field name when displaying a validation error message. | ||
module AttributeNameMapper | ||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
def attribute_map | ||
{} | ||
end | ||
|
||
def human_attribute_name(attr, options = {}) | ||
map = ActiveSupport::HashWithIndifferentAccess.new(attribute_map) | ||
if map.has_key?(attr) | ||
l(map[attr]) | ||
else | ||
super(attr, options) | ||
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
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
9 changes: 9 additions & 0 deletions
9
db/migrate/20230330055341_change_global_note_template_projects_table_name.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,9 @@ | ||
class ChangeGlobalNoteTemplateProjectsTableName < ActiveRecord::Migration[5.2] | ||
def up | ||
rename_table :global_note_template_projects, :global_note_templates_projects | ||
end | ||
|
||
def down | ||
rename_table :global_note_templates_projects, :global_note_template_projects | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../spec_helper' | ||
require_relative '../rails_helper' | ||
require_relative '../support/login_helper' | ||
|
||
RSpec.configure do |c| | ||
c.include LoginHelper | ||
end | ||
|
||
feature 'Update template', js: true do | ||
given(:user) { FactoryBot.create(:user, :password_same_login, login: 'test-manager', language: 'en', admin: false) } | ||
given(:project) { FactoryBot.create(:project_with_enabled_modules) } | ||
given(:tracker) { FactoryBot.create(:tracker, :with_default_status) } | ||
given(:role) { FactoryBot.create(:role, :manager_role) } | ||
given(:status) { IssueStatus.create(name: 'open', is_closed: false) } | ||
given(:expected_note_description) { 'Note Template desctiption' } | ||
given!(:template) { | ||
NoteTemplate.create(project_id: project.id, tracker_id: tracker.id, | ||
name: 'Note Template name', description: expected_note_description, enabled: true) | ||
} | ||
|
||
background(:all) do | ||
Redmine::Plugin.register(:redmine_issue_templates) do | ||
settings partial: 'settings/redmine_issue_templates', | ||
default: { 'apply_global_template_to_all_projects' => 'false', 'apply_template_when_edit_issue' => 'true' } | ||
end | ||
end | ||
|
||
background do | ||
project.trackers << tracker | ||
|
||
priority = IssuePriority.create( | ||
name: 'Low', | ||
position: 1, is_default: false, type: 'IssuePriority', active: true, project_id: nil, parent_id: nil, | ||
position_name: 'lowest' | ||
) | ||
|
||
member = Member.new(project: project, user_id: user.id) | ||
member.member_roles << MemberRole.new(role: role) | ||
member.save | ||
|
||
Issue.create(project_id: project.id, tracker_id: tracker.id, | ||
author_id: user.id, | ||
priority: priority, | ||
subject: 'test_create', | ||
status_id: status.id, | ||
description: 'IssueTest#test_create') | ||
end | ||
|
||
context 'Have show_issue_template permission' do | ||
|
||
background do | ||
assign_template_priv(role, add_permission: :show_issue_templates) | ||
end | ||
|
||
scenario 'Cannot edit the template, only view it' do | ||
visit_log_user(user) | ||
visit "/projects/#{project.identifier}/note_templates/#{template.id}" | ||
sleep(0.2) | ||
expect(page).to have_no_selector('div#edit-note_template') | ||
expect(page).to have_selector('div#view-note_template') | ||
end | ||
end | ||
|
||
context 'Have edit_issue_template permission' do | ||
|
||
background do | ||
assign_template_priv(role, add_permission: :edit_issue_templates) | ||
assign_template_priv(role, add_permission: :show_issue_templates) | ||
end | ||
|
||
scenario 'Can edit the template, and view it' do | ||
visit_log_user(user) | ||
visit "/projects/#{project.identifier}/note_templates/#{template.id}" | ||
sleep(0.2) | ||
expect(page).to have_selector('div#edit-note_template') | ||
expect(page).to have_no_selector('div#view-note_template') | ||
end | ||
end | ||
|
||
private | ||
|
||
def visit_log_user(user) | ||
user.update_attribute(:admin, false) | ||
log_user(user.login, user.login) | ||
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