Blame view

sources/3rdparty/sabre/dav/lib/Sabre/CalDAV/Principal/User.php 3.76 KB
03e52840d   Kload   Init
1
  <?php
6d9380f96   Cédric Dupont   Update sources OC...
2
3
4
  namespace Sabre\CalDAV\Principal;
  use Sabre\DAV;
  use Sabre\DAVACL;
03e52840d   Kload   Init
5
6
7
8
9
10
11
  /**
   * CalDAV principal
   *
   * This is a standard user-principal for CalDAV. This principal is also a
   * collection and returns the caldav-proxy-read and caldav-proxy-write child
   * principals.
   *
6d9380f96   Cédric Dupont   Update sources OC...
12
13
14
   * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/).
   * @author Evert Pot (http://evertpot.com/)
   * @license http://sabre.io/license/ Modified BSD License
03e52840d   Kload   Init
15
   */
6d9380f96   Cédric Dupont   Update sources OC...
16
  class User extends DAVACL\Principal implements DAV\ICollection {
03e52840d   Kload   Init
17
18
19
20
21
22
  
      /**
       * Creates a new file in the directory
       *
       * @param string $name Name of the file
       * @param resource $data Initial payload, passed as a readable stream resource.
6d9380f96   Cédric Dupont   Update sources OC...
23
       * @throws DAV\Exception\Forbidden
03e52840d   Kload   Init
24
25
26
       * @return void
       */
      public function createFile($name, $data = null) {
6d9380f96   Cédric Dupont   Update sources OC...
27
          throw new DAV\Exception\Forbidden('Permission denied to create file (filename ' . $name . ')');
03e52840d   Kload   Init
28
29
30
31
32
33
34
  
      }
  
      /**
       * Creates a new subdirectory
       *
       * @param string $name
6d9380f96   Cédric Dupont   Update sources OC...
35
       * @throws DAV\Exception\Forbidden
03e52840d   Kload   Init
36
37
38
       * @return void
       */
      public function createDirectory($name) {
6d9380f96   Cédric Dupont   Update sources OC...
39
          throw new DAV\Exception\Forbidden('Permission denied to create directory');
03e52840d   Kload   Init
40
41
42
43
44
45
46
  
      }
  
      /**
       * Returns a specific child node, referenced by its name
       *
       * @param string $name
6d9380f96   Cédric Dupont   Update sources OC...
47
       * @return DAV\INode
03e52840d   Kload   Init
48
49
50
51
52
       */
      public function getChild($name) {
  
          $principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/' . $name);
          if (!$principal) {
6d9380f96   Cédric Dupont   Update sources OC...
53
              throw new DAV\Exception\NotFound('Node with name ' . $name . ' was not found');
03e52840d   Kload   Init
54
55
          }
          if ($name === 'calendar-proxy-read')
6d9380f96   Cédric Dupont   Update sources OC...
56
              return new ProxyRead($this->principalBackend, $this->principalProperties);
03e52840d   Kload   Init
57
58
  
          if ($name === 'calendar-proxy-write')
6d9380f96   Cédric Dupont   Update sources OC...
59
              return new ProxyWrite($this->principalBackend, $this->principalProperties);
03e52840d   Kload   Init
60

6d9380f96   Cédric Dupont   Update sources OC...
61
          throw new DAV\Exception\NotFound('Node with name ' . $name . ' was not found');
03e52840d   Kload   Init
62
63
64
65
66
67
  
      }
  
      /**
       * Returns an array with all the child nodes
       *
6d9380f96   Cédric Dupont   Update sources OC...
68
      * @return DAV\INode[]
03e52840d   Kload   Init
69
70
71
72
73
       */
      public function getChildren() {
  
          $r = array();
          if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-read')) {
6d9380f96   Cédric Dupont   Update sources OC...
74
              $r[] = new ProxyRead($this->principalBackend, $this->principalProperties);
03e52840d   Kload   Init
75
76
          }
          if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL() . '/calendar-proxy-write')) {
6d9380f96   Cédric Dupont   Update sources OC...
77
              $r[] = new ProxyWrite($this->principalBackend, $this->principalProperties);
03e52840d   Kload   Init
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
          }
  
          return $r;
  
      }
  
      /**
       * Returns whether or not the child node exists
       *
       * @param string $name
       * @return bool
       */
      public function childExists($name) {
  
          try {
              $this->getChild($name);
              return true;
6d9380f96   Cédric Dupont   Update sources OC...
95
          } catch (DAV\Exception\NotFound $e) {
03e52840d   Kload   Init
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
              return false;
          }
  
      }
  
      /**
       * 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
       */
      public function getACL() {
  
          $acl = parent::getACL();
          $acl[] = array(
              'privilege' => '{DAV:}read',
              'principal' => $this->principalProperties['uri'] . '/calendar-proxy-read',
              'protected' => true,
          );
          $acl[] = array(
              'privilege' => '{DAV:}read',
              'principal' => $this->principalProperties['uri'] . '/calendar-proxy-write',
              'protected' => true,
          );
          return $acl;
  
      }
  
  }