diff --git a/README.md b/README.md index 73b41ae..7effa94 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ Inspired by original `redmine_tags` of Eric Davis. ``` 3. Restart your Redmine web server. +4. Assign edit permissions to roles. +5. Enable Tags per project. ## Running tests diff --git a/app/views/issues/_tags.html.erb b/app/views/issues/_tags.html.erb index 3800666..8dfd0cb 100755 --- a/app/views/issues/_tags.html.erb +++ b/app/views/issues/_tags.html.erb @@ -1,3 +1,4 @@ +<% if @project.module_enabled?(:tags) %> <% unless issue.tag_list.empty? %>
@@ -8,3 +9,4 @@
<% end %> +<% end %> diff --git a/app/views/issues/_tags_form.html.erb b/app/views/issues/_tags_form.html.erb index 3ef2288..b9bff0f 100755 --- a/app/views/issues/_tags_form.html.erb +++ b/app/views/issues/_tags_form.html.erb @@ -1,3 +1,4 @@ +<% if @project.module_enabled?(:tags) && User.current.allowed_to?(:issue_edit_tags, @project) %>

<%= form.text_field :tag_list, :size => 60, :value => issue.tag_list.to_s %>

<%= javascript_tag "$('#issue_tag_list').tagit({ @@ -17,3 +18,4 @@ removeConfirmation: true, showAutocompleteOnFocus: true, });" %> +<% end %> \ No newline at end of file diff --git a/app/views/issues/_tags_sidebar.html.erb b/app/views/issues/_tags_sidebar.html.erb index 7377164..d51b6a3 100644 --- a/app/views/issues/_tags_sidebar.html.erb +++ b/app/views/issues/_tags_sidebar.html.erb @@ -1,4 +1,4 @@ -<% if defined?(sidebar_tags) && !sidebar_tags.empty? && !@issue %> +<% if (defined?(sidebar_tags)) && @project.module_enabled?(:tags) && !sidebar_tags.empty? && !@issue %> <%= stylesheet_link_tag 'jquery.tagit.css', plugin: 'redmine_tags' %> <%= stylesheet_link_tag 'redmine_tags', plugin: 'redmine_tags' %>

<%= l :tags %>

diff --git a/app/views/wiki/_tags.html.erb b/app/views/wiki/_tags.html.erb index 3ee609a..58e21aa 100644 --- a/app/views/wiki/_tags.html.erb +++ b/app/views/wiki/_tags.html.erb @@ -1,4 +1,6 @@ +<% if @project.module_enabled?(:tags) -%> <% unless page.tag_list.empty? %> <%= l :tags %>: <%= safe_join(page.tag_counts.collect{|t| render_tag_link(t, show_count: false, open_only: false) }, RedmineTags.settings[:issues_use_colors].to_i > 0 ? ' ' : ', ') %> <% end %> +<% end %> diff --git a/app/views/wiki/_tags_form.html.erb b/app/views/wiki/_tags_form.html.erb index f92f59f..3acd01f 100644 --- a/app/views/wiki/_tags_form.html.erb +++ b/app/views/wiki/_tags_form.html.erb @@ -1,3 +1,4 @@ +<% if @project.module_enabled?(:tags) && User.current.allowed_to?(:wiki_edit_tags, @project) %>

<%= label_tag l(:tags), nil, for: :wiki_page_tag_list %> <%= text_field_tag 'wiki_page[tag_list]', page.tag_list.to_s, class: 'hol', @@ -23,3 +24,4 @@ caseSensitive: false, removeConfirmation: true, });" %> +<% end %> diff --git a/app/views/wiki/_tags_sidebar.html.erb b/app/views/wiki/_tags_sidebar.html.erb index 834f154..3aa099a 100644 --- a/app/views/wiki/_tags_sidebar.html.erb +++ b/app/views/wiki/_tags_sidebar.html.erb @@ -1,6 +1,8 @@ +<% if @project.module_enabled?(:tags) -%> <% unless sidebar_tags.empty? %> <%= stylesheet_link_tag 'jquery.tagit.css', plugin: 'redmine_tags' %> <%= stylesheet_link_tag 'redmine_tags', plugin: 'redmine_tags' %>

<%= l :tags %>

<%= render_sidebar_tags %> <% end %> +<% end %> diff --git a/db/migrate/20170421205001_enable_for_all_projects_migration.rb b/db/migrate/20170421205001_enable_for_all_projects_migration.rb new file mode 100644 index 0000000..e90bdcb --- /dev/null +++ b/db/migrate/20170421205001_enable_for_all_projects_migration.rb @@ -0,0 +1,84 @@ +class EnableForAllProjectsMigration < ActiveRecord::Migration + def up + # Do not migrate for new installations + if ActsAsTaggableOn::Tag.count == 0 + return + end + + # Do not migrate if a project already has Redmine Tags enabled + + Project.all.each do |p| + if p.module_enabled?(:tags) + puts "Some projects have Tags already enabled. Not enabling Tags for all projects" + return + end + end + + puts '********' * 10 + puts 'Redmine Tags now supports enabling tagging per project, and a permission per role' + puts 'to edit tags. This script can help you migrate to this new functionality.' + puts '' + puts 'There are two possible migration scenarios:' + puts '1. Enable Tags for all projects, and give edit permissions to all roles.' + puts ' This leaves the functionality of Redmine Tags as before the introduction of' + puts ' permissions and per-project settings.' + puts '2. Do not enable Tags for any project, and do not give edit permissions' + puts ' to any role. Instead, you must enable Tags for specific projects manually' + puts ' and give permissions to roles manually. In this case, tags will not be visible on' + puts ' issues until Tags is enabled again for that project. No user can edit tags' + puts ' until their role has the permission to edit tags.' + puts 'Select option 1 if you are satisfied with the current way Redmine Tags works, and like' + puts 'keep it that way. Select option 2 for a greater influence on how you want to set up' + puts 'Redmine Tags.' + puts 'Note that for new projects and new roles, Tags and the edit permissions must be' + puts 'enabled when creating the project/role.' + puts '' + puts '1. Enable for all projects/roles' + puts '2. Do not enable for any project/role, but let me do it manually' + puts 'Choose your migration scenario [1,2]:' + + input = STDIN.gets.chomp + + while !(input == '1' or input == '2') + puts 'Invalid choice. Please enter 1 or 2' + input = STDIN.gets.chomp + end + + if input == '1' + Project.all.each do |p| + enabled_module_names = p.enabled_module_names + if !enabled_module_names.include?(:tags) + enabled_module_names.push(:tags) + end + + p.enabled_module_names = enabled_module_names + if p.save + puts "Enable Tags for " + p.name + else + puts "Failed to enable Tags for " + p.name + end + end + + Role.all.each do |r| + enabled_permissions = r.permissions + if !enabled_permissions.include?(:issue_edit_tags) + enabled_permissions.push(:issue_edit_tags) + end + if !enabled_permissions.include?(:wiki_edit_tags) + enabled_permissions.push(:wiki_edit_tags) + end + + r.permissions = enabled_permissions + if r.save + puts "Enable edit tag permissions for " + r.name + else + puts "Failed to enable tag permissions for " + r.name + end + end + else + puts '' + puts 'Please remember to enable the Tags module for your projects, and give' + puts 'permission to roles who should be able to edit tags.' + end + end +end diff --git a/init.rb b/init.rb index ac44cb0..fbf9813 100755 --- a/init.rb +++ b/init.rb @@ -17,6 +17,10 @@ requires_redmine version_or_higher: '3.0.0' + project_module :tags do + permission :issue_edit_tags, { } + permission :wiki_edit_tags, { } + end settings \ default: { issues_sidebar: 'none', @@ -26,6 +30,8 @@ issues_sort_order: 'asc' }, partial: 'tags/settings' + + end Rails.application.config.after_initialize do