Repository: zeppelin Updated Branches: refs/heads/master dd6308e4f -> a39ce0141
Show dialog if owners field set to be empty on shiro ### What is this PR for? This PR is for a showing dialog when note's permission set `Readers/Writers` but `Owners` is empty. Currently, after merged #849, if user set `Owners` is empty, it's automatically set as the current user. So, It would be better to show a dialog before `Owners` is fill with the current user because user might think it is not intended. Plus, if a user only set `Readers` role, all field(`Writers` and `Owners`) role is filled as the current user like below. It's not necessary to fill because the `Owner` role can read and write note.  ### What type of PR is it? [ Improvement ] ### What is the Jira issue? * [ZEPPELIN-2206; Be added a writer account when adding a reader account on Shiro](https://issues.apache.org/jira/browse/ZEPPELIN-2206) * [ZEPPELIN-2418; show dialog if user set to the empty owner permission](https://issues.apache.org/jira/browse/ZEPPELIN-2418) ### How should this be tested? 1. Turn on shiro. 2. Set permission `Writers` and `Readers` except `Owner` role. 3. Check the dialog appears ### Screenshots (if appropriate) [Before] * Set `Readers` and `Writers` except `Owners`  * Set only 'Writers`  * set only `Readers`; this screen is attached above. [After] * Set `Readers` and `Writers` except `Owners` ( Set only `Writers`; this result is same)  * Set only 'Readers`  ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: soralee <sora0...@zepl.com> Closes #2239 from soralee/ZEPPELIN-2206_auto_shiro and squashes the following commits: 6168166fc [soralee] check empty and anonymous and revert config when cancel click Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/a39ce014 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/a39ce014 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/a39ce014 Branch: refs/heads/master Commit: a39ce0141006d5762058b6f7d0cf1ba349d869ac Parents: dd6308e Author: soralee <sora0...@zepl.com> Authored: Mon Apr 10 18:54:25 2017 +0900 Committer: Khalid Huseynov <khalid...@gmail.com> Committed: Tue Jun 27 10:31:16 2017 +0900 ---------------------------------------------------------------------- .../apache/zeppelin/rest/NotebookRestApi.java | 3 -- .../src/app/notebook/notebook.controller.js | 49 +++++++++++++++++++- 2 files changed, 48 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/a39ce014/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java index 9c511d4..50a8671 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java @@ -208,9 +208,6 @@ public class NotebookRestApi { HashSet<String> writers = permMap.get("writers"); // Set readers, if writers and owners is empty -> set to user requesting the change if (readers != null && !readers.isEmpty()) { - if (writers.isEmpty()) { - writers = Sets.newHashSet(SecurityUtils.getPrincipal()); - } if (owners.isEmpty()) { owners = Sets.newHashSet(SecurityUtils.getPrincipal()); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/a39ce014/zeppelin-web/src/app/notebook/notebook.controller.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/notebook/notebook.controller.js b/zeppelin-web/src/app/notebook/notebook.controller.js index a512664..8a3a97b 100644 --- a/zeppelin-web/src/app/notebook/notebook.controller.js +++ b/zeppelin-web/src/app/notebook/notebook.controller.js @@ -761,7 +761,40 @@ function NotebookCtrl ($scope, $route, $routeParams, $location, $rootScope, } $scope.savePermissions = function () { + if ($scope.isAnonymous || $rootScope.ticket.principal.trim().length === 0) { + $scope.blockAnonUsers() + } convertPermissionsToArray() + if ($scope.isOwnerEmpty()) { + BootstrapDialog.show({ + closable: false, + title: 'Setting Owners Permissions', + message: 'Please fill the [Owners] field. If not, it will set as current user.\n\n' + + 'Current user : [ ' + $rootScope.ticket.principal + ']', + buttons: [ + { + label: 'Set', + action: function(dialog) { + dialog.close() + $scope.permissions.owners = [$rootScope.ticket.principal] + $scope.setPermissions() + } + }, + { + label: 'Cancel', + action: function(dialog) { + dialog.close() + $scope.openPermissions() + } + } + ] + }) + } else { + $scope.setPermissions() + } + } + + $scope.setPermissions = function() { $http.put(baseUrlSrv.getRestApiBase() + '/notebook/' + $scope.note.id + '/permissions', $scope.permissions, {withCredentials: true}) .success(function (data, status, headers, config) { @@ -769,7 +802,7 @@ function NotebookCtrl ($scope, $route, $routeParams, $location, $rootScope, console.log('Note permissions %o saved', $scope.permissions) BootstrapDialog.alert({ closable: true, - title: 'Permissions Saved Successfully!!!', + title: 'Permissions Saved Successfully', message: 'Owners : ' + $scope.permissions.owners + '\n\n' + 'Readers : ' + $scope.permissions.readers + '\n\n' + 'Writers : ' + $scope.permissions.writers }) @@ -877,6 +910,20 @@ function NotebookCtrl ($scope, $route, $routeParams, $location, $rootScope, angular.element('.ace_autocomplete').hide() }) + $scope.isOwnerEmpty = function() { + if ($scope.permissions.owners.length > 0) { + for (let i = 0; i < $scope.permissions.owners.length; i++) { + if ($scope.permissions.owners[i].trim().length > 0) { + return false + } else if (i === $scope.permissions.owners.length - 1) { + return true + } + } + } else { + return true + } + } + /* ** $scope.$on functions below */