Added deprecation messages to deprecated services
- invite group members
- add member roles
- subscribe
- unsubscribe
Change-Id: I644050fae8fc90f037aae59ae2652fb5f3b282c4
diff --git a/src/main/java/de/ids_mannheim/korap/constant/OAuth2Scope.java b/src/main/java/de/ids_mannheim/korap/constant/OAuth2Scope.java
index f24956b..5319d46 100644
--- a/src/main/java/de/ids_mannheim/korap/constant/OAuth2Scope.java
+++ b/src/main/java/de/ids_mannheim/korap/constant/OAuth2Scope.java
@@ -25,7 +25,7 @@
DELETE_USER_GROUP_MEMBER, ADD_USER_GROUP_MEMBER,
- EDIT_USER_GROUP_MEMBER_ROLE, ADD_USER_GROUP_MEMBER_ROLE, DELETE_USER_GROUP_MEMBER_ROLE,
+ ADD_MEMBER_ROLE, DELETE_MEMBER_ROLE,
CREATE_VC, VC_INFO, EDIT_VC, DELETE_VC,
diff --git a/src/main/java/de/ids_mannheim/korap/constant/PrivilegeType.java b/src/main/java/de/ids_mannheim/korap/constant/PrivilegeType.java
index 5aea201..e3454c6 100644
--- a/src/main/java/de/ids_mannheim/korap/constant/PrivilegeType.java
+++ b/src/main/java/de/ids_mannheim/korap/constant/PrivilegeType.java
@@ -10,7 +10,8 @@
public enum PrivilegeType {
READ_MEMBER,
WRITE_MEMBER,
- DELETE_MEMBER,
+ DELETE_MEMBER,
+ DELETE_SELF,
SHARE_QUERY,
DELETE_QUERY,
READ_QUERY,
diff --git a/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java b/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
index 5026b6e..11e9c12 100644
--- a/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
+++ b/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
@@ -14,7 +14,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import de.ids_mannheim.korap.config.FullConfiguration;
import de.ids_mannheim.korap.constant.PredefinedRole;
import de.ids_mannheim.korap.constant.PrivilegeType;
import de.ids_mannheim.korap.constant.UserGroupStatus;
@@ -62,10 +61,6 @@
@Autowired
private UserGroupConverter converter;
@Autowired
- private FullConfiguration config;
- @Autowired
- private MailService mailService;
- @Autowired
private RandomCodeGenerator random;
/**
@@ -169,7 +164,7 @@
private Set<Role> prepareMemberRoles (UserGroup userGroup) {
Role r1 = new Role(PredefinedRole.GROUP_MEMBER,
- PrivilegeType.DELETE_MEMBER, userGroup);
+ PrivilegeType.DELETE_SELF, userGroup);
roleDao.addRole(r1);
Set<Role>memberRoles = new HashSet<Role>();
memberRoles.add(r1);
@@ -282,43 +277,6 @@
return groupId;
}
- /**
- * Adds a user to the specified usergroup. If the username with
- * {@link GroupMemberStatus} DELETED exists as a member of the
- * group,
- * the entry will be deleted first, and a new entry will be added.
- *
- * If a username with other statuses exists, a KustvaktException
- * will
- * be thrown.
- *
- * @see GroupMemberStatus
- *
- * @param username
- * a username
- * @param userGroup
- * a user group
- * @param createdBy
- * the user (query-access admin/system) adding the user
- * the user-group
- * @param status
- * the status of the membership
- * @throws KustvaktException
- */
- @Deprecated
- public void inviteGroupMember (String username, UserGroup userGroup,
- String createdBy)
- throws KustvaktException {
-
- addGroupMember(username, userGroup, createdBy,null);
-
- if (config.isMailEnabled()
- && userGroup.getStatus() != UserGroupStatus.HIDDEN) {
- mailService.sendMemberInvitationNotification(username,
- userGroup.getName(), createdBy);
- }
- }
-
public void addGroupMember (String username, UserGroup userGroup,
String createdBy, Set<Role> roles)
throws KustvaktException {
@@ -377,62 +335,6 @@
return false;
}
- public boolean isUserGroupAdmin (UserGroupMember member)
- throws KustvaktException {
-
- for (Role r : member.getRoles()) {
- if (r.getName().equals(PredefinedRole.GROUP_ADMIN)) {
- return true;
- }
- }
- return false;
- }
-
-
- /**
- * Updates the {@link GroupMemberStatus} of a pending member
- * to {@link GroupMemberStatus#ACTIVE} and add default member
- * roles.
- *
- * @param groupId
- * groupId
- * @param username
- * the username of the group member
- * @throws KustvaktException
- */
- @Deprecated
- public void acceptInvitation (String groupName, String username)
- throws KustvaktException {
-
- ParameterChecker.checkStringValue(username, "userId");
- ParameterChecker.checkStringValue(groupName, "groupName");
-
- UserGroup userGroup = retrieveUserGroupByName(groupName);
- UserGroupMember member = groupMemberDao.retrieveMemberById(username,
- userGroup.getId());
- // status pending
-// else {
-// if (DEBUG) {
-// jlog.debug("status: " + member.getStatusDate());
-// }
-// ZonedDateTime expiration = member.getStatusDate().plusMinutes(30);
-// ZonedDateTime now = ZonedDateTime.now();
-// if (DEBUG) {
-// jlog.debug("expiration: " + expiration + ", now: " + now);
-// }
-//
-// if (expiration.isAfter(now)) {
-// member.setStatus(GroupMemberStatus.ACTIVE);
- Set<Role> memberRoles = prepareMemberRoles(userGroup);
- member.setRoles(memberRoles);
- groupMemberDao.updateMember(member);
-// }
-// else {
-// throw new KustvaktException(StatusCodes.INVITATION_EXPIRED);
-// }
-// }
- }
-
public boolean isMember (String username, UserGroup userGroup)
throws KustvaktException {
List<UserGroupMember> members = groupMemberDao
diff --git a/src/main/java/de/ids_mannheim/korap/web/controller/UserGroupController.java b/src/main/java/de/ids_mannheim/korap/web/controller/UserGroupController.java
index c0325b8..881dbc9 100644
--- a/src/main/java/de/ids_mannheim/korap/web/controller/UserGroupController.java
+++ b/src/main/java/de/ids_mannheim/korap/web/controller/UserGroupController.java
@@ -10,6 +10,7 @@
import de.ids_mannheim.korap.constant.PredefinedRole;
import de.ids_mannheim.korap.dto.UserGroupDto;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.oauth2.service.OAuth2ScopeService;
import de.ids_mannheim.korap.security.context.TokenContext;
import de.ids_mannheim.korap.service.UserGroupService;
@@ -201,6 +202,20 @@
* usernames separated by comma
* @return if successful, HTTP response status OK
*/
+ @Deprecated
+ @POST
+ @Path("@{groupName}/invite")
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ public Response inviteGroupMembers (
+ @Context SecurityContext securityContext,
+ @PathParam("groupName") String groupName,
+ @FormParam("members") String members) {
+ throw kustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.DEPRECATED,
+ "This web-service is deprecated and will be completely removed "
+ + "in API v1.1."));
+ }
+
@PUT
@Path("@{groupName}/member")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@@ -214,12 +229,39 @@
scopeService.verifyScope(context,
OAuth2Scope.ADD_USER_GROUP_MEMBER);
service.addGroupMembers(groupName, members, context.getUsername());
- return Response.ok("SUCCESS").build();
+ return Response.ok().build();
}
catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
}
+
+ /**
+ * Adds roles of an active member of a user-group. Only user-group
+ * admins and system admins are allowed.
+ *
+ * @param securityContext
+ * @param groupName
+ * a group name
+ * @param memberUsername
+ * a username of a group member
+ * @param roleId
+ * a role id or multiple role ids
+ * @return if successful, HTTP response status OK
+ */
+ @Deprecated
+ @POST
+ @Path("@{groupName}/role/add")
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ public Response addMemberRoles (@Context SecurityContext securityContext,
+ @PathParam("groupName") String groupName,
+ @FormParam("memberUsername") String memberUsername,
+ @FormParam("roleId") List<Integer> roleIds) {
+ throw kustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.DEPRECATED,
+ "This web-service is deprecated and will be completely removed "
+ + "in API v1.1."));
+ }
/**Add group admin role to a member in a group
*
@@ -240,10 +282,10 @@
.getUserPrincipal();
try {
scopeService.verifyScope(context,
- OAuth2Scope.ADD_USER_GROUP_MEMBER_ROLE);
+ OAuth2Scope.ADD_MEMBER_ROLE);
service.addAdminRole(context.getUsername(), groupName,
memberUsername);
- return Response.ok("SUCCESS").build();
+ return Response.ok().build();
}
catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
@@ -270,15 +312,24 @@
public Response deleteMemberRoles (@Context SecurityContext securityContext,
@PathParam("groupName") String groupName,
@FormParam("memberUsername") String memberUsername,
+ @FormParam("roleId") List<Integer> roleIds,
@FormParam("role") List<PredefinedRole> roles) {
TokenContext context = (TokenContext) securityContext
.getUserPrincipal();
try {
scopeService.verifyScope(context,
- OAuth2Scope.DELETE_USER_GROUP_MEMBER_ROLE);
- service.deleteMemberRoles(context.getUsername(), groupName,
- memberUsername, roles);
- return Response.ok("SUCCESS").build();
+ OAuth2Scope.DELETE_MEMBER_ROLE);
+ if (roleIds != null && !roleIds.isEmpty()){
+ throw kustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.DEPRECATED,
+ "Parameter roleIds is deprecated and will be completely"
+ + " removed in API v1.1."));
+ }
+ else {
+ service.deleteMemberRoles(context.getUsername(), groupName,
+ memberUsername, roles);
+ }
+ return Response.ok().build();
}
catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
@@ -299,17 +350,10 @@
@Path("@{groupName}/subscribe")
public Response subscribeToGroup (@Context SecurityContext securityContext,
@PathParam("groupName") String groupName) {
- TokenContext context = (TokenContext) securityContext
- .getUserPrincipal();
- try {
- scopeService.verifyScope(context,
- OAuth2Scope.ADD_USER_GROUP_MEMBER);
- service.acceptInvitation(groupName, context.getUsername());
- return Response.ok("SUCCESS").build();
- }
- catch (KustvaktException e) {
- throw kustvaktResponseHandler.throwit(e);
- }
+ throw kustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.DEPRECATED,
+ "This web-service is deprecated and will be completely removed "
+ + "in API v1.1."));
}
/**
@@ -329,17 +373,9 @@
public Response unsubscribeFromGroup (
@Context SecurityContext securityContext,
@PathParam("groupName") String groupName) {
- TokenContext context = (TokenContext) securityContext
- .getUserPrincipal();
- try {
- scopeService.verifyScope(context,
- OAuth2Scope.DELETE_USER_GROUP_MEMBER);
- service.deleteGroupMember(context.getUsername(), groupName,
- context.getUsername());
- return Response.ok("SUCCESS").build();
- }
- catch (KustvaktException e) {
- throw kustvaktResponseHandler.throwit(e);
- }
+ throw kustvaktResponseHandler.throwit(new KustvaktException(
+ StatusCodes.DEPRECATED,
+ "This web-service is deprecated and will be complete removed "
+ + "in API v1.1."));
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
index 919c3c0..292c8e0 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
@@ -104,8 +104,6 @@
testUpdateUserGroup(groupName);
testAddMember(groupName, username, "darla");
testDeleteGroup(groupName,username);
-// testSubscribeToDeletedGroup(groupName);
-// testUnsubscribeToDeletedGroup(groupName);
}
private void testUpdateUserGroup (String groupName)
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
index b8f3bc1..630ee66 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
@@ -73,25 +73,12 @@
return response;
}
-// protected Response inviteMember (String groupName, String invitor,
-// String invitee) throws KustvaktException {
-// Form form = new Form();
-// form.param("members", invitee);
-// Response response = target().path(API_VERSION).path("group")
-// .path("@" + groupName).path("invite").request()
-// .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
-// .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
-// .createBasicAuthorizationHeaderValue(invitor, "pass"))
-// .post(Entity.form(form));
-//// assertEquals(Status.OK.getStatusCode(), response.getStatus());
-// return response;
-// }
-
protected void testAddMember (String groupName, String username,
String memberUsername)
throws KustvaktException {
Response response = addMember(groupName, memberUsername, username);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
// list group
JsonNode node = listUserGroups(username);
node = node.get(0);
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
index 3f1c8c0..5a1b900 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
@@ -301,7 +301,7 @@
JsonNode node = listUserGroups(testUser).get(0);
assertEquals(2, node.get("members").size());
assertEquals(memberName, node.at("/members/1/userId").asText());
- assertEquals(PrivilegeType.DELETE_MEMBER.name(),
+ assertEquals(PrivilegeType.DELETE_SELF.name(),
node.at("/members/1/privileges/0").asText());
}