Setting permission on share requests works

This commit is contained in:
brantje 2016-10-05 12:48:59 +02:00
parent eb915e065e
commit 4bc90d904e
No known key found for this signature in database
GPG key ID: 5FF1D117F918687F
3 changed files with 92 additions and 40 deletions

View file

@ -11,6 +11,7 @@
namespace OCA\Passman\Controller; namespace OCA\Passman\Controller;
use OCA\Files_External\NotFoundException;
use OCA\Passman\Db\ShareRequest; use OCA\Passman\Db\ShareRequest;
use OCA\Passman\Db\SharingACL; use OCA\Passman\Db\SharingACL;
use OCA\Passman\Db\Vault; use OCA\Passman\Db\Vault;
@ -112,9 +113,24 @@ class ShareController extends ApiController {
$credential_owner = $credential->getUserId(); $credential_owner = $credential->getUserId();
$first_vault = $vaults[0]; $first_vault = $vaults[0];
$shareRequests = $this->shareService->getPendingShareRequests($item_guid, $first_vault['user_id']); try {
if(count($shareRequests) > 0){ $shareRequests = $this->shareService->getPendingShareRequests($item_guid, $first_vault['user_id']);
return new JSONResponse(array('error'=> 'User got already pending requests')); if (count($shareRequests) > 0) {
return new JSONResponse(array('error' => 'User got already pending requests'));
}
} catch (DoesNotExistException $exception){
}
$acl = null;
try {
$acl = $this->shareService->getCredentialAclForUser($first_vault['user_id'], $item_guid);
} catch (DoesNotExistException $exception){
}
if($acl){
return new JSONResponse(array('error'=> 'User got already this credential'));
} }
$result = $this->shareService->createBulkRequests($item_id, $item_guid, $vaults, $permissions, $credential_owner); $result = $this->shareService->createBulkRequests($item_id, $item_guid, $vaults, $permissions, $credential_owner);
@ -379,9 +395,21 @@ class ShareController extends ApiController {
return new NotFoundResponse(); return new NotFoundResponse();
} }
if($this->userId->getUID() == $credential->getUserId()){ if($this->userId->getUID() == $credential->getUserId()){
$acl = $this->shareService->getACL($user_id, $item_guid); $acl = null;
$acl->setPermissions($permission); try {
$this->shareService->updateCredentialACL($acl); $acl = $this->shareService->getACL($user_id, $item_guid);
$acl->setPermissions($permission);
return $this->shareService->updateCredentialACL($acl);
} catch (DoesNotExistException $exception){
}
if($acl === null){
$sr = $this->shareService->getPendingShareRequestsForCredential($item_guid, $user_id);
foreach ($sr as $shareRequest){
$shareRequest->setPermissions($permission);
$this->shareService->updateCredentialShareRequest($shareRequest);
}
}
} }
} }

View file

