Commit 345451c8 authored by Matija Obreza's avatar Matija Obreza

Admin GUI updates

parent 11242cd0
......@@ -45,7 +45,7 @@ public class LoggerController {
loggers.add(allLoggers.get(firstelement + i));
}
PageImpl<Logger> pagedData = new PageImpl<Logger>(loggers, new PageRequest(page, defaultPageSize), allLoggers.size());
PageImpl<Logger> pagedData = new PageImpl<Logger>(loggers, new PageRequest(page - 1, defaultPageSize), allLoggers.size());
model.addAttribute("loggers", pagedData);
return "/admin/logger/index";
}
......@@ -60,7 +60,7 @@ public class LoggerController {
logger = LogManager.getLogger(loggerName);
model.addAttribute("logger", logger);
model.addAttribute("appenders", logger.getRootLogger().getAllAppenders());
model.addAttribute("appenders", Logger.getRootLogger().getAllAppenders());
return "/admin/logger/edit";
}
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.servlet.controller.admin;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.exception.UserException;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.EMailVerificationService;
import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.TokenVerificationService.NoSuchVerificationTokenException;
import org.genesys2.server.service.UserService;
import org.genesys2.server.servlet.controller.BaseController;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller("adminUsersController")
@RequestMapping(UserProfileController.URLBASE)
public class UserProfileController extends BaseController {
public static final String URLBASE = "/admin/users/";
public static final String VIEWBASE = "/admin/users/";
@Autowired
private UserService userService;
@Autowired
private TeamService teamService;
@Autowired
private EMailVerificationService emailVerificationService;
@RequestMapping("/")
public String list(ModelMap model, @RequestParam(value = "page", defaultValue = "1") int page) {
model.addAttribute("pagedData", userService.listUsers(new PageRequest(page - 1, 50, new Sort("name"))));
return VIEWBASE + "index";
}
@RequestMapping("/{uuid:.+}/vetted-user")
public String addRoleVettedUser(@PathVariable("uuid") String uuid) {
userService.addVettedUserRole(uuid);
return "redirect:" + URLBASE + uuid;
}
@RequestMapping("/{uuid:.+}")
public String someProfile(ModelMap model, @PathVariable("uuid") String uuid) {
final User user = userService.getUserByUuid(uuid);
if (user == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("user", user);
model.addAttribute("teams", teamService.listUserTeams(user));
return VIEWBASE + "profile";
}
@RequestMapping("/{uuid:.+}/edit")
public String edit(ModelMap model, @PathVariable("uuid") String uuid) {
someProfile(model, uuid);
model.addAttribute("availableRoles", userService.listAvailableRoles());
return VIEWBASE + "edit";
}
@RequestMapping(value = "/{uuid}/send", method = RequestMethod.GET)
public String sendEmail(ModelMap model, @PathVariable("uuid") String uuid) {
final User user = userService.getUserByUuid(uuid);
emailVerificationService.sendVerificationEmail(user);
return "redirect:" + URLBASE + user.getUuid();
}
@RequestMapping(value = "/{tokenUuid:.+}/cancel", method = RequestMethod.GET)
public String cancelValidation(ModelMap model, @PathVariable("tokenUuid") String tokenUuid) {
emailVerificationService.cancelValidation(tokenUuid);
return "redirect:" + URLBASE;
}
@RequestMapping(value = "/{tokenUuid:.+}/validate", method = RequestMethod.GET)
public String validateEmail(ModelMap model, @PathVariable("tokenUuid") String tokenUuid) {
model.addAttribute("tokenUuid", tokenUuid);
return VIEWBASE + "validateemail";
}
@RequestMapping(value = "/{tokenUuid:.+}/validate", method = RequestMethod.POST)
public String validateEmail2(ModelMap model, @PathVariable("tokenUuid") String tokenUuid, @RequestParam(value = "key", required = true) String key) {
try {
emailVerificationService.validateEMail(tokenUuid, key);
return "redirect:/profile";
} catch (final NoSuchVerificationTokenException e) {
// Not valid
model.addAttribute("tokenUuid", tokenUuid);
model.addAttribute("error", "error");
return VIEWBASE + "validateemail";
}
}
@RequestMapping(value = "/password/reset", method = RequestMethod.POST)
public String resetPassword(ModelMap model, @RequestParam("email") String email) {
final User user = userService.getUserByEmail(email);
if (user != null) {
emailVerificationService.sendPasswordResetEmail(user);
}
return "redirect:/content/user.password-reset-email-sent";
}
@RequestMapping(value = "/{tokenUuid:.+}/pwdreset", method = RequestMethod.GET)
public String passwordReset(ModelMap model, @PathVariable("tokenUuid") String tokenUuid) {
model.addAttribute("tokenUuid", tokenUuid);
return VIEWBASE + "password";
}
@RequestMapping(value = "/{tokenUuid:.+}/pwdreset", method = RequestMethod.POST)
public String updatePassword(ModelMap model, @PathVariable("tokenUuid") String tokenUuid, @RequestParam(value = "key", required = true) String key,
@RequestParam("password") String password) throws UserException {
try {
emailVerificationService.changePassword(tokenUuid, key, password);
return "redirect:/content/user.password-reset";
} catch (final NoSuchVerificationTokenException e) {
// Not valid
model.addAttribute("tokenUuid", tokenUuid);
model.addAttribute("error", "error");
return VIEWBASE + "password";
}
}
@RequestMapping(value = "/{uuid:.+}/update", method = { RequestMethod.POST })
public String update(ModelMap model, @PathVariable("uuid") String uuid, @RequestParam("name") String name, @RequestParam("email") String email,
@RequestParam("pwd1") String pwd1, @RequestParam("pwd2") String pwd2) {
final User user = userService.getUserByUuid(uuid);
if (user == null) {
throw new ResourceNotFoundException();
}
userService.updateData(user.getId(), name, email);
if (StringUtils.isNotBlank(pwd1)) {
if (pwd1.equals(pwd2)) {
try {
_logger.info("Updating password for " + user);
userService.updatePassword(user.getId(), pwd1);
_logger.warn("Password updated for " + user);
} catch (final UserException e) {
_logger.error(e.getMessage(), e);
}
} else {
_logger.warn("Passwords didn't match for " + user);
}
}
return "redirect:" + URLBASE + user.getUuid();
}
@RequestMapping(value = "/{uuid:.+}/update-roles", method = { RequestMethod.POST })
public String updateRoles(ModelMap model, @PathVariable("uuid") String uuid, @RequestParam("role") List<String> selectedRoles) {
final User user = userService.getUserByUuid(uuid);
if (user == null) {
throw new ResourceNotFoundException();
}
userService.updateRoles(user, selectedRoles);
return "redirect:" + URLBASE + user.getUuid();
}
}
......@@ -9,7 +9,7 @@ $link-color: #5476b2;
/* $link-color: darken($brand-primary, 10%) !default; */
// Background color for `<body>`.
$body-bg: #fff !default;
$body-bg: #f0f0f0 !default;
// Global text color on `<body>`.
$text-color: #000 !default;
......@@ -27,15 +27,15 @@ $font-size-h5: $font-size-base !default;
$font-size-h6: ceil(($font-size-base * 0.85)) !default; // ~12px
*/
//** Background color used for `.table-striped`.
$table-bg-accent: #dadad0 !default;
// bower:scss
@import "bootstrap-sass/assets/stylesheets/_bootstrap.scss";
// endbower
body {
background-color: #e7e5df;
}
/* bootstrap columns fix */
/* bootstrap columns fix
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12, .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6,
.col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12, .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11,
.col-md-12, .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
......@@ -44,10 +44,13 @@ body {
padding-right: 10px;
position: relative;
}
*/
/** RTL **/
html[dir="rtl"] {
.text-left { text-align: right; }
.text-right { text-align: left; }
.pull-left {
float: right !important;
}
......@@ -104,15 +107,17 @@ html[dir="rtl"] {
}
}
.navbar-right {
margin-right: 0;
}
.text-clip {
@include text-overflow;
}
/*
.navbar-right {
margin-right: 0;
}
.btn-default {
background-color: #eee;
}
\ No newline at end of file
}
*/
\ No newline at end of file
......@@ -4,6 +4,8 @@ $break-small: 320px;
$break-normal: 1024px;
$break-xlarge: 1200px;
$footer-height: 60px;
$table-bg-accent: #dadad0 !default;
@font-face {
font-family: 'FontAwesome';
......@@ -63,7 +65,7 @@ footer {
.rows-striped {
> .row:nth-of-type(odd) {
background-color: #f0f0f0;
background-color: $table-bg-accent;
}
}
......@@ -78,3 +80,14 @@ footer {
}
h1.page-title {
background-color: rgb(136, 186, 66);
padding-top: 10px;
font-size: 20px;
font-weight: bold;
padding-bottom: 5px;
color: Black;
margin-top: 0px;
border-top: 2px solid White;
border-bottom: 2px solid white;
}
......@@ -87,12 +87,12 @@
</a>
<ul class="dropdown-menu pull-left">
<li>
<a href="<c:url value="/1/profile/list" />">
<a href="<c:url value="/1/admin/users/" />">
<spring:message code="user.pulldown.users" />
</a>
</li>
<li>
<a href="<c:url value="/1/team" />">
<a href="<c:url value="/1/admin/teams/" />">
<spring:message code="user.pulldown.teams" />
</a>
</li>
......@@ -125,9 +125,11 @@
<sitemesh:write property="page.header" />
</div>
<div id="content-body" class="">
<%-- <h1>
<sitemesh:write property="title" />
</h1>--%>
<div class="row">
<h1 class="col-xs-12 page-title">
<sitemesh:write property="title" />
</h1>
</div>
<div id="dialog" class="row"></div>
<div id="content-body-content" class="" typeof="<sitemesh:write property="body.typeof" />">
<sitemesh:write property="body" />
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<html>
<head>
<title><spring:message code="admin.cache.page.title" />1
</title>
<title><spring:message code="admin.cache.page.title" />1</title>
</head>
<body>
<div class="row">
<div class="col-xs-12">
<form class="form-inline" method="post" action="<c:url value="/admin/cache/clearCache" />">
<button type="submit" name="clearTiles" class="btn btn-warning">Clear tiles cache</button>
<button type="submit" name="clearAll" class="btn btn-warning">Clear all caches</button>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
</div>
</div>
<div class="row row-header">
<div class="col-sm-7 col-xs-12"></div>
......@@ -34,7 +24,15 @@
<div class="col-sm-1 col-xs-2">
<spring:message code="cache.stat.map.hits" />
</div>
<div class="col-sm-1 col-xs-2"></div>
<div class="col-sm-1 col-xs-2">
<form class="form-inline" method="post"
action="<c:url value="/admin/cache/clearCache" />">
<button type="submit" name="clearAll" class="btn btn-warning">Clear</button>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
</div>
</div>
<div class="rows-striped">
......@@ -42,11 +40,8 @@
<div class="row">
<div class="col-sm-7 col-xs-12">
<div class="form-control-static">
<b>
<c:out value="${cacheMap.name}" />
</b>
<small>
<c:out value="${cacheMap.serviceName}" />
<b> <c:out value="${cacheMap.name}" />
</b> <small> <c:out value="${cacheMap.serviceName}" />
</small>
</div>
</div>
......@@ -73,11 +68,13 @@
</div>
<div class="col-sm-1 col-xs-2">
<form method="post" action="<c:url value="/admin/cache/clearCache" />">
<form method="post"
action="<c:url value="/admin/cache/clearCache" />">
<input type="hidden" name="name" value="${cacheMap.name}" />
<button type="submit" class="btn btn-default btn-sm">Clear</button>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
</div>
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<html>
<head>
<title><spring:message code="loggers.list.page" /></title>
</head>
<body>
<table class="table table-striped">
<thead>
<tr>
<th class="col-xs-8"><spring:message code="logger.name" /></th>
<th class="col-xs-4 text-right"><spring:message
code="logger.log-level" /></th>
</tr>
</thead>
<tbody>
<c:forEach items="${loggers.content}" var="logger" varStatus="status">
<tr>
<td class="col-xs-8 form-control-static"><a
href="<c:url value="/admin/logger/${logger.name}." />">${logger.name}</a>
</td>
<td class="col-xs-4 text-right form-control-static"><c:out
value="${logger.level}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
<div class="row">
<form method="post" action=<c:url value="/admin/logger/addLoger"/>>
<div class="form-group col-xs-8">
<input class="form-control" type="text" name="nameNewLogger"
placeholder="com.example.package.Class" />
</div>
<div class="form-group col-xs-4">
<select class="form-control" name="loggerLevel">
<c:forTokens items="all,debug,info,warn,error,fatal,off,trace"
delims="," var="level">
<option value="${level}" ${level == "debug" ? "selected" : ""}>
${level}</option>
</c:forTokens>
</select>
</div>
<div class="form-group col-xs-2">
<input type="submit" class="btn btn-primary"
value="<spring:message code="logger.add-logger" />" />
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
</div>
<local:paginate2 page="${loggers}" />
</body>
</html>
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="userprofile.update.title" /></title>
</head>
<body>
<form role="form" class="form-horizontal validate" action="<c:url value="/admin/users/${user.uuid}/update" />" method="post">
<div class="form-group">
<label for="name" class="col-lg-2 control-label"><spring:message code="registration.full-name" /></label>
<div class="col-lg-3">
<input type="text" id="name" name="name" class="span3 form-control" value="${user.name}" />
</div>
</div>
<div class="form-group">
<label for="email" class="col-lg-2 control-label"><spring:message code="registration.email" /></label>
<div class="col-lg-3">
<input type="text" id="email" name="email" class="span3 form-control" value="${user.email}" />
</div>
</div>
<div class="form-group">
<label for="password" class="col-lg-2 control-label"><spring:message code="registration.password" /></label>
<div class="col-lg-3">
<input type="password" id="password" name="pwd1" class="span3 form-control" autocomplete="off" />
</div>
</div>
<div class="form-group">
<label for="confirm_password" class="col-lg-2 control-label"><spring:message code="registration.confirm-password" /></label>
<div class="col-lg-3">
<input type="password" id="confirm_password" name="pwd2" class="span3 required form-control" autocomplete="off" equalTo="#pwd1" />
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<input type="submit" value="<spring:message code="save"/>" class="btn btn-primary" />
<a class="btn btn-default" href="<c:url value="/admin/users/${user.uuid}" />" class="btn"> <spring:message code="cancel" />
</a>
</div>
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<security:authorize access="hasRole('ADMINISTRATOR')">
<h1>
<spring:message code="user.roles" />
</h1>
<form role="form" class="form-horizontal validate" action="<c:url value="/profile/${user.uuid}/update-roles" />" method="post">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<c:forEach items="${availableRoles}" var="role">
<div class="form-group">
<div class="col-lg-12">
<label><input type="checkbox" name="role" value="${role}" ${user.hasRole(role) ? 'checked="true"' : ''} /> ${role}</label>
</div>
</div>
</c:forEach>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<input type="submit" value="<spring:message code="save"/>" class="btn btn-primary" />
</div>
</div>
</form>
</security:authorize>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="user.page.list.title" /></title>
</head>
<body>
<table class="table table-striped">
<thead>
<tr>
<th class="col-xs-5"><spring:message code="registration.full-name" /></th>
<th class="col-xs-2"> 1</th>
<th class="col-xs-5"><spring:message code="registration.email" /></th>
</tr>
</thead>
<tbody>
<c:forEach items="${pagedData.content}" var="user" varStatus="status">
<tr>
<td class="col-xs-5"><c:if test="${not user.systemAccount}">
<a href="<c:url value="/admin/users/${user.uuid}" />"><c:out
value="${user.name}" /></a>
</c:if></td>
<td class="col-xs-2"><c:if test="${user.systemAccount}">SYSTEM</c:if>
<c:if test="${not user.enabled}">DISABLED</c:if> <c:if
test="${user.accountLocked}">LOCKED</c:if></td>
<td class="col-xs-5">${user.email}</td>
</tr>
</c:forEach>
</tbody>
</table>
<local:paginate2 page="${pagedData}" />
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="userprofile.page.title" /></title>
</head>
<body>
<security:authorize access="hasRole('ADMINISTRATOR') || (isAuthenticated() && principal.user.id == #user.id)">
<a href="<c:url value="/admin/users/${user.uuid}/edit" />" class="close"> <spring:message code="edit" /></a>
</security:authorize>
<div class="form-horizontal">
<div class="form-group">
<label for="password" class="col-lg-2 control-label"><spring:message code="user.full-name" /></label>
<div class="col-lg-5 form-control-static">${user.name}</div>
</div>
<security:authorize access="hasRole('ADMINISTRATOR') || (isAuthenticated() && principal.user.id == #user.id)">
<div class="form-group">
<label for="password" class="col-lg-2 control-label"><spring:message code="user.email" /></label>
<div class="col-lg-5 form-control-static">${user.email}</div>
</div>