Commit 8bdf6f91 by CVirtuaali Kehittaja

Added rest api /v2/user/userid/addrole for adding roles to users

1 parent 3b053f40
...@@ -4,6 +4,7 @@ import fi.codecrew.moya.beans.*; ...@@ -4,6 +4,7 @@ import fi.codecrew.moya.beans.*;
import fi.codecrew.moya.enums.Gender; import fi.codecrew.moya.enums.Gender;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.model.*; import fi.codecrew.moya.model.*;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.rest.PojoUtils; import fi.codecrew.moya.rest.PojoUtils;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo; import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardUpdateCodePojo; import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardUpdateCodePojo;
...@@ -50,7 +51,8 @@ public class UserRestViewV2 { ...@@ -50,7 +51,8 @@ public class UserRestViewV2 {
private ReaderBeanLocal readerbean; private ReaderBeanLocal readerbean;
@EJB @EJB
private CardTemplateBeanLocal cardBean; private CardTemplateBeanLocal cardBean;
@EJB
private transient RoleBeanLocal roleBean;
@Inject @Inject
PojoFactoryV2 pojoFactory; PojoFactoryV2 pojoFactory;
...@@ -294,4 +296,34 @@ public class UserRestViewV2 { ...@@ -294,4 +296,34 @@ public class UserRestViewV2 {
} }
} }
// This add role to user. And add user to event if needed. Sorry but I dont have method to get list of roles XDDD
@PUT
@Operation(description = "Add role to eventuser")
@Path("/{userid}/addrole")
public Response addUserRole(PrintedCardUpdateCodePojo codepojo, @PathParam("userid") @Parameter(description = "Event user id") Integer userId, @QueryParam("roleId") Integer roleId) {
try {
if (permissionBean.hasPermission(UserPermission.VIEW_ALL) == false) {
return Response.status(Response.Status.FORBIDDEN).build();
}
EventUser user = userBean.findByEventUserId(userId);
if (user == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
Role role = roleBean.find(roleId);
if (role == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
roleBean.addRole(user, role);
return Response.ok(pojoFactory.createUserPojo(user)).build();
} catch (Exception e) {
logger.error("Adding user role failed to event user", e);
return Response.serverError().entity(PojoUtils.initErrorPojo("adding role failed to event user")).build();
}
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!