@ -94,44 +94,55 @@ angular.module('passmanApp')
} }
}; };
var getAcl = function() {
ShareService.getSharedCredentialACL($scope.storedCredential).then(function (aclList) { ShareService.getSharedCredentialACL($scope.storedCredential).then(function (aclList) {
var _list = []
var enc_key = ($scope.storedCredential.shared_key) ? EncryptService.decryptString(angular.copy($scope.storedCredential.shared_key)) : false; var enc_key = ($scope.storedCredential.shared_key) ? EncryptService.decryptString(angular.copy($scope.storedCredential.shared_key)) : false;
for (var i = 0; i < aclList.length; i++) {
for(var i = 0; i < aclList.length; i++){ var acl = aclList[i];
var acl = aclList[i]; if (acl.user_id === null) {
if(acl.user_id === null){ $scope.share_settings.linkSharing = {
$scope.share_settings.linkSharing ={ enabled: true,
enabled: true, settings: {
settings: { expire_time: new Date(acl.expire * 1000),
expire_time: new Date(acl.expire * 1000), expire_views: acl.expire_views,
expire_views: acl.expire_views, acl: new SharingACL(acl.permissions)
acl: new SharingACL(acl.permissions) }
};
if (enc_key) {
var hash = window.btoa($scope.storedCredential.guid + '<::>' + enc_key)
$scope.share_link = $location.$$protocol + '://' + $location.$$host + OC.generateUrl('apps/passman/share/public#') + hash;
} }
}; } else {
if(enc_key) { var obj = {
var hash = window.btoa($scope.storedCredential.guid + '<::>' + enc_key) userId: acl.user_id,
$scope.share_link = $location.$$protocol + '://' + $location.$$host + OC.generateUrl('apps/passman/share/public#') + hash; displayName: acl.user_id,
type: 'user',
acl: new SharingACL(acl.permissions),
acl_id: acl.acl_id,
pending: acl.pending,
credential_guid: acl.item_guid,
created: acl.created
};
_list.push(obj);
} }
} else {
var obj = {
userId: acl.user_id,
displayName: acl.user_id,
type: 'user',
acl: new SharingACL(acl.permissions),
acl_id: acl.acl_id
};
$scope.share_settings.credentialSharedWithUserAndGroup.push(obj);
} }
$scope.share_settings.credentialSharedWithUserAndGroup = _list;
} });
}); };
getAcl();
var acl = new SharingACL(0); var acl = new SharingACL(0);
$scope.$watch('share_settings.upload_progress.done', function () {
console.log();
if($scope.share_settings.upload_progress.done == $scope.share_settings.upload_progress.total){
getAcl()
}
});
$scope.inputSharedWith = []; $scope.inputSharedWith = [];
$scope.selectedAccessLevel = '1'; $scope.selectedAccessLevel = '1';
@ -156,7 +167,9 @@ angular.module('passmanApp')
userId: shareWith[i].uid, userId: shareWith[i].uid,
displayName: shareWith[i].text, displayName: shareWith[i].text,
type: shareWith[i].type, type: shareWith[i].type,
acl: angular.copy($scope.default_permissions) acl: angular.copy($scope.default_permissions),
pending: true,
credential_guid: $scope.selectedCredential.guid
}; };
if ($scope.share_settings.credentialSharedWithUserAndGroup.indexOf(obj) === -1) { if ($scope.share_settings.credentialSharedWithUserAndGroup.indexOf(obj) === -1) {
$scope.share_settings.credentialSharedWithUserAndGroup.push(obj) $scope.share_settings.credentialSharedWithUserAndGroup.push(obj)
@ -240,13 +253,17 @@ angular.module('passmanApp')
for (var i = 0; i < list.length; i++) { for (var i = 0; i < list.length; i++) {
var iterator = i; var iterator = i;
var target_user = list[i]; var target_user = list[i];
if(target_user.hasOwnProperty('acl_id')){ console.log(target_user)
if(target_user.hasOwnProperty('created')){
console.log('Updating permissions')
var acl = { var acl = {
user_id: target_user.userId, user_id: target_user.userId,
permission: target_user.acl.getAccessLevel() permission: target_user.acl.getAccessLevel()
}; };
ShareService.updateCredentialAcl($scope.storedCredential, acl); ShareService.updateCredentialAcl($scope.storedCredential, acl);
} else { } else {
console.log('Creating new share')
$scope.applyShareToUser(list[iterator], enc_key); $scope.applyShareToUser(list[iterator], enc_key);
} }
} }

View file

@ -257,7 +257,14 @@ class ShareService {
return $this->shareRequest->updateShareRequest($shareRequest); return $this->shareRequest->updateShareRequest($shareRequest);
} }
public function getPendingShareRequests($item_guid, $user_id){
/**
* Get pending share requests by guid and uid
*
* @param ShareRequest $request
* @return \OCA\Passman\Db\ShareRequest[]
*/
public function getPendingShareRequestsForCredential($item_guid, $user_id){
return $this->shareRequest->getPendingShareRequests($item_guid, $user_id); return $this->shareRequest->getPendingShareRequests($item_guid, $user_id);
} }
} }