From 3b9a66d1d884a9bbd9fa467de86c6d3e9ee2c169 Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 19 Mar 2016 19:56:02 +0100 Subject: [PATCH] #18: administrators group --- .../com/sismics/docs/core/dao/jpa/GroupDao.java | 7 +++++-- .../src/main/resources/db/update/dbupdate-008-0.sql | 3 +++ .../java/com/sismics/docs/rest/TestAclResource.java | 13 ++++++++++++- .../com/sismics/docs/rest/TestGroupResource.java | 12 ++++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/GroupDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/GroupDao.java index c22af1c1..f5e695b9 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/GroupDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/GroupDao.java @@ -152,7 +152,10 @@ public class GroupDao { Map parameterMap = new HashMap(); List criteriaList = new ArrayList(); - StringBuilder sb = new StringBuilder("select g.GRP_ID_C as c0, g.GRP_NAME_C as c1, g.GRP_IDPARENT_C as c2, ug.UGP_ID_C "); + StringBuilder sb = new StringBuilder("select g.GRP_ID_C as c0, g.GRP_NAME_C as c1, g.GRP_IDPARENT_C as c2 "); + if (criteria.getUserId() != null) { + sb.append(" , ug.UGP_ID_C "); + } sb.append(" from T_GROUP g "); // Add search criterias @@ -189,7 +192,7 @@ public class GroupDao { .setName((String) o[i++]) .setParentId((String) o[i++]); groupDtoList.add(groupDto); - if (o[i++] != null) { + if (criteria.getUserId() != null && o[i++] != null) { userGroupDtoList.add(groupDto); } } diff --git a/docs-core/src/main/resources/db/update/dbupdate-008-0.sql b/docs-core/src/main/resources/db/update/dbupdate-008-0.sql index 6f32919e..47738c2f 100644 --- a/docs-core/src/main/resources/db/update/dbupdate-008-0.sql +++ b/docs-core/src/main/resources/db/update/dbupdate-008-0.sql @@ -1,4 +1,7 @@ create memory table T_GROUP ( GRP_ID_C varchar(36) not null, GRP_IDPARENT_C varchar(36), GRP_NAME_C varchar(50) not null, GRP_DELETEDATE_D datetime, primary key (GRP_ID_C) ); create memory table T_USER_GROUP ( UGP_ID_C varchar(36) not null, UGP_IDUSER_C varchar(36) not null, UGP_IDGROUP_C varchar(36) not null, UGP_DELETEDATE_D datetime, primary key (UGP_ID_C) ); +insert into T_GROUP(GRP_ID_C, GRP_NAME_C) values('administrators', 'administrators'); +insert into T_USER_GROUP(UGP_ID_C, UGP_IDUSER_C, UGP_IDGROUP_C) values('admin-administrators', 'admin', 'administrators'); + update T_CONFIG set CFG_VALUE_C = '8' where CFG_ID_C = 'DB_VERSION'; diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java index 30fc9efb..fce7cec4 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java @@ -219,7 +219,7 @@ public class TestAclResource extends BaseJerseyTest { .delete(); Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus())); - // Search target list + // Search target list (acl) json = target().path("/acl/target/search") .queryParam("search", "acl") .request() @@ -229,5 +229,16 @@ public class TestAclResource extends BaseJerseyTest { Assert.assertEquals(2, users.size()); JsonArray groups = json.getJsonArray("groups"); Assert.assertEquals(1, groups.size()); + + // Search target list (admin) + json = target().path("/acl/target/search") + .queryParam("search", "admin") + .request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl1Token) + .get(JsonObject.class); + users = json.getJsonArray("users"); + Assert.assertEquals(1, users.size()); + groups = json.getJsonArray("groups"); + Assert.assertEquals(1, groups.size()); } } \ No newline at end of file diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestGroupResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestGroupResource.java index 2c26250d..68e877d7 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestGroupResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestGroupResource.java @@ -41,11 +41,19 @@ public class TestGroupResource extends BaseJerseyTest { clientUtil.createUser("group1", "g112", "g12"); String group1Token = clientUtil.login("group1"); - // Check group1 groups (all computed groups) + // Check admin groups (all computed groups) JsonObject json = target().path("/user").request() - .cookie(TokenBasedSecurityFilter.COOKIE_NAME, group1Token) + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) .get(JsonObject.class); JsonArray groups = json.getJsonArray("groups"); + Assert.assertEquals(1, groups.size()); + Assert.assertEquals("administrators", groups.getString(0)); + + // Check group1 groups (all computed groups) + json = target().path("/user").request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, group1Token) + .get(JsonObject.class); + groups = json.getJsonArray("groups"); List groupList = new ArrayList<>(); for (int i = 0; i < groups.size(); i++) { groupList.add(groups.getString(i));