From 21b3ba2bf673ab41d466b96ed78ddd16639ffaaa Mon Sep 17 00:00:00 2001 From: jendib Date: Sun, 20 Mar 2016 12:20:12 +0100 Subject: [PATCH] #18: Handle new audit log for groups, filter users by group --- docs-android/app/app.iml | 52 +++++++------------ docs-android/app/build.gradle | 8 +-- .../docs/adapter/AuditLogListAdapter.java | 1 + .../sismics/docs/core/dao/jpa/GroupDao.java | 2 +- .../sismics/docs/core/dao/jpa/UserDao.java | 5 ++ .../core/dao/jpa/criteria/UserCriteria.java | 14 +++++ .../docs/rest/resource/UserResource.java | 17 +++++- .../src/partial/docs/directive.auditlog.html | 3 ++ .../sismics/docs/rest/TestGroupResource.java | 9 ++++ 9 files changed, 72 insertions(+), 39 deletions(-) diff --git a/docs-android/app/app.iml b/docs-android/app/app.iml index 7c02049b..e93ef14d 100644 --- a/docs-android/app/app.iml +++ b/docs-android/app/app.iml @@ -61,13 +61,6 @@ - - - - - - - @@ -75,53 +68,48 @@ + + + + + + + - - - - - - - - - + + + + + + - - - - - - - - - - + - + - - - + + + - + - + \ No newline at end of file diff --git a/docs-android/app/build.gradle b/docs-android/app/build.gradle index 7b93e78d..1b86dd75 100644 --- a/docs-android/app/build.gradle +++ b/docs-android/app/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0-alpha1' + classpath 'com.android.tools.build:gradle:2.1.0-alpha3' } } apply plugin: 'com.android.application' @@ -50,9 +50,9 @@ android { dependencies { compile fileTree(dir: 'libs', include: '*.jar') - compile 'com.android.support:appcompat-v7:23.2.0' - compile 'com.android.support:recyclerview-v7:23.2.0' - compile 'com.android.support:design:23.2.0' + compile 'com.android.support:appcompat-v7:23.2.1' + compile 'com.android.support:recyclerview-v7:23.2.1' + compile 'com.android.support:design:23.2.1' compile 'it.sephiroth.android.library.imagezoom:imagezoom:1.0.5' compile 'org.greenrobot:eventbus:3.0.0' compile 'com.squareup.picasso:picasso:2.5.2' diff --git a/docs-android/app/src/main/java/com/sismics/docs/adapter/AuditLogListAdapter.java b/docs-android/app/src/main/java/com/sismics/docs/adapter/AuditLogListAdapter.java index b529bccd..b77061d6 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/adapter/AuditLogListAdapter.java +++ b/docs-android/app/src/main/java/com/sismics/docs/adapter/AuditLogListAdapter.java @@ -76,6 +76,7 @@ public class AuditLogListAdapter extends BaseAdapter { case "Acl": case "Tag": case "User": + case "Group": message.append(" : "); message.append(log.optString("message")); break; 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 36663a1b..f6881005 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 @@ -35,7 +35,7 @@ public class GroupDao { * Returns a group by name. * * @param name Name - * @return Tag + * @return Group */ public Group getActiveByName(String name) { EntityManager em = ThreadLocalContext.get().getEntityManager(); diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/UserDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/UserDao.java index c502621e..92cb1718 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/UserDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/UserDao.java @@ -281,6 +281,11 @@ public class UserDao { parameterMap.put("search", "%" + criteria.getSearch() + "%"); } + if (criteria.getGroupId() != null) { + sb.append(" join T_USER_GROUP ug on ug.UGP_IDUSER_C = u.USE_ID_C and ug.UGP_IDGROUP_C = :groupId and ug.UGP_DELETEDATE_D is null "); + parameterMap.put("groupId", criteria.getGroupId()); + } + criteriaList.add("u.USE_DELETEDATE_D is null"); if (!criteriaList.isEmpty()) { diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/criteria/UserCriteria.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/criteria/UserCriteria.java index 74d84ed6..a94ac347 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/criteria/UserCriteria.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/criteria/UserCriteria.java @@ -10,6 +10,11 @@ public class UserCriteria { * Search query. */ private String search; + + /** + * Group ID. + */ + private String groupId; public String getSearch() { return search; @@ -19,4 +24,13 @@ public class UserCriteria { this.search = search; return this; } + + public String getGroupId() { + return groupId; + } + + public UserCriteria setGroupId(String groupId) { + this.groupId = groupId; + return this; + } } diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/UserResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/UserResource.java index e9a8eae5..c32a15f6 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/UserResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/UserResource.java @@ -42,6 +42,7 @@ import com.sismics.docs.core.model.context.AppContext; import com.sismics.docs.core.model.jpa.AuthenticationToken; import com.sismics.docs.core.model.jpa.Document; import com.sismics.docs.core.model.jpa.File; +import com.sismics.docs.core.model.jpa.Group; import com.sismics.docs.core.model.jpa.User; import com.sismics.docs.core.util.EncryptionUtil; import com.sismics.docs.core.util.jpa.SortCriteria; @@ -534,13 +535,15 @@ public class UserResource extends BaseResource { * * @param sortColumn Sort index * @param asc If true, ascending sorting, else descending + * @param groupName Only return users from this group * @return Response */ @GET @Path("list") public Response list( @QueryParam("sort_column") Integer sortColumn, - @QueryParam("asc") Boolean asc) { + @QueryParam("asc") Boolean asc, + @QueryParam("group") String groupName) { if (!authenticate()) { throw new ForbiddenClientException(); } @@ -548,8 +551,18 @@ public class UserResource extends BaseResource { JsonArrayBuilder users = Json.createArrayBuilder(); SortCriteria sortCriteria = new SortCriteria(sortColumn, asc); + // Validate the group + String groupId = null; + if (!Strings.isNullOrEmpty(groupName)) { + GroupDao groupDao = new GroupDao(); + Group group = groupDao.getActiveByName(groupName); + if (group != null) { + groupId = group.getId(); + } + } + UserDao userDao = new UserDao(); - List userDtoList = userDao.findByCriteria(new UserCriteria(), sortCriteria); + List userDtoList = userDao.findByCriteria(new UserCriteria().setGroupId(groupId), sortCriteria); for (UserDto userDto : userDtoList) { users.add(Json.createObjectBuilder() .add("id", userDto.getId()) diff --git a/docs-web/src/main/webapp/src/partial/docs/directive.auditlog.html b/docs-web/src/main/webapp/src/partial/docs/directive.auditlog.html index bd2e633c..3a15eba9 100644 --- a/docs-web/src/main/webapp/src/partial/docs/directive.auditlog.html +++ b/docs-web/src/main/webapp/src/partial/docs/directive.auditlog.html @@ -36,6 +36,9 @@ {{ log.message }} + + {{ log.message }} + 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 a9763bc2..961d9508 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 @@ -86,6 +86,15 @@ public class TestGroupResource extends BaseJerseyTest { Assert.assertEquals("g112", groups.getString(0)); Assert.assertEquals("g12", groups.getString(1)); + // List all users in group1 + json = target().path("/user/list") + .queryParam("group", "g112") + .request() + .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken) + .get(JsonObject.class); + JsonArray users = json.getJsonArray("users"); + Assert.assertEquals(1, users.size()); + // Add group1 to g112 (again) json = target().path("/group/g112").request() .cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)