From 28d7b8d07a4abd284505b347719c0fad15be12d3 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Mon, 9 Dec 2013 15:11:25 +0100 Subject: [PATCH] #187 - Approval workflow permissions --- app/controllers/dmsf_controller.rb | 1 + app/controllers/dmsf_workflows_controller.rb | 2 +- app/views/dmsf/show.html.erb | 142 +++++++++---------- init.rb | 32 +++-- 4 files changed, 92 insertions(+), 85 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index a6abf645..494c1613 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -35,6 +35,7 @@ class DmsfController < ApplicationController def show @folder_manipulation_allowed = User.current.allowed_to?(:folder_manipulation, @project) @file_manipulation_allowed = User.current.allowed_to?(:folder_manipulation, @project) + @force_file_unlock_allowed = User.current.allowed_to?(:force_file_unlock, @project) unless @folder @subfolders = @project.dmsf_folders.visible diff --git a/app/controllers/dmsf_workflows_controller.rb b/app/controllers/dmsf_workflows_controller.rb index 31001b88..1e8aae9c 100644 --- a/app/controllers/dmsf_workflows_controller.rb +++ b/app/controllers/dmsf_workflows_controller.rb @@ -23,7 +23,7 @@ class DmsfWorkflowsController < ApplicationController before_filter :find_workflow, :except => [:create, :new, :index, :assign, :assignment] before_filter :find_project, :except => [:start] before_filter :authorize_global - before_filter :authorize_custom, :except => [:assignment, :start, :new_action] + before_filter :authorize_custom, :except => [:assignment, :start, :new_action] def index if @project diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index e5fcfed5..343a414c 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -134,20 +134,18 @@ <%= h(subfolder.user) %> - <% if @folder_manipulation_allowed %> - <% if User.current.allowed_to?(:file_approval, @project) %> -
- <% if subfolder.notification %> - <%= link_to_function(image_tag('notify.png', :plugin => :redmine_dmsf), - "manipulation_link('#{url_for(:action => 'notify_deactivate', :id => @project, :folder_id => subfolder)}')", - :title => l(:title_notifications_active_deactivate)) %> - <% else %> - <%= link_to_function(image_tag('notifynot.png', :plugin => :redmine_dmsf), - "manipulation_link('#{url_for(:action => 'notify_activate', :id => @project, :folder_id => subfolder)}')", - :title => l(:title_notifications_not_active_activate)) %> - <% end %> -
- <% end %> + <% if @folder_manipulation_allowed %> +
+ <% if subfolder.notification %> + <%= link_to_function(image_tag('notify.png', :plugin => :redmine_dmsf), + "manipulation_link('#{url_for(:action => 'notify_deactivate', :id => @project, :folder_id => subfolder)}')", + :title => l(:title_notifications_active_deactivate)) %> + <% else %> + <%= link_to_function(image_tag('notifynot.png', :plugin => :redmine_dmsf), + "manipulation_link('#{url_for(:action => 'notify_activate', :id => @project, :folder_id => subfolder)}')", + :title => l(:title_notifications_not_active_activate)) %> + <% end %> +
<%= link_to(image_tag('edit.png', :class =>'detail_icon'), @@ -234,74 +232,72 @@ <%= h(file.last_revision.user) %> - <% if @file_manipulation_allowed %> - <% if User.current.allowed_to?(:file_approval, @project) %> -
- <% if file.notification %> - <%= link_to_function(image_tag('notify.png', :plugin => :redmine_dmsf), - "manipulation_link('#{url_for(:controller => 'dmsf_files', :action => 'notify_deactivate', :id => file)}')", - :title => l(:title_notifications_active_deactivate)) %> - <% else %> - <%= link_to_function(image_tag('notifynot.png', :plugin => :redmine_dmsf), - "manipulation_link('#{url_for(:controller => 'dmsf_files', :action => 'notify_activate', :id => file)}')", - :title => l(:title_notifications_not_active_activate)) %> - <% end %> - <% case file.last_revision.workflow %> - <% when DmsfWorkflow::STATE_WAITING_FOR_APPROVAL %> - <% if wf %> - <% assignments = wf.next_assignments(file.last_revision.id) %> - <% index = assignments.find_index{|assignment| assignment.user_id == User.current.id} if assignments %> - <% if index %> - <%= link_to( - image_tag('waiting_for_approval.png', :plugin => :redmine_dmsf), - action_dmsf_workflow_path( - :project_id => @project.id, - :id => wf.id, - :dmsf_workflow_step_assignment_id => assignments[index].id, - :dmsf_file_revision_id => file.last_revision.id), - :title => l(:title_waiting_for_approval), - :remote => true) %> - <% else %> - <%= image_tag('waiting_for_approval.png', :title => "#{l(:label_dmsf_wokflow_action_approve)} #{l(:label_dmsf_wokflow_action_reject)} #{l(:label_dmsf_wokflow_action_delegate)}", :plugin => :redmine_dmsf) %> - <% end %> + <% if @file_manipulation_allowed %> +
+ <% if file.notification %> + <%= link_to_function(image_tag('notify.png', :plugin => :redmine_dmsf), + "manipulation_link('#{url_for(:controller => 'dmsf_files', :action => 'notify_deactivate', :id => file)}')", + :title => l(:title_notifications_active_deactivate)) %> + <% else %> + <%= link_to_function(image_tag('notifynot.png', :plugin => :redmine_dmsf), + "manipulation_link('#{url_for(:controller => 'dmsf_files', :action => 'notify_activate', :id => file)}')", + :title => l(:title_notifications_not_active_activate)) %> + <% end %> + <% case file.last_revision.workflow %> + <% when DmsfWorkflow::STATE_WAITING_FOR_APPROVAL %> + <% if wf %> + <% assignments = wf.next_assignments(file.last_revision.id) %> + <% index = assignments.find_index{|assignment| assignment.user_id == User.current.id} if assignments %> + <% if index %> + <%= link_to( + image_tag('waiting_for_approval.png', :plugin => :redmine_dmsf), + action_dmsf_workflow_path( + :project_id => @project.id, + :id => wf.id, + :dmsf_workflow_step_assignment_id => assignments[index].id, + :dmsf_file_revision_id => file.last_revision.id), + :title => l(:title_waiting_for_approval), + :remote => true) %> <% else %> <%= image_tag('waiting_for_approval.png', :title => "#{l(:label_dmsf_wokflow_action_approve)} #{l(:label_dmsf_wokflow_action_reject)} #{l(:label_dmsf_wokflow_action_delegate)}", :plugin => :redmine_dmsf) %> <% end %> - <% when DmsfWorkflow::STATE_APPROVED %> - <%= image_tag('approved.png', :title => l(:title_approved), :plugin => :redmine_dmsf) %> - <% when DmsfWorkflow::STATE_ASSIGNED %> - <% if User.current && (file.last_revision.dmsf_workflow_assigned_by == User.current.id) && wf %> - <%= link_to_function(image_tag('assigned.png', :plugin => :redmine_dmsf), - "manipulation_link('#{start_dmsf_workflow_path( - :id => file.last_revision.dmsf_workflow_id, - :dmsf_file_revision_id => file.last_revision.id)}')", - :title => l(:label_dmsf_wokflow_action_start)) %> - <% else %> - <%= image_tag('assigned.png', :title => l(:label_dmsf_wokflow_action_start), :plugin => :redmine_dmsf) %> - <% end %> - <% when DmsfWorkflow::STATE_REJECTED %> - <%= image_tag('rejected.png', :title => l(:title_rejected), :plugin => :redmine_dmsf) %> - <% else %> - <% if workflows_available %> - <%= link_to( - image_tag('none.png', :plugin => :redmine_dmsf), - assign_dmsf_workflow_path( - :project_id => @project.id, - :dmsf_file_revision_id => file.last_revision.id), - :title => l(:label_dmsf_wokflow_action_assign), - :remote => true) %> - <% end %> - <% end %> -
- <% end %> + <% else %> + <%= image_tag('waiting_for_approval.png', :title => "#{l(:label_dmsf_wokflow_action_approve)} #{l(:label_dmsf_wokflow_action_reject)} #{l(:label_dmsf_wokflow_action_delegate)}", :plugin => :redmine_dmsf) %> + <% end %> + <% when DmsfWorkflow::STATE_APPROVED %> + <%= image_tag('approved.png', :title => l(:title_approved), :plugin => :redmine_dmsf) %> + <% when DmsfWorkflow::STATE_ASSIGNED %> + <% if User.current && (file.last_revision.dmsf_workflow_assigned_by == User.current.id) && wf %> + <%= link_to_function(image_tag('assigned.png', :plugin => :redmine_dmsf), + "manipulation_link('#{start_dmsf_workflow_path( + :id => file.last_revision.dmsf_workflow_id, + :dmsf_file_revision_id => file.last_revision.id)}')", + :title => l(:label_dmsf_wokflow_action_start)) %> + <% else %> + <%= image_tag('assigned.png', :title => l(:label_dmsf_wokflow_action_start), :plugin => :redmine_dmsf) %> + <% end %> + <% when DmsfWorkflow::STATE_REJECTED %> + <%= image_tag('rejected.png', :title => l(:title_rejected), :plugin => :redmine_dmsf) %> + <% else %> + <% if workflows_available %> + <%= link_to( + image_tag('none.png', :plugin => :redmine_dmsf), + assign_dmsf_workflow_path( + :project_id => @project.id, + :dmsf_file_revision_id => file.last_revision.id), + :title => l(:label_dmsf_wokflow_action_assign), + :remote => true) %> + <% end %> + <% end %> +
<%= link_to(image_tag('filedetails.png', :plugin => :redmine_dmsf, :class =>'detail_icon'), {:controller => 'dmsf_files', :action => :show, :id => file }, :title => l(:link_details, :title =>h(file.last_revision.title))) %>
-
- <% unless locked_for_user && !User.current.allowed_to?(:force_file_unlock, @project)%> +
+ <% if !locked_for_user || @force_file_unlock_allowed %> <% if locked %> <% if file.unlockable? %> <%= link_to_function(image_tag('unlock.png', :plugin => :redmine_dmsf), diff --git a/init.rb b/init.rb index 5739edb8..67c5d752 100644 --- a/init.rb +++ b/init.rb @@ -50,17 +50,27 @@ Redmine::Plugin.register :redmine_dmsf do activity_provider :dmsf_files, :class_name => 'DmsfFileRevision', :default => true project_module :dmsf do - permission :view_dmsf_folders, {:dmsf => [:show], :dmsf_folders_copy => [:new, :copy_to, :move_to]}, :read => true - permission :user_preferences, {:dmsf_state => [:user_pref_save]} - permission :view_dmsf_files, {:dmsf => [:entries_operation, :entries_email], - :dmsf_files => [:show], :dmsf_files_copy => [:new, :create, :move]}, :read => true - permission :folder_manipulation, {:dmsf => [:new, :create, :delete, :edit, :save, :edit_root, :save_root, :lock, :unlock]} - permission :file_manipulation, {:dmsf_files => [:create_revision, :delete, :lock, :unlock], - :dmsf_upload => [:upload_files, :upload_file, :commit_files]} - permission :file_approval, {:dmsf_files => [:delete_revision, :notify_activate, :notify_deactivate], - :dmsf => [:notify_activate, :notify_deactivate], - :dmsf_workflows => [:index, :new, :create, :destroy, :edit, :add_step, :remove_step, :reorder_steps, :update, :start, :assign, :assignment, :action, :new_action, :log, :autocomplete_for_user]} - permission :force_file_unlock, {} + permission :view_dmsf_folders, + {:dmsf => [:show], + :dmsf_folders_copy => [:new, :copy_to, :move_to]}, + :read => true + permission :user_preferences, + {:dmsf_state => [:user_pref_save]} + permission :view_dmsf_files, + {:dmsf => [:entries_operation, :entries_email], + :dmsf_files => [:show], + :dmsf_files_copy => [:new, :create, :move], + :dmsf_workflows => [:log]}, + :read => true + permission :folder_manipulation, + {:dmsf => [:new, :create, :delete, :edit, :save, :edit_root, :save_root, :lock, :unlock, :notify_activate, :notify_deactivate]} + permission :file_manipulation, + {:dmsf_files => [:create_revision, :delete, :lock, :unlock, :delete_revision, :notify_activate, :notify_deactivate], + :dmsf_upload => [:upload_files, :upload_file, :commit_files], + :dmsf_workflows => [:action, :new_action, :autocomplete_for_user, :start, :assign, :assignment]} + permission :manage_workflows, + {:dmsf_workflows => [:index, :new, :create, :destroy, :edit, :add_step, :remove_step, :reorder_steps, :update]} + permission :force_file_unlock, {} end # Administration menu extension