2016-10-02 07:56:36 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: wolfi
|
|
|
|
* Date: 1/10/16
|
|
|
|
* Time: 21:54
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Passman\Service;
|
|
|
|
|
|
|
|
|
|
|
|
use OCA\Passman\Db\ShareRequest;
|
|
|
|
use OCA\Passman\Db\ShareRequestMapper;
|
|
|
|
use OCA\Passman\Db\SharingACLMapper;
|
|
|
|
|
|
|
|
class ShareService {
|
|
|
|
private $sharingACL;
|
|
|
|
private $shareRequest;
|
|
|
|
|
|
|
|
public function __construct(SharingACLMapper $sharingACL, ShareRequestMapper $shareRequest) {
|
|
|
|
$this->sharingACL = $sharingACL;
|
|
|
|
$this->shareRequest = $shareRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates requests for all the items on the request array of objects.
|
|
|
|
* This array objects must follow this spec:
|
|
|
|
* {
|
|
|
|
* vault_id: The id of the target vault
|
|
|
|
* guid: The guid of the target vault
|
|
|
|
* key: The shared key cyphered with the target vault RSA public key
|
|
|
|
* }
|
|
|
|
* @param $target_item_id string The shared item ID
|
|
|
|
* @param $target_item_guid string The shared item GUID
|
2016-10-02 17:43:31 +08:00
|
|
|
* @param $request_array array
|
2016-10-02 07:56:36 +08:00
|
|
|
* @param $permissions integer Must be created with a bitmask from options on the ShareRequest class
|
2016-10-02 17:43:31 +08:00
|
|
|
* @return array Array of sharing requests
|
2016-10-02 07:56:36 +08:00
|
|
|
*/
|
|
|
|
public function createBulkRequests($target_item_id, $target_item_guid, $request_array, $permissions) {
|
|
|
|
$created = (new \DateTime())->getTimestamp();
|
2016-10-02 17:43:31 +08:00
|
|
|
$requests = array();
|
2016-10-02 07:56:36 +08:00
|
|
|
foreach ($request_array as $req){
|
|
|
|
$t = new ShareRequest();
|
|
|
|
$t->setItemId($target_item_id);
|
|
|
|
$t->setItemGuid($target_item_guid);
|
2016-10-02 17:43:31 +08:00
|
|
|
$t->setTargetVaultId($req['vault_id']);
|
|
|
|
$t->setTargetVaultGuid($req['guid']);
|
|
|
|
$t->setSharedKey($req['key']);
|
2016-10-02 07:56:36 +08:00
|
|
|
$t->setPermissions($permissions);
|
|
|
|
$t->setCreated($created);
|
2016-10-02 17:43:31 +08:00
|
|
|
array_push($requests, $this->shareRequest->createRequest($t));
|
2016-10-02 07:56:36 +08:00
|
|
|
}
|
2016-10-02 17:43:31 +08:00
|
|
|
return $requests;
|
2016-10-02 07:56:36 +08:00
|
|
|
}
|
|
|
|
}
|