1: <?php
2: /**
3: * Maps folder permissions into the Horde_Permission system.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Perms
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Perms
12: */
13:
14: /**
15: * Maps folder permissions into the Horde_Permission system.
16: *
17: * Copyright 2006-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Horde
23: * @package Perms
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Perms
27: */
28: class Horde_Perms_Permission_Kolab
29: extends Horde_Perms_Permission
30: {
31: /** Kolab ACL speak for all permissions on a shared object. */
32: const ALL = 'lrid';
33:
34: /**
35: * The Kolab Folder these permissions belong to.
36: *
37: * @var Horde_Perms_Permission_Kolab_Storage
38: */
39: private $_storage;
40:
41: /**
42: * The group handler.
43: *
44: * @var Horde_Group_Base
45: */
46: private $_groups;
47:
48: /**
49: * A cache for the folder acl settings. The cache holds the permissions
50: * in horde compatible format, not in the IMAP permission format.
51: *
52: * @var string
53: */
54: public $data;
55:
56: /**
57: * Constructor.
58: *
59: * @param Horde_Perms_Permission_Kolab_Storage $storage The storage object
60: * represented by this
61: * permission instance.
62: *
63: * @param Horde_Group_Base $groups The group handler.
64: */
65: public function __construct(Horde_Perms_Permission_Kolab_Storage $storage,
66: Horde_Group_Base $groups)
67: {
68: parent::__construct(__CLASS__ . '::' . $storage->getPermissionId());
69: $this->_storage = $storage;
70: $this->_groups = $groups;
71: $this->data = $this->getCurrentPermissions();
72: }
73:
74: /**
75: * Gets the current permission of the folder and stores the values in the
76: * cache.
77: *
78: * @return NULL
79: */
80: public function getCurrentPermissions()
81: {
82: $data = array();
83: /**
84: * @todo: Can we lazy load $this->data so that we restrict to using
85: * MYRIGHTS only when that is all we need and use the full GETACL just
86: * when required.
87: */
88: $acl = new Horde_Perms_Permission_Kolab_AclIterator(
89: $this->_storage->getAcl(),
90: $this->_storage->getOwner()
91: );
92: foreach ($acl as $element) {
93: $element->toHorde($data);
94: }
95: $data['type'] = 'matrix';
96: return $data;
97: }
98:
99: /**
100: * Saves the current permission values from the cache to the IMAP folder.
101: *
102: * @return NULL
103: */
104: public function save()
105: {
106: /**
107: * @todo: If somebody else accessed the folder before us, we will
108: * overwrite the change here.
109: */
110: $current = $this->getCurrentPermissions();
111:
112: $elements = new Horde_Perms_Permission_Kolab_ElementIterator(
113: $this->data, $this->_groups, $this->_storage->getOwner()
114: );
115: foreach ($elements as $element) {
116: $this->_storage->setAcl($element->getId(), $element->fromHorde());
117: $element->unsetInCurrent($current);
118: }
119:
120: // Delete ACLs that have been removed
121: $elements = new Horde_Perms_Permission_Kolab_ElementIterator(
122: $current, $this->_groups, $this->_storage->getOwner()
123: );
124: foreach ($elements as $element) {
125: $this->_storage->deleteAcl($element->getId());
126: }
127:
128: // Load the permission from the folder again
129: $this->data = $this->getCurrentPermissions();
130: }
131:
132: }
133: