@@ -371,8 +371,8 @@ public void broadcastReloadedNoteList() {
371371 broadcastAll (new Message (OP .NOTES_INFO ).put ("notes" , notesInfo ));
372372 }
373373
374- void permissionError (NotebookSocket conn , String op , HashSet <String > current ,
375- HashSet <String > allowed ) throws IOException {
374+ void permissionError (NotebookSocket conn , String op , Set <String > current ,
375+ Set <String > allowed ) throws IOException {
376376 LOG .info ("Cannot {}. Connection readers {}. Allowed readers {}" ,
377377 op , current , allowed );
378378 conn .send (serializeMessage (new Message (OP .AUTH_INFO ).put ("info" ,
@@ -395,9 +395,10 @@ private void sendNote(NotebookSocket conn, HashSet<String> userAndRoles, Noteboo
395395 }
396396
397397 Note note = notebook .getNote (noteId );
398+ NotebookAuthorization notebookAuthorization = notebook .getNotebookAuthorization ();
398399 if (note != null ) {
399- if (!note .isReader (userAndRoles )) {
400- permissionError (conn , "read" , userAndRoles , note .getReaders ());
400+ if (!notebookAuthorization .isReader (noteId , userAndRoles )) {
401+ permissionError (conn , "read" , userAndRoles , notebookAuthorization .getReaders (noteId ));
401402 broadcastNoteList ();
402403 return ;
403404 }
@@ -417,8 +418,9 @@ private void sendHomeNote(NotebookSocket conn, HashSet<String> userAndRoles,
417418 }
418419
419420 if (note != null ) {
420- if (!note .isReader (userAndRoles )) {
421- permissionError (conn , "read" , userAndRoles , note .getReaders ());
421+ NotebookAuthorization notebookAuthorization = notebook .getNotebookAuthorization ();
422+ if (!notebookAuthorization .isReader (noteId , userAndRoles )) {
423+ permissionError (conn , "read" , userAndRoles , notebookAuthorization .getReaders (noteId ));
422424 broadcastNoteList ();
423425 return ;
424426 }
@@ -502,9 +504,9 @@ private void removeNote(NotebookSocket conn, HashSet<String> userAndRoles,
502504 }
503505
504506 Note note = notebook .getNote (noteId );
505-
506- if (!note .isOwner (userAndRoles )) {
507- permissionError (conn , "remove" , userAndRoles , note .getOwners ());
507+ NotebookAuthorization notebookAuthorization = notebook . getNotebookAuthorization ();
508+ if (!notebookAuthorization .isOwner (noteId , userAndRoles )) {
509+ permissionError (conn , "remove" , userAndRoles , notebookAuthorization .getOwners (noteId ));
508510 return ;
509511 }
510512
@@ -524,10 +526,11 @@ private void updateParagraph(NotebookSocket conn, HashSet<String> userAndRoles,
524526 .get ("params" );
525527 Map <String , Object > config = (Map <String , Object >) fromMessage
526528 .get ("config" );
527- final Note note = notebook .getNote (getOpenNoteId (conn ));
528-
529- if (!note .isWriter (userAndRoles )) {
530- permissionError (conn , "write" , userAndRoles , note .getWriters ());
529+ String noteId = getOpenNoteId (conn );
530+ final Note note = notebook .getNote (noteId );
531+ NotebookAuthorization notebookAuthorization = notebook .getNotebookAuthorization ();
532+ if (!notebookAuthorization .isWriter (noteId , userAndRoles )) {
533+ permissionError (conn , "write" , userAndRoles , notebookAuthorization .getWriters (noteId ));
531534 return ;
532535 }
533536
@@ -572,11 +575,11 @@ private void removeParagraph(NotebookSocket conn, HashSet<String> userAndRoles,
572575 if (paragraphId == null ) {
573576 return ;
574577 }
575-
576- final Note note = notebook .getNote (getOpenNoteId ( conn ) );
577-
578- if (!note .isWriter (userAndRoles )) {
579- permissionError (conn , "write" , userAndRoles , note .getWriters ());
578+ String noteId = getOpenNoteId ( conn );
579+ final Note note = notebook .getNote (noteId );
580+ NotebookAuthorization notebookAuthorization = notebook . getNotebookAuthorization ();
581+ if (!notebookAuthorization .isWriter (noteId , userAndRoles )) {
582+ permissionError (conn , "write" , userAndRoles , notebookAuthorization .getWriters (noteId ));
580583 return ;
581584 }
582585
@@ -594,11 +597,11 @@ private void clearParagraphOutput(NotebookSocket conn, HashSet<String> userAndRo
594597 if (paragraphId == null ) {
595598 return ;
596599 }
597-
598- final Note note = notebook .getNote (getOpenNoteId ( conn ) );
599-
600- if (!note .isWriter (userAndRoles )) {
601- permissionError (conn , "write" , userAndRoles , note .getWriters ());
600+ String noteId = getOpenNoteId ( conn );
601+ final Note note = notebook .getNote (noteId );
602+ NotebookAuthorization notebookAuthorization = notebook . getNotebookAuthorization ();
603+ if (!notebookAuthorization .isWriter (noteId , userAndRoles )) {
604+ permissionError (conn , "write" , userAndRoles , notebookAuthorization .getWriters (noteId ));
602605 return ;
603606 }
604607
@@ -722,10 +725,11 @@ private void moveParagraph(NotebookSocket conn, HashSet<String> userAndRoles, No
722725
723726 final int newIndex = (int ) Double .parseDouble (fromMessage .get ("index" )
724727 .toString ());
725- final Note note = notebook .getNote (getOpenNoteId (conn ));
726-
727- if (!note .isWriter (userAndRoles )) {
728- permissionError (conn , "write" , userAndRoles , note .getWriters ());
728+ String noteId = getOpenNoteId (conn );
729+ final Note note = notebook .getNote (noteId );
730+ NotebookAuthorization notebookAuthorization = notebook .getNotebookAuthorization ();
731+ if (!notebookAuthorization .isWriter (noteId , userAndRoles )) {
732+ permissionError (conn , "write" , userAndRoles , notebookAuthorization .getWriters (noteId ));
729733 return ;
730734 }
731735
@@ -738,10 +742,11 @@ private void insertParagraph(NotebookSocket conn, HashSet<String> userAndRoles,
738742 Notebook notebook , Message fromMessage ) throws IOException {
739743 final int index = (int ) Double .parseDouble (fromMessage .get ("index" )
740744 .toString ());
741- final Note note = notebook .getNote (getOpenNoteId (conn ));
742-
743- if (!note .isWriter (userAndRoles )) {
744- permissionError (conn , "write" , userAndRoles , note .getWriters ());
745+ String noteId = getOpenNoteId (conn );
746+ final Note note = notebook .getNote (noteId );
747+ NotebookAuthorization notebookAuthorization = notebook .getNotebookAuthorization ();
748+ if (!notebookAuthorization .isWriter (noteId , userAndRoles )) {
749+ permissionError (conn , "write" , userAndRoles , notebookAuthorization .getWriters (noteId ));
745750 return ;
746751 }
747752
@@ -757,10 +762,11 @@ private void cancelParagraph(NotebookSocket conn, HashSet<String> userAndRoles,
757762 return ;
758763 }
759764
760- final Note note = notebook .getNote (getOpenNoteId (conn ));
761-
762- if (!note .isWriter (userAndRoles )) {
763- permissionError (conn , "write" , userAndRoles , note .getWriters ());
765+ String noteId = getOpenNoteId (conn );
766+ final Note note = notebook .getNote (noteId );
767+ NotebookAuthorization notebookAuthorization = notebook .getNotebookAuthorization ();
768+ if (!notebookAuthorization .isWriter (noteId , userAndRoles )) {
769+ permissionError (conn , "write" , userAndRoles , notebookAuthorization .getWriters (noteId ));
764770 return ;
765771 }
766772
@@ -775,10 +781,11 @@ private void runParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Not
775781 return ;
776782 }
777783
778- final Note note = notebook .getNote (getOpenNoteId (conn ));
779-
780- if (!note .isWriter (userAndRoles )) {
781- permissionError (conn , "write" , userAndRoles , note .getWriters ());
784+ String noteId = getOpenNoteId (conn );
785+ final Note note = notebook .getNote (noteId );
786+ NotebookAuthorization notebookAuthorization = notebook .getNotebookAuthorization ();
787+ if (!notebookAuthorization .isWriter (noteId , userAndRoles )) {
788+ permissionError (conn , "write" , userAndRoles , notebookAuthorization .getWriters (noteId ));
782789 return ;
783790 }
784791
0 commit comments