Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Tag permissions #168 reroll #177

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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/views/issues/_tags.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% if @project.module_enabled?(:tags) %>
<% unless issue.tag_list.empty? %>
<div class="tags attribute">
<div class="label">
Expand All @@ -8,3 +9,4 @@
</div>
</div>
<% end %>
<% end %>
2 changes: 2 additions & 0 deletions app/views/issues/_tags_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% if @project.module_enabled?(:tags) && User.current.allowed_to?(:issue_edit_tags, @project) %>
<p><%= form.text_field :tag_list, :size => 60, :value => issue.tag_list.to_s %></p>

<%= javascript_tag "$('#issue_tag_list').tagit({
Expand All @@ -17,3 +18,4 @@
removeConfirmation: true,
showAutocompleteOnFocus: true,
});" %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/issues/_tags_sidebar.html.erb
Original file line number Diff line number Diff line change
@@ -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' %>
<h3><%= l :tags %></h3>
Expand Down
2 changes: 2 additions & 0 deletions app/views/wiki/_tags.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<% if @project.module_enabled?(:tags) -%>
<% unless page.tag_list.empty? %>
<b><%= l :tags %>:</b>
<%= 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 %>
2 changes: 2 additions & 0 deletions app/views/wiki/_tags_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% if @project.module_enabled?(:tags) && User.current.allowed_to?(:wiki_edit_tags, @project) %>
<p id="wiki_tags">
<%= label_tag l(:tags), nil, for: :wiki_page_tag_list %>
<%= text_field_tag 'wiki_page[tag_list]', page.tag_list.to_s, class: 'hol',
Expand All @@ -23,3 +24,4 @@
caseSensitive: false,
removeConfirmation: true,
});" %>
<% end %>
2 changes: 2 additions & 0 deletions app/views/wiki/_tags_sidebar.html.erb
Original file line number Diff line number Diff line change
@@ -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' %>
<h3><%= l :tags %></h3>
<%= render_sidebar_tags %>
<% end %>
<% end %>
84 changes: 84 additions & 0 deletions db/migrate/20170421205001_enable_for_all_projects_migration.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -26,6 +30,8 @@
issues_sort_order: 'asc'
},
partial: 'tags/settings'


end

Rails.application.config.after_initialize do
Expand Down