From 2084a16c55943032d74e02b1c7c2fbd247d10e5e Mon Sep 17 00:00:00 2001 From: Marcos Zuriaga Date: Mon, 3 Oct 2016 18:31:20 +0200 Subject: [PATCH] Fixed js permissions check Improved default permissions handling --- js/app/controllers/share.js | 13 +++++++++---- js/app/factory/sharingacl.js | 6 +++++- js/templates.js | 2 +- .../partials/forms/share_credential/basics.html | 8 ++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/js/app/controllers/share.js b/js/app/controllers/share.js index d8ba2278..daa8c441 100644 --- a/js/app/controllers/share.js +++ b/js/app/controllers/share.js @@ -77,6 +77,13 @@ angular.module('passmanApp') } }; + $scope.default_permissions = new SharingACL(0); + $scope.default_permissions.addPermission( + $scope.default_permissions.permissions.READ | + $scope.default_permissions.permissions.WRITE | + $scope.default_permissions.permissions.FILES + ); + $scope.accessLevels = [ { label: 'Can edit', @@ -99,7 +106,7 @@ angular.module('passmanApp') }; $scope.hasPermission = function(acl, permission){ - console.log(acl, permission) + return acl.hasPermission(permission); }; $scope.shareWith = function (shareWith, selectedAccessLevel) { @@ -107,13 +114,11 @@ angular.module('passmanApp') $scope.inputSharedWith = []; if (shareWith.length > 0) { for (var i = 0; i < shareWith.length; i++) { - var acl = new SharingACL(0); - acl.addPermission(acl.permissions.READ | acl.permissions.WRITE | acl.permissions.FILES); var obj = { userId: shareWith[i].uid, displayName: shareWith[i].text, type: shareWith[i].type, - accessLevel: acl + acl: angular.copy($scope.default_permissions) }; if ($scope.share_settings.credentialSharedWithUserAndGroup.indexOf(obj) === -1) { $scope.share_settings.credentialSharedWithUserAndGroup.push(obj) diff --git a/js/app/factory/sharingacl.js b/js/app/factory/sharingacl.js index 1b7df570..bb8272d0 100644 --- a/js/app/factory/sharingacl.js +++ b/js/app/factory/sharingacl.js @@ -21,7 +21,7 @@ angular.module('passmanApp').factory('SharingACL', function(){ * @returns {boolean} */ ACL.prototype.hasPermission = function(permission){ - return this.permission == (this.permission & permission); + return permission == (this.permission & permission); }; /** @@ -40,5 +40,9 @@ angular.module('passmanApp').factory('SharingACL', function(){ this.permission = this.permission & !permission; }; + ACL.prototype.getAccessLevel = function() { + return this.permission; + }; + return ACL; }); \ No newline at end of file diff --git a/js/templates.js b/js/templates.js index 2904ca5a..bece3fae 100644 --- a/js/templates.js +++ b/js/templates.js @@ -81,7 +81,7 @@ angular.module('views/partials/forms/settings/tool.html', []).run(['$templateCac angular.module('views/partials/forms/share_credential/basics.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/share_credential/basics.html', - '
Cyphering...
UserCrypto time
{{user.user}}{{user.time}} s
Total time spent cyphering: {{ calculate_total_time() }}
UserReadWriteFilesRevisions
{{user.userId}} {{user}}
'); }]); diff --git a/templates/views/partials/forms/share_credential/basics.html b/templates/views/partials/forms/share_credential/basics.html index 45341085..9fc1b401 100644 --- a/templates/views/partials/forms/share_credential/basics.html +++ b/templates/views/partials/forms/share_credential/basics.html @@ -70,10 +70,10 @@ {{user.userId}} {{user}} - - - - + + + +