Class: Tilia::DavAcl::AbstractPrincipalCollection
- Inherits:
-
Tilia::Dav::Collection
- Object
- Tilia::Dav::Node
- Tilia::Dav::Collection
- Tilia::DavAcl::AbstractPrincipalCollection
- Includes:
- IPrincipalCollection
- Defined in:
- lib/tilia/dav_acl/abstract_principal_collection.rb
Overview
Principals Collection
This is a helper class that easily allows you to create a collection that has a childnode for every principal.
To use this class, simply implement the getChildForPrincipal method.
Direct Known Subclasses
CalDav::CalendarRoot, CardDav::AddressBookRoot, Fs::HomeCollection, PrincipalCollection
Instance Attribute Summary collapse
-
#disable_listing ⇒ Object
If this value is set to true, it effectively disables listing of users it still allows user to find other users if they have an exact url.
Instance Method Summary collapse
-
#child(name) ⇒ Object
Returns a child object, by its name.
-
#child_for_principal(principal_info) ⇒ Object
This method returns a node for a principal.
-
#children ⇒ Object
Return the list of users.
-
#find_by_uri(uri) ⇒ Object
Finds a principal by its URI.
-
#initialize(principal_backend, principal_prefix = 'principals') ⇒ AbstractPrincipalCollection
constructor
Creates the object.
-
#name ⇒ Object
Returns the name of this collection.
-
#search_principals(search_properties, test = 'allof') ⇒ Object
This method is used to search for principals matching a set of properties.
Methods included from Tilia::Dav::ICollection
#child_exists, #create_directory, #create_file
Methods included from Tilia::Dav::INode
#delete, #last_modified, #name=
Methods inherited from Tilia::Dav::Collection
#child_exists, #create_directory, #create_file
Methods inherited from Tilia::Dav::Node
#delete, #last_modified, #name=
Constructor Details
#initialize(principal_backend, principal_prefix = 'principals') ⇒ AbstractPrincipalCollection
Creates the object
This object must be passed the principal backend. This object will filter all principals from a specified prefix (principal_prefix). The default is ‘principals’, if your principals are stored in a different collection, override principal_prefix
42 43 44 45 46 |
# File 'lib/tilia/dav_acl/abstract_principal_collection.rb', line 42 def initialize(principal_backend, principal_prefix = 'principals') @disable_listing = false @principal_prefix = principal_prefix @principal_backend = principal_backend end |
Instance Attribute Details
#disable_listing ⇒ Object
If this value is set to true, it effectively disables listing of users it still allows user to find other users if they have an exact url.
30 31 32 |
# File 'lib/tilia/dav_acl/abstract_principal_collection.rb', line 30 def disable_listing @disable_listing end |
Instance Method Details
#child(name) ⇒ Object
Returns a child object, by its name.
86 87 88 89 90 |
# File 'lib/tilia/dav_acl/abstract_principal_collection.rb', line 86 def child(name) principal_info = @principal_backend.principal_by_path("#{@principal_prefix}/#{name}") fail Dav::Exception::NotFound, "Principal with name #{name} not found" unless principal_info child_for_principal(principal_info) end |
#child_for_principal(principal_info) ⇒ Object
This method returns a node for a principal.
The passed array contains principal information, and is guaranteed to at least contain a uri item. Other properties may or may not be supplied by the authentication backend.
56 57 |
# File 'lib/tilia/dav_acl/abstract_principal_collection.rb', line 56 def child_for_principal(principal_info) end |
#children ⇒ Object
Return the list of users
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tilia/dav_acl/abstract_principal_collection.rb', line 70 def children fail Dav::Exception::MethodNotAllowed, 'Listing members of this collection is disabled' if @disable_listing children = [] @principal_backend.principals_by_prefix(@principal_prefix).each do |principal_info| children << child_for_principal(principal_info) end children end |
#find_by_uri(uri) ⇒ Object
Finds a principal by its URI.
This method may receive any type of uri, but mailto: addresses will be the most common.
Implementation of this API is optional. It is currently used by the CalDAV system to find principals based on their email addresses. If this API is not implemented, some features may not work correctly.
This method must return a relative principal path, or null, if the principal was not found or you refuse to find it.
138 139 140 |
# File 'lib/tilia/dav_acl/abstract_principal_collection.rb', line 138 def find_by_uri(uri) @principal_backend.find_by_uri(uri, @principal_prefix) end |
#name ⇒ Object
Returns the name of this collection.
62 63 64 65 |
# File 'lib/tilia/dav_acl/abstract_principal_collection.rb', line 62 def name name = Http::UrlUtil.split_path(@principal_prefix)[1] name end |
#search_principals(search_properties, test = 'allof') ⇒ Object
This method is used to search for principals matching a set of properties.
This search is specifically used by RFC3744’s principal-property-search REPORT. You should at least allow searching on sabredav.org/ns}email-address.
The actual search should be a unicode-non-case-sensitive search. The keys in searchProperties are the WebDAV property names, while the values are the property values to search on.
By default, if multiple properties are submitted to this method, the various properties should be combined with ‘AND’. If test is set to ‘anyof’, it should be combined using ‘OR’.
This method should simply return a list of ‘child names’, which may be used to call self.child in the future.
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/tilia/dav_acl/abstract_principal_collection.rb', line 113 def search_principals(search_properties, test = 'allof') result = @principal_backend.search_principals(@principal_prefix, search_properties, test) r = [] result.each do |row| r << Http::UrlUtil.split_path(row)[1] end r end |