Skip to content
Snippets Groups Projects
Commit 5dfffe66 authored by uhensler's avatar uhensler
Browse files

OO-4172: Use different, parallel existing access tokens for read and edit

A user needs to open a file in in both mode simultaneously.
parent a5e229c5
No related branches found
No related tags found
No related merge requests found
...@@ -96,7 +96,7 @@ class AccessDAO { ...@@ -96,7 +96,7 @@ class AccessDAO {
return accesses.isEmpty() ? null : accesses.get(0); return accesses.isEmpty() ? null : accesses.get(0);
} }
Access loadAccess(VFSMetadata metadata, Identity identity, String app) { Access loadAccess(VFSMetadata metadata, Identity identity, String app, boolean canEdit) {
if (metadata == null || identity == null) return null; if (metadata == null || identity == null) return null;
QueryBuilder sb = new QueryBuilder(); QueryBuilder sb = new QueryBuilder();
...@@ -107,12 +107,14 @@ class AccessDAO { ...@@ -107,12 +107,14 @@ class AccessDAO {
sb.and().append("access.metadata.key = :metadataKey"); sb.and().append("access.metadata.key = :metadataKey");
sb.and().append("access.identity.key = :identityKey"); sb.and().append("access.identity.key = :identityKey");
sb.and().append("access.app = :app"); sb.and().append("access.app = :app");
sb.and().append("access.canEdit = :canEdit");
List<Access> accesses = dbInstance.getCurrentEntityManager() List<Access> accesses = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Access.class) .createQuery(sb.toString(), Access.class)
.setParameter("metadataKey", metadata.getKey()) .setParameter("metadataKey", metadata.getKey())
.setParameter("identityKey", identity.getKey()) .setParameter("identityKey", identity.getKey())
.setParameter("app", app) .setParameter("app", app)
.setParameter("canEdit", canEdit)
.getResultList(); .getResultList();
return accesses.isEmpty() ? null : accesses.get(0); return accesses.isEmpty() ? null : accesses.get(0);
} }
......
...@@ -121,7 +121,7 @@ public class WopiServiceImpl implements WopiService { ...@@ -121,7 +121,7 @@ public class WopiServiceImpl implements WopiService {
@Override @Override
public Access getOrCreateAccess(VFSMetadata vfsMetadata, Identity identity, DocEditorSecurityCallback secCallback, public Access getOrCreateAccess(VFSMetadata vfsMetadata, Identity identity, DocEditorSecurityCallback secCallback,
String app, Date expiresAt) { String app, Date expiresAt) {
Access access = accessDao.loadAccess(vfsMetadata, identity, app); Access access = accessDao.loadAccess(vfsMetadata, identity, app, getCanEdit(secCallback));
if (access != null) { if (access != null) {
if (accessUnchanged(access, secCallback) && !expired(access)) { if (accessUnchanged(access, secCallback) && !expired(access)) {
access = accessDao.updateExpiresAt(access, expiresAt); access = accessDao.updateExpiresAt(access, expiresAt);
...@@ -135,7 +135,6 @@ public class WopiServiceImpl implements WopiService { ...@@ -135,7 +135,6 @@ public class WopiServiceImpl implements WopiService {
} }
private boolean accessUnchanged(Access access, DocEditorSecurityCallback secCallback) { private boolean accessUnchanged(Access access, DocEditorSecurityCallback secCallback) {
if (access.isCanEdit() != getCanEdit(secCallback)) return false;
if (access.isCanClose() != secCallback.canClose()) return false; if (access.isCanClose() != secCallback.canClose()) return false;
if (access.isVersionControlled() != secCallback.isVersionControlled()) return false; if (access.isVersionControlled() != secCallback.isVersionControlled()) return false;
return true; return true;
......
...@@ -126,11 +126,13 @@ public class AccessDAOTest extends OlatTestCase { ...@@ -126,11 +126,13 @@ public class AccessDAOTest extends OlatTestCase {
Identity identity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("wopi2"); Identity identity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("wopi2");
VFSMetadata vfsMetadata = vfsMetadataDAO.createMetadata(random(), "relPath", "file.name", new Date(), 1000l, false, "", "file", null); VFSMetadata vfsMetadata = vfsMetadataDAO.createMetadata(random(), "relPath", "file.name", new Date(), 1000l, false, "", "file", null);
String app = random(); String app = random();
Access access = sut.createAccess(vfsMetadata, identity, app, random(), true, true, true, null); boolean canEdit = true;
sut.createAccess(vfsMetadata, identity2, app, random(), true, true, true, null); Access access = sut.createAccess(vfsMetadata, identity, app, random(), canEdit, true, true, null);
sut.createAccess(vfsMetadata, identity2, app, random(), canEdit, true, true, null);
sut.createAccess(vfsMetadata, identity, app, random(), !canEdit, true, true, null);
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
Access reloadedAccess = sut.loadAccess(vfsMetadata, identity, app); Access reloadedAccess = sut.loadAccess(vfsMetadata, identity, app, canEdit);
assertThat(reloadedAccess).isEqualTo(access); assertThat(reloadedAccess).isEqualTo(access);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment