Files remain locked after content editing

This commit is contained in:
karel.picman@lbcfree.net 2021-05-05 13:50:48 +02:00
parent 9dd2d08f78
commit 589531d9fa
2 changed files with 21 additions and 13 deletions

View File

@ -40,7 +40,7 @@
<% if locked %>
<%= context_menu_link l(:button_unlock), unlock_dmsf_files_path(id: dmsf_file), class: 'icon icon-unlock',
title: l(:title_locked_by_user, user: dmsf_file.locked_by),
disabled: !allowed || !unlockable %>
disabled: !unlockable %>
<% else %>
<%= context_menu_link l(:button_lock), lock_dmsf_files_path(id: dmsf_file), class: 'icon icon-lock',
disabled: !allowed %>

View File

@ -90,23 +90,25 @@ module RedmineDmsf
# By using the path upwards, surely this would be quicker?
def locked_for_user?(args = nil)
return false unless locked?
b_shared = nil
shared = nil
self.dmsf_path.each do |entity|
locks = entity.locks || entity.lock(false)
next if locks.empty?
locks.each do |lock|
next if lock.expired? # In case we're in between updates
owner = args[:owner] if args
owner ||= User.current&.login
if lock.lock_scope == :scope_exclusive
return true if (lock.user&.id != User.current.id) || ((lock.owner != (args ? args[:owner] : nil)))
return true if (lock.user&.id != User.current.id) || (lock.owner && (lock.owner != owner))
else
b_shared = true if b_shared.nil?
if b_shared && (lock.user&.id == User.current.id) && (lock.owner == (args ? args[:owner] : nil)) ||
shared = true if shared.nil?
if shared && (lock.user&.id == User.current.id) && (!lock.owner || (lock.owner == owner)) ||
(args && (args[:scope] == 'shared'))
b_shared = false
shared = false
end
end
end
return true if b_shared
return true if shared
end
false
end
@ -114,6 +116,7 @@ module RedmineDmsf
def unlock!(force_file_unlock_allowed = false, owner = nil)
raise DmsfLockError.new(l(:warning_file_not_locked)) unless self.locked?
existing = self.lock(true)
destroyed = false
# If its empty its a folder that's locked (not root)
if existing.empty? || (!self.dmsf_folder.nil? && self.dmsf_folder.locked?)
raise DmsfLockError.new(l(:error_unlock_parent_locked))
@ -125,26 +128,31 @@ module RedmineDmsf
# Now we need to determine lock type and do the needful
if (existing.count == 1) && (existing[0].lock_scope == :exclusive)
existing[0].destroy
destroyed = true
else
b_destroyed = false
existing.each do |lock|
owner = User.current&.login if lock.owner && owner.nil?
if ((lock.user&.id == User.current.id) && (lock.owner == owner)) || User.current.admin?
lock.destroy
b_destroyed = true
destroyed = true
break
end
end
# At first it was going to be allowed for someone with force_file_unlock to delete all shared by default
# Instead, they by default remove themselves from shared lock, and everyone from shared lock if they're not
# on said lock
if !b_destroyed && (User.current.allowed_to?(:force_file_unlock, self.project) || force_file_unlock_allowed)
if !destroyed && (User.current.allowed_to?(:force_file_unlock, self.project) || force_file_unlock_allowed)
locks.delete_all
destroyed = true
end
end
end
reload
locks.reload
if destroyed
reload
locks.reload
end
destroyed
end
true
end
end