@@ -218,7 +218,8 @@ public function writeDocumentState(int $documentId, string $content): void {
218218 */
219219 public function addStep (Document $ document , Session $ session , array $ steps , int $ version , ?int $ recoveryAttempt , ?string $ shareToken ): array {
220220 $ documentId = $ session ->getDocumentId ();
221- $ readOnly = $ this ->isReadOnlyCached ($ session , $ shareToken );
221+ $ file = $ this ->getFileForSession ($ session , $ shareToken );
222+ $ readOnly = $ this ->isReadOnly ($ file , $ shareToken );
222223 $ stepsToInsert = [];
223224 $ stepsIncludeQuery = false ;
224225 $ documentState = null ;
@@ -384,7 +385,7 @@ public function autosave(Document $document, File $file, int $version, string $a
384385 $ documentId = $ document ->getId ();
385386
386387 if ($ this ->isReadOnly ($ file , $ shareToken )) {
387- return $ document ;
388+ throw new NotPermittedException ( ' Read-only permission cannot save document changes. Please reload the page. ' ) ;
388389 }
389390
390391 $ this ->assertNoOutsideConflict ($ document , $ file , $ force );
@@ -600,29 +601,14 @@ public function getFileByShareToken(string $shareToken, ?string $path = null): F
600601 throw new \InvalidArgumentException ('No proper share data ' );
601602 }
602603
603- public function isReadOnlyCached (Session $ session , ?string $ shareToken = null ): bool {
604- $ cacheKey = 'read-only- ' . $ session ->getId ();
605- $ isReadOnly = $ this ->cache ->get ($ cacheKey );
606- if ($ isReadOnly === null ) {
607- $ file = $ this ->getFileForSession ($ session , $ shareToken );
608- $ isReadOnly = $ this ->isReadOnly ($ file , $ shareToken );
609- $ this ->cache ->set ($ cacheKey , $ isReadOnly , 60 * 5 );
610- return $ isReadOnly ;
611- }
612-
613- return $ isReadOnly ;
614- }
615-
616604 public function isReadOnly (File $ file , ?string $ token ): bool {
617- $ readOnly = true ;
605+ $ readOnly = ! $ file -> isUpdateable () ;
618606 if ($ token !== null ) {
619607 try {
620608 $ this ->checkSharePermissions ($ token , Constants::PERMISSION_UPDATE );
621- $ readOnly = false ;
622609 } catch (NotFoundException $ e ) {
610+ $ readOnly = true ;
623611 }
624- } else {
625- $ readOnly = !$ file ->isUpdateable ();
626612 }
627613
628614 $ lockInfo = $ this ->getLockInfo ($ file );
0 commit comments