Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4BB4B200B2B for ; Tue, 28 Jun 2016 18:08:47 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4A46E160A56; Tue, 28 Jun 2016 16:08:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 933AD160A28 for ; Tue, 28 Jun 2016 18:08:46 +0200 (CEST) Received: (qmail 66207 invoked by uid 500); 28 Jun 2016 16:08:45 -0000 Mailing-List: contact commits-help@zeppelin.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zeppelin.apache.org Delivered-To: mailing list commits@zeppelin.apache.org Received: (qmail 66194 invoked by uid 99); 28 Jun 2016 16:08:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jun 2016 16:08:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9E233E08FE; Tue, 28 Jun 2016 16:08:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: prabhjyotsingh@apache.org To: commits@zeppelin.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: zeppelin git commit: [ZEPPELIN-1060] validate user before saving Date: Tue, 28 Jun 2016 16:08:45 +0000 (UTC) archived-at: Tue, 28 Jun 2016 16:08:47 -0000 Repository: zeppelin Updated Branches: refs/heads/master 7951e6c69 -> c0cee7caf [ZEPPELIN-1060] validate user before saving ### What is this PR for? Zeppelin notebook permissions change has an issue while reconfiguring permissions by clearing textbox ### What type of PR is it? [Bug Fix] ### Todos * [x] - Validate user list before saving * [x] - getPermissions from server again before showing popup ### What is the Jira issue? * [ZEPPELIN-1060](https://issues.apache.org/jira/browse/ZEPPELIN-1060) ### How should this be tested? 1) I log in as user 'admin' 2) I create a notebook 'Untitled Notebbok 1' as user admin 3) I setup permissions of the notebook as owners = admin, readers= admin, writers= admin and click save button It works file 4) Now I again try to give owners permission to 'All users' by clearing owners field. Since in step-3 owners = admin ; it allows me to save these changes successfully 5) Now I again try to toggle permissions of the notebook. Since in step-4 I cleared owners field, it should allow all users to change permissions. But it is not happening, instead it gives an error box that only User = [] has sufficient permissions ### Questions: * Does the licenses files need update? n/a * Is there breaking changes for older versions? n/a * Does this needs documentation? n/a Author: Prabhjyot Singh Closes #1080 from prabhjyotsingh/ZEPPELIN-1060 and squashes the following commits: 93aa640 [Prabhjyot Singh] Merge remote-tracking branch 'origin/master' into ZEPPELIN-1060 f735133 [Prabhjyot Singh] validate user before saving Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/c0cee7ca Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/c0cee7ca Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/c0cee7ca Branch: refs/heads/master Commit: c0cee7cafd56c0981590c2ce867e92484370334a Parents: 7951e6c Author: Prabhjyot Singh Authored: Sat Jun 25 09:18:06 2016 +0530 Committer: Prabhjyot Singh Committed: Tue Jun 28 21:38:35 2016 +0530 ---------------------------------------------------------------------- zeppelin-web/src/app/notebook/notebook.controller.js | 15 +++++++++------ .../zeppelin/notebook/NotebookAuthorization.java | 13 +++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/c0cee7ca/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 3a13057..0b93ae9 100644 --- a/zeppelin-web/src/app/notebook/notebook.controller.js +++ b/zeppelin-web/src/app/notebook/notebook.controller.js @@ -713,13 +713,16 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', $http.put(baseUrlSrv.getRestApiBase() + '/notebook/' + $scope.note.id + '/permissions', $scope.permissions, {withCredentials: true}). success(function (data, status, headers, config) { - console.log('Note permissions %o saved', $scope.permissions); - BootstrapDialog.alert({ - closable: true, - title: 'Permissions Saved Successfully!!!', - message: 'Owners : ' + $scope.permissions.owners + '\n\n' + 'Readers : ' + $scope.permissions.readers + '\n\n' + 'Writers : ' + $scope.permissions.writers + getPermissions(function() { + console.log('Note permissions %o saved', $scope.permissions); + BootstrapDialog.alert({ + closable: true, + title: 'Permissions Saved Successfully!!!', + message: 'Owners : ' + $scope.permissions.owners + '\n\n' + 'Readers : ' + + $scope.permissions.readers + '\n\n' + 'Writers : ' + $scope.permissions.writers + }); + $scope.showPermissions = false; }); - $scope.showPermissions = false; }). error(function (data, status, headers, config) { console.log('Error %o %o', status, data.message); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/c0cee7ca/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java index 82f6138..0633906 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java @@ -102,8 +102,19 @@ public class NotebookAuthorization { } } + private Set validateUser(Set users) { + Set returnUser = new HashSet<>(); + for (String user : users) { + if (!user.trim().isEmpty()) { + returnUser.add(user.trim()); + } + } + return returnUser; + } + public void setOwners(String noteId, Set entities) { Map> noteAuthInfo = authInfo.get(noteId); + entities = validateUser(entities); if (noteAuthInfo == null) { noteAuthInfo = new LinkedHashMap(); noteAuthInfo.put("owners", new LinkedHashSet(entities)); @@ -118,6 +129,7 @@ public class NotebookAuthorization { public void setReaders(String noteId, Set entities) { Map> noteAuthInfo = authInfo.get(noteId); + entities = validateUser(entities); if (noteAuthInfo == null) { noteAuthInfo = new LinkedHashMap(); noteAuthInfo.put("owners", new LinkedHashSet()); @@ -132,6 +144,7 @@ public class NotebookAuthorization { public void setWriters(String noteId, Set entities) { Map> noteAuthInfo = authInfo.get(noteId); + entities = validateUser(entities); if (noteAuthInfo == null) { noteAuthInfo = new LinkedHashMap(); noteAuthInfo.put("owners", new LinkedHashSet());