Commit 5f26d934 authored by Kevin Robert's avatar Kevin Robert
Browse files

Légère modification du fonctionnement des permissions pour corriger l'affchage...

Légère modification du fonctionnement des permissions pour corriger l'affchage de la liste des formulaires.
parent fd4c13f9
......@@ -69,14 +69,14 @@ public abstract class PermissionService<T extends PermissionEntity> {
* Cette méthode s'occupe de vérifier la présence du wildcard et, dans le cas ou il est présent, de simplement récupérer toutes les entités.
*
* @param user L'utilisateur.
* @param parentElement L'élément parent.
* @param idParentElement L'identifiant de l'élément parent.
* @return Les entités.
*/
public <U extends PermissionEntity> List<T> find(User user, U parentElement) {
public List<T> find(User user, Long idParentElement) {
if (hasWildcard(user)) {
return findAllByParent(parentElement);
return findAllByParent(idParentElement);
}
return findWithPermission(user, parentElement);
return findWithPermission(user, idParentElement);
}
/**
......@@ -99,7 +99,7 @@ public abstract class PermissionService<T extends PermissionEntity> {
*
* @return Les entités.
*/
public abstract <U extends PermissionEntity> List<T> findAllByParent(U parent);
public abstract List<T> findAllByParent(Long idParent);
/**
* Permet la récupération d'une entité en particulier via son identifiant.
......@@ -120,10 +120,10 @@ public abstract class PermissionService<T extends PermissionEntity> {
* Méthode interne permettant de récupérer les entités que l'utilisateur a la permission d'administer.
*
* @param user L'utilisateur.
* @param parentElement L'élément parent.
* @param idParentElement L'identifiant de l'élément parent.
* @return Les entités.
*/
protected abstract <U extends PermissionEntity> List<T> findWithPermission(User user, U parentElement);
protected abstract List<T> findWithPermission(User user, Long idParentElement);
/**
* Méthode interne permettant de vérifier unitairement la permission d'un utilisateur sur une entité.
......
......@@ -149,9 +149,8 @@ public abstract class PermissionController {
@GetMapping("/find/{loginUser}/{idParentEtity}")
public List<PermissionEntity> find(@PathVariable final String loginUser, @PathVariable final Long idParentEtity) {
final Optional<User> userOptional = userService.getUserWithAuthoritiesByLogin(loginUser);
final Optional<PermissionEntity> entityOptional = permissionService.findOne(idParentEtity);
if (userOptional.isPresent() && entityOptional.isPresent()) {
return permissionService.find(userOptional.get(), entityOptional.get());
if (userOptional.isPresent()) {
return permissionService.find(userOptional.get(), idParentEtity);
}
return Collections.emptyList();
}
......
......@@ -177,9 +177,9 @@ public class FormService extends PermissionService<FormDTO> {
@PreAuthorize("hasAuthority('VIEW_FORMS')")
@Override
protected <U extends PermissionEntity> List<FormDTO> findWithPermission(User user, U parentElement) {
protected List<FormDTO> findWithPermission(User user, Long idParentElement) {
return formRepository
.findWithPermission(user.getId(), parentElement.getId())
.findWithPermission(user.getId(), idParentElement)
.stream()
.map(formMapper::toDto)
.collect(Collectors.toList());
......@@ -187,9 +187,9 @@ public class FormService extends PermissionService<FormDTO> {
@PreAuthorize("hasAuthority('VIEW_FORMS')")
@Override
public <U extends PermissionEntity> List<FormDTO> findAllByParent(U parentElement) {
public List<FormDTO> findAllByParent(Long idParentElement) {
return formRepository
.findAllByWorkspaceId(parentElement.getId())
.findAllByWorkspaceId(idParentElement)
.stream()
.map(formMapper::toDto)
.collect(Collectors.toCollection(LinkedList::new));
......
......@@ -145,14 +145,14 @@ public class WorkspaceService extends PermissionService<WorkspaceDTO> {
@PreAuthorize("hasAuthority('VIEW_WORKSPACE')")
@Override
public <U extends PermissionEntity> List<WorkspaceDTO> findAllByParent(U parent) {
public List<WorkspaceDTO> findAllByParent(Long idParent) {
// On ignore l'élément parent car le workspace n'en possède pas.
return findAll();
}
@PreAuthorize("hasAuthority('VIEW_WORKSPACE')")
@Override
protected <U extends PermissionEntity> List<WorkspaceDTO> findWithPermission(User user, U parentElement) {
protected List<WorkspaceDTO> findWithPermission(User user, Long idParentElement) {
// On ignore l'élément parent car le workspace n'en possède pas.
return workspaceRepository.findWithPermission(user.getId()).stream().map(workspaceMapper::toDto).collect(Collectors.toList());
}
......
......@@ -3,7 +3,7 @@
class="relative p-4 overflow-hidden transition bg-white border rounded-md cursor-pointer h-52 group hover:border-gray-300 hover:shadow-2xl"
>
<h2>
<router-link :to="{ name: link }" class="mb-2 font-semibold line-clamp-3 group-hover:text-blue-600">{{ title }}</router-link>
<router-link :to="link" class="mb-2 font-semibold line-clamp-3 group-hover:text-blue-600">{{ title }}</router-link>
</h2>
<div class="absolute bottom-4 left-4">
<div class="mb-2 leading-tight">
......
......@@ -45,4 +45,8 @@ export default class WorkspaceList extends Vue {
this.workspaces = []
});
}
public getWorkspaceLink(workspaceId: number) {
return `/admin/workspace/${workspaceId}/view`;
}
}
......@@ -3,7 +3,7 @@
<section class="max-w-6xl px-4 mx-auto py-9 xl:px-0">
<toolbar title="Workspaces" addActionName="Ajouter un workspace" actionLink="/admin/workspace/creation"></toolbar>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4">
<card v-for="(workspace, index) in workspaces" :key="index" :title="workspace.name" :number="workspace.number_element" type="Espace de travail" :link="'/admin/workspace/' + workspace.id + '/view'"></card>
<card v-for="(workspace, index) in workspaces" :key="index" :title="workspace.name" :number="workspace.number_element" type="Espace de travail" :link="getWorkspaceLink(workspace.id)"></card>
</div>
</section>
</main>
......
......@@ -24,7 +24,7 @@ export default class WorkspaceView extends Vue {
*/
public forms: Object[] = [];
public idWorkspace;
public idWorkspace = -1;
/**
* Récupération des workspaces avant de faire l'affichage.
......
......@@ -23,7 +23,7 @@ class FormPermissionServiceTest extends AbstractPermissionTest {
@Test
void roleAlone() {
formService.addRole(user);
List<FormDTO> forms = formService.find(user, workspaceDTO1);
List<FormDTO> forms = formService.find(user, workspaceDTO1.getId());
assertTrue(forms.isEmpty());
}
......@@ -33,7 +33,7 @@ class FormPermissionServiceTest extends AbstractPermissionTest {
@Test
void roleAloneWithWildcard() {
formService.addRoleWithWildcard(user);
List<FormDTO> forms = formService.find(user, workspaceDTO1);
List<FormDTO> forms = formService.find(user, workspaceDTO1.getId());
assertEquals(3, forms.size());
}
......@@ -45,7 +45,7 @@ class FormPermissionServiceTest extends AbstractPermissionTest {
formService.addRole(user);
formService.addPermission(user, formDTO1);
formService.addPermission(user, formDTO2);
List<FormDTO> forms = formService.find(user, workspaceDTO1);
List<FormDTO> forms = formService.find(user, workspaceDTO1.getId());
assertEquals(2, forms.size());
assertTrue(forms.contains(formDTO1));
assertTrue(forms.contains(formDTO2));
......@@ -60,7 +60,7 @@ class FormPermissionServiceTest extends AbstractPermissionTest {
// Création du role et des permisisons pour l'utilisateur.
roleAndPermissions();
formService.removeRole(user);
List<FormDTO> forms = formService.find(user, workspaceDTO1);
List<FormDTO> forms = formService.find(user, workspaceDTO1.getId());
assertTrue(forms.isEmpty());
}
......@@ -72,7 +72,7 @@ class FormPermissionServiceTest extends AbstractPermissionTest {
// Création du role et des permisisons pour l'utilisateur.
roleAndPermissions();
formService.removePermission(user, formDTO1);
List<FormDTO> forms = formService.find(user, workspaceDTO1);
List<FormDTO> forms = formService.find(user, workspaceDTO1.getId());
assertEquals(1, forms.size());
assertFalse(forms.contains(formDTO1));
assertTrue(forms.contains(formDTO2));
......@@ -88,12 +88,12 @@ class FormPermissionServiceTest extends AbstractPermissionTest {
formService.addPermission(user, formDTO1);
formService.addPermission(user, formDTO3);
formService.addPermission(user, formDTO4);
List<FormDTO> formsWorkspace1 = formService.find(user, workspaceDTO1);
List<FormDTO> formsWorkspace1 = formService.find(user, workspaceDTO1.getId());
assertEquals(2, formsWorkspace1.size());
assertTrue(formsWorkspace1.contains(formDTO1));
assertFalse(formsWorkspace1.contains(formDTO2));
assertTrue(formsWorkspace1.contains(formDTO3));
List<FormDTO> formsWorkspace2 = formService.find(user, workspaceDTO2);
List<FormDTO> formsWorkspace2 = formService.find(user, workspaceDTO2.getId());
assertEquals(1, formsWorkspace2.size());
assertTrue(formsWorkspace2.contains(formDTO4));
assertFalse(formsWorkspace2.contains(formDTO5));
......
......@@ -34,7 +34,7 @@ public class WorkspacePermissionServiceTest extends AbstractPermissionTest {
@Test
void roleAloneWithWildcard() {
workspaceService.addRoleWithWildcard(user);
List<WorkspaceDTO> workspaces = workspaceService.find(user, formDTO1);
List<WorkspaceDTO> workspaces = workspaceService.find(user, formDTO1.getId());
assertEquals(3, workspaces.size());
}
......
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