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

Merge branch 'feature/gestion_responsables' into 'develop'

UNOTOPLYS-150 | UNOTOPLYS-155 : Mise en place des la gestion des responsables.

See merge request !57
parents b063125c b7b4d339
......@@ -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}`);
}
}
......@@ -7,7 +7,7 @@
</ol>
<!-- Tabs-->
<ul class="px-4 py-2 border-b md:flex md:justify-center md:text-center md:py-0">
<tab-item v-for="tab in tabs()" :title="tab.title" :link="tab.link" :state="tab.isCurrent ? 'current' : ''" />
<tab-item v-for="(tab, index) in tabs()" :key="index" :title="tab.title" :link="tab.link" :state="tab.isCurrent ? 'current' : ''" />
</ul>
</nav>
<login username="Bob" />
......
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 +35,11 @@
<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}`);
}
}
......@@ -2,17 +2,12 @@ import { Store } from 'vuex';
import axios from 'axios';
import VueI18n from 'vue-i18n';
import TranslationService from '@/locale/translation.service';
import { TABS } from '@/shared/service/tabs-constants';
const filArianeBaseApiUrl = 'api/filariane';
export default class HeaderService {
public static readonly TAB_KEY_SETTINGS = 'settings';
public static readonly TAB_KEY_VIEW = 'view';
public static readonly TAB_KEY_VARIABLE = 'variable';
public static readonly TAB_KEY_WORKSPACES = 'workspaces';
public static readonly TAB_KEY_USERS= 'users';
constructor(private store: Store<any>, private translationService: TranslationService, private i18n: VueI18n) {
this.translationService.refreshTranslation(this.store.getters.currentLanguage);
}
......@@ -22,12 +17,12 @@ export default class HeaderService {
{
title: this.i18n.t('onglets.parametrages'),
link: `/admin/workspace/${workspaceId}/settings`,
isCurrent: currentKey === HeaderService.TAB_KEY_SETTINGS,
isCurrent: currentKey === TABS.KEY_SETTINGS,
},
{
title: this.i18n.t('onglets.forms'),
link: `/admin/workspace/${workspaceId}/view`,
isCurrent: currentKey === HeaderService.TAB_KEY_VIEW,
isCurrent: currentKey === TABS.KEY_VIEW,
},
];
this.store.commit('tabs', tabs);
......@@ -38,17 +33,17 @@ export default class HeaderService {
{
title: this.i18n.t('onglets.parametrages'),
link: `/admin/workspace/${workspaceId}/form/${formId}/settings`,
isCurrent: currentKey === HeaderService.TAB_KEY_SETTINGS,
isCurrent: currentKey === TABS.KEY_SETTINGS,
},
{
title: this.i18n.t('onglets.edition'),
link: `/admin/workspace/${workspaceId}/form/${formId}/view`,
isCurrent: currentKey === HeaderService.TAB_KEY_VIEW,
isCurrent: currentKey === TABS.KEY_VIEW,
},
{
'title': this.i18n.t('variable.onglets.list'),
'link': `/admin/workspace/${workspaceId}/form/${formId}/variable/list`,
'isCurrent': currentKey === HeaderService.TAB_KEY_VARIABLE
'isCurrent': currentKey === TABS.KEY_VARIABLE
},
];
this.store.commit('tabs', tabs);
......@@ -59,12 +54,12 @@ export default class HeaderService {
{
title: this.i18n.t('onglets.workspaces'),
link: '/admin/workspace/list',
isCurrent: currentTab === HeaderService.TAB_KEY_WORKSPACES,
isCurrent: currentTab === TABS.KEY_WORKSPACES,
},
{
title: this.i18n.t('onglets.utilisateurs'),
link: '/admin/user/list',
isCurrent: currentTab === HeaderService.TAB_KEY_USERS,
isCurrent: currentTab === TABS.KEY_USERS,
},
];
this.store.commit('tabs', tabs);
......
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,16 @@ 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.'));
}
}
......@@ -21,7 +21,7 @@
></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);
});
}
......
import Vue from 'vue';
import Component from 'vue-class-component';
import {Inject} from 'vue-property-decorator';
import { Inject } from 'vue-property-decorator';
import VariableService from '@/entities/variable/variable.service';
import {IVariable, Variable} from '@/shared/model/variable.model';
import { IVariable, Variable } from '@/shared/model/variable.model';
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: {
......@@ -34,7 +35,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) {
......
......@@ -4,7 +4,8 @@ import HeaderService from '@/shared/service/header-service';
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 { IVariable } from '@/shared/model/variable.model';
import { TABS } from '@/shared/service/tabs-constants';
@Component({
components: {
......@@ -33,7 +34,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,16 @@ 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,7 @@
></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: {
......@@ -38,7 +39,7 @@ export default class WorkspaceView extends Vue {
beforeRouteEnter(to, from, next) {
next(vm => {
vm.retrieveWorkspace(to.params.idWorkspace);
vm.headerService().updateTabsForWorkspaceId(to.params.idWorkspace, HeaderService.TAB_KEY_VIEW);
vm.headerService().updateTabsForWorkspaceId(to.params.idWorkspace, TABS.KEY_VIEW);
vm.headerService().filArianeForWorkspace(to.params.idWorkspace);
});
}
......
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