Commit 3a5c576f authored by igoshin's avatar igoshin Committed by Matija Obreza
Browse files

Final version of user story "Add role VETTEDUSER"

#10509
parent 0c6b6ed4
...@@ -18,7 +18,7 @@ package org.genesys2.server.model; ...@@ -18,7 +18,7 @@ package org.genesys2.server.model;
public enum UserRole { public enum UserRole {
USER("User"), ADMINISTRATOR("Administrator"), ORGANIZATION_ADMINISTRATOR("Organization Administrator"), NETWORK_ADMINISTRATOR("Network Administrator"), VALIDATEDUSER( USER("User"), ADMINISTRATOR("Administrator"), ORGANIZATION_ADMINISTRATOR("Organization Administrator"), NETWORK_ADMINISTRATOR("Network Administrator"), VALIDATEDUSER(
"Validated user"); "Validated user"),VETTEDUSER("Vetted user");
String label; String label;
......
...@@ -71,4 +71,6 @@ public interface UserService { ...@@ -71,4 +71,6 @@ public interface UserService {
void setAccountLockLocal(String uuid, boolean locked); void setAccountLockLocal(String uuid, boolean locked);
void userEmailValidated(String uuid); void userEmailValidated(String uuid);
void addVettedUserRole(String uuid);
} }
...@@ -16,12 +16,6 @@ ...@@ -16,12 +16,6 @@
package org.genesys2.server.service.impl; package org.genesys2.server.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.genesys2.server.exception.NoUserFoundException; import org.genesys2.server.exception.NoUserFoundException;
...@@ -52,6 +46,8 @@ import org.springframework.security.crypto.password.PasswordEncoder; ...@@ -52,6 +46,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Service @Service
@Transactional(readOnly = true) @Transactional(readOnly = true)
public class UserServiceImpl implements UserService { public class UserServiceImpl implements UserService {
...@@ -349,10 +345,27 @@ public class UserServiceImpl implements UserService { ...@@ -349,10 +345,27 @@ public class UserServiceImpl implements UserService {
addRoleToCurrentUser(user, UserRole.VALIDATEDUSER.getName()); addRoleToCurrentUser(user, UserRole.VALIDATEDUSER.getName());
LOG.info("Ensured VALIDATEDUSER role for user " + user); LOG.info("Ensured VALIDATEDUSER role for user " + user);
} catch (UserException e) { } catch (UserException e) {
LOG.error(e);
} }
} }
@Override
public void addVettedUserRole(String uuid){
User user = userPersistence.findByUuid(uuid);
Set<UserRole> userRoles = user.getRoles();
userRoles.add(UserRole.VETTEDUSER);
try {
updateUser(user);
addRoleToCurrentUser(user, UserRole.VETTEDUSER.getName());
LOG.info("Add role VETTEDUSER for user "+user);
} catch (UserException e) {
LOG.error(e);
}
}
private void addRoleToCurrentUser(User user, String role) { private void addRoleToCurrentUser(User user, String role) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
......
...@@ -80,6 +80,13 @@ public class UserProfileController extends BaseController { ...@@ -80,6 +80,13 @@ public class UserProfileController extends BaseController {
return "/user/index"; return "/user/index";
} }
@RequestMapping("/{uuid:.+}/addRoleVettedUser")
@PreAuthorize("hasRole('ADMINISTRATOR')")
public String addRoleVettedUser(@PathVariable("uuid")String uuid){
userService.addVettedUserRole(uuid);
return "redirect:/profile/list";
}
@RequestMapping("/{uuid:.+}") @RequestMapping("/{uuid:.+}")
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
public String someProfile(ModelMap model, @PathVariable("uuid") String uuid) { public String someProfile(ModelMap model, @PathVariable("uuid") String uuid) {
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
<c:if test="${not user.enabled}">DISABLED</c:if> <c:if test="${not user.enabled}">DISABLED</c:if>
<c:if test="${user.accountLocked}">LOCKED</c:if> <c:if test="${user.accountLocked}">LOCKED</c:if>
</td> </td>
<td><a href="<c:url value="/profile/${user.uuid}/addRoleVettedUser"/> "class="btn btn-default"/>VETTED USER</td>
</tr> </tr>
</c:forEach> </c:forEach>
</table> </table>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment