Skip to content

Commit 469526c

Browse files
committed
fixed checkinContent
1 parent 2f07879 commit 469526c

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

logicaldoc-webapp/src/main/java/com/logicaldoc/web/service/DocumentServiceImpl.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,13 +2498,11 @@ public GUIDocument checkinContent(long docId, String content) throws ServerExcep
24982498

24992499
try {
25002500
DocumentDAO docDao = Context.get(DocumentDAO.class);
2501-
Document doc = docDao.findById(docId);
2501+
Document doc = docDao.findDocument(docId);
25022502
if (doc == null)
25032503
throw new ServerException(UNEXISTING_DOCUMENT);
25042504

2505-
FolderDAO fDao = Context.get(FolderDAO.class);
2506-
if (!fDao.isWriteAllowed(doc.getFolder().getId(), session.getUserId()))
2507-
throw new PermissionException(session.getUsername(), DOCUMENT_STR + docId, Permission.WRITE);
2505+
docDao.isWriteAllowed(docId, session.getUserId());
25082506

25092507
if (doc.getStatus() != DocumentStatus.CHECKEDOUT || doc.getLockUserId() != session.getUserId())
25102508
throw new PermissionException("You have not checked out the file " + docId);
@@ -2535,15 +2533,11 @@ public void replaceFile(long docId, String fileVersion, String comment) throws S
25352533

25362534
try {
25372535
DocumentDAO docDao = Context.get(DocumentDAO.class);
2538-
Document doc = docDao.findById(docId);
2536+
Document doc = docDao.findDocument(docId);
25392537
if (doc == null)
25402538
throw new ServerException(UNEXISTING_DOCUMENT);
25412539

2542-
FolderDAO fDao = Context.get(FolderDAO.class);
2543-
if (!fDao.isWriteAllowed(doc.getFolder().getId(), session.getUserId()))
2544-
throw new IOException("You don't have the WRITE permission");
2545-
2546-
doc = docDao.findDocument(docId);
2540+
docDao.isWriteAllowed(docId, session.getUserId());
25472541

25482542
if (doc.getStatus() != DocumentStatus.UNLOCKED)
25492543
throw new IOException("The document is locked");

logicaldoc-webapp/src/test/java/com/logicaldoc/web/service/DocumentServiceImplTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,25 @@ public void testCreateWithContent() throws ServerException {
342342
}
343343

344344
@Test
345-
public void testCheckinContext() throws ServerException {
345+
public void testCheckinContext() throws ServerException, PersistenceException {
346346
testCreateWithContent();
347347
testSubject.checkout(List.of(7L));
348348

349349
testSubject.checkinContent(7, "checkedin contents");
350350

351-
assertEquals("checkedin contents", testSubject.getContentAsString(7));
351+
// try to work on an alias
352+
Document alias=new Document();
353+
alias.setFileName("alias.txt");
354+
alias.setDocRef(7L);
355+
alias.setFolder(folderDao.findById(5L));
356+
357+
assertEquals("checkedin contents", testSubject.getContentAsString(7L));
358+
359+
docDao.store(alias);
360+
testSubject.checkout(List.of(alias.getId()));
361+
testSubject.checkinContent(alias.getId(), "checkedin contents2");
362+
363+
assertEquals("checkedin contents2", testSubject.getContentAsString(alias.getId()));
352364
}
353365

354366
@Test

0 commit comments

Comments
 (0)