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 63297200B8F for ; Fri, 16 Sep 2016 01:14:13 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 61DE1160AF2; Thu, 15 Sep 2016 23:14:13 +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 7D970160AF1 for ; Fri, 16 Sep 2016 01:14:12 +0200 (CEST) Received: (qmail 80979 invoked by uid 500); 15 Sep 2016 23:14:11 -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 80970 invoked by uid 99); 15 Sep 2016 23:14:11 -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; Thu, 15 Sep 2016 23:14:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 21468E0243; Thu, 15 Sep 2016 23:14:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: moon@apache.org To: commits@zeppelin.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: zeppelin git commit: [ZEPPELIN-1142] Zeppelin allows two users to simultaneously edit the notebook permissions Date: Thu, 15 Sep 2016 23:14:11 +0000 (UTC) archived-at: Thu, 15 Sep 2016 23:14:13 -0000 Repository: zeppelin Updated Branches: refs/heads/master 383402dc6 -> 294eef132 [ZEPPELIN-1142] Zeppelin allows two users to simultaneously edit the notebook permissions ### What is this PR for? This is about storing the owner information on creating a note so when the same user tries to edit the permissions of the note he could do it successfully. ### What type of PR is it? Improvement ### Todos NA ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-1142 ### How should this be tested? Check the below cases via the web application or REST API calls and the owner information should be persisted properly. * Create note * Clone note * Import note ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Kavin Closes #1393 from kavinkumarks/zeppelin-1142-simultaneous-note-permission-error and squashes the following commits: 5a45c9e [Kavin] Ensure that the authentication instance is created only when the input prinicipal is not null. 7642f63 [Kavin] Removed the duplicate instance of notebook variable and reused the existing one. e1b8b08 [Kavin] Store owner information on creating a note and added integration test cases for the relevant scenarios. Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/294eef13 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/294eef13 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/294eef13 Branch: refs/heads/master Commit: 294eef1327e4300aa198406048501c356d2eddb5 Parents: 383402d Author: Kavin Authored: Wed Sep 7 12:40:09 2016 +0530 Committer: Lee moon soo Committed: Thu Sep 15 16:14:03 2016 -0700 ---------------------------------------------------------------------- .../apache/zeppelin/socket/NotebookServer.java | 5 ++- .../org/apache/zeppelin/notebook/Notebook.java | 7 ++++ .../apache/zeppelin/notebook/NotebookTest.java | 35 ++++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/294eef13/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index e332802..73c940f 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -724,7 +724,10 @@ public class NotebookServer extends WebSocketServlet implements if (fromMessage != null) { String noteName = (String) ((Map) fromMessage.get("notebook")).get("name"); String noteJson = gson.toJson(fromMessage.get("notebook")); - AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); + AuthenticationInfo subject = null; + if (fromMessage.principal != null) { + subject = new AuthenticationInfo(fromMessage.principal); + } note = notebook.importNote(noteJson, noteName, subject); note.persist(subject); broadcastNote(note); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/294eef13/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index ae448e3..cb39197 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -24,10 +24,12 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; import com.google.gson.Gson; @@ -158,6 +160,11 @@ public class Notebook implements NoteEventListener { bindInterpretersToNote(note.getId(), interpreterIds); } + if (subject != null && !"anonymous".equals(subject.getUser())) { + Set owners = new HashSet(); + owners.add(subject.getUser()); + notebookAuthorization.setOwners(note.getId(), owners); + } notebookIndex.addIndexDoc(note); note.persist(subject); fireNoteCreateEvent(note); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/294eef13/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java index 648062e..7718ec4 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java @@ -42,6 +42,7 @@ import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.scheduler.SchedulerFactory; import org.apache.zeppelin.search.SearchService; +import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.user.Credentials; import org.junit.After; import org.junit.Before; @@ -210,6 +211,18 @@ public class NotebookTest implements JobListenerFactory{ } @Test + public void testCreateNoteWithSubject() throws IOException, SchedulerException, RepositoryException { + AuthenticationInfo subject = new AuthenticationInfo("user1"); + Note note = notebook.createNote(subject); + + assertNotNull(notebook.getNotebookAuthorization().getOwners(note.getId())); + assertEquals(1, notebook.getNotebookAuthorization().getOwners(note.getId()).size()); + Set owners = new HashSet<>(); + owners.add("user1"); + assertEquals(owners, notebook.getNotebookAuthorization().getOwners(note.getId())); + } + + @Test public void testClearParagraphOutput() throws IOException, SchedulerException{ Note note = notebook.createNote(null); Paragraph p1 = note.addParagraph(); @@ -351,7 +364,7 @@ public class NotebookTest implements JobListenerFactory{ @Test public void testExportAndImportNote() throws IOException, CloneNotSupportedException, - InterruptedException { + InterruptedException, InterpreterException, SchedulerException, RepositoryException { Note note = notebook.createNote(null); factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); @@ -374,11 +387,20 @@ public class NotebookTest implements JobListenerFactory{ assertEquals(p.getId(), p2.getId()); assertEquals(p.text, p2.text); assertEquals(p.getResult().message(), p2.getResult().message()); + + // Verify import note with subject + AuthenticationInfo subject = new AuthenticationInfo("user1"); + Note importedNote2 = notebook.importNote(exportedNoteJson, "Title2", subject); + assertNotNull(notebook.getNotebookAuthorization().getOwners(importedNote2.getId())); + assertEquals(1, notebook.getNotebookAuthorization().getOwners(importedNote2.getId()).size()); + Set owners = new HashSet<>(); + owners.add("user1"); + assertEquals(owners, notebook.getNotebookAuthorization().getOwners(importedNote2.getId())); } @Test public void testCloneNote() throws IOException, CloneNotSupportedException, - InterruptedException { + InterruptedException, InterpreterException, SchedulerException, RepositoryException { Note note = notebook.createNote(null); factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); @@ -396,6 +418,15 @@ public class NotebookTest implements JobListenerFactory{ assertEquals(cp.getId(), p.getId()); assertEquals(cp.text, p.text); assertEquals(cp.getResult().message(), p.getResult().message()); + + // Verify clone note with subject + AuthenticationInfo subject = new AuthenticationInfo("user1"); + Note cloneNote2 = notebook.cloneNote(note.getId(), "clone note2", subject); + assertNotNull(notebook.getNotebookAuthorization().getOwners(cloneNote2.getId())); + assertEquals(1, notebook.getNotebookAuthorization().getOwners(cloneNote2.getId()).size()); + Set owners = new HashSet<>(); + owners.add("user1"); + assertEquals(owners, notebook.getNotebookAuthorization().getOwners(cloneNote2.getId())); } @Test