On Tue, 2010-04-20 at 17:47 +0200, Sebastian Gau? wrote:
> Hi,
>
> i am currently working on exporting all the collections a user can
> access (read or read+write). I want to get a list that shows the
> dav_name of all collectios a given user_no/pricipal_id can access, and
> if they have just read or read+write access.
>
> Any ideas how to get this done via SQL Query? If any better solution
> exists I would also bei open to it ;)
Something like this should do what you want:
SELECT dav_name,
bits_to_privilege(path_privs($PRINCIPAL_ID, dav_name, 2))
FROM collection
WHERE ( ( path_privs($PRINCIPAL_ID, dav_name, 2)
& privilege_to_bits( ARRAY[ 'DAV::read' ] ) )
= privilege_to_bits( ARRAY[ 'DAV::read' ] ) );
Explanation:
Insert your pre-loved principal_id into this in both places in place of
$PRINCIPAL_ID :-)
privilege_to_bits() converts an array of privilege strings into a
bitmask. Maybe specify the array as ARRAY[ 'DAV::read', 'DAV::write' ]
if you think you have some with write access but not read(!) Note that
privilege_to_bits( ARRAY[ 'DAV::read' ] ) returns a set of three
privileges, so we have to test that "(A & B) = B" in order to confirm
they really have read privileges, and not just read-free-busy.
bits_to_privilege() converts a bitmask of privileges to a human-readable
comma-separated list of privilege names.
path_privs( principal_id, pathname, depth ) returns a bitmask of the
expanded privileges for the identified principal in respect of
'pathname'. The third 'depth' parameter is a shortcut for how deeply it
searches through layers of groups which are members of groups, which are
members of groups, and '2' is more than enough for almost everyone (it's
also the system-wide default).
Regards,
Andrew.
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
You have a strong appeal for members of your own sex.
------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20100421/0fc1971e/attachment.pgp>
-------------- next part --------------
> Hi,
>
> i am currently working on exporting all the collections a user can
> access (read or read+write). I want to get a list that shows the
> dav_name of all collectios a given user_no/pricipal_id can access, and
> if they have just read or read+write access.
>
> Any ideas how to get this done via SQL Query? If any better solution
> exists I would also bei open to it ;)
Something like this should do what you want:
SELECT dav_name,
bits_to_privilege(path_privs($PRINCIPAL_ID, dav_name, 2))
FROM collection
WHERE ( ( path_privs($PRINCIPAL_ID, dav_name, 2)
& privilege_to_bits( ARRAY[ 'DAV::read' ] ) )
= privilege_to_bits( ARRAY[ 'DAV::read' ] ) );
Explanation:
Insert your pre-loved principal_id into this in both places in place of
$PRINCIPAL_ID :-)
privilege_to_bits() converts an array of privilege strings into a
bitmask. Maybe specify the array as ARRAY[ 'DAV::read', 'DAV::write' ]
if you think you have some with write access but not read(!) Note that
privilege_to_bits( ARRAY[ 'DAV::read' ] ) returns a set of three
privileges, so we have to test that "(A & B) = B" in order to confirm
they really have read privileges, and not just read-free-busy.
bits_to_privilege() converts a bitmask of privileges to a human-readable
comma-separated list of privilege names.
path_privs( principal_id, pathname, depth ) returns a bitmask of the
expanded privileges for the identified principal in respect of
'pathname'. The third 'depth' parameter is a shortcut for how deeply it
searches through layers of groups which are members of groups, which are
members of groups, and '2' is more than enough for almost everyone (it's
also the system-wide default).
Regards,
Andrew.
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
You have a strong appeal for members of your own sex.
------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.morphoss.com/pipermail/davical-users/attachments/20100421/0fc1971e/attachment.pgp>
-------------- next part --------------