You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2016/09/15 23:14:11 UTC
zeppelin git commit: [ZEPPELIN-1142] Zeppelin allows two users to
simultaneously edit the notebook permissions
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 <ka...@imaginea.com>
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 <ka...@imaginea.com>
Authored: Wed Sep 7 12:40:09 2016 +0530
Committer: Lee moon soo <mo...@apache.org>
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<String> owners = new HashSet<String>();
+ 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<String> 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<String> 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<String> owners = new HashSet<>();
+ owners.add("user1");
+ assertEquals(owners, notebook.getNotebookAuthorization().getOwners(cloneNote2.getId()));
}
@Test