ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\DAV\Sharing\Plugin Class Reference

This plugin implements HTTP requests and properties related to: More...

+ Inheritance diagram for Sabre\DAV\Sharing\Plugin:
+ Collaboration diagram for Sabre\DAV\Sharing\Plugin:

Public Member Functions

 getFeatures ()
 This method should return a list of server-features. More...
 
 getPluginName ()
 Returns a plugin name. More...
 
 initialize (Server $server)
 This initializes the plugin. More...
 
 shareResource ($path, array $sharees)
 Updates the list of sharees on a shared resource. More...
 
 propFind (PropFind $propFind, INode $node)
 This event is triggered when properties are requested for nodes. More...
 
 httpPost (RequestInterface $request, ResponseInterface $response)
 We intercept this to handle POST requests on shared resources. More...
 
 getSupportedPrivilegeSet (INode $node, array &$supportedPrivilegeSet)
 This method is triggered whenever a subsystem reqeuests the privileges hat are supported on a particular node. More...
 
 getPluginInfo ()
 Returns a bunch of meta-data about the plugin. More...
 
 htmlActionsPanel (INode $node, &$output, $path)
 This method is used to generate HTML output for the DAV. More...
 
 browserPostAction ($path, $action, $postVars)
 This method is triggered for POST actions generated by the browser plugin. More...
 
- Public Member Functions inherited from Sabre\DAV\ServerPlugin
 initialize (Server $server)
 This initializes the plugin. More...
 
 getFeatures ()
 This method should return a list of server-features. More...
 
 getHTTPMethods ($path)
 Use this method to tell the server this plugin defines additional HTTP methods. More...
 
 getPluginName ()
 Returns a plugin name. More...
 
 getSupportedReportSet ($uri)
 Returns a list of reports this plugin supports. More...
 
 getPluginInfo ()
 Returns a bunch of meta-data about the plugin. More...
 

Data Fields

const ACCESS_NOTSHARED = 0
 
const ACCESS_SHAREDOWNER = 1
 
const ACCESS_READ = 2
 
const ACCESS_READWRITE = 3
 
const ACCESS_NOACCESS = 4
 
const INVITE_NORESPONSE = 1
 
const INVITE_ACCEPTED = 2
 
const INVITE_DECLINED = 3
 
const INVITE_INVALID = 4
 

Protected Attributes

 $server
 

Detailed Description

This plugin implements HTTP requests and properties related to:

draft-pot-webdav-resource-sharing

This specification allows people to share webdav resources with others.

Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 27 of file Plugin.php.

Member Function Documentation

◆ browserPostAction()

Sabre\DAV\Sharing\Plugin::browserPostAction (   $path,
  $action,
  $postVars 
)

This method is triggered for POST actions generated by the browser plugin.

Parameters
string$path
string$action
array$postVars

Definition at line 307 of file Plugin.php.

References $action, $path, and Sabre\DAV\Sharing\Plugin\shareResource().

307  {
308 
309  if ($action !== 'share') {
310  return;
311  }
312 
313  if (empty($postVars['href'])) {
314  throw new BadRequest('The "href" POST parameter is required');
315  }
316  if (empty($postVars['access'])) {
317  throw new BadRequest('The "access" POST parameter is required');
318  }
319 
320  $accessMap = [
321  'readwrite' => self::ACCESS_READWRITE,
322  'read' => self::ACCESS_READ,
323  'no-access' => self::ACCESS_NOACCESS,
324  ];
325 
326  if (!isset($accessMap[$postVars['access']])) {
327  throw new BadRequest('The "access" POST must be readwrite, read or no-access');
328  }
329  $sharee = new Sharee([
330  'href' => $postVars['href'],
331  'access' => $accessMap[$postVars['access']],
332  ]);
333 
334  $this->shareResource(
335  $path,
336  [$sharee]
337  );
338  return false;
339 
340  }
$path
Definition: aliased.php:25
$action
shareResource($path, array $sharees)
Updates the list of sharees on a shared resource.
Definition: Plugin.php:115
+ Here is the call graph for this function:

◆ getFeatures()

Sabre\DAV\Sharing\Plugin::getFeatures ( )

This method should return a list of server-features.

This is for example 'versioning' and is added to the DAV: header in an OPTIONS response.

Returns
array

Definition at line 55 of file Plugin.php.

55  {
56 
57  return ['resource-sharing'];
58 
59  }

◆ getPluginInfo()

Sabre\DAV\Sharing\Plugin::getPluginInfo ( )

Returns a bunch of meta-data about the plugin.

Providing this information is optional, and is mainly displayed by the Browser plugin.

The description key in the returned array may contain html and will not be sanitized.

