Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-neil committed Dec 18, 2023
2 parents 24142d4 + 156362f commit 048c3be
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 163 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ This file keep track of the changes.

## UNRELEASED

# [1.2.0] - 2023-12-18
### CHANGED
- Require at least php 8.3
- Use the new symfony mailer library
- Update Symfony 5.4 to 6.4

# [1.1.0] - 2023-12-18
### ADDED
- Ajout des templates manquants
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.4|^8.0",
"php": "^8.3",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-ldap": "*",
Expand All @@ -13,7 +13,6 @@
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.7",
"phpdocumentor/reflection-docblock": "^5.1",
"sensio/framework-extra-bundle": "^5.5",
"spipu/html2pdf": "^5.2",
"symfony/apache-pack": "^1.0",
"symfony/asset": "*",
Expand All @@ -36,7 +35,6 @@
"symfony/security-bundle": "*",
"symfony/serializer": "*",
"symfony/string": "*",
"symfony/swiftmailer-bundle": "^3.5",
"symfony/translation": "*",
"symfony/twig-bundle": "*",
"symfony/validator": "*",
Expand Down Expand Up @@ -99,7 +97,7 @@
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.4.*"
"require": "6.4.*"
}
},
"name": "romain-neil/confcall",
Expand Down
2 changes: 0 additions & 2 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
];
4 changes: 0 additions & 4 deletions config/packages/dev/swiftmailer.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions config/packages/sensio_framework_extra.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions config/packages/swiftmailer.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions config/packages/test/swiftmailer.yaml

This file was deleted.

