mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-05-26 02:44:29 +00:00
Refactor the construction of DAV::acl and report owner acl
This commit is contained in:
parent
8b5b4b861d
commit
45e1222a9d
@ -852,6 +852,27 @@ EOQRY;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BuildACE - construct an XMLElement subtree for a DAV::ace
|
||||||
|
*/
|
||||||
|
function BuildACE( &$xmldoc, $privs, $principal ) {
|
||||||
|
$privilege_names = bits_to_privilege($privs);
|
||||||
|
$privileges = array();
|
||||||
|
foreach( $privilege_names AS $k ) {
|
||||||
|
$privilege = new XMLElement('privilege');
|
||||||
|
if ( isset($xmldoc) )
|
||||||
|
$xmldoc->NSElement($privilege,$k);
|
||||||
|
else
|
||||||
|
$privilege->NewElement($k);
|
||||||
|
$privileges[] = $privilege;
|
||||||
|
}
|
||||||
|
$ace = new XMLElement('ace', array(
|
||||||
|
new XMLElement('principal', $principal),
|
||||||
|
new XMLElement('grant', $privileges ) )
|
||||||
|
);
|
||||||
|
return $ace;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return ACL settings
|
* Return ACL settings
|
||||||
*/
|
*/
|
||||||
@ -863,20 +884,7 @@ EOQRY;
|
|||||||
if ( isset($this->collection->default_privileges) ) $default_privs = $this->collection->default_privileges;
|
if ( isset($this->collection->default_privileges) ) $default_privs = $this->collection->default_privileges;
|
||||||
|
|
||||||
$acl = array();
|
$acl = array();
|
||||||
$privilege_names = bits_to_privilege($default_privs);
|
$acl[] = $this->BuildACE($xmldoc, pow(2,25) - 1, new XMLElement('owner') );
|
||||||
$privileges = array();
|
|
||||||
foreach( $privilege_names AS $k ) {
|
|
||||||
$privilege = new XMLElement('privilege');
|
|
||||||
if ( isset($xmldoc) )
|
|
||||||
$xmldoc->NSElement($privilege,$k);
|
|
||||||
else
|
|
||||||
$privilege->NewElement($k);
|
|
||||||
$privileges[] = $privilege;
|
|
||||||
}
|
|
||||||
$acl[] = new XMLElement('ace', array(
|
|
||||||
new XMLElement('principal', new XMLElement('authenticated')),
|
|
||||||
new XMLElement('grant', $privileges ) )
|
|
||||||
);
|
|
||||||
|
|
||||||
$qry = new AwlQuery('SELECT dav_principal.dav_name, grants.* FROM grants JOIN dav_principal ON (to_principal=principal_id) WHERE by_collection = :collection_id OR by_principal = :principal_id ORDER BY by_collection',
|
$qry = new AwlQuery('SELECT dav_principal.dav_name, grants.* FROM grants JOIN dav_principal ON (to_principal=principal_id) WHERE by_collection = :collection_id OR by_principal = :principal_id ORDER BY by_collection',
|
||||||
array( ':collection_id' => $this->collection->collection_id, ':principal_id' => $this->principal->principal_id ) );
|
array( ':collection_id' => $this->collection->collection_id, ':principal_id' => $this->principal->principal_id ) );
|
||||||
@ -885,23 +893,12 @@ EOQRY;
|
|||||||
while( $grant = $qry->Fetch() ) {
|
while( $grant = $qry->Fetch() ) {
|
||||||
if ( !isset($by_collection) ) $by_collection = isset($grant->by_collection);
|
if ( !isset($by_collection) ) $by_collection = isset($grant->by_collection);
|
||||||
if ( $by_collection && !isset($grant->by_collection) ) break;
|
if ( $by_collection && !isset($grant->by_collection) ) break;
|
||||||
|
$acl[] = $this->BuildACE($xmldoc, $grant->privileges, $xmldoc->href(ConstructURL($grant->dav_name)) );
|
||||||
$privilege_names = bits_to_privilege($grant->privileges);
|
|
||||||
$privileges = array();
|
|
||||||
foreach( $privilege_names AS $k ) {
|
|
||||||
$privilege = new XMLElement('privilege');
|
|
||||||
if ( isset($xmldoc) )
|
|
||||||
$xmldoc->NSElement($privilege,$k);
|
|
||||||
else
|
|
||||||
$privilege->NewElement($k);
|
|
||||||
$privileges[] = $privilege;
|
|
||||||
}
|
|
||||||
$acl[] = new XMLElement('ace', array(
|
|
||||||
new XMLElement('principal', $xmldoc->href(ConstructURL($grant->dav_name))),
|
|
||||||
new XMLElement('grant', $privileges ) )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$acl[] = $this->BuildACE($xmldoc, $default_privs, new XMLElement('authenticated') );
|
||||||
|
|
||||||
return $acl;
|
return $acl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user