Returns
array

Definition at line 250 of file Plugin.php.

References Sabre\DAV\Sharing\Plugin\getPluginName().

250  {
251 
252  return [
253  'name' => $this->getPluginName(),
254  'description' => 'This plugin implements WebDAV resource sharing',
255  'link' => 'https://github.com/evert/webdav-sharing'
256  ];
257 
258  }
getPluginName()
Returns a plugin name.
Definition: Plugin.php:69
+ Here is the call graph for this function:

◆ getPluginName()

Sabre\DAV\Sharing\Plugin::getPluginName ( )

Returns a plugin name.

Using this name other plugins will be able to access other plugins using ::getPlugin

Returns
string

Definition at line 69 of file Plugin.php.

Referenced by Sabre\DAV\Sharing\Plugin\getPluginInfo().

69  {
70 
71  return 'sharing';
72 
73  }
+ Here is the caller graph for this function:

◆ getSupportedPrivilegeSet()

Sabre\DAV\Sharing\Plugin::getSupportedPrivilegeSet ( INode  $node,
array &  $supportedPrivilegeSet 
)

This method is triggered whenever a subsystem reqeuests the privileges hat are supported on a particular node.

We need to add a number of privileges for scheduling purposes.

Parameters
INode$node
array$supportedPrivilegeSet

Definition at line 229 of file Plugin.php.

229  {
230 
231  if ($node instanceof ISharedNode) {
232  $supportedPrivilegeSet['{DAV:}share'] = [
233  'abstract' => false,
234  'aggregates' => [],
235  ];
236  }
237  }

◆ htmlActionsPanel()

Sabre\DAV\Sharing\Plugin::htmlActionsPanel ( INode  $node,
$output,
  $path 
)

This method is used to generate HTML output for the DAV.

Parameters
INode$node
string$output
string$path
Returns
bool|null

Definition at line 269 of file Plugin.php.

References $aclPlugin, Sabre\VObject\$output, and $path.

269  {
270 
271  if (!$node instanceof ISharedNode) {
272  return;
273  }
274 
275  $aclPlugin = $this->server->getPlugin('acl');
276  if ($aclPlugin) {
277  if (!$aclPlugin->checkPrivileges($path, '{DAV:}share', \Sabre\DAVACL\Plugin::R_PARENT, false)) {
278  // Sharing is not permitted, we will not draw this interface.
279  return;
280  }
281  }
282 
283  $output .= '<tr><td colspan="2"><form method="post" action="">
284  <h3>Share this resource</h3>
285  <input type="hidden" name="sabreAction" value="share" />
286  <label>Share with (uri):</label> <input type="text" name="href" placeholder="mailto:user@example.org"/><br />
287  <label>Access</label>
288  <select name="access">
289  <option value="readwrite">Read-write</option>
290  <option value="read">Read-only</option>
291  <option value="no-access">Revoke access</option>
292  </select><br />
293  <input type="submit" value="share" />
294  </form>
295  </td></tr>';
296 
297  }
$path
Definition: aliased.php:25
$aclPlugin

◆ httpPost()

Sabre\DAV\Sharing\Plugin::httpPost ( RequestInterface  $request,
ResponseInterface  $response 
)

We intercept this to handle POST requests on shared resources.

Parameters
RequestInterface$request
ResponseInterface$response
Returns
null|bool

Definition at line 184 of file Plugin.php.

References $contentType, $message, $path, Sabre\HTTP\MessageInterface\getBody(), Sabre\HTTP\MessageInterface\getHeader(), Sabre\HTTP\RequestInterface\getPath(), Sabre\HTTP\RequestInterface\getUrl(), Sabre\HTTP\MessageInterface\setHeader(), Sabre\HTTP\ResponseInterface\setStatus(), and Sabre\DAV\Sharing\Plugin\shareResource().

184  {
185 
186  $path = $request->getPath();
187  $contentType = $request->getHeader('Content-Type');
188 
189  // We're only interested in the davsharing content type.
190  if (strpos($contentType, 'application/davsharing+xml') === false) {
191  return;
192  }
193 
194  $message = $this->server->xml->parse(
195  $request->getBody(),
196  $request->getUrl(),
197  $documentType
198  );
199 
200  switch ($documentType) {
201 
202  case '{DAV:}share-resource':
203 
204  $this->shareResource($path, $message->sharees);
205  $response->setStatus(200);
206  // Adding this because sending a response body may cause issues,
207  // and I wanted some type of indicator the response was handled.
208  $response->setHeader('X-Sabre-Status', 'everything-went-well');
209 
210  // Breaking the event chain
211  return false;
212 
213  default :
214  throw new BadRequest('Unexpected document type: ' . $documentType . ' for this Content-Type');
215 
216  }
217 
218  }
$path
Definition: aliased.php:25
foreach($paths as $path) $request
Definition: asyncclient.php:32
catch(Exception $e) $message
if($path[strlen($path) - 1]==='/') if(is_dir($path)) if(!file_exists($path)) if(preg_match('#\.php$#D', mb_strtolower($path, 'UTF-8'))) $contentType
Definition: module.php:144
$response
shareResource($path, array $sharees)
Updates the list of sharees on a shared resource.
Definition: Plugin.php:115
+ Here is the call graph for this function:

◆ initialize()

Sabre\DAV\Sharing\Plugin::initialize ( Server  $server)

This initializes the plugin.

This function is called by Sabre, after addPlugin is called.

This method should set up the required event subscriptions.

Parameters
Server$server
Returns
void

Definition at line 86 of file Plugin.php.

References Sabre\DAV\Sharing\Plugin\$server, and Sabre\Event\EventEmitterInterface\on().

86  {
87 
88  $this->server = $server;
89 
90  $server->xml->elementMap['{DAV:}share-resource'] = 'Sabre\\DAV\\Xml\\Request\\ShareResource';
91 
92  array_push(
93  $server->protectedProperties,
94  '{DAV:}share-mode'
95  );
96 
97  $server->on('method:POST', [$this, 'httpPost']);
98  $server->on('propFind', [$this, 'propFind']);
99  $server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']);
100  $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']);
101  $server->on('onBrowserPostAction', [$this, 'browserPostAction']);
102 
103  }
+ Here is the call graph for this function:

◆ propFind()

Sabre\DAV\Sharing\Plugin::propFind ( PropFind  $propFind,
INode  $node 
)

This event is triggered when properties are requested for nodes.

This allows us to inject any sharings-specific properties.

Parameters
PropFind$propFind
INode$node
Returns
void

Definition at line 153 of file Plugin.php.

References Sabre\DAV\PropFind\handle().

153  {
154 
155  if ($node instanceof ISharedNode) {
156 
157  $propFind->handle('{DAV:}share-access', function() use ($node) {
158 
159  return new Property\ShareAccess($node->getShareAccess());
160 
161  });
162  $propFind->handle('{DAV:}invite', function() use ($node) {
163 
164  return new Property\Invite($node->getInvites());
165 
166  });
167  $propFind->handle('{DAV:}share-resource-uri', function() use ($node) {
168 
169  return new Property\Href($node->getShareResourceUri());
170 
171  });
172 
173  }
174 
175  }
+ Here is the call graph for this function:

◆ shareResource()

Sabre\DAV\Sharing\Plugin::shareResource (   $path,
array  $sharees 
)

Updates the list of sharees on a shared resource.

The sharees array is a list of people that are to be added modified or removed in the list of shares.

Parameters
string$path
Sharee[]$sharees
Returns
void

Definition at line 115 of file Plugin.php.

References $path.

Referenced by Sabre\DAV\Sharing\Plugin\browserPostAction(), and Sabre\DAV\Sharing\Plugin\httpPost().

115  {
116 
117  $node = $this->server->tree->getNodeForPath($path);
118 
119  if (!$node instanceof ISharedNode) {
120 
121  throw new Forbidden('Sharing is not allowed on this node');
122 
123  }
124 
125  // Getting ACL info
126  $acl = $this->server->getPlugin('acl');
127 
128  // If there's no ACL support, we allow everything
129  if ($acl) {
130  $acl->checkPrivileges($path, '{DAV:}share');
131  }
132 
133  foreach ($sharees as $sharee) {
134  // We're going to attempt to get a local principal uri for a share
135  // href by emitting the getPrincipalByUri event.
136  $principal = null;
137  $this->server->emit('getPrincipalByUri', [$sharee->href, &$principal]);
138  $sharee->principal = $principal;
139  }
140  $node->updateInvites($sharees);
141 
142  }
$path
Definition: aliased.php:25
+ Here is the caller graph for this function:

Field Documentation

◆ $server

Sabre\DAV\Sharing\Plugin::$server
protected

Definition at line 45 of file Plugin.php.

Referenced by Sabre\DAV\Sharing\Plugin\initialize().

◆ ACCESS_NOACCESS

◆ ACCESS_NOTSHARED

◆ ACCESS_READ

◆ ACCESS_READWRITE

◆ ACCESS_SHAREDOWNER

◆ INVITE_ACCEPTED

◆ INVITE_DECLINED

◆ INVITE_INVALID

◆ INVITE_NORESPONSE


The documentation for this class was generated from the following file: