From 9c6ebae9bc41266a4cdb421b9982b581866dbff1 Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 4 Sep 2020 11:19:24 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20query=20GraphQL=20pour=20v?= =?UTF-8?q?=C3=A9rifier=20les=20autorisations=20c=C3=B4t=C3=A9=20serveur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Intégration des vérifications de droits sur la page de création/modification des groupes de travail --- .../src/components/WorkgroupPage/InfoForm.tsx | 17 +++++- .../WorkgroupPage/WorkgroupPage.tsx | 2 + client/src/gql/client.tsx | 5 ++ client/src/gql/mutations/workgroups.tsx | 39 +++++++++++- client/src/gql/queries/authorization.tsx | 19 ++++++ internal/graph/authorization_handler.go | 59 +++++++++++++++++++ internal/graph/error.go | 3 +- internal/graph/query.graphql | 7 +++ internal/graph/query.resolvers.go | 4 ++ internal/model/user_repository.go | 12 ++++ 10 files changed, 160 insertions(+), 7 deletions(-) create mode 100644 client/src/gql/queries/authorization.tsx create mode 100644 internal/graph/authorization_handler.go diff --git a/client/src/components/WorkgroupPage/InfoForm.tsx b/client/src/components/WorkgroupPage/InfoForm.tsx index cb3a3f8..9921b36 100644 --- a/client/src/components/WorkgroupPage/InfoForm.tsx +++ b/client/src/components/WorkgroupPage/InfoForm.tsx @@ -1,12 +1,13 @@ import React, { useState, ChangeEvent, useEffect } from 'react'; import { Workgroup } from '../../types/workgroup'; +import { useIsAuthorized } from '../../gql/queries/authorization'; export interface InfoFormProps { workgroup: Workgroup onChange?: (workgroup: Workgroup) => void } -export function InfoForm({ workgroup, onChange }: InfoFormProps) { +export function InfoForm({ workgroup, onChange }: InfoFormProps) { const [ state, setState ] = useState({ changed: false, workgroup: { @@ -17,6 +18,15 @@ export function InfoForm({ workgroup, onChange }: InfoFormProps) { } }); + const { isAuthorized } = useIsAuthorized({ + variables: { + action: 'update', + object: { + workgroupId: state.workgroup.id, + } + } + }, state.workgroup.id === '' ? true : false); + useEffect(() => { setState({ changed: false, @@ -60,7 +70,8 @@ export function InfoForm({ workgroup, onChange }: InfoFormProps) {
-
@@ -85,7 +96,7 @@ export function InfoForm({ workgroup, onChange }: InfoFormProps) { null }
-