mirror of
https://github.com/nextcloud/passman.git
synced 2024-11-10 17:27:40 +08:00
Merge branch 'sharing_no_groups' of github.com:nextcloud/passman into sharing_no_groups
This commit is contained in:
commit
ed7fa681ae
4 changed files with 96 additions and 16 deletions
|
@ -12,6 +12,8 @@
|
|||
namespace OCA\Passman\Controller;
|
||||
|
||||
use OCA\Passman\Db\Vault;
|
||||
use OCA\Passman\Service\CredentialService;
|
||||
use OCA\Passman\Service\NotificationService;
|
||||
use OCA\Passman\Service\ShareService;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
@ -27,14 +29,15 @@ use OCA\Passman\Service\ActivityService;
|
|||
use OCA\Passman\Activity;
|
||||
|
||||
|
||||
|
||||
class ShareController extends ApiController {
|
||||
private $userId;
|
||||
private $activityService;
|
||||
private $groupManager;
|
||||
private $userManager;
|
||||
private $vaultService;
|
||||
private $shareService;
|
||||
private $shareService;
|
||||
private $credentialService;
|
||||
private $notificationService;
|
||||
|
||||
private $limit = 50;
|
||||
private $offset = 0;
|
||||
|
@ -46,27 +49,60 @@ class ShareController extends ApiController {
|
|||
IUserManager $userManager,
|
||||
ActivityService $activityService,
|
||||
VaultService $vaultService,
|
||||
ShareService $shareService
|
||||
ShareService $shareService,
|
||||
CredentialService $credentialService,
|
||||
NotificationService $notificationService
|
||||
) {
|
||||
parent::__construct($AppName, $request);
|
||||
|
||||
$this->userId = $UserId;
|
||||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->activityService = $activityService;
|
||||
$this->vaultService = $vaultService;
|
||||
$this->shareService = $shareService;
|
||||
$this->shareService = $shareService;
|
||||
$this->credentialService = $credentialService;
|
||||
$this->notificationService = $notificationService;
|
||||
}
|
||||
|
||||
public function applyIntermediateShare($item_id, $item_guid, $vaults, $permissions){
|
||||
return new JSONResponse($this->shareService->createBulkRequests($item_id, $item_guid, $vaults, $permissions));
|
||||
}
|
||||
public function applyIntermediateShare($item_id, $item_guid, $vaults, $permissions) {
|
||||
/**
|
||||
* Assemble notification
|
||||
*/
|
||||
$credential = $this->credentialService->getCredentialById($item_id, $this->userId->getUID());
|
||||
$result = $this->shareService->createBulkRequests($item_id, $item_guid, $vaults, $permissions);
|
||||
if ($credential) {
|
||||
$processed_users = array();
|
||||
|
||||
foreach ($result as $vault){
|
||||
if(!in_array($vault->getTargetUserId(), $processed_users)){
|
||||
$target_user = $vault->getTargetUserId();
|
||||
$notification = array(
|
||||
'from_user' => ucfirst($this->userId->getDisplayName()),
|
||||
'credential_label' => $credential->getLabel(),
|
||||
'credential_id' => $credential->getId(),
|
||||
'item_id' => $credential->getId(),
|
||||
'target_user' => $target_user,
|
||||
'req_id' => $vault->getId()
|
||||
);
|
||||
$this->notificationService->credentialSharedNotification(
|
||||
$notification
|
||||
);
|
||||
array_push($processed_users, $target_user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return new JSONResponse($result);
|
||||
}
|
||||
|
||||
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) {
|
||||
if ($this->userId != $user->getUID() && count($this->vaultService->getByUser($user->getUID())) >= 1) {
|
||||
$users[] = array(
|
||||
'text' => $user->getDisplayName(),
|
||||
'uid' => $user->getUID(),
|
||||
|
@ -90,10 +126,10 @@ class ShareController extends ApiController {
|
|||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function getVaultsByUser($user_id){
|
||||
public function getVaultsByUser($user_id) {
|
||||
$user_vaults = $this->vaultService->getByUser($user_id);
|
||||
$result = array();
|
||||
foreach($user_vaults as $vault){
|
||||
foreach ($user_vaults as $vault) {
|
||||
array_push($result,
|
||||
array(
|
||||
'vault_id' => $vault->getId(),
|
||||
|
@ -105,7 +141,7 @@ class ShareController extends ApiController {
|
|||
return new JSONResponse($result);
|
||||
}
|
||||
|
||||
public function share($credential){
|
||||
public function share($credential) {
|
||||
|
||||
$link = '';
|
||||
$this->activityService->add(
|
||||
|
@ -115,11 +151,11 @@ class ShareController extends ApiController {
|
|||
}
|
||||
|
||||
public function savePendingRequest($item_guid, $target_vault_guid, $final_shared_key) {
|
||||
$this->shareService->applyShare($item_guid, $target_vault_guid, $final_shared_key);
|
||||
}
|
||||
$this->shareService->applyShare($item_guid, $target_vault_guid, $final_shared_key);
|
||||
}
|
||||
|
||||
public function getPendingRequests() {
|
||||
return new JSONResponse($this->shareService->getUserPendingRequests());
|
||||
}
|
||||
return new JSONResponse($this->shareService->getUserPendingRequests());
|
||||
}
|
||||
|
||||
}
|
|
@ -54,7 +54,9 @@ class Application extends App {
|
|||
$server->getUserManager(),
|
||||
$c->query('ActivityService'),
|
||||
$c->query('VaultService'),
|
||||
$c->query('ShareService')
|
||||
$c->query('ShareService'),
|
||||
$c->query('CredentialService'),
|
||||
$c->query('NotificationService')
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -61,6 +61,26 @@ class Notifier implements INotifier {
|
|||
}
|
||||
return $notification;
|
||||
break;
|
||||
|
||||
case 'credential_shared':
|
||||
$notification->setParsedSubject(
|
||||
(string) $l->t('%s shared "%s" with you. Click here to accept', $notification->getSubjectParameters())
|
||||
);
|
||||
|
||||
// Deal with the actions for a known subject
|
||||
foreach ($notification->getActions() as $action) {
|
||||
switch ($action->getLabel()) {
|
||||
case 'decline':
|
||||
$action->setParsedLabel(
|
||||
(string) $l->t('Decline')
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$notification->addParsedAction($action);
|
||||
}
|
||||
return $notification;
|
||||
break;
|
||||
default:
|
||||
// Unknown subject => Unknown notification => throw
|
||||
throw new \InvalidArgumentException();
|
||||
|
|
|
@ -50,4 +50,26 @@ class NotificationService {
|
|||
$this->manager->notify($notification);
|
||||
}
|
||||
|
||||
|
||||
function credentialSharedNotification($data){
|
||||
$urlGenerator = \OC::$server->getURLGenerator();
|
||||
$link = $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('','index.php/apps/passman/#/'));
|
||||
$api = $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'index.php/apps/passman'));
|
||||
$notification = $this->manager->createNotification();
|
||||
|
||||
$declineAction = $notification->createAction();
|
||||
$declineAction->setLabel('decline')
|
||||
->setLink($api . '/api/v2/sharing/decline/'. $data['req_id'], 'DELETE');
|
||||
|
||||
$notification->setApp('passman')
|
||||
->setUser($data['target_user'])
|
||||
->setDateTime(new \DateTime())
|
||||
->setObject('credential', $data['item_id']) // $type and $id
|
||||
->setSubject('credential_shared', [$data['from_user'], $data['credential_label']]) // $subject and $parameters
|
||||
->setLink($link)
|
||||
->addAction($declineAction);
|
||||
|
||||
$this->manager->notify($notification);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue