Commit c987c375 authored by Kevin Robert's avatar Kevin Robert
Browse files

Prise en compte des remarques de PR et corrections suite à la mise à jour de Jhipster.

parent ea1460a1
package com.unantes.orientactive.security.permissions;
import com.unantes.orientactive.domain.User;
import com.unantes.orientactive.service.dto.UserDTO;
import java.util.List;
import java.util.Optional;
import com.unantes.orientactive.service.dto.AdminUserDTO;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.List;
import java.util.Optional;
/**
* Abstraction des services comprenant la gestion des permissions.
* Oblige l'implémentation des méthodes de gestion des droits.
......@@ -113,7 +114,7 @@ public abstract class PermissionService<T extends PermissionEntity> {
* @param element L'élément.
* @return La liste des utilisateurs.
*/
public abstract List<UserDTO> findAllWithPermission(T element);
public abstract List<AdminUserDTO> findAllWithPermission(T element);
/**
* Méthode interne permettant de récupérer les entités que l'utilisateur a la permission d'administer.
......
......@@ -4,13 +4,14 @@ import com.unantes.orientactive.domain.User;
import com.unantes.orientactive.security.permissions.PermissionEntity;
import com.unantes.orientactive.security.permissions.PermissionService;
import com.unantes.orientactive.service.UserService;
import com.unantes.orientactive.service.dto.UserDTO;
import com.unantes.orientactive.service.dto.AdminUserDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* Mutualisation de la mise en place de l'API des permissions.
......@@ -179,9 +180,9 @@ public abstract class PermissionController {
* @return La liste des utilisateurs.
*/
@GetMapping("/findAllWithPermission/{idEntity}")
public List<UserDTO> findAllWithPermission(@PathVariable final long idEntity) {
public List<AdminUserDTO> findAllWithPermission(@PathVariable final long idEntity) {
final Optional<PermissionEntity> entity = permissionService.findOne(idEntity);
List<UserDTO> users = new LinkedList<>();
List<AdminUserDTO> users = new LinkedList<>();
if (entity.isPresent()) {
users = permissionService.findAllWithPermission(entity.get());
}
......
......@@ -6,19 +6,20 @@ import com.unantes.orientactive.repository.FormRepository;
import com.unantes.orientactive.security.permissions.PermissionEntity;
import com.unantes.orientactive.security.permissions.PermissionService;
import com.unantes.orientactive.security.permissions.Role;
import com.unantes.orientactive.service.dto.AdminUserDTO;
import com.unantes.orientactive.service.dto.FormDTO;
import com.unantes.orientactive.service.dto.UserDTO;
import com.unantes.orientactive.service.mapper.FormMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Service Implementation for managing {@link Form}.
*/
......@@ -201,7 +202,7 @@ public class FormService extends PermissionService<FormDTO> {
}
@Override
public List<UserDTO> findAllWithPermission(FormDTO element) {
public List<AdminUserDTO> findAllWithPermission(FormDTO element) {
return userService.findAllWithPermissionOnForm(Role.CONTRIBUTEUR.getId(), element.getId());
}
......
......@@ -9,10 +9,6 @@ import com.unantes.orientactive.security.AuthoritiesConstants;
import com.unantes.orientactive.security.SecurityUtils;
import com.unantes.orientactive.service.dto.AdminUserDTO;
import com.unantes.orientactive.service.dto.UserDTO;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager;
......@@ -24,6 +20,15 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.jhipster.security.RandomUtil;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Service class for managing users.
*/
......@@ -299,8 +304,8 @@ public class UserService {
}
@Transactional(readOnly = true)
public List<UserDTO> getAllManagedUsers() {
return userRepository.findAllByLoginNot(Constants.ANONYMOUS_USER).stream().map(UserDTO::new).collect(Collectors.toList());
public List<AdminUserDTO> getAllManagedUsers() {
return userRepository.findAll().stream().map(AdminUserDTO::new).collect(Collectors.toList());
}
@Transactional(readOnly = true)
......@@ -381,12 +386,12 @@ public class UserService {
}
}
public List<UserDTO> findAllWithPermissionOnWorkspace(final int idRole, final Long idWorkspace) {
return userRepository.findAllWithPermissionOnWorkspace(idRole, idWorkspace).stream().map(UserDTO::new).collect(Collectors.toList());
public List<AdminUserDTO> findAllWithPermissionOnWorkspace(final int idRole, final Long idWorkspace) {
return userRepository.findAllWithPermissionOnWorkspace(idRole, idWorkspace).stream().map(AdminUserDTO::new).collect(Collectors.toList());
}
public List<UserDTO> findAllWithPermissionOnForm(final int idRole, final Long idForm) {
return userRepository.findAllWithPermissionOnForm(idRole, idForm).stream().map(UserDTO::new).collect(Collectors.toList());
public List<AdminUserDTO> findAllWithPermissionOnForm(final int idRole, final Long idForm) {
return userRepository.findAllWithPermissionOnForm(idRole, idForm).stream().map(AdminUserDTO::new).collect(Collectors.toList());
}
public List<String> findAllAuthorities(Long idUser) {
......
......@@ -6,6 +6,7 @@ import com.unantes.orientactive.repository.WorkspaceRepository;
import com.unantes.orientactive.security.permissions.PermissionEntity;
import com.unantes.orientactive.security.permissions.PermissionService;
import com.unantes.orientactive.security.permissions.Role;
import com.unantes.orientactive.service.dto.AdminUserDTO;
import com.unantes.orientactive.service.dto.UserDTO;
import com.unantes.orientactive.service.dto.WorkspaceDTO;
import com.unantes.orientactive.service.mapper.WorkspaceMapper;
......@@ -163,7 +164,7 @@ public class WorkspaceService extends PermissionService<WorkspaceDTO> {
}
@Override
public List<UserDTO> findAllWithPermission(WorkspaceDTO element) {
public List<AdminUserDTO> findAllWithPermission(WorkspaceDTO element) {
return userService.findAllWithPermissionOnWorkspace(Role.RESPONSABLE_ESPACE.getId(), element.getId());
}
......
......@@ -7,18 +7,26 @@ import com.unantes.orientactive.service.MailService;
import com.unantes.orientactive.service.UserService;
import com.unantes.orientactive.service.dto.AdminUserDTO;
import com.unantes.orientactive.service.dto.PasswordChangeDTO;
import com.unantes.orientactive.service.dto.UserDTO;
import com.unantes.orientactive.web.rest.errors.*;
import com.unantes.orientactive.web.rest.errors.EmailAlreadyUsedException;
import com.unantes.orientactive.web.rest.errors.InvalidPasswordException;
import com.unantes.orientactive.web.rest.errors.LoginAlreadyUsedException;
import com.unantes.orientactive.web.rest.vm.KeyAndPasswordVM;
import com.unantes.orientactive.web.rest.vm.ManagedUserVM;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Optional;
/**
* REST controller for managing the current user's account.
......
......@@ -169,7 +169,7 @@ public class UserResource {
*/
@GetMapping("/users")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<List<UserDTO>> getAllUsers() {
public ResponseEntity<List<AdminUserDTO>> getAllUsers() {
return new ResponseEntity<>(userService.getAllManagedUsers(), HttpStatus.OK);
}
......@@ -196,10 +196,11 @@ public class UserResource {
* @param id the id of the user to find.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the "login" user, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/users/{id}")
public ResponseEntity<UserDTO> getUserById(@PathVariable Long id) {
@GetMapping("/users/id/{id}")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<AdminUserDTO> getUserById(@PathVariable Long id) {
log.debug("REST request to get User : {}", id);
return ResponseUtil.wrapOrNotFound(userService.getUserWithAuthoritiesById(id).map(UserDTO::new));
return ResponseUtil.wrapOrNotFound(userService.getUserWithAuthoritiesById(id).map(AdminUserDTO::new));
}
/**
......
......@@ -5,30 +5,30 @@ import { Authority } from '@/shared/security/authority';
export default class UserManagementService {
public get(userId: number): Promise<any> {
return axios.get(`api/users/${userId}`);
return axios.get(`api/admin/users/id/${userId}`);
}
public create(user): Promise<any> {
return axios.post('api/users', user);
return axios.post('api/admin/users', user);
}
public update(user): Promise<any> {
return axios.put('api/users', user);
return axios.put('api/admin/users', user);
}
public remove(userId: number): Promise<any> {
return axios.delete(`api/users/${userId}`);
return axios.delete(`api/admin/users/${userId}`);
}
public retrieve(req?: any): Promise<any> {
return axios.get(`api/users?${buildPaginationQueryOpts(req)}`);
return axios.get(`api/admin/users?${buildPaginationQueryOpts(req)}`);
}
public retrieveAllManagedUsers(): Promise<any> {
return axios.get(`api/users`);
return axios.get(`api/admin/users`);
}
public retrieveAuthorities(): Promise<any> {
return axios.get('api/users/authorities');
return axios.get('api/admin/users/authorities');
}
}
......@@ -34,7 +34,7 @@ export default class FormService {
public retrieveWithPermission(login: string, workspaceId: number): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
.get(baseApiUrl + '/find/' + login + '/' + workspaceId)
.get(`${baseApiUrl}/find/${login}/${workspaceId}`)
.then(res => {
resolve(res);
})
......@@ -47,7 +47,7 @@ export default class FormService {
public findAllWithPermission(idEntity: number): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
.get(baseApiUrl + '/findAllWithPermission/' + idEntity)
.get(`${baseApiUrl}/findAllWithPermission/${idEntity}`)
.then(res => {
resolve(res);
})
......@@ -99,7 +99,7 @@ export default class FormService {
public export(entity: IForm): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
.get(baseApiUrl + '/export/' + entity.reference)
.get(`${baseApiUrl}/export/${entity.reference}`)
.then(res => {
resolve(res);
})
......
......@@ -34,7 +34,7 @@ export default class WorkspaceService {
public retrieveWithPermission(login: string): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
.get(baseApiUrl + '/find/' + login)
.get(`${baseApiUrl}/find/${login}`)
.then(res => {
resolve(res);
})
......@@ -47,7 +47,7 @@ export default class WorkspaceService {
public findAllWithPermission(idEntity: number): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
.get(baseApiUrl + '/findAllWithPermission/' + idEntity)
.get(`${baseApiUrl}/findAllWithPermission/${idEntity}`)
.then(res => {
resolve(res);
})
......
import Vue from 'vue';
import Component from 'vue-class-component';
import {Inject} from "vue-property-decorator";
import OaInput from "@/components/forms/input/oa-input.vue";
import OaTextarea from "@/components/forms/textarea/oa-textarea.vue";
import OaButton from "@/components/button/oa-button.vue";
import {Form} from "@/shared/model/form.model";
import FormService from "@/entities/form/form.service";
import { Inject } from 'vue-property-decorator';
import OaInput from '@/components/forms/input/oa-input.vue';
import OaTextarea from '@/components/forms/textarea/oa-textarea.vue';
import OaButton from '@/components/button/oa-button.vue';
import { Form } from '@/shared/model/form.model';
import FormService from '@/entities/form/form.service';
@Component({
......
......@@ -60,6 +60,10 @@ export default class FormSettings extends Vue {
});
}
public getUserEditLink(userId: String) {
return `/admin/user/${userId}/edit`;
}
setName(name: String) {
this.form.name = name;
}
......
......@@ -21,10 +21,10 @@
</thead>
<tbody>
<tr v-for="(user, index) in authorizedUsers" class="text-left align-top border-b">
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.id }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.firstName }} {{ user.lastName }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.email }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.activated }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.id }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.firstName }} {{ user.lastName }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.email }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.activated }}</a></td>
</tr>
</tbody>
</table>
......
import Vue from 'vue';
import Component from 'vue-class-component';
import OaInput from '@/components/forms/input/oa-input.vue';
import {Inject} from "vue-property-decorator";
import {Inject} from 'vue-property-decorator';
import UserManagementService from '@/admin/user-management/user-management.service';
import {IUser, User} from "@/shared/model/user.model";
import {IUser, User} from '@/shared/model/user.model';
import OaButton from '@/components/button/oa-button.vue';
@Component({
......
import Vue from 'vue';
import Component from 'vue-class-component';
import Toolbar from '@/components/toolbar/toolbar.vue';
import {Inject} from "vue-property-decorator";
import UserManagementService from "@/admin/user-management/user-management.service";
import {Inject} from 'vue-property-decorator';
import UserManagementService from '@/admin/user-management/user-management.service';
@Component({
components: {
......@@ -27,4 +27,8 @@ export default class UserList extends Vue {
this.users = res.data;
});
}
public getUserEditLink(userId: String) {
return `/admin/user/${userId}/edit`;
}
}
......@@ -13,10 +13,10 @@
</thead>
<tbody>
<tr v-for="(user, index) in users" class="text-left align-top border-b">
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.id }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.firstName }} {{ user.lastName }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.email }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.activated }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.id }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.firstName }} {{ user.lastName }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.email }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.activated }}</a></td>
</tr>
</tbody>
</table>
......
......@@ -2,9 +2,9 @@ import Vue from 'vue';
import Component from 'vue-class-component';
import OaInput from '@/components/forms/input/oa-input.vue';
import OaTextarea from '@/components/forms/textarea/oa-textarea.vue';
import {Inject} from "vue-property-decorator";
import WorkspaceService from "@/entities/workspace/workspace.service";
import Workspace from "@/shared/model/workspace.model";
import {Inject} from 'vue-property-decorator';
import WorkspaceService from '@/entities/workspace/workspace.service';
import Workspace from '@/shared/model/workspace.model';
import OaButton from '@/components/button/oa-button.vue';
@Component({
......
......@@ -60,6 +60,10 @@ export default class WorkspaceSettings extends Vue {
});
}
public getUserEditLink(userId: String) {
return `/admin/user/${userId}/edit`;
}
public setName(name: String) {
this.workspace.name = name;
}
......
......@@ -21,10 +21,10 @@
</thead>
<tbody>
<tr v-for="(user, index) in authorizedUsers" class="text-left align-top border-b">
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.id }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.firstName }} {{ user.lastName }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.email }}</a></td>
<td class="p-2"><a :href="'/admin/user/' + user.id + '/edit'">{{ user.activated }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.id }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.firstName }} {{ user.lastName }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.email }}</a></td>
<td class="p-2"><a :href="getUserEditLink(user.id)">{{ user.activated }}</a></td>
</tr>
</tbody>
</table>
......
import Vue from 'vue';
import Component from 'vue-class-component';
import {Inject} from "vue-property-decorator";
import Card from "@/components/card/card.vue";
import Toolbar from "@/components/toolbar/toolbar.vue";
import FormService from "@/entities/form/form.service";
import {Inject} from 'vue-property-decorator';
import Card from '@/components/card/card.vue';
import Toolbar from '@/components/toolbar/toolbar.vue';
import FormService from '@/entities/form/form.service';
@Component({
components: {
......
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