diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 4dce49e0..fd1f6edd 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -20,7 +20,7 @@ class DmsfController < ApplicationController unloadable before_filter :find_project - before_filter :authorize, :except => [:delete_entries] + before_filter :authorize, :except => [:delete_entries] before_filter :find_folder, :except => [:new, :create, :edit_root, :save_root] before_filter :find_parent, :only => [:new, :create] @@ -28,8 +28,8 @@ class DmsfController < ApplicationController def show if @folder.nil? - @subfolders = @project.dmsf_folders.visible #DmsfFolder.project_root_folders(@project) - @files = @project.dmsf_files.visible #DmsfFile.project_root_files(@project) + @subfolders = @project.dmsf_folders.visible + @files = @project.dmsf_files.visible else @subfolders = @folder.subfolders.visible @files = @folder.files.visible @@ -225,6 +225,39 @@ class DmsfController < ApplicationController {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder} end + + def lock + if @folder.nil? + flash[:warning] = l(:warning_foler_unlockable) + elsif @folder.locked? + flash[:warning] = l(:warning_folder_already_locked) + else + @folder.lock! + flash[:notice] = l(:notice_folder_locked) + end + redirect_to params[:current] ? params[:current] : + {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder} + end + + def unlock + if @folder.nil? + flash[:warning] = l(:warning_foler_unlockable) + elsif !@folder.locked? + flash[:warning] = l(:warning_folder_not_locked) + else + if @folder.locks[0].user == User.current || User.current.allowed_to?(:force_file_unlock, @project) + @folder.unlock! + flash[:notice] = l(:notice_folder_unlocked) + else + flash[:error] = l(:error_only_user_that_locked_folder_can_unlock_it) + end + end + redirect_to params[:current] ? params[:current] : + {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder} + end + + + private def log_activity(file, action) diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index a8ad98d7..a13c7979 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -107,9 +107,13 @@ class DmsfFilesController < ApplicationController @revision.copy_file_content(file_upload) end - if @file.locked? - DmsfFileLock.file_lock_state(@file, false) - flash[:notice] = l(:notice_file_unlocked) + ", " + if @file.locked? && !@file.locks.empty? + begin + @file.unlock! + flash[:notice] = l(:notice_file_unlocked) + ", " + rescue + #Nothing to do here + end end @file.save! @file.reload diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index f7dd94cd..277fa2fd 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -2,15 +2,33 @@
<% if User.current.allowed_to?(:folder_manipulation, @project) %> + <% if !@folder.nil? && (!@folder.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @project)) %> + <% if @folder.locked? %> + <% unless @folder.unlockable? %> + <%= image_tag("locked.png", :plugin => :redmine_dmsf, :title => l(:title_folder_parent_locked, :name => @folder.folder.lock.reverse[0].folder.title)) unless @folder.nil?%> + <% else %> + <%= link_to_function(image_tag("unlock.png", :plugin => "redmine_dmsf"), + "manipulation_link('#{url_for(:action => 'unlock', :id => @project, :folder_id => @folder, :current => request.url)}')", + :title => l(:title_unlock_folder)) unless @folder.nil?%> + <% end %> + <% else %> + <%= link_to_function(image_tag("lock.png", :plugin => "redmine_dmsf"), + "manipulation_link('#{url_for(:action => 'lock', :id => @project, :folder_id => @folder, :current => request.url)}')", + :title => l(:title_lock_folder)) unless @folder.nil?%> + <% end %> + <% end %> <% if @folder.nil? %> +   <%= link_to("", {:action => "edit_root", :id => @project}, - :title => l(:link_edit, :title => l(:link_documents)), :class => "icon icon-edit") %>   - <% else @folder.nil? %> + :title => l(:link_edit, :title => l(:link_documents)), :class => "icon icon-edit") %> + <% elsif (!@folder.nil? && !@folder.locked_for_user? ) %> +   <%= link_to("", {:action => "edit", :id => @project, :folder_id => @folder }, - :title => l(:link_edit, :title => h(@folder.title)), :class => "icon icon-edit") %>   + :title => l(:link_edit, :title => h(@folder.title)), :class => "icon icon-edit") %> <% end %> +   <%= link_to("", {:action => "new", :id => @project, :parent_id => @folder }, - :title => l(:link_create_folder), :class => "icon icon-add") %> + :title => l(:link_create_folder), :class => "icon icon-add") unless (!@folder.nil? && @folder.locked_for_user?) %> <% end %>
@@ -88,7 +106,25 @@ :title => l(:link_edit, :title => h(subfolder.title))) %> <% end %> -
+
+ <% unless subfolder.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> + <% if subfolder.locked? %> + <% if subfolder.unlockable? %> + <%= link_to_function(image_tag("unlock.png", :plugin => :redmine_dmsf), + "manipulation_link('#{url_for(:controller => "dmsf", :action => 'unlock', + :id => @project, :folder_id => subfolder)}')", + :title => l(:title_unlock_file))%> + <% else %> + <%= image_tag("locked.png", :plugin => :redmine_dmsf, :title => l(:title_folder_parent_locked, :name => subfolder.folder.lock.reverse[0].folder.title)) %> + <% end %> + <% else %> + <%= link_to_function(image_tag("lock.png", :plugin => :redmine_dmsf), + "manipulation_link('#{url_for(:controller => "dmsf", :action => 'lock', + :id => @project, :folder_id => subfolder)}')", + :title => l(:title_lock_file)) %> + <% end %> +   + <% end %> <%= link_to_function(image_tag("delete.png", :plugin => :redmine_dmsf), "confirmation_link('#{url_for(:action => 'delete', :id => @project, :folder_id => @folder, :delete_folder_id => subfolder)}')", :title => l(:title_delete))%> @@ -156,15 +192,19 @@
<% unless file.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> - <% if file.locked? %> + <% if file.locked? %> + <% if file.unlockable? %> <%= link_to_function(image_tag("unlock.png", :plugin => :redmine_dmsf), "manipulation_link('#{url_for(:controller => "dmsf_files", :action => 'unlock', :id => file)}')", - :title => l(:title_unlock_file)) %> - <% else %> + :title => l(:title_unlock_file))%> + <% else %> + <%= image_tag("locked.png", :plugin => :redmine_dmsf, :title => l(:title_file_parent_locked, :name => file.folder.lock.reverse[0].folder.title)) %> + <% end%> + <% else %> <%= link_to_function(image_tag("lock.png", :plugin => :redmine_dmsf), "manipulation_link('#{url_for(:controller => "dmsf_files", :action => 'lock', :id => file)}')", :title => l(:title_lock_file)) %> - <% end %> + <% end %>   <% end %> <% if User.current.allowed_to?(:file_manipulation, @project) && !file.locked_for_user? %> diff --git a/app/views/dmsf_files/show.html.erb b/app/views/dmsf_files/show.html.erb index 94dfeef3..8213e2fb 100644 --- a/app/views/dmsf_files/show.html.erb +++ b/app/views/dmsf_files/show.html.erb @@ -4,14 +4,18 @@ <% if User.current.allowed_to?(:file_manipulation, @project) %> <% unless @file.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> <% if @file.locked? %> + <% unless @file.unlockable? %> + <%= image_tag("locked.png", :plugin => :redmine_dmsf, :title => l(:title_file_parent_locked, :name => @file.lock[0].folder.title)) %> + <% else %> <%= link_to_function(image_tag("unlock.png", :plugin => "redmine_dmsf"), "manipulation_link('#{url_for(:action => 'unlock', :id => @file, :current => request.url)}')", :title => l(:title_unlock_file)) %> - <% else %> + <% end %> + <% else %> <%= link_to_function(image_tag("lock.png", :plugin => "redmine_dmsf"), "manipulation_link('#{url_for(:action => 'lock', :id => @file, :current => request.url)}')", :title => l(:title_lock_file)) %> - <% end %> + <% end %> <% end %> <% if User.current.allowed_to?(:file_manipulation, @project) && !@file.locked_for_user? %>   diff --git a/config/locales/en.yml b/config/locales/en.yml index 67ae45d0..b1b5f52d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -192,3 +192,15 @@ en: :note_webdav: "Webdav once enabled can be found at http://.../dmsf/webdav/" :label_webdav: "Webdav functionality" :label_dmsf_plural: "Copy DMSF files and folders (%{files} files in %{folders} folders)" + + :warning_folder_already_locked: "This folder is already locked" + :notice_folder_locked: "The folder was successfully locked" + :warning_folder_not_locked: "Unfortunately, the folder could not be locked" + :notice_folder_unlocked: "The folder was successfully unlocked" + :error_only_user_that_locked_folder_can_unlock_it: "You are not authorised to unlock this folder" + :title_folder_parent_locked: "Parent folder %{name} is locked" + :title_file_parent_locked: "Parent folder %{name} is locked" + :title_unlock_folder: "Unlock to allow changes for other members" + :title_lock_folder: "Lock to prevent changes for other members" + + diff --git a/config/routes.rb b/config/routes.rb index d09f6280..5d00a4c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,8 @@ RedmineApp::Application.routes.draw do post '/projects/:id/dmsf/entries', :controller => 'dmsf', :action => 'entries_operation' post '/projects/:id/dmsf/entries/delete', :controller => 'dmsf', :action => 'delete_entries' post '/projects/:id/dmsf/entries/email', :controller => 'dmsf', :action => 'entries_email' + post '/projects/:id/dmsf/lock', :controller => 'dmsf', :action => 'lock' + post '/projects/:id/dmsf/unlock', :controller => 'dmsf', :action => 'unlock' get '/projects/:id/dmsf/', :controller => 'dmsf', :action => 'show' get '/projects/:id/dmsf/new', :controller => 'dmsf', :action => 'new' get '/projects/:id/dmsf/edit', :controller=> 'dmsf', :action => 'edit' diff --git a/init.rb b/init.rb index 1c1fe69f..be5ef4af 100644 --- a/init.rb +++ b/init.rb @@ -52,7 +52,7 @@ Redmine::Plugin.register :redmine_dmsf do 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]} - permission :folder_manipulation, {:dmsf => [:new, :create, :delete, :edit, :save, :edit_root, :save_root]} + 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], diff --git a/lib/redmine_dmsf/lockable.rb b/lib/redmine_dmsf/lockable.rb index 9e94db5f..3b0a7d9e 100644 --- a/lib/redmine_dmsf/lockable.rb +++ b/lib/redmine_dmsf/lockable.rb @@ -45,6 +45,13 @@ module RedmineDmsf return l end + def unlockable? + return false unless self.locked? + existing = self.lock(true) + return false if existing.empty? || (!self.folder.nil? && self.folder.locked?) #If its empty its a folder thats locked (not root) + true + end + # # By using the path upwards, surely this would be quicker? def locked_for_user?(tree = true)