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

Ajout des paramètres workspaces et formulaires.

parent 4e52909d
package com.unantes.orientactive.repository;
import com.unantes.orientactive.domain.Form;
import com.unantes.orientactive.domain.User;
import com.unantes.orientactive.security.permissions.RoleRepository;
import com.unantes.orientactive.service.dto.UserDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
......@@ -96,7 +98,7 @@ public interface FormRepository extends JpaRepository<Form, Long>, RoleRepositor
* @param idRole L'identifiant du rôle.
* @param idForm L'identifiant du formulaire.
*/
@Query(value = "with new_scope as (insert into scope (id_user, id_role) values (:idUser, :idRole) on conflict on constraint unique_scope do nothing returning id) insert into scope_form (id_scope, id_form) values (coalesce((select id from new_scope), (select id from scope where id_user = :idUser and id_role = :idRole)), :idForm)", nativeQuery = true)
@Query(value = "with new_scope as (insert into scope (id_user, id_role) values (:idUser, :idRole) on conflict on constraint unique_scope do nothing returning id) insert into scope_form (id_scope, id_form) values (coalesce((select id from new_scope), (select id from scope where id_user = :idUser and id_role = :idRole)), :idForm) on conflict on constraint unique_scope_form do nothing", nativeQuery = true)
@Modifying
void addRoleWithPermission(@Param("idUser") Long idUser, @Param("idRole") int idRole, @Param("idForm") Long idForm);
}
......@@ -53,4 +53,10 @@ public interface UserRepository extends JpaRepository<User, Long> {
@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);
@Query(value = "(select u.* from jhi_user u join scope s on s.id_user = u.id where s.wildcard = true and s.id_role = :idRole) union (select u.* from jhi_user u join scope s on s.id_user = u.id join scope_workspace sw on sw.id_scope = s.id where s.wildcard = false and s.id_role = :idRole and sw.id_workspace = :idWorkspace)", nativeQuery = true)
List<User> findAllWithPermissionOnWorkspace(@Param("idRole") int idRole, @Param("idWorkspace") Long idWorkspace);
@Query(value = "(select u.* from jhi_user u join scope s on s.id_user = u.id where s.wildcard = true and s.id_role = :idRole) union (select u.* from jhi_user u join scope s on s.id_user = u.id join scope_form sf on sf.id_scope = s.id where s.wildcard = false and s.id_role = :idRole and sf.id_form = :idForm)", nativeQuery = true)
List<User> findAllWithPermissionOnForm(@Param("idRole") int idRole, @Param("idForm") Long idForm);
}
......@@ -67,7 +67,7 @@ public interface WorkspaceRepository extends JpaRepository<Workspace, Long>, Rol
* @param idRole L'identifiant du rôle.
* @param idWorkspace L'identifiant du workspace.
*/
@Query(value = "with new_scope as (insert into scope (id_user, id_role) values (:idUser, :idRole) on conflict on constraint unique_scope do nothing returning id) insert into scope_workspace (id_scope, id_workspace) values (coalesce((select id from new_scope), (select id from scope where id_user = :idUser and id_role = :idRole)), :idWorkspace)", nativeQuery = true)
@Query(value = "with new_scope as (insert into scope (id_user, id_role) values (:idUser, :idRole) on conflict on constraint unique_scope do nothing returning id) insert into scope_workspace (id_scope, id_workspace) values (coalesce((select id from new_scope), (select id from scope where id_user = :idUser and id_role = :idRole)), :idWorkspace) on conflict on constraint unique_scope_workspace do nothing", nativeQuery = true)
@Modifying
void addRoleWithPermission(@Param("idUser") Long idUser, @Param("idRole") int idRole, @Param("idWorkspace") Long idWorkspace);
}
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;
......@@ -104,6 +105,14 @@ public abstract class PermissionService<T extends PermissionEntity> {
*/
public abstract Optional<T> findOne(Long idElement);
/**
* Récupération de tous les utilisareurs ayant les permissions sur l'élément.
*
* @param element L'élément.
* @return La liste des utilisateurs.
*/
public abstract List<UserDTO> findAllWithPermission(T element);
/**
* Méthode interne permettant de récupérer les entités que l'utilisateur a la permission d'administer.
*
......
......@@ -5,10 +5,12 @@ 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 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;
......@@ -150,4 +152,20 @@ public abstract class PermissionController {
}
return false;
}
/**
* Récupération des utilisateurs ayant des droits sur l'entité.
*
* @param idEntity Identifiant de l'entité.
* @return La liste des utilisateurs.
*/
@GetMapping("/findAllWithPermission/{idEntity}")
public List<UserDTO> findAllWithPermission(@PathVariable final long idEntity) {
final Optional<PermissionEntity> entity = permissionService.findOne(idEntity);
List<UserDTO> users = new LinkedList<>();
if (entity.isPresent()) {
users = permissionService.findAllWithPermission(entity.get());
}
return users;
}
}
......@@ -7,6 +7,7 @@ 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.FormDTO;
import com.unantes.orientactive.service.dto.UserDTO;
import com.unantes.orientactive.service.mapper.FormMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -182,6 +183,11 @@ public class FormService extends PermissionService<FormDTO> {
return formRepository.hasWildcard(user.getId(), Role.CONTRIBUTEUR.getId());
}
@Override
public List<UserDTO> findAllWithPermission(FormDTO element) {
return userService.findAllWithPermissionOnForm(Role.CONTRIBUTEUR.getId(), element.getId());
}
@PreAuthorize("hasAuthority('VIEW_FORMS')")
@Override
protected boolean existPermission(User user, FormDTO element) {
......
......@@ -340,6 +340,14 @@ 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<UserDTO> findAllWithPermissionOnForm(final int idRole, final Long idForm) {
return userRepository.findAllWithPermissionOnForm(idRole, idForm).stream().map(UserDTO::new).collect(Collectors.toList());
}
public List<String> findAllAuthorities(Long idUser) {
return userRepository.findAllAuthorities(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.UserDTO;
import com.unantes.orientactive.service.dto.WorkspaceDTO;
import com.unantes.orientactive.service.mapper.WorkspaceMapper;
import org.slf4j.Logger;
......@@ -145,6 +146,11 @@ public class WorkspaceService extends PermissionService<WorkspaceDTO> {
return workspaceRepository.hasWildcard(user.getId(), Role.RESPONSABLE_ESPACE.getId());
}
@Override
public List<UserDTO> findAllWithPermission(WorkspaceDTO element) {
return userService.findAllWithPermissionOnWorkspace(Role.RESPONSABLE_ESPACE.getId(), element.getId());
}
@PreAuthorize("hasAuthority('VIEW_WORKSPACE')")
@Override
protected boolean existPermission(User user, WorkspaceDTO element) {
......
......@@ -44,6 +44,19 @@ export default class FormService {
});
}
public findAllWithPermission(idEntity: number): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
.get(baseApiUrl + '/findAllWithPermission/' + idEntity)
.then(res => {
resolve(res);
})
.catch(err => {
reject(err);
});
});
}
public delete(id: number): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
......
......@@ -44,6 +44,19 @@ export default class WorkspaceService {
});
}
public findAllWithPermission(idEntity: number): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
.get(baseApiUrl + '/findAllWithPermission/' + idEntity)
.then(res => {
resolve(res);
})
.catch(err => {
reject(err);
});
});
}
public delete(id: number): Promise<any> {
return new Promise<any>((resolve, reject) => {
axios
......
......@@ -35,7 +35,7 @@ export default [
meta: { authorities: [Authority.ADMIN] },
},
{
path: '/admin/form/:idForm/settings',
path: '/admin/workspace/:idWorkspace/form/:idForm/settings',
name: 'FormSettingsComponent',
component: FormSettingsComponent,
meta: { authorities: [Authority.ADMIN] },
......
import Vue from 'vue';
import Component from 'vue-class-component';
import {Inject} from 'vue-property-decorator';
import {Form, IForm} from '@/shared/model/form.model';
import FormService from '@/entities/form/form.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';
@Component
@Component({
components: {
OaInput,
OaTextarea,
OaButton
}
})
export default class FormSettings extends Vue {
@Inject('formService')
private formService: () => FormService;
public form: IForm = new Form();
private isSaving: boolean = false;
public authorizedUsers: Object[] = [];
beforeRouteEnter(to, from, next) {
next(vm => {
if (to.params.idForm) {
vm.retrieveForm(to.params.idForm);
vm.retrieveAuthorizedUsers(to.params.idForm);
}
});
}
public save(): void {
this.isSaving = true;
this.formService()
.update(this.form)
.then(() => {
this.isSaving = false;
this.$router.go(-1);
});
}
public retrieveForm(idForm: number): void {
this.formService()
.find(idForm)
.then(res => {
this.form = res;
});
}
public retrieveAuthorizedUsers(idForm: number): void {
this.formService()
.findAllWithPermission(idForm)
.then(res => {
this.authorizedUsers = res.data;
});
}
setName(name: String) {
this.form.name = name;
}
setDescription(description: String) {
this.form.description = description;
}
setReference(reference: String) {
this.form.reference = reference;
}
}
<template>
<main>
<section class="max-w-4xl mx-auto p-9">
<h2 class="mb-4 text-2xl" id="s1">Informations générales</h2>
<form v-on:submit.prevent="save()">
<oa-input id="id" label="ID" type="text" :value="form.id" required="true" disabled="true"></oa-input>
<oa-input id="reference" label="Référence" type="text" :value="form.reference" required="true" @update="setReference"></oa-input>
<oa-input id="name" label="Nom" type="text" :value="form.name" required="true" @update="setName"></oa-input>
<oa-textarea id="description" label="Description" :value="form.description" @update="setDescription"></oa-textarea>
<oa-button type="submit" variant="primary" label="Enregistrer" ></oa-button>
</form>
<h2 class="mb-4 text-2xl">Utilisateurs</h2>
<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 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>
</tr>
</tbody>
</table>
</section>
</main>
</template>
<script lang="ts" src="./form-settings.component.ts"/>
import Vue from 'vue';
import Component from 'vue-class-component';
import {Inject} from 'vue-property-decorator';
import WorkspaceService from '@/entities/workspace/workspace.service';
import {IWorkspace, Workspace} from '@/shared/model/workspace.model';
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';
@Component
@Component({
components: {
OaInput,
OaTextarea,
OaButton
}
})
export default class WorkspaceSettings extends Vue {
@Inject('workspaceService')
private workspaceService: () => WorkspaceService;
public workspace: IWorkspace = new Workspace();
public authorizedUsers: Object[] = [];
private isSaving: boolean = false;
beforeRouteEnter(to, from, next) {
next(vm => {
if (to.params.idWorkspace) {
vm.retrieveWorkspace(to.params.idWorkspace);
vm.retrieveAuthorizedUsers(to.params.idWorkspace);
}
});
}
public save(): void {
this.isSaving = true;
this.workspaceService()
.update(this.workspace)
.then(() => {
this.isSaving = false;
this.$router.go(-1);
});
}
public retrieveWorkspace(idWorkspace: number): void {
this.workspaceService()
.find(idWorkspace)
.then(res => {
this.workspace = res;
});
}
public retrieveAuthorizedUsers(idWorkspace: number): void {
this.workspaceService()
.findAllWithPermission(idWorkspace)
.then(res => {
this.authorizedUsers = res.data;
});
}
public setName(name: String) {
this.workspace.name = name;
}
public setDescription(description: String) {
this.workspace.description = description;
}
}
<template>
<main>
<section class="max-w-4xl mx-auto p-9">
<h2 class="mb-4 text-2xl">Informations générales</h2>
<form v-on:submit.prevent="save()">
<oa-input id="id" label="ID" type="text" :value="workspace.id" required="true" disabled="true"></oa-input>
<oa-input id="name" label="Nom" type="text" :value="workspace.name" required="true" @update="setName"></oa-input>
<oa-textarea id="description" label="Description" :value="workspace.description" @update="setDescription"></oa-textarea>
<oa-button type="submit" variant="primary" label="Enregistrer" ></oa-button>
</form>
<h2 class="mb-4 text-2xl">Utilisateurs</h2>
<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 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>
</tr>
</tbody>
</table>
</section>
</main>
</template>
<script lang="ts" src="./workspace-settings.component.ts"/>
Supports Markdown
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