Commit 4e52909d authored by Kevin Robert's avatar Kevin Robert
Browse files

Gestion des utilisateurs.

parent 5250e90e
......@@ -39,12 +39,18 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
Optional<User> findOneWithAuthoritiesByLogin(String login);
@EntityGraph(attributePaths = "authorities")
@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
Optional<User> findOneWithAuthoritiesById(Long id);
@EntityGraph(attributePaths = "authorities")
@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE)
Optional<User> findOneWithAuthoritiesByEmailIgnoreCase(String email);
Page<User> findAllByLoginNot(Pageable pageable, String login);
List<User> findAllByLoginNot(String login);
@Query(nativeQuery = true, value = "select distinct id_jhi_authority from role r join role_jhi_authority rj on rj.id_role = r.id join scope s on s.id_role = r.id where id_user = :idUser")
List<String> findAllAuthorities(@Param("idUser") Long idUser);
}
......@@ -261,6 +261,11 @@ public class UserService {
return userRepository.findAllByLoginNot(pageable, Constants.ANONYMOUS_USER).map(UserDTO::new);
}
@Transactional(readOnly = true)
public List<UserDTO> getAllManagedUsers() {
return userRepository.findAllByLoginNot(Constants.ANONYMOUS_USER).stream().map(UserDTO::new).collect(Collectors.toList());
}
@Transactional(readOnly = true)
public Optional<User> getUserWithAuthoritiesByLogin(String login) {
Optional<User> user = userRepository.findOneWithAuthoritiesByLogin(login);
......@@ -268,6 +273,13 @@ public class UserService {
return user;
}
@Transactional(readOnly = true)
public Optional<User> getUserWithAuthoritiesById(Long id) {
Optional<User> user = userRepository.findOneWithAuthoritiesById(id);
extractUserAuthority(user);
return user;
}
@Transactional(readOnly = true)
public Optional<User> getUserWithAuthorities() {
Optional<User> user = SecurityUtils.getCurrentUserLogin().flatMap(userRepository::findOneWithAuthoritiesByLogin);
......
......@@ -106,7 +106,8 @@ public class UserResource {
throw new EmailAlreadyUsedException();
} else {
User newUser = userService.createUser(userDTO);
mailService.sendCreationEmail(newUser);
// Aucune gestion des mails pour le moment. On n'envoi donc pas de mail de confirmation de création de compte.
// mailService.sendCreationEmail(newUser);
return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin()))
.headers(HeaderUtil.createAlert(applicationName, "userManagement.created", newUser.getLogin()))
.body(newUser);
......@@ -145,8 +146,8 @@ public class UserResource {
* @param pageable the pagination information.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body all users.
*/
@GetMapping("/users")
public ResponseEntity<List<UserDTO>> getAllUsers(Pageable pageable) {
@GetMapping("/userspageable")
public ResponseEntity<List<UserDTO>> getAllUsersPageable(Pageable pageable) {
if (!onlyContainsAllowedProperties(pageable)) {
return ResponseEntity.badRequest().build();
}
......@@ -156,6 +157,16 @@ public class UserResource {
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
/**
* {@code GET /users} : get all users.
*
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body all users.
*/
@GetMapping("/users")
public ResponseEntity<List<UserDTO>> getAllUsers() {
return new ResponseEntity<>(userService.getAllManagedUsers(), HttpStatus.OK);
}
private boolean onlyContainsAllowedProperties(Pageable pageable) {
return pageable.getSort().stream().map(Sort.Order::getProperty).allMatch(ALLOWED_ORDERED_PROPERTIES::contains);
}
......@@ -184,6 +195,20 @@ public class UserResource {
.map(UserDTO::new));
}
/**
* {@code GET /users/:id} : get the "id" user.
*
* @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) {
log.debug("REST request to get User : {}", id);
return ResponseUtil.wrapOrNotFound(
userService.getUserWithAuthoritiesById(id)
.map(UserDTO::new));
}
/**
* {@code DELETE /users/:login} : delete the "login" User.
*
......
......@@ -24,6 +24,10 @@ export default class UserManagementService {
return axios.get(`api/users?${buildPaginationQueryOpts(req)}`);
}
public retrieveAllManagedUsers(): Promise<any> {
return axios.get(`api/users`);
}
public retrieveAuthorities(): Promise<any> {
return axios.get('api/users/authorities');
}
......
......@@ -10,6 +10,12 @@ export default [
component: UserEditComponent,
meta: { authorities: [Authority.ADMIN] },
},
{
path: '/admin/user/creation',
name: 'UserEditComponent',
component: UserEditComponent,
meta: { authorities: [Authority.ADMIN] },
},
{
path: '/admin/user/list',
name: 'UserListComponent',
......
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 UserManagementService from '@/admin/user-management/user-management.service';
import {IUser, User} from "@/shared/model/user.model";
import OaButton from '@/components/button/oa-button.vue';
@Component
@Component({
components: {
OaInput,
OaButton
}
})
export default class UserEdit extends Vue {
@Inject('userService')
private userManagementService: () => UserManagementService;
public userAccount: IUser;
private isSaving: boolean = false;
public idUserParam: String = '';
public constructor() {
super();
this.userAccount = new User();
}
beforeRouteEnter(to, from, next) {
next(vm => {
if (to.params.idUser) {
vm.idUserParam = to.params.idUser;
vm.userManagementService()
.get(vm.idUserParam)
.then(res => {
res.dateTime = new Date(res.dateTime);
vm.userAccount = res.data;
});
}
});
}
public save() {
this.isSaving = true;
if (this.userAccount.id) {
this.userManagementService()
.update(this.userAccount)
.then(() => {
this.isSaving = false;
this.$router.go(-1);
});
} else {
this.userManagementService()
.create(this.userAccount)
.then(() => {
this.isSaving = false;
this.$router.go(-1);
});
}
}
public setLastname(lastname: String) {
this.userAccount.lastName = lastname;
}
public setFirstname(firstname: String) {
this.userAccount.firstName = firstname;
}
public setEmail(email: String) {
this.userAccount.email = email;
}
public setActivatedUser(active: boolean) {
this.userAccount.activated = active;
}
public setLogin(login: String) {
this.userAccount.login = login;
}
}
<template>
<main>
<section class="max-w-4xl mx-auto p-9">
<div class="flex items-center mb-8">
<h1 class="flex-auto text-4xl">Édition d'un utilisateur</h1>
</div>
<form v-on:submit.prevent="save()">
<oa-input v-if="idUserParam" id="id" label="ID" type="text" :value="userAccount.id" required="true" disabled="true"></oa-input>
<oa-input id="login" label="Login" type="text" :value="userAccount.login" required="true" @update="setLogin"></oa-input>
<oa-input id="lastname" label="Nom" type="text" :value="userAccount.lastName" required="true" @update="setLastname"></oa-input>
<oa-input id="firstname" label="Prénom" type="text" :value="userAccount.firstName" required="true" @update="setFirstname"></oa-input>
<oa-input id="email" label="Email" type="text" :value="userAccount.email" required="true" @update="setEmail"></oa-input>
<oa-input id="active" label="Activé" type="checkbox" :value="userAccount.activated" @update="setActivatedUser"></oa-input>
<oa-button type="submit" variant="primary" label="Enregistrer" ></oa-button>
</form>
</section>
</main>
</template>
<script lang="ts" src="./user-edit.component.ts"/>
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";
@Component
@Component({
components: {
Toolbar
}
})
export default class UserList extends Vue {
@Inject('userService')
private userManagementService: () => UserManagementService;
public users: any[] = [];
public mounted(): void {
this.loadAll();
}
public loadAll(): void {
this.userManagementService()
.retrieveAllManagedUsers()
.then(res => {
this.users = res.data;
});
}
}
<template>
<main>
<section class="max-w-6xl px-4 mx-auto py-9 xl:px-0">
<toolbar title="Utilisateurs" addActionName="Ajouter un utilisateur" actionLink="/admin/user/creation"></toolbar>
<table class="w-full bg-white border-t-2">
<thead class="font-bold">
<tr class="border-b-2">
<th class="p-2 text-left">Id</th>
<th class="p-2 text-left">Nom</th>
<th class="p-2 text-left">Email</th>
<th class="p-2 text-left">Actif</th>
</tr>
</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>
</tr>
</tbody>
</table>
</section>
</main>
</template>
<script lang="ts" src="./user-list.component.ts"/>
<template>
<form v-on:submit.prevent="save()">
<oa-input id="nom" label="Nom" type="text" placeholder="Mon workspace" value="name" required="true" @update="setName"></oa-input>
<oa-textarea id="description" label="Description" placeholder="Ma description" value="description" required="true" @update="setDescription"></oa-textarea>
<oa-button type="submit" variant="primary" label="Enregistrer"></oa-button>
</form>
<main>
<section class="max-w-4xl mx-auto p-9">
<div class="flex items-center mb-8">
<h1 class="flex-auto text-4xl">Nouvel espace de travail</h1>
</div>
<form v-on:submit.prevent="save()">
<oa-input id="nom" label="Nom" type="text" placeholder="Mon workspace" value="name" required="true" @update="setName"></oa-input>
<oa-textarea id="description" label="Description" placeholder="Ma description" value="description" required="true" @update="setDescription"></oa-textarea>
<oa-button type="submit" variant="primary" label="Enregistrer"></oa-button>
</form>
</section>
</main>
</template>
<script lang="ts" src="./workspace-creation.component.ts"/>
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