TSK-572: fixed NPE in WorkbasketServiceImpl

This commit is contained in:
Holger Hagen 2018-06-21 12:02:24 +02:00 committed by Martin Rojas Miguel Angel
parent 4e04eb4f60
commit 3aee44f52b
3 changed files with 27 additions and 8 deletions

View File

@ -216,11 +216,13 @@ public interface WorkbasketService {
Workbasket newWorkbasket(String key, String domain);
/**
* Returns a set with all permissions of the current user at this workbasket.
* Returns a set with all permissions of the current user at this workbasket.<br>
* If the workbasketId is invalid, an empty list of permissions is returned since there is no distinction made
* between the situation that the workbasket is not found and the caller has no permissions on the workbasket.
*
* @param workbasketId
* the id of the referenced workbasket
* @return a Set with all permissions
* @return a {@link List} with all {@link WorkbasketPermission}s of the caller on the requested workbasket.
*/
List<WorkbasketPermission> getPermissionsForWorkbasket(String workbasketId);

View File

@ -4,6 +4,7 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -411,8 +412,11 @@ public class WorkbasketServiceImpl implements WorkbasketService {
List<WorkbasketPermission> permissions = new ArrayList<>();
WorkbasketAccessItem wbAcc = workbasketAccessMapper.findByWorkbasketAndAccessId(workbasketId,
CurrentUserContext.getAccessIds());
if (wbAcc != null) {
this.addWorkbasketAccessItemValuesToPermissionSet(wbAcc, permissions);
}
return permissions;
}
@Override

View File

@ -1,7 +1,7 @@
package acceptance.workbasket;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;
@ -96,6 +96,18 @@ public class GetWorkbasketAccTest extends AbstractAccTest {
assertTrue(permissions.contains(WorkbasketPermission.APPEND));
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
public void testGetWorkbasketPermissionsForInvalidWorkbasketId() {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
List<WorkbasketPermission> permissions = workbasketService
.getPermissionsForWorkbasket("WBI:invalid");
assertEquals(0, permissions.size());
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@ -104,7 +116,8 @@ public class GetWorkbasketAccTest extends AbstractAccTest {
throws NotAuthorizedException, WorkbasketNotFoundException {
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
WorkbasketSummary workbasketSummary = workbasketService.getWorkbasket("WBI:100000000000000000000000000000000007").asSummary();
WorkbasketSummary workbasketSummary = workbasketService
.getWorkbasket("WBI:100000000000000000000000000000000007").asSummary();
assertEquals("DOMAIN_A", workbasketSummary.getDomain());
assertEquals("PPK User 2 KSC 1", workbasketSummary.getDescription());