Implementing folder locking (Issue #14)
This commit is contained in:
parent
f120b04b30
commit
c9d6c32ba4
@ -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)
|
||||
|
||||
@ -107,9 +107,13 @@ class DmsfFilesController < ApplicationController
|
||||
@revision.copy_file_content(file_upload)
|
||||
end
|
||||
|
||||
if @file.locked?
|
||||
DmsfFileLock.file_lock_state(@file, false)
|
||||
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
|
||||
|
||||
@ -2,15 +2,33 @@
|
||||
|
||||
<div class="contextual">
|
||||
<% if User.current.allowed_to?(:folder_manipulation, @project) %>
|
||||
<% 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? %>
|
||||
<%= link_to("", {:action => "edit", :id => @project, :folder_id => @folder },
|
||||
:title => l(:link_edit, :title => h(@folder.title)), :class => "icon icon-edit") %>
|
||||
<% 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") %>
|
||||
<% 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") %>
|
||||
<% 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 %>
|
||||
</div>
|
||||
|
||||
@ -88,7 +106,25 @@
|
||||
:title => l(:link_edit, :title => h(subfolder.title))) %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div style="float: right">
|
||||
<div style="float: right; width: 44px;">
|
||||
<% 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))%>
|
||||
@ -157,9 +193,13 @@
|
||||
<div style="float: right; width: 44px;">
|
||||
<% unless file.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%>
|
||||
<% 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 %>
|
||||
<%= 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)}')",
|
||||
|
||||
@ -4,9 +4,13 @@
|
||||
<% 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)) %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= link_to_function(image_tag("lock.png", :plugin => "redmine_dmsf"),
|
||||
"manipulation_link('#{url_for(:action => 'lock', :id => @file, :current => request.url)}')",
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
|
||||
@ -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'
|
||||
|
||||
2
init.rb
2
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],
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user