class Tilia::DavAcl::Principal
Principal
class
This class is a representation of a simple principal
Many WebDAV specs require a user to show up in the directory structure.
This principal also has basic ACL settings, only allowing the principal access it's own principal.
Public Class Methods
Creates the principal object
@param IPrincipalBackend principal_backend @param array principal_properties
# File lib/tilia/dav_acl/principal.rb, line 33 def initialize(principal_backend, principal_properties = {}) fail Dav::Exception, 'The principal properties must at least contain the \'uri\' key' unless principal_properties.key?('uri') @principal_backend = principal_backend @principal_properties = principal_properties end
Public Instance Methods
Returns a list of ACE's for this node.
Each ACE has the following properties:
* 'privilege', a string such as {DAV:}read or {DAV:}write. These are currently the only supported privileges * 'principal', a url to the principal who owns the node * 'protected' (optional), indicating that this ACE is not allowed to be updated.
@return array
# File lib/tilia/dav_acl/principal.rb, line 178 def acl [ { 'privilege' => '{DAV:}read', 'principal' => '{DAV:}authenticated', 'protected' => true } ] end
Updates the ACL
This method will receive a list of new ACE's.
@param array acl @return void
# File lib/tilia/dav_acl/principal.rb, line 194 def acl=(_acl) fail Dav::Exception::MethodNotAllowed, 'Updating ACLs is not allowed here' end
Returns a list of alternative urls for a principal
This can for example be an email address, or ldap url.
@return array
# File lib/tilia/dav_acl/principal.rb, line 52 def alternate_uri_set uris = [] if @principal_properties.key?('{DAV:}alternate-URI-set') uris = @principal_properties['{DAV:}alternate-URI-set'] end if @principal_properties.key?('{http://sabredav.org/ns}email-address') uris << "mailto:#{@principal_properties['{http://sabredav.org/ns}email-address']}" end uris.uniq end
Returns the name of the user
@return string
# File lib/tilia/dav_acl/principal.rb, line 110 def displayname if @principal_properties.key?('{DAV:}displayname') return @principal_properties['{DAV:}displayname'] else return name end end
Returns a group principal
This must be a url to a principal, or null if there's no owner
@return string|null
# File lib/tilia/dav_acl/principal.rb, line 164 def group nil end
Returns the list of group members
If this principal is a group, this function should return all member principal uri's for the group.
@return array
# File lib/tilia/dav_acl/principal.rb, line 71 def group_member_set @principal_backend.group_member_set(@principal_properties['uri']) end
Sets a list of group members
If this principal is a group, this method sets all the group members. The list of members is always overwritten, never appended to.
This method should throw an exception if the members could not be set.
@param array group_members @return void
# File lib/tilia/dav_acl/principal.rb, line 94 def group_member_set=(group_members) @principal_backend.update_group_member_set(@principal_properties['uri'], group_members) end
Returns the list of groups this principal is member of
If this principal is a member of a (list of) groups, this function should return a list of principal uri's for it's members.
@return array
# File lib/tilia/dav_acl/principal.rb, line 81 def group_membership @principal_backend.group_membership(@principal_properties['uri']) end
Returns this principals name.
@return string
# File lib/tilia/dav_acl/principal.rb, line 101 def name uri = @principal_properties['uri'] name = Http::UrlUtil.split_path(uri)[1] name end
Returns the owner principal
This must be a url to a principal, or null if there's no owner
@return string|null
# File lib/tilia/dav_acl/principal.rb, line 155 def owner @principal_properties['uri'] end
Returns the full principal url
@return string
# File lib/tilia/dav_acl/principal.rb, line 43 def principal_url @principal_properties['uri'] end
Updates properties on this node.
This method received a PropPatch object, which contains all the information about the update.
To update specific properties, call the 'handle' method on this object. Read the PropPatch documentation for more information.
@param DAVPropPatch prop_patch
@return void
# File lib/tilia/dav_acl/principal.rb, line 143 def prop_patch(prop_patch) @principal_backend.update_principal( @principal_properties['uri'], prop_patch ) end
Returns a list of properties
@param array requested_properties @return array
# File lib/tilia/dav_acl/principal.rb, line 122 def properties(requested_properties) new_properties = {} requested_properties.each do |prop_name| if @principal_properties.key?(prop_name) new_properties[prop_name] = @principal_properties[prop_name] end end new_properties end
Returns the list of supported privileges for this node.
The returned data structure is a list of nested privileges. See Tilia::DavAcl::Plugin::getDefaultSupportedPrivilegeSet for a simple standard structure.
If null is returned from this method, the default privilege set is used, which is fine for most common usecases.
@return array|null
# File lib/tilia/dav_acl/principal.rb, line 208 def supported_privilege_set nil end