Fixed getEditorSetting for having users' info

This commit is contained in:
Jongyoul Lee 2016-09-26 16:16:49 +09:00
parent 12a27db790
commit d1c4344f43
3 changed files with 9 additions and 8 deletions

View file

@ -1655,9 +1655,10 @@ public class NotebookServer extends WebSocketServlet implements
String paragraphId = (String) fromMessage.get("paragraphId");
String replName = (String) fromMessage.get("magic");
String noteId = getOpenNoteId(conn);
String user = SecurityUtils.getPrincipal();
Message resp = new Message(OP.EDITOR_SETTING);
resp.put("paragraphId", paragraphId);
resp.put("editor", notebook().getInterpreterFactory().getEditorSetting(noteId, replName));
resp.put("editor", notebook().getInterpreterFactory().getEditorSetting(user, noteId, replName));
conn.send(serializeMessage(resp));
return;
}

View file

@ -1338,8 +1338,8 @@ public class InterpreterFactory implements InterpreterGroupFactory {
this.env = env;
}
public Map<String, Object> getEditorSetting(String noteId, String replName) {
Interpreter intp = getInterpreter(noteId, replName);
public Map<String, Object> getEditorSetting(String user, String noteId, String replName) {
Interpreter intp = getInterpreter(user, noteId, replName);
Map<String, Object> editor = Maps.newHashMap(
ImmutableMap.<String, Object>builder()
.put("language", "text").build());

View file

@ -219,7 +219,7 @@ public class InterpreterFactoryTest {
@Test
public void testMultiUser() throws IOException, RepositoryException {
factory = new InterpreterFactory(conf, null, null, null, depResolver);
final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true);
final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true, null);
factory.add("group1", new ArrayList<InterpreterInfo>(){{
add(info1);
}}, new ArrayList<Dependency>(), new InterpreterOption(true), new Properties(), "/path1");
@ -260,19 +260,19 @@ public class InterpreterFactoryTest {
intpIds.add(intpSetting.getId());
}
}
Note note = notebook.createNote(intpIds, null);
Note note = notebook.createNote(intpIds, new AuthenticationInfo("anonymous"));
// get editor setting from interpreter-setting.json
Map<String, Object> editor = factory.getEditorSetting(note.getId(), "mock11");
Map<String, Object> editor = factory.getEditorSetting("user1", note.getId(), "mock11");
assertEquals("java", editor.get("language"));
// when interpreter is not loaded via interpreter-setting.json
// or editor setting doesn't exit
editor = factory.getEditorSetting(note.getId(), "mock1");
editor = factory.getEditorSetting("user1", note.getId(), "mock1");
assertEquals(null, editor.get("language"));
// when interpreter is not bound to note
editor = factory.getEditorSetting(note.getId(), "mock2");
editor = factory.getEditorSetting("user1", note.getId(), "mock2");
assertEquals("text", editor.get("language"));
}
}