set new note permissions

This commit is contained in:
Khalid Huseynov 2016-11-13 22:15:13 +09:00
parent 97324096f6
commit 44297a40fd

View file

@ -62,6 +62,7 @@ public class NotebookAuthorization {
private static ZeppelinConfiguration conf;
private static Gson gson;
private static String filePath;
private static boolean isPublic;
private NotebookAuthorization() {}
@ -73,6 +74,7 @@ public class NotebookAuthorization {
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
gson = builder.create();
isPublic = config.isNotebokPublic();
try {
loadFromFile();
} catch (IOException e) {
@ -325,4 +327,26 @@ public class NotebookAuthorization {
}
}).toList();
}
public void setNewNotePermissions(String noteId, AuthenticationInfo subject) {
if (!AuthenticationInfo.isAnonymous(subject)) {
if (isPublic) {
// add current user to owners - can be public
Set<String> owners = getOwners(noteId);
owners.add(subject.getUser());
setOwners(noteId, owners);
} else {
// add current user to owners, readers, writers - private note
Set<String> entities = getOwners(noteId);
entities.add(subject.getUser());
setOwners(noteId, entities);
entities = getReaders(noteId);
entities.add(subject.getUser());
setReaders(noteId, entities);
entities = getWriters(noteId);
entities.add(subject.getUser());
setWriters(noteId, entities);
}
}
}
}