Commit fc8cb7e7 authored by François-Xavier Lebastard's avatar François-Xavier Lebastard
Browse files

Merge branch 'develop' into feature/gestion_des_ecrans

parents 28d57f2c d9180922
......@@ -65,4 +65,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
nativeQuery = true
)
List<User> findAllWithPermissionOnForm(@Param("idRole") int idRole, @Param("idForm") Long idForm);
List<User> findByLoginContaining(String login);
}
......@@ -401,4 +401,8 @@ public class UserService {
public List<String> findAllAuthorities(Long idUser) {
return userRepository.findAllAuthorities(idUser);
}
public List<AdminUserDTO> findByLoginContaining(final String login) {
return userRepository.findByLoginContaining(login).stream().map(AdminUserDTO::new).collect(Collectors.toList());
}
}
......@@ -217,4 +217,10 @@ public class UserResource {
userService.deleteUser(login);
return ResponseEntity.noContent().headers(HeaderUtil.createAlert(applicationName, "userManagement.deleted", login)).build();
}
@GetMapping("/users/autocomplete")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")")
public ResponseEntity<List<AdminUserDTO>> getUsersAutocomplete(@RequestParam("login") final String login) {
return new ResponseEntity<>(userService.findByLoginContaining(login), HttpStatus.OK);
}
}
......@@ -31,4 +31,8 @@ export default class UserManagementService {
public retrieveAuthorities(): Promise<any> {
return axios.get('api/admin/users/authorities');
}
public findAllByLoginLike(login: string): Promise<any> {
return axios.get(`api/admin/users/autocomplete?login=${login}`);
}
}
import Vue from 'vue';
import Component from 'vue-class-component';
import { User } from '@/shared/model/user.model';
import { Prop } from 'vue-property-decorator';
import { IUser, User } from '@/shared/model/user.model';
import { Inject, Prop } from 'vue-property-decorator';
import OaInput from '@/components/forms/input/oa-input.vue';
import UserManagementService from '@/admin/user-management/user-management.service';
import OaButton from '@/components/button/oa-button.vue';
import Icon from '@/components/icon/icon.vue';
@Component
@Component({
components: {
OaInput,
OaButton,
Icon,
},
})
export default class AdminUsersTable extends Vue {
@Prop()
public users: User[];
public authorizedUsers: User[];
public loginSearch: string = '';
private userSelected: IUser = new User();
public autocompleteUsers: IUser[] = [];
@Inject('userService')
private userManagementService: () => UserManagementService;
public getUserEditLink(userId: string) {
return `/admin/user/${userId}/edit`;
}
public set currentLoginSearch(login: string) {
this.loginSearch = login;
if (this.loginSearch) {
this.userManagementService()
.findAllByLoginLike(this.loginSearch)
.then(res => {
this.autocompleteUsers = res.data;
});
}
}
public get currentLoginSearch(): string {
return this.loginSearch;
}
public getDisplayStringAutocomplete(user: IUser) {
return `${user.firstName} ${user.lastName} (${user.login})`;
}
public selectUser(user: IUser) {
this.loginSearch = user.login;
this.userSelected = user;
this.autocompleteUsers = [];
}
public addPermission() {
if (this.userSelected) {
this.$emit('addPermission', this.userSelected);
this.authorizedUsers.push(this.userSelected);
}
}
public deletePermission(user: IUser) {
this.$emit('removePermission', user);
this.authorizedUsers = this.authorizedUsers.filter(value => value.id !== user.id);
}
}
<template>
<main>
<h2 class="mb-4 text-2xl" v-text="$t('user.table.titre')">Utilisateurs</h2>
<h2 class="mb-4 text-2xl">{{ $t('user.table.titre') }}</h2>
<p class="mb-4">{{ $t('user.table.info') }}</p>
<div class="flex items-center">
<input
class="w-full px-6 py-4 text-lg transition bg-white border rounded-md outline-none ring-inset focus:ring"
:placeholder="$t('user.actions.addContrib')"
v-model="currentLoginSearch"
list="user-choice"
/>
<oa-button variant="primary" :label="$t('user.actions.addUser')" @click="addPermission"></oa-button>
</div>
<div class="mb-8">
<datalist v-if="autocompleteUsers" class="bg-white" id="user-choice">
<option v-for="(user, index) in autocompleteUsers" :key="index" @click="selectUser(user)">
{{ getDisplayStringAutocomplete(user) }}
</option>
</datalist>
</div>
<table class="w-full bg-white border-t-2">
<thead class="font-bold">
<tr class="border-b-2">
<th class="p-2 text-left" v-text="$t('user.table.id')">ID</th>
<th class="p-2 text-left" v-text="$t('user.table.nom')">Nom</th>
<th class="p-2 text-left" v-text="$t('user.table.email')">Email</th>
<th class="p-2 text-left" v-text="$t('user.table.actif')">Actif</th>
<th class="p-2 text-left">{{ $t('user.table.id') }}</th>
<th class="p-2 text-left">{{ $t('user.table.nom') }}</th>
<th class="p-2 text-left">{{ $t('user.table.email') }}</th>
<th class="p-2 text-left">{{ $t('user.table.actif') }}</th>
<th class="p-2 text-center">{{ $t('user.table.actions') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(user, index) in users" :key="index" class="text-left align-top border-b">
<tr v-for="(user, index) in authorizedUsers" :key="index" class="text-left align-top border-b">
<td class="p-2">
<a :href="getUserEditLink(user.id)">{{ user.id }}</a>
</td>
......@@ -24,6 +42,14 @@
<td class="p-2">
<a :href="getUserEditLink(user.id)">{{ user.activated }}</a>
</td>
<td class="p-2">
<button
class="flex items-center p-2 text-red-600 transition ml-auto mr-auto hover:bg-red-600 focus:ring hover:text-red-100"
@click="deletePermission(user)"
>
<icon name="trash"></icon>
</button>
</td>
</tr>
</tbody>
</table>
......
......@@ -108,4 +108,12 @@ export default class FormService {
});
});
}
public addRoleWithPermission(loginUser: string, idForm: number): Promise<any> {
return axios.get(`${baseApiUrl}/addRoleWithPermission/${loginUser}/${idForm}`);
}
public removePermission(loginUser: string, idForm: number): Promise<any> {
return axios.get(`${baseApiUrl}/removePermission/${loginUser}/${idForm}`);
}
}
......@@ -95,4 +95,12 @@ export default class WorkspaceService {
});
});
}
public addRoleWithPermission(loginUser: string, idWorkspace: number): Promise<any> {
return axios.get(`${baseApiUrl}/addRoleWithPermission/${loginUser}/${idWorkspace}`);
}
public removePermission(loginUser: string, idWorkspace: number): Promise<any> {
return axios.get(`${baseApiUrl}/removePermission/${loginUser}/${idWorkspace}`);
}
}
export const TABS = {
KEY_SETTINGS: 'settings',
KEY_VIEW: 'view',
KEY_VARIABLE: 'variable',
KEY_WORKSPACES: 'workspaces',
KEY_USERS: 'users',
};
......@@ -8,6 +8,8 @@ import OaTextarea from '@/components/forms/textarea/oa-textarea.vue';
import OaButton from '@/components/button/oa-button.vue';
import AdminUsersTable from '@/components/table/admin-users-table.vue';
import HeaderService from '@/shared/service/header-service';
import { IUser } from '@/shared/model/user.model';
import { TABS } from '@/shared/service/tabs-constants';
@Component({
components: {
......@@ -26,6 +28,8 @@ export default class FormSettings extends Vue {
public form: IForm = new Form();
private currentIdForm: number = -1;
private isSaving = false;
public authorizedUsers: Object[] = [];
......@@ -34,7 +38,7 @@ export default class FormSettings extends Vue {
next(vm => {
vm.headerService().filArianeForForm(to.params.idForm);
if (to.params.idForm) {
vm.headerService().updateTabsForFormId(to.params.idWorkspace, to.params.idForm, HeaderService.TAB_KEY_SETTINGS);
vm.headerService().updateTabsForFormId(to.params.idWorkspace, to.params.idForm, TABS.KEY_SETTINGS);
vm.retrieveForm(to.params.idForm);
vm.retrieveAuthorizedUsers(to.params.idForm);
}
......@@ -55,6 +59,7 @@ export default class FormSettings extends Vue {
this.formService()
.find(idForm)
.then(res => {
this.currentIdForm = idForm;
this.form = res;
});
}
......@@ -78,4 +83,18 @@ export default class FormSettings extends Vue {
setReference(reference: string) {
this.form.reference = reference;
}
public addPermision(user: IUser) {
this.formService()
.addRoleWithPermission(user.login, this.currentIdForm)
.then(() => console.log('Ajout de permission réussi.'))
.catch(() => console.log("Erreur dans l'ajout des permissions."));
}
public removePermision(user: IUser) {
this.formService()
.removePermission(user.login, this.currentIdForm)
.then(() => console.log('Suppression des permissions réussi.'))
.catch(() => console.log('Erreur dans la suppression des permissions.'));
}
}
......@@ -10,7 +10,7 @@
type="text"
:value="form.reference"
required="true"
@update="setReference"
disabled="true"
></oa-input>
<oa-input id="name" :label="$t('form.settings.name')" type="text" :value="form.name" required="true" @update="setName"></oa-input>
<oa-textarea
......@@ -21,7 +21,11 @@
></oa-textarea>
<oa-button type="submit" variant="primary" :label="$t('button.save')"></oa-button>
</form>
<admin-users-table :users="authorizedUsers"></admin-users-table>
<admin-users-table
:authorizedUsers="authorizedUsers"
@addPermission="addPermision"
@removePermission="removePermision"
></admin-users-table>
</section>
</main>
</template>
......
......@@ -4,6 +4,7 @@ import Toolbar from '@/components/toolbar/toolbar.vue';
import { Inject } from 'vue-property-decorator';
import UserManagementService from '@/admin/user-management/user-management.service';
import HeaderService from '@/shared/service/header-service';
import { TABS } from '@/shared/service/tabs-constants';
@Component({
components: {
......@@ -25,7 +26,7 @@ export default class UserList extends Vue {
beforeRouteEnter(to, from, next) {
next(vm => {
vm.headerService().filArianeForHome();
vm.headerService().updateTabsForAdmin(HeaderService.TAB_KEY_USERS);
vm.headerService().updateTabsForAdmin(TABS.KEY_USERS);
});
}
......
......@@ -7,6 +7,7 @@ import HeaderService from '@/shared/service/header-service';
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 { TABS } from '@/shared/service/tabs-constants';
@Component({
components: {
......@@ -33,7 +34,7 @@ export default class VariableEdit extends Vue {
beforeRouteEnter(to, from, next) {
next(vm => {
vm.headerService().updateTabsForFormId(to.params.idWorkspace, to.params.idForm, HeaderService.TAB_KEY_VARIABLE);
vm.headerService().updateTabsForFormId(to.params.idWorkspace, to.params.idForm, TABS.KEY_VARIABLE);
let idVariable = to.params.idVariable;
vm.variable.formId = to.params.idForm;
if (idVariable) {
......
......@@ -5,6 +5,7 @@ import VariableService from '@/entities/variable/variable.service';
import Toolbar from '@/components/toolbar/toolbar.vue';
import Icon from '@/components/icon/icon.vue';
import { IVariable } from '@/shared/model/variable.model';
import { TABS } from '@/shared/service/tabs-constants';
@Component({
components: {
......@@ -32,7 +33,7 @@ export default class VariableList extends Vue {
next(vm => {
vm.idForm = to.params.idForm;
vm.idWorkspace = to.params.idWorkspace;
vm.headerService().updateTabsForFormId(vm.idWorkspace, vm.idForm, HeaderService.TAB_KEY_VARIABLE);
vm.headerService().updateTabsForFormId(vm.idWorkspace, vm.idForm, TABS.KEY_VARIABLE);
vm.loadAll(to.params.idForm);
});
}
......
......@@ -4,6 +4,7 @@ import WorkspaceService from '@/entities/workspace/workspace.service';
import Card from '@/components/card/card.vue';
import Toolbar from '@/components/toolbar/toolbar.vue';
import HeaderService from '@/shared/service/header-service';
import { TABS } from '@/shared/service/tabs-constants';
@Component({
components: {
......@@ -35,7 +36,7 @@ export default class WorkspaceList extends Vue {
beforeRouteEnter(to, from, next) {
next(vm => {
vm.retrieveWorkspace();
vm.headerService().updateTabsForAdmin(HeaderService.TAB_KEY_WORKSPACES);
vm.headerService().updateTabsForAdmin(TABS.KEY_WORKSPACES);
vm.headerService().filArianeForHome();
});
}
......
......@@ -8,6 +8,8 @@ import OaTextarea from '@/components/forms/textarea/oa-textarea.vue';
import OaButton from '@/components/button/oa-button.vue';
import AdminUsersTable from '@/components/table/admin-users-table.vue';
import HeaderService from '@/shared/service/header-service';
import { IUser } from '@/shared/model/user.model';
import { TABS } from '@/shared/service/tabs-constants';
@Component({
components: {
......@@ -30,12 +32,14 @@ export default class WorkspaceSettings extends Vue {
private isSaving = false;
private currentWorkspaceId: number = -1;
beforeRouteEnter(to, from, next) {
next(vm => {
if (to.params.idWorkspace) {
vm.retrieveWorkspace(to.params.idWorkspace);
vm.retrieveAuthorizedUsers(to.params.idWorkspace);
vm.headerService().updateTabsForWorkspaceId(to.params.idWorkspace, HeaderService.TAB_KEY_SETTINGS);
vm.headerService().updateTabsForWorkspaceId(to.params.idWorkspace, TABS.KEY_SETTINGS);
vm.headerService().filArianeForWorkspace(to.params.idWorkspace);
}
});
......@@ -55,6 +59,7 @@ export default class WorkspaceSettings extends Vue {
this.workspaceService()
.find(idWorkspace)
.then(res => {
this.currentWorkspaceId = idWorkspace;
this.workspace = res;
});
}
......@@ -74,4 +79,18 @@ export default class WorkspaceSettings extends Vue {
public setDescription(description: string) {
this.workspace.description = description;
}
public addPermision(user: IUser) {
this.workspaceService()
.addRoleWithPermission(user.login, this.currentWorkspaceId)
.then(() => console.log('Ajout de permission réussi.'))
.catch(() => console.log("Erreur dans l'ajout des permissions"));
}
public removePermision(user: IUser) {
this.workspaceService()
.removePermission(user.login, this.currentWorkspaceId)
.then(() => console.log('Suppression des permissions réussi.'))
.catch(() => console.log('Erreur dans la suppression des permissions.'));
}
}
......@@ -20,7 +20,11 @@
></oa-textarea>
<oa-button type="submit" variant="primary" :label="$t('button.save')"></oa-button>
</form>
<admin-users-table :users="authorizedUsers"></admin-users-table>
<admin-users-table
:authorizedUsers="authorizedUsers"
@addPermission="addPermision"
@removePermission="removePermision"
></admin-users-table>
</section>
</main>
</template>
......
......@@ -5,6 +5,7 @@ import Card from '@/components/card/card.vue';
import Toolbar from '@/components/toolbar/toolbar.vue';
import FormService from '@/entities/form/form.service';
import HeaderService from '@/shared/service/header-service';
import { TABS } from '@/shared/service/tabs-constants';
@Component({
components: {
......
{
"user": {
"table": {
"titre": "Utilisateurs",
"titre": "Responsables",
"id": "ID",
"nom": "Nom",
"email": "Email",
"actif": "Actif"
"actif": "Actif",
"info": "Vous pouvez ajouter ou supprimer des responsables sur cet espace.",
"actions": "actions"
},
"actions": {
"nouveau": "Ajouter un utilisateur"
"nouveau": "Ajouter un utilisateur",
"addUser": "Ajouter",
"addContrib": "Ajouter un contributeur"
}
}
}
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