gestion droit d'access au application pour les compagnies
This commit is contained in:
parent
2b9b030d9a
commit
016c415c11
|
|
@ -1,11 +1,16 @@
|
||||||
import {Controller} from '@hotwired/stimulus'
|
import {Controller} from '@hotwired/stimulus'
|
||||||
import Quill from 'quill'
|
import Quill from 'quill'
|
||||||
// controllers/application_controller.js
|
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
static targets = ['hidden']
|
static values = {
|
||||||
|
application: String,
|
||||||
|
organization: String,
|
||||||
|
}
|
||||||
|
static targets = ['hidden', 'submitBtn']
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
// Map each editor to its toolbar and hidden field
|
// Map each editor to its toolbar and hidden field
|
||||||
|
if (document.querySelector('#editor-description')) {
|
||||||
this.editors = [
|
this.editors = [
|
||||||
{
|
{
|
||||||
editorSelector: '#editor-description',
|
editorSelector: '#editor-description',
|
||||||
|
|
@ -22,19 +27,84 @@ export default class extends Controller {
|
||||||
this.editors.forEach(({editorSelector, toolbarSelector, hiddenTarget}) => {
|
this.editors.forEach(({editorSelector, toolbarSelector, hiddenTarget}) => {
|
||||||
const quill = new Quill(editorSelector, {
|
const quill = new Quill(editorSelector, {
|
||||||
modules: {
|
modules: {
|
||||||
toolbar: toolbarSelector, // HTML toolbar container
|
toolbar: toolbarSelector,
|
||||||
},
|
},
|
||||||
theme: 'snow', // include quill.snow.css
|
theme: 'snow',
|
||||||
placeholder: 'Écrivez votre texte...',
|
placeholder: 'Écrivez votre texte...',
|
||||||
})
|
})
|
||||||
|
|
||||||
// Keep hidden field in sync with editor HTML
|
|
||||||
quill.on('text-change', () => {
|
quill.on('text-change', () => {
|
||||||
hiddenTarget.value = quill.root.innerHTML
|
hiddenTarget.value = quill.root.innerHTML
|
||||||
})
|
})
|
||||||
|
|
||||||
// Ensure initial value sync in case user submits without changes
|
|
||||||
hiddenTarget.value = quill.root.innerHTML
|
hiddenTarget.value = quill.root.innerHTML
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleAuthorizeSubmit(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const originalText = this.submitBtnTarget.textContent;
|
||||||
|
|
||||||
|
if (!confirm(`Vous vous apprêtez à donner l'accès à ${this.organizationValue} pour ${this.applicationValue}. Êtes‑vous sûr(e) ?`)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.submitBtnTarget.textContent = 'En cours...';
|
||||||
|
this.submitBtnTarget.disabled = true;
|
||||||
|
|
||||||
|
fetch(event.target.action, {
|
||||||
|
method: 'POST',
|
||||||
|
body: new FormData(event.target)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
this.submitBtnTarget.textContent = 'Autorisé ✓';
|
||||||
|
this.submitBtnTarget.classList.replace('btn-secondary', 'btn-success');
|
||||||
|
} else {
|
||||||
|
this.submitBtnTarget.textContent = originalText;
|
||||||
|
this.submitBtnTarget.disabled = false;
|
||||||
|
alert('Erreur lors de l\'action');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
this.submitBtnTarget.textContent = originalText;
|
||||||
|
this.submitBtnTarget.disabled = false;
|
||||||
|
alert('Erreur lors de l\'action');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRemoveSubmit(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const originalText = this.submitBtnTarget.textContent;
|
||||||
|
|
||||||
|
if (!confirm(`Vous vous apprêtez à retirer l'accès à ${this.applicationValue} pour ${this.organizationValue}. Êtes‑vous sûr(e) ?`)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.submitBtnTarget.textContent = 'En cours...';
|
||||||
|
this.submitBtnTarget.disabled = true;
|
||||||
|
|
||||||
|
fetch(event.target.action, {
|
||||||
|
method: 'POST',
|
||||||
|
body: new FormData(event.target)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
this.submitBtnTarget.textContent = 'Retiré ✓';
|
||||||
|
this.submitBtnTarget.classList.replace('btn-secondary', 'btn-danger');
|
||||||
|
} else {
|
||||||
|
this.submitBtnTarget.textContent = originalText;
|
||||||
|
this.submitBtnTarget.disabled = false;
|
||||||
|
alert('Erreur lors de l\'action');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
this.submitBtnTarget.textContent = originalText;
|
||||||
|
this.submitBtnTarget.disabled = false;
|
||||||
|
alert('Erreur lors de l\'action');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\Apps;
|
use App\Entity\Apps;
|
||||||
|
use App\Entity\Organizations;
|
||||||
use App\Service\ActionService;
|
use App\Service\ActionService;
|
||||||
use App\Service\UserService;
|
use App\Service\UserService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
@ -64,4 +65,39 @@ class ApplicationController extends AbstractController
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route(path: '/authorize/{id}', name: 'authorize', methods: ['POST'])]
|
||||||
|
public function authorize(int $id, Request $request)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
|
||||||
|
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||||
|
$application = $this->entityManager->getRepository(Apps::class)->find($id);
|
||||||
|
if (!$application) {
|
||||||
|
throw $this->createNotFoundException("L'application n'existe pas.");
|
||||||
|
}
|
||||||
|
$orgId = $request->get('organizationId');
|
||||||
|
|
||||||
|
$organization = $this->entityManager->getRepository(Organizations::Class)->find($orgId);
|
||||||
|
$application->addOrganization($organization);
|
||||||
|
|
||||||
|
$this->actionService->createAction("Authorization d'accès", $actingUser, $organization, $application->getName());
|
||||||
|
return new Response('', Response::HTTP_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route(path: '/remove/{id}', name: 'remove', methods: ['POST'])]
|
||||||
|
public function remove(int $id, Request $request)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
|
||||||
|
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||||
|
$application = $this->entityManager->getRepository(Apps::class)->find($id);
|
||||||
|
if (!$application) {
|
||||||
|
throw $this->createNotFoundException("L'application n'existe pas.");
|
||||||
|
}
|
||||||
|
$orgId = $request->get('organizationId');
|
||||||
|
$organization = $this->entityManager->getRepository(Organizations::Class)->find($orgId);
|
||||||
|
$application->removeOrganization($organization);
|
||||||
|
|
||||||
|
$this->actionService->createAction("Authorization retirer", $actingUser, $organization, $application->getName());
|
||||||
|
|
||||||
|
return new Response('', Response::HTTP_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,53 @@
|
||||||
|
|
||||||
<div class="card ">
|
<div class="card ">
|
||||||
<div class="card-header d-flex gap-2">
|
<div class="card-header d-flex gap-2">
|
||||||
<img class="rounded-circle " style="width:50px; height:50px;" src="{{ asset(application.entity.logoUrl) }}" alt="Logo application">
|
<img class="rounded-circle " style="width:50px; height:50px;" src="{{ asset(application.entity.logoUrl) }}"
|
||||||
|
alt="Logo application">
|
||||||
<div class="card-title">
|
<div class="card-title">
|
||||||
<h1>{{ application.entity.name }}</h1>
|
<h1>{{ application.entity.name }}</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body d-flex flex-column align-items-center">
|
<div class="card-body d-flex flex-column align-items-center">
|
||||||
<p class="card-text">{{ application.entity.descriptionSmall|raw }}</p>
|
<p class="card-text">{{ application.entity.descriptionSmall|raw }}</p>
|
||||||
|
|
||||||
{% if application.hasAccess %}
|
{% if application.hasAccess %}
|
||||||
|
{% if is_granted("ROLE_SUPER_ADMIN") %}
|
||||||
|
<form method="POST"
|
||||||
|
action="{{ path('application_remove', {'id': application.entity.id}) }}"
|
||||||
|
data-controller="application"
|
||||||
|
data-application-application-value="{{ application.entity.name }}"
|
||||||
|
data-application-organization-value="{{ organization.name|capitalize }}"
|
||||||
|
data-action="submit->application#handleRemoveSubmit"
|
||||||
|
style="display: inline-block;">
|
||||||
|
<input type="hidden" name="organizationId" value="{{ organization.id }}">
|
||||||
|
<button class="btn btn-secondary" type="submit" data-application-target="submitBtn">
|
||||||
|
Retirer l'accès
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
<div>
|
<div>
|
||||||
<a href="http://{{ application.entity.subDomain }}.solutions-easy.moi" class="btn btn-primary me-2">Y
|
<a href="http://{{ application.entity.subDomain }}.solutions-easy.moi"
|
||||||
accéder</a>
|
class="btn btn-primary me-2">Y accéder</a>
|
||||||
<a href="#" class="btn btn-secondary">Gérer l'application</a>
|
<a href="#" class="btn btn-secondary">Gérer l'application</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
{% if is_granted("ROLE_SUPER_ADMIN") %}
|
||||||
|
<form method="POST"
|
||||||
|
action="{{ path('application_authorize', {'id': application.entity.id}) }}"
|
||||||
|
data-controller="application"
|
||||||
|
data-application-application-value="{{ application.entity.name }}"
|
||||||
|
data-application-organization-value="{{ organization.name|capitalize }}"
|
||||||
|
data-action="submit->application#handleAuthorizeSubmit"
|
||||||
|
style="display: inline-block;">
|
||||||
|
<input type="hidden" name="organizationId" value="{{ organization.id }}">
|
||||||
|
<button class="btn btn-secondary" type="submit" data-application-target="submitBtn">
|
||||||
|
Autoriser l'accès
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="#" class="btn btn-primary">Demander l'accès</a>
|
<a href="#" class="btn btn-primary">Demander l'accès</a>
|
||||||
{#TODO: page d'accès#}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue