From 5c9aac94955a3b1559146427baaa923118494d4d Mon Sep 17 00:00:00 2001 From: brantje Date: Tue, 4 Oct 2016 14:15:34 +0200 Subject: [PATCH] Expire shared items after a certain date --- controller/sharecontroller.php | 9 ++++++--- js/app/controllers/import.js | 1 - js/app/controllers/share.js | 14 ++++++-------- js/templates.js | 2 +- lib/Service/CronService.php | 1 - .../forms/share_credential/link_sharing.html | 5 +++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index 14c96f0c..2cc815b0 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -285,7 +285,6 @@ class ShareController extends ApiController { ->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->cleanItemRequestsForUser($sr); return new JSONResponse(array('result'=> true)); @@ -299,18 +298,22 @@ class ShareController extends ApiController { * @PublicPage */ public function getPublicCredentialData($credential_guid) { - //@TODO if ExpireViews --, if 0 delete + //@TODO Check expire date $acl = $this->shareService->getACL(null, $credential_guid); $views = $acl->getExpireViews(); if($views === 0){ return new NotFoundResponse(); - } else { + } else if($views != -1) { $views--; $acl->setExpireViews($views); $this->shareService->updateCredentialACL($acl); } + if($acl->getExpire() > 0 && time() > $acl->getExpire()){ + return new NotFoundResponse(); + } + try { $credential = $this->shareService->getSharedItem(null, $credential_guid); return new JSONResponse($credential); diff --git a/js/app/controllers/import.js b/js/app/controllers/import.js index 26ce9cc0..ed8c2c3c 100644 --- a/js/app/controllers/import.js +++ b/js/app/controllers/import.js @@ -9,7 +9,6 @@ */ angular.module('passmanApp') .controller('ImportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', function ($scope, $window, CredentialService, VaultService) { - //@TODo read the available importers from $window.PassmanImporter $scope.available_importers = [ ]; diff --git a/js/app/controllers/share.js b/js/app/controllers/share.js index 31a78627..fb8d7bd5 100644 --- a/js/app/controllers/share.js +++ b/js/app/controllers/share.js @@ -76,8 +76,8 @@ angular.module('passmanApp') linkSharing: { enabled: false, settings: { - expire_time: 0, - expire_views: 0, + expire_time: new Date("2999-12-31T22:59:59"), + expire_views: 5, acl: link_acl } }, @@ -99,10 +99,9 @@ angular.module('passmanApp') value: '1' } ]; - console.log(SharingACL); var acl = new SharingACL(0); - console.log(acl); + $scope.inputSharedWith = []; $scope.selectedAccessLevel = '1'; @@ -138,7 +137,6 @@ angular.module('passmanApp') $scope.unshareCredential = function (credential) { ShareService.unshareCredential(credential); - //@TODO check why an item locks up after being shared with only a link var _credential = angular.copy(credential); _credential.shared_key = null; CredentialService.updateCredential(_credential).then(function () { @@ -154,7 +152,6 @@ angular.module('passmanApp') $scope.share_settings.cypher_progress.times_total = []; ShareService.generateSharedKey(20).then(function (key) { - console.log(key); var encryptedSharedCredential = ShareService.encryptSharedCredential($scope.storedCredential, key); CredentialService.updateCredential(encryptedSharedCredential, true); @@ -194,11 +191,12 @@ angular.module('passmanApp') } if($scope.share_settings.linkSharing.enabled){ + var expire_time = new Date(angular.copy( $scope.share_settings.linkSharing.settings.expire_time)).getTime()/1000; var shareObj = { item_id: $scope.storedCredential.credential_id, item_guid: $scope.storedCredential.guid, permissions: $scope.share_settings.linkSharing.settings.acl.getAccessLevel(), - expire_timestamp: $scope.share_settings.linkSharing.settings.expire_time, + expire_timestamp: expire_time, expire_views: $scope.share_settings.linkSharing.settings.expire_views }; ShareService.createPublicSharedCredential(shareObj).then(function(){ @@ -207,13 +205,13 @@ angular.module('passmanApp') }); } + NotificationService.showNotification('Credential shared', 4000) }) }; $scope.uploadChanges = function (user) { user.accessLevel = angular.copy(user.acl.getAccessLevel()); ShareService.shareWithUser(storedCredential, user); - //@TODO Encrypt the credential once all users have the sharing keys. }; $scope.calculate_total_time = function () { diff --git a/js/templates.js b/js/templates.js index f8f9662a..508156f2 100644 --- a/js/templates.js +++ b/js/templates.js @@ -89,7 +89,7 @@ angular.module('views/partials/forms/share_credential/basics.html', []).run(['$t angular.module('views/partials/forms/share_credential/link_sharing.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/share_credential/link_sharing.html', - '
Enable link sharing.
Share until date No expire date set
Share until views
Show files
'); + '
Enable link sharing.
Share until date {{ share_settings.linkSharing.settings.expire_time | date:\'dd-MM-yyyy @ HH:mm:ss\' }}
Expire after views
Show files
'); }]); angular.module('views/partials/password-meter.html', []).run(['$templateCache', function($templateCache) { diff --git a/lib/Service/CronService.php b/lib/Service/CronService.php index 435d6c68..9703469b 100644 --- a/lib/Service/CronService.php +++ b/lib/Service/CronService.php @@ -34,7 +34,6 @@ class CronService { $this->db = $db; } //@TODO rename to a general name with sub tasks - //@TODO Add cron task which expires shared credentials public function expireCredentials() { $this->logger->info('Passman cron test', array('app' => 'passman')); $expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime()); diff --git a/templates/views/partials/forms/share_credential/link_sharing.html b/templates/views/partials/forms/share_credential/link_sharing.html index 2fa8516c..b3afe316 100644 --- a/templates/views/partials/forms/share_credential/link_sharing.html +++ b/templates/views/partials/forms/share_credential/link_sharing.html @@ -11,11 +11,12 @@ class="link" future-only close-on-select="false" - > No expire date set + timestamp="true" + >{{ share_settings.linkSharing.settings.expire_time | date:'dd-MM-yyyy @ HH:mm:ss' }}
- Share until views + Expire after views