82 changes: 38 additions & 44 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,40 @@
use App\Service\AsteriskApi;
use DateTime;
use Exception;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Html2Pdf;
use Swift_Attachment;
use Swift_Mailer;
use Swift_Message;
use Swift_Mime_SimpleMessage;
use Swift_SmtpTransport;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Ldap\Security\LdapUser;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class HomeController extends AbstractController {

/**
* @Route("/", name="app_index")
* @return Response
* @IsGranted("ROLE_USER")
*/
#[Route('/', name: 'app_index')]
#[IsGranted('ROLE_USER')]
public function index(): Response {
return $this->render("index.html.twig", [
"calls" => AsteriskApi::getConfList()
]);
}

/**
* @Route("/admin", name="admin")
* @IsGranted("ROLE_ADMIN")
* @return Response
*/
#[Route('/admin', name: 'admin')]
#[IsGranted('ROLE_ADMIN')]
public function admin(): Response {
return $this->render("admin.html.twig", [
"calls" => AsteriskApi::getConfList(),
Expand All @@ -47,23 +48,23 @@ public function admin(): Response {
/**
* Tâche cron qui est appelée en ajax depuis l'administration
*
* @Route("/cron", name="cron")
* @IsGranted("ROLE_ADMIN")
* @return Response
*/
#[Route('/cron', name: 'cron')]
#[IsGranted('ROLE_ADMIN')]
public function cron(): Response {
AsteriskApi::cron();

return new Response("OK.");
}

/**
* @Route("/create", name="create")
* @param Request $req
* @return Response
* @IsGranted("ROLE_USER")
* @throws Exception
*/
#[Route('/create', name: 'create')]
#[IsGranted('ROLE_USER')]
public function create(Request $req): Response {
$user = $this->getUser();
$date = new DateTime($req->query->get('d'));
Expand All @@ -85,26 +86,28 @@ public function create(Request $req): Response {
}

/**
* @Route("/del/{id}", name="del_conf")
* @IsGranted("ROLE_USER")
* @param $id
* @return RedirectResponse
*/
#[Route('/del/{id}', name: 'del_conf')]
#[IsGranted('ROLE_USER')]
public function deleteConf($id): RedirectResponse {
AsteriskAPI::deleteConference($id);

return $this->redirect("/");
}

/**
* @Route("/pdf", name="gen_pdf")
* @IsGranted("ROLE_USER")
* @param Request $request
* @return RedirectResponse|Response
* @param MailerInterface $mailer
* @return Response
* @throws Html2PdfException
* @throws TransportExceptionInterface
*/
public function genPdf(Request $request) {
/** @var \Symfony\Component\Ldap\Security\LdapUser $user */
#[Route('/pdf', name: 'gen_pdf')]
#[IsGranted('ROLE_USER')]
public function genPdf(Request $request, MailerInterface $mailer): Response {
/** @var LdapUser $user */
$user = $this->getUser();

$id = $request->query->get('id');
Expand All @@ -127,35 +130,26 @@ public function genPdf(Request $request) {
);

if($shouldSendMail) {
$transport = new Swift_SmtpTransport("ip_serveur_smtp", 25); // ip/url ; port

//Attention: ne pas supprimer les 2 prochaines lignes
$transport->setUsername(""); //Mettre ici l'utilisateur smtp
$transport->setPassword(""); //Mettre ici le mot de passe de l'utilisateur

$mailer = new Swift_Mailer($transport);

$attachment = new Swift_Attachment($pdf->output('', 'S'), "invitation_$id.pdf", "application/pdf");
$invit = $pdf->output('', 'S');

$message = (new Swift_Message())
->setSubject("Fiche récapitulative audio conférence")
->setFrom("[email protected]", "ne-pas-repondre")
->setTo($user->getEntry()->getAttribute('mail'))
->setBody($this->renderView('emails/invitation.html.twig'))
->setContentType('text/html')
->setPriority(Swift_Mime_SimpleMessage::PRIORITY_HIGH)
->attach($attachment)
;
$email = (new TemplatedEmail())
->subject("Fiche récapitulative audio conférence")
->from("[email protected]", "ne-pas-repondre")
->to($user->getEntry()->getAttribute('mail'))
->htmlTemplate('emails/invitation.html.twig')
->priority(Email::PRIORITY_HIGH)
->addPart(new DataPart($invit, "invitation_$id.pdf"))
;

//On a plusieurs messages à envoyer
if($addresses !== false && $addresses !== "") {
$message->setFrom($user->getExtraFields()["mail"]);
$email->from($user->getExtraFields()["mail"]);
$addresses = explode(";", urldecode($addresses));

foreach($addresses as $addr) {
if($addr !== '') {
$message->setTo($addr);
$mailer->send($message);
$email->to($addr);
$mailer->send($email);
}
}

Expand All @@ -164,7 +158,7 @@ public function genPdf(Request $request) {
'La fiche récapitulative a bien été envoyée aux utilisateurs'
);
} else {
$mailer->send($message);
$mailer->send($email);

$this->addFlash(
'success',
Expand Down
8 changes: 3 additions & 5 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;

class SecurityController extends AbstractController {

/**
* @Route("/login", name="app_login")
* @param AuthenticationUtils $authenticationUtils
* @return Response
*/
#[Route('/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response {
if ($this->getUser()) {
return $this->redirectToRoute('app_index');
Expand All @@ -26,9 +26,7 @@ public function login(AuthenticationUtils $authenticationUtils): Response {
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}

/**
* @Route("/logout", name="app_logout")
*/
#[Route('/logout', name: 'app_logout')]
public function logout() {
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
Expand Down
3 changes: 1 addition & 2 deletions src/Security/CustomLdapUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Ldap\Entry;
use Symfony\Component\Ldap\Security\LdapUser;
use Symfony\Component\Ldap\Security\LdapUserProvider;
use Symfony\Component\Security\Core\User\UserInterface;
use function count;

class CustomLdapUserProvider extends LdapUserProvider {
Expand Down Expand Up @@ -34,7 +33,7 @@ protected function loadUser(string $identifier, Entry $entry): LdapUser {
$extraFields[$field] = $this->getAttributeValue($entry, $field);
}

if (strpos($entry->getDn(), "01-Service Informatique") !== false) {
if (str_contains($entry->getDn(), "01-Service Informatique")) {
$roles[] = "ROLE_ADMIN";
}

Expand Down
94 changes: 0 additions & 94 deletions src/Security/LdapFormAuthenticator.php

This file was deleted.

0 comments on commit 048c3be

Please sign in to comment.