diff --git a/appinfo/routes.php b/appinfo/routes.php index e65fb00d..a9236c83 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -52,6 +52,7 @@ return [ ['name' => 'share#applyIntermediateShare', 'url' => '/api/v2/sharing/share', 'verb' => 'POST'], ['name' => 'share#savePendingRequest', 'url' => '/api/v2/sharing/save', 'verb' => 'POST'], ['name' => 'share#getPendingRequests', 'url' => '/api/v2/sharing/pending', 'verb' => 'GET'], + ['name' => 'share#deleteShareRequest', 'url' => '/api/v2/sharing/decline/{share_request_id}', 'verb' => 'DELETE'], //Internal API diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index c9296d45..a077be8c 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -11,6 +11,7 @@ namespace OCA\Passman\Controller; +use OCA\Passman\Db\ShareRequest; use OCA\Passman\Db\Vault; use OCA\Passman\Service\CredentialService; use OCA\Passman\Service\NotificationService; @@ -180,4 +181,17 @@ class ShareController extends ApiController { return new JSONResponse($results); } + public function deleteShareRequest($share_request_id){ + echo $share_request_id; + + $manager = \OC::$server->getNotificationManager(); + $notification = $manager->createNotification(); + $notification->setApp('passman') + ->setObject('passman_share_request', $share_request_id) + ->setUser($this->userId->getUID()); + $manager->markProcessed($notification); + //@TODO load other requests and delete them by item id. + $this->shareService->deleteShareRequestById($share_request_id); + } + } \ No newline at end of file diff --git a/lib/Db/ShareRequestMapper.php b/lib/Db/ShareRequestMapper.php index f6b141ac..f88f3d13 100644 --- a/lib/Db/ShareRequestMapper.php +++ b/lib/Db/ShareRequestMapper.php @@ -9,6 +9,7 @@ namespace OCA\Passman\Db; +use Icewind\SMB\Share; use OCA\Passman\Utility\Utils; use OCP\AppFramework\Db\Mapper; use OCP\IDBConnection; @@ -52,4 +53,8 @@ class ShareRequestMapper extends Mapper { $q = "SELECT * FROM *PREFIX*". self::TABLE_NAME ." WHERE target_user_id = ?"; return $this->findEntities($q, [$user_id]); } + + public function deleteShareRequest(ShareRequest $shareRequest){ + $this->delete($shareRequest); + } } \ No newline at end of file diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index e4568f50..e124d3f0 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -64,7 +64,7 @@ class NotificationService { $notification->setApp('passman') ->setUser($data['target_user']) ->setDateTime(new \DateTime()) - ->setObject('credential', $data['item_id']) // $type and $id + ->setObject('passman_share_request', $data['req_id']) // $type and $id ->setSubject('credential_shared', [$data['from_user'], $data['credential_label']]) // $subject and $parameters ->setLink($link) ->addAction($declineAction); diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index bc29cddf..128b5cd9 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -88,4 +88,16 @@ class ShareService { public function getUserPendingRequests($user_id){ return $this->shareRequest->getUserPendingRequests($user_id); } + + /** + * Deletes an share reuqest by id + * @param $share_request_id + * + */ + public function deleteShareRequestById($id){ + $t = new ShareRequest(); + $t->setId($id); + $this->shareRequest->deleteShareRequest($t); + + } } \ No newline at end of file