Skip to content

Commit

Permalink
#1133 Litmus test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
picman committed Jan 29, 2021
1 parent 6faed31 commit 49dbdcb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 41 deletions.
27 changes: 4 additions & 23 deletions lib/redmine_dmsf/lockable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,11 @@ def lock!(scope = :scope_exclusive, type = :type_write, expire = nil, owner = ni
l.entity_type = self.is_a?(DmsfFile) ? 0 : 1
l.lock_type = type
l.lock_scope = scope
###
#Rails.logger.info ">>> #{scope}"
###
l.user = User.current
l.expires_at = expire
l.dmsf_file_last_revision_id = self.last_revision.id if self.is_a?(DmsfFile)
l.owner = owner
l.save!
# reload
# locks.reload
# l.reload
l
end

Expand All @@ -92,7 +86,6 @@ def unlockable?
(existing.empty? || (self.dmsf_folder&.locked?)) ? false : true
end

#
# By using the path upwards, surely this would be quicker?
def locked_for_user?(args = nil)
return false unless locked?
Expand All @@ -102,18 +95,8 @@ def locked_for_user?(args = nil)
next if locks.empty?
locks.each do |lock|
next if lock.expired? # In case we're in between updates

# if lock.owner.present? && (lock.user.to_s != lock.owner)
# Rails.logger.info ">>> #{lock.user} X #{User.current} X #{lock.owner}"
# end

if lock.lock_scope == :scope_exclusive #&& b_shared.nil?
#return true if (lock.user&.id != User.current.id) || (lock.owner != (args ? args[:owner] : nil))
#if args && (args[:method] == 'put') && args[:owner].blank?
# return true if (lock.user&.id != User.current.id) #|| ((lock.owner != (args ? args[:owner] : nil)))
#else
if lock.lock_scope == :scope_exclusive
return true if (lock.user&.id != User.current.id) || ((lock.owner != (args ? args[:owner] : nil)))
#end
else
b_shared = true if b_shared.nil?
if b_shared && (lock.user&.id == User.current.id) && (lock.owner == (args ? args[:owner] : nil)) ||
Expand All @@ -122,24 +105,22 @@ def locked_for_user?(args = nil)
end
end
end
Rails.logger.info ">>> #{b_shared}"
return true if b_shared
end
Rails.logger.info ">>> false"
false
end

def unlock!(force_file_unlock_allowed = false, owner = nil)
raise DmsfLockError.new(l(:warning_file_not_locked)) unless self.locked?
existing = self.lock(true)
if existing.empty? || (!self.dmsf_folder.nil? && self.dmsf_folder.locked?) # If its empty its a folder that's locked (not root)
# 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))
else
# If entity is locked to you, you aren't the lock originator (or named in a shared lock) so deny action
# Unless of course you have the rights to force an unlock
raise DmsfLockError.new(l(:error_only_user_that_locked_file_can_unlock_it)) if (
self.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, self.project) && !force_file_unlock_allowed)

# Now we need to determine lock type and do the needful
if (existing.count == 1) && (existing[0].lock_scope == :exclusive)
existing[0].destroy
Expand All @@ -165,4 +146,4 @@ def unlock!(force_file_unlock_allowed = false, owner = nil)
end
true
end
end
end
19 changes: 1 addition & 18 deletions lib/redmine_dmsf/webdav/custom_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,7 @@ def initialize(app)
root_uri_path: path,
resource_class: RedmineDmsf::Webdav::ResourceProxy,
log_to: Rails.logger,
allow_unauthenticated_options_on_root: true,
namespaces: {
'http://apache.org/dav/props/' => 'd',
'http://ucb.openoffice.org/dav/props/' => 'd', # LibreOffice
'SAR:' => 'd', # Cyberduck
'http://webdav.org/neon/litmus/' => 'd', # Litmus
'http://example.com/neon/litmus/' => 'ns1',
'http://example.com/alpha' => 'ns2',
'http://example.com/beta' => 'ns3',
'http://example.com/gamma' => 'ns4',
'http://example.com/delta' => 'ns5',
'http://example.com/epsilon' => 'ns6',
'http://example.com/zeta' => 'ns7',
'http://example.com/eta' => 'ns8',
'http://example.com/theta' => 'ns9',
'http://example.com/iota' => 'ns10',
'http://example.com/kappa' => 'ns11'
}
allow_unauthenticated_options_on_root: true
)
end
}.to_app
Expand Down
10 changes: 10 additions & 0 deletions lib/redmine_dmsf/webdav/dmsf_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,16 @@ def lockdiscovery_xml
x
end

# Adds the given xml namespace to namespaces and returns the prefix
def add_namespace(ns, prefix = "unknown#{rand 65536}")
@__proxy.add_namespace ns, prefix
end

# returns the prefix for the given namespace, adding it if necessary
def prefix_for(ns_href)
@__proxy.prefix_for ns_href
end

private

# Prepare file for download using Rack functionality:
Expand Down
18 changes: 18 additions & 0 deletions lib/redmine_dmsf/webdav/resource_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ def set_property(element, value)
@resource_c.set_property element, value
end

# Adds the given xml namespace to namespaces and returns the prefix
def add_namespace(ns, prefix = "unknown#{rand 65536}")
if ns.present?
prefix = 'ns1'
2.step do |i|
break unless namespaces.has_value?(prefix)
prefix = "ns#{i}"
end
namespaces[ns] = prefix
prefix
end
end

# returns the prefix for the given namespace, adding it if necessary
def prefix_for(ns_href)
namespaces[ns_href] || add_namespace(ns_href)
end

private

def get_resource_class(path)
Expand Down

0 comments on commit 49dbdcb

Please sign in to comment.