WIP
This commit is contained in:
@@ -24,6 +24,7 @@ require 'calligraphy/web_dav_request/propfind'
|
||||
require 'calligraphy/web_dav_request/proppatch'
|
||||
require 'calligraphy/web_dav_request/put'
|
||||
require 'calligraphy/web_dav_request/unlock'
|
||||
require 'calligraphy/web_dav_request/acl'
|
||||
|
||||
#:nodoc:
|
||||
module Calligraphy
|
||||
@@ -43,7 +44,7 @@ module Calligraphy
|
||||
mattr_accessor :allowed_http_methods
|
||||
@@allowed_http_methods = %w[
|
||||
options get put delete copy move
|
||||
mkcol propfind proppatch lock unlock
|
||||
mkcol propfind proppatch lock unlock acl
|
||||
]
|
||||
|
||||
# Proc responsible for returning the user's password, API key,
|
||||
@@ -70,7 +71,7 @@ module Calligraphy
|
||||
mattr_accessor :web_dav_actions
|
||||
@@web_dav_actions = %i[
|
||||
options get put delete copy move
|
||||
mkcol propfind proppatch lock unlock
|
||||
mkcol propfind proppatch lock unlock acl
|
||||
]
|
||||
|
||||
# Default way to set up Calligraphy.
|
||||
|
||||
15
lib/calligraphy/acl_utils.rb
Normal file
15
lib/calligraphy/acl_utils.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Calligraphy
|
||||
module AclUtils
|
||||
def parse_acl(xml)
|
||||
[].tap do |ace|
|
||||
xml.each do |node|
|
||||
next unless node.is_a? Nokogiri::XML::Element
|
||||
|
||||
ace << node
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,6 +5,13 @@ module ActionDispatch
|
||||
class Mapper
|
||||
#:nodoc:
|
||||
module HttpHelpers
|
||||
# Define a Calligraphy route that only recognizes HTTP ACL.
|
||||
# acl 'bacon', to: 'food#bacon'
|
||||
def acl(*args, &block)
|
||||
args = web_dav_args args
|
||||
map_method :acl, args, &block
|
||||
end
|
||||
|
||||
# Define a Calligraphy route that only recognizes HTTP COPY.
|
||||
# copy 'bacon', to: 'food#bacon'
|
||||
def copy(*args, &block)
|
||||
@@ -137,6 +144,7 @@ module ActionDispatch
|
||||
# PROPPATCH /photos/*resource
|
||||
# LOCK /photos/*resource
|
||||
# UNLOCK /photos/*resource
|
||||
# ACL /photos/*resource
|
||||
def calligraphy_resource(*resources, &block)
|
||||
options = resources.extract_options!.dup
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ module Calligraphy
|
||||
def unlock
|
||||
Calligraphy::Unlock.new(web_dav_request).execute
|
||||
end
|
||||
|
||||
def acl
|
||||
Calligraphy::Acl.new(web_dav_request).execute
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -596,11 +596,6 @@ module Calligraphy
|
||||
prop
|
||||
end
|
||||
|
||||
# def include(prop)
|
||||
# # TODO: Implement
|
||||
# prop
|
||||
# end
|
||||
|
||||
def lockdiscovery(prop)
|
||||
prop.content = fetch_lock_info
|
||||
prop
|
||||
|
||||
@@ -71,6 +71,7 @@ module Calligraphy
|
||||
# Used in OPTIONS requests.
|
||||
def dav_compliance
|
||||
compliance_classes = %w[1 2 3]
|
||||
compliance_classes.push 'access-control' if enable_access_control?
|
||||
compliance_classes.push 'extended-mkcol' if enable_extended_mkcol?
|
||||
|
||||
compliance_classes.join ', '
|
||||
@@ -84,6 +85,12 @@ module Calligraphy
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
# Responsible for returning a boolean indicating whether the resource
|
||||
# supports Access Control Protocol (see RFC3744).
|
||||
def enable_access_control?
|
||||
false
|
||||
end
|
||||
|
||||
# Responsible for returning a boolean indicating whether the resource
|
||||
# supports Extended MKCOL (see RFC5689).
|
||||
def enable_extended_mkcol?
|
||||
|
||||
111
lib/calligraphy/web_dav_request/acl.rb
Normal file
111
lib/calligraphy/web_dav_request/acl.rb
Normal file
@@ -0,0 +1,111 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Calligraphy
|
||||
# TODO: CHANGE DESCRIPTIONS
|
||||
# Responsible for processing instructions specified in the request body
|
||||
# to set and/or remove properties defined on the resource.
|
||||
class Acl < WebDavRequest
|
||||
include Calligraphy::XML::Utils
|
||||
# include Calligraphy::AclUtils
|
||||
|
||||
# Responsible for evaluating preconditions for the WebDAV request.
|
||||
def preconditions
|
||||
# conflict_preconditions
|
||||
# forbidden_preconditions
|
||||
end
|
||||
|
||||
# Executes the WebDAV request for a particular resource.
|
||||
def execute
|
||||
return :locked if @resource.locked_to_user? @headers
|
||||
|
||||
# The `acl` tag contains the request to modify the access control list
|
||||
# of a resource.
|
||||
xml = xml_for body: body, node: 'acl'
|
||||
return :bad_request if xml == :bad_request
|
||||
|
||||
ace = search_xml_for body: body, search: 'ace'
|
||||
|
||||
binding.pry
|
||||
@resource.acl ace
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Array with compact and first?
|
||||
def conflict_preconditions
|
||||
[
|
||||
no_ace_conflict,
|
||||
no_protected_ace_conflict,
|
||||
no_inherited_ace_conflict
|
||||
].compact.first
|
||||
end
|
||||
|
||||
def forbidden_preconditions
|
||||
[
|
||||
limited_number_of_aces,
|
||||
deny_before_grant,
|
||||
grant_only,
|
||||
no_invert,
|
||||
no_abstract,
|
||||
not_supported_priviledge,
|
||||
missing_required_principal,
|
||||
recognized_principal,
|
||||
allowed_principal
|
||||
].compact.first
|
||||
end
|
||||
|
||||
def build_error(response)
|
||||
{ error: response }
|
||||
end
|
||||
|
||||
def no_ace_conflict
|
||||
build_error 'no_ace_conflict'
|
||||
end
|
||||
|
||||
def no_protected_ace_conflict
|
||||
build_error 'no-protected-ace-conflict'
|
||||
end
|
||||
|
||||
def no_inherited_ace_conflict
|
||||
build_error 'no-inherited-ace-conflict'
|
||||
end
|
||||
|
||||
def limited_number_of_aces
|
||||
build_error 'limited-number-of-aces'
|
||||
end
|
||||
|
||||
def deny_before_grant
|
||||
build_error 'deny-before-grant'
|
||||
end
|
||||
|
||||
def grant_only
|
||||
build_error 'grant-only'
|
||||
end
|
||||
|
||||
def no_invert
|
||||
build_error 'no-invert'
|
||||
end
|
||||
|
||||
def no_abstract
|
||||
build_error 'no-abstract'
|
||||
end
|
||||
|
||||
def not_supported_privilege
|
||||
build_error 'not-supported-priviledge'
|
||||
end
|
||||
|
||||
def missing_required_principal
|
||||
build_error 'missing-required-principal'
|
||||
end
|
||||
|
||||
def recognized_principal
|
||||
build_error 'recognized-principal'
|
||||
end
|
||||
|
||||
def allowed_principal
|
||||
build_error 'allowed-principal'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,7 @@ Calligraphy.configure do |config|
|
||||
# HTTP verbs and URLs and WebDAV controller actions.
|
||||
# config.web_dav_actions = [
|
||||
# :options, :get, :put, :delete, :copy, :move,
|
||||
# :mkcol, :propfind, :proppatch, :lock, :unlock
|
||||
# :mkcol, :propfind, :proppatch, :lock, :unlock, :acl
|
||||
# ]
|
||||
|
||||
# HTTP methods allowed by the WebDavRequests controller.
|
||||
@@ -15,7 +15,7 @@ Calligraphy.configure do |config|
|
||||
# HTTP 405 (Method Not Allowed) response.
|
||||
# config.allowed_http_methods = %w(
|
||||
# options get put delete copy move
|
||||
# mkcol propfind proppatch lock unlock
|
||||
# mkcol propfind proppatch lock unlock acl
|
||||
# )
|
||||
|
||||
# If Digest Authentication is enabled by default. False by default.
|
||||
|
||||
Reference in New Issue
Block a user