Repository: zeppelin Updated Branches: refs/heads/master 64190707f -> 29021896b
[ZEPPELIN-1144]Zeppelin home page should only list notebooks with read or write permission ### What is this PR for? If logged in user does not have Read and Write permission for a notebook, user should not see the notebook in the zeppelin home page. ### What type of PR is it? Bug Fix ### Todos ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-1144 ### How should this be tested? * unit test * online test ### 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: Minwoo Kang <minwoo.k...@outlook.com> Closes #1330 from mwkang/ZEPPELIN-1144 and squashes the following commits: 82beb18 [Minwoo Kang] User see read, write, owner permission notebook. Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/29021896 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/29021896 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/29021896 Branch: refs/heads/master Commit: 29021896bfcf442f2923546a8a12ed667bf19b88 Parents: 6419070 Author: Minwoo Kang <minwoo.k...@outlook.com> Authored: Sat Aug 13 16:49:32 2016 +0900 Committer: Lee moon soo <m...@apache.org> Committed: Fri Sep 16 09:29:17 2016 -0700 ---------------------------------------------------------------------- .../apache/zeppelin/socket/NotebookServer.java | 3 +- .../org/apache/zeppelin/notebook/Notebook.java | 32 ++++++++++++++++++++ .../apache/zeppelin/notebook/NotebookTest.java | 20 ++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/29021896/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 73c940f..8b6329a 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 @@ -472,8 +472,7 @@ public class NotebookServer extends WebSocketServlet implements LOG.error("Fail to reload notes from repository", e); } } - - List<Note> notes = notebook.getAllNotes(); + List<Note> notes = notebook.getAllNotes(subject); List<Map<String, String>> notesInfo = new LinkedList<>(); for (Note note : notes) { Map<String, String> info = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/29021896/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 4449223..38ddf46 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 @@ -32,6 +32,9 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Sets; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.stream.JsonReader; @@ -532,6 +535,35 @@ public class Notebook implements NoteEventListener { } } + public List<Note> getAllNotes(AuthenticationInfo subject) { + final Set<String> entities = Sets.newHashSet(); + if (subject != null) { + entities.add(subject.getUser()); + } + + synchronized (notes) { + return FluentIterable.from(notes.values()).filter(new Predicate<Note>() { + @Override + public boolean apply(Note input) { + return input != null && notebookAuthorization.isReader(input.getId(), entities); + } + }).toSortedList(new Comparator<Note>() { + @Override + public int compare(Note note1, Note note2) { + String name1 = note1.id(); + if (note1.getName() != null) { + name1 = note1.getName(); + } + String name2 = note2.id(); + if (note2.getName() != null) { + name2 = note2.getName(); + } + return name1.compareTo(name2); + } + }); + } + } + private Map<String, Object> getParagraphForJobManagerItem(Paragraph paragraph) { Map<String, Object> paragraphItem = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/29021896/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 7718ec4..0ec8e7c 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 @@ -853,6 +853,26 @@ public class NotebookTest implements JobListenerFactory{ notebook.removeNote(note1.getId(), null); } + @Test + public void testGetAllNotes() throws Exception { + Note note1 = notebook.createNote(null); + Note note2 = notebook.createNote(null); + assertEquals(2, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size()); + + notebook.getNotebookAuthorization().setOwners(note1.getId(), Sets.newHashSet("user1")); + notebook.getNotebookAuthorization().setWriters(note1.getId(), Sets.newHashSet("user1")); + notebook.getNotebookAuthorization().setReaders(note1.getId(), Sets.newHashSet("user1")); + assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size()); + assertEquals(2, notebook.getAllNotes(new AuthenticationInfo("user1")).size()); + + notebook.getNotebookAuthorization().setOwners(note2.getId(), Sets.newHashSet("user2")); + notebook.getNotebookAuthorization().setWriters(note2.getId(), Sets.newHashSet("user2")); + notebook.getNotebookAuthorization().setReaders(note2.getId(), Sets.newHashSet("user2")); + assertEquals(0, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size()); + assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("user1")).size()); + assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("user2")).size()); + } + private void delete(File file){ if(file.isFile()) file.delete(); else if(file.isDirectory()){