Files remain locked after content editing

This commit is contained in:
karel.picman@lbcfree.net 2021-05-06 10:31:29 +02:00
commit d19586a8d8
3 changed files with 20 additions and 20 deletions

View File

@ -97,12 +97,12 @@ module RedmineDmsf
locks.each do |lock| locks.each do |lock|
next if lock.expired? # In case we're in between updates next if lock.expired? # In case we're in between updates
owner = args[:owner] if args owner = args[:owner] if args
owner ||= User.current&.login owner ||= User.current&.login if lock.owner
if lock.lock_scope == :scope_exclusive if lock.lock_scope == :scope_exclusive
return true if (lock.user&.id != User.current.id) || (lock.owner && (lock.owner != owner)) return true if (lock.user&.id != User.current.id) || (lock.owner != owner)
else else
shared = true if shared.nil? shared = true if shared.nil?
if shared && (lock.user&.id == User.current.id) && (!lock.owner || (lock.owner == owner)) || if shared && (lock.user&.id == User.current.id) && (lock.owner == owner) ||
(args && (args[:scope] == 'shared')) (args && (args[:scope] == 'shared'))
shared = false shared = false
end end

View File

@ -479,6 +479,7 @@ module RedmineDmsf
return super(token) return super(token)
end end
if token.nil? || token.empty? || (token == '<(null)>') || User.current.anonymous? if token.nil? || token.empty? || (token == '<(null)>') || User.current.anonymous?
Rails.logger.info ">>> bad token 2: #{token}"
BadRequest BadRequest
else else
if token =~ /([a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12})/ if token =~ /([a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12})/
@ -486,21 +487,20 @@ module RedmineDmsf
else else
return BadRequest return BadRequest
end end
begin l = DmsfLock.find_by_uuid(token)
l = DmsfLock.find(token) unless l
# Additional case: if a user tries to unlock the file instead of the folder that's locked return NoContent
# This should throw forbidden as only the lock at level initiated should be unlocked end
entity = file || folder # Additional case: if a user tries to unlock the file instead of the folder that's locked
return NoContent unless entity&.locked? # This should throw forbidden as only the lock at level initiated should be unlocked
l_entity = l.file || l.folder entity = file || folder
if l_entity != entity return NoContent unless entity&.locked?
Forbidden l_entity = l.file || l.folder
else if l_entity != entity
entity.unlock! Forbidden
NoContent else
end entity.unlock!
rescue NoContent
BadRequest
end end
end end
end end

View File

@ -58,7 +58,7 @@ class DmsfWebdavUnlockTest < RedmineDmsf::Test::IntegrationTest
assert_response :success assert_response :success
process :unlock, "/dmsf/webdav/#{@file2.project.identifier}/#{@file2.name}", params: nil, process :unlock, "/dmsf/webdav/#{@file2.project.identifier}/#{@file2.name}", params: nil,
headers: @admin.merge!({ HTTP_DEPTH: 'infinity', HTTP_TIMEOUT: 'Infinite', HTTP_LOCK_TOKEN: l.uuid }) headers: @admin.merge!({ HTTP_DEPTH: 'infinity', HTTP_TIMEOUT: 'Infinite', HTTP_LOCK_TOKEN: l.uuid })
assert_response :bad_request assert_response :no_content
end end
def test_unlock_folder_wrong_path def test_unlock_folder_wrong_path
@ -89,7 +89,7 @@ class DmsfWebdavUnlockTest < RedmineDmsf::Test::IntegrationTest
process :unlock, "/dmsf/webdav/#{@folder2.project.identifier}/#{@folder2.dmsf_folder.title}/#{@folder2.title}", process :unlock, "/dmsf/webdav/#{@folder2.project.identifier}/#{@folder2.dmsf_folder.title}/#{@folder2.title}",
params: nil, params: nil,
headers: @jsmith.merge!({ HTTP_DEPTH: 'infinity', HTTP_TIMEOUT: 'Infinite', HTTP_LOCK_TOKEN: l.uuid }) headers: @jsmith.merge!({ HTTP_DEPTH: 'infinity', HTTP_TIMEOUT: 'Infinite', HTTP_LOCK_TOKEN: l.uuid })
assert_response :bad_request assert_response :no_content
end end
def test_unlock_file_in_subproject def test_unlock_file_in_subproject