passman/controller/sharecontroller.php

116 lines
2.8 KiB
PHP
Raw Normal View History

2016-09-23 18:02:41 +08:00
<?php
/**
* Nextcloud - passman
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Sander Brand <brantje@gmail.com>
* @copyright Sander Brand 2016
*/
namespace OCA\Passman\Controller;
use OCA\Passman\Db\Vault;
use OCA\Passman\Service\ShareService;
2016-09-23 18:02:41 +08:00
use OCP\IRequest;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\ApiController;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUser;
use OCA\Passman\Service\VaultService;
2016-09-24 21:58:02 +08:00
use OCA\Passman\Service\ActivityService;
2016-09-23 18:02:41 +08:00
class ShareController extends ApiController {
private $userId;
2016-09-23 23:03:36 +08:00
private $activityService;
2016-09-23 18:02:41 +08:00
private $groupManager;
private $userManager;
private $vaultService;
private $shareService;
2016-09-23 18:02:41 +08:00
private $limit = 50;
private $offset = 0;
public function __construct($AppName,
IRequest $request,
2016-09-27 03:23:24 +08:00
$UserId,
2016-09-23 18:02:41 +08:00
IGroupManager $groupManager,
2016-09-23 23:03:36 +08:00
IUserManager $userManager,
ActivityService $activityService,
VaultService $vaultService,
ShareService $shareService
2016-09-23 18:02:41 +08:00
) {
parent::__construct($AppName, $request);
$this->userId = $UserId;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
2016-09-23 23:03:36 +08:00
$this->activityService = $activityService;
$this->vaultService = $vaultService;
$this->shareService = $shareService;
2016-09-23 18:02:41 +08:00
}
public function applyIntermediateShare($item_id, $item_guid, $vaults, $permissions){
2016-10-02 17:43:31 +08:00
return new JSONResponse($this->shareService->createBulkRequests($item_id, $item_guid, $vaults, $permissions));
}
2016-09-23 18:02:41 +08:00
public function searchUsers($search) {
$users = array();
$usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset);
foreach ($usersTmp as $user) {
if($this->userId != $user->getUID() && count($this->vaultService->getByUser($user->getUID())) >= 1) {
2016-09-27 01:20:48 +08:00
$users[] = array(
'text' => $user->getDisplayName(),
'uid' => $user->getUID(),
'type' => 'user'
);
}
2016-09-23 18:02:41 +08:00
}
return $users;
2016-09-23 18:02:41 +08:00
}
/**
* @NoAdminRequired
*/
public function search($search) {
$user_search = $this->searchUsers($search);
return new JSONResponse($user_search);
2016-09-23 18:02:41 +08:00
}
/**
* @NoAdminRequired
*/
public function getVaultsByUser($user_id){
$user_vaults = $this->vaultService->getByUser($user_id);
$result = array();
foreach($user_vaults as $vault){
array_push($result,
array(
'vault_id' => $vault->getId(),
'guid' => $vault->getGuid(),
'public_sharing_key' => $vault->getPublicSharingKey(),
'user_id' => $user_id,
));
}
return new JSONResponse($result);
}
2016-09-23 23:03:36 +08:00
public function share($credential){
$link = '';
$this->activityService->add(
'item_shared', array($credential->label, $this->userId),
'', array(),
$link, $this->userId, Activity::TYPE_ITEM_ACTION);
}
2016-09-23 18:02:41 +08:00
}