From 44fba54287022c2627ba013f83a7ecef43eff280 Mon Sep 17 00:00:00 2001 From: Martin Ledvinka Date: Tue, 10 Dec 2024 16:33:18 +0100 Subject: [PATCH] [Fix] When term occurrence does not exist, let authorization consider access to it allowed. --- .../authorization/TermOccurrenceAuthorizationService.java | 2 +- .../TermOccurrenceAuthorizationServiceTest.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/termit/service/security/authorization/TermOccurrenceAuthorizationService.java b/src/main/java/cz/cvut/kbss/termit/service/security/authorization/TermOccurrenceAuthorizationService.java index f3c063cd..820360f4 100644 --- a/src/main/java/cz/cvut/kbss/termit/service/security/authorization/TermOccurrenceAuthorizationService.java +++ b/src/main/java/cz/cvut/kbss/termit/service/security/authorization/TermOccurrenceAuthorizationService.java @@ -56,6 +56,6 @@ public boolean canModify(TermOccurrence occurrence) { @Transactional(readOnly = true) public boolean canModify(URI occurrenceId) { - return dao.find(occurrenceId).map(this::canModify).orElse(false); + return dao.find(occurrenceId).map(this::canModify).orElse(true); } } diff --git a/src/test/java/cz/cvut/kbss/termit/service/security/authorization/TermOccurrenceAuthorizationServiceTest.java b/src/test/java/cz/cvut/kbss/termit/service/security/authorization/TermOccurrenceAuthorizationServiceTest.java index 360f73ff..95bc35da 100644 --- a/src/test/java/cz/cvut/kbss/termit/service/security/authorization/TermOccurrenceAuthorizationServiceTest.java +++ b/src/test/java/cz/cvut/kbss/termit/service/security/authorization/TermOccurrenceAuthorizationServiceTest.java @@ -20,7 +20,6 @@ import java.net.URI; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; @@ -79,8 +78,8 @@ void canModifyResolvesResourceVocabularyAndChecksIfUserCanModifyItWhenTermOccurr } @Test - void canModifyReturnsFalseWhenTermOccurrenceDoesNotExist() { + void canModifyReturnsTrueWhenTermOccurrenceDoesNotExist() { when(toDao.find(any())).thenReturn(Optional.empty()); - assertFalse(sut.canModify(Generator.generateUri())); + assertTrue(sut.canModify(Generator.generateUri())); } }