Commit 8ab8abab authored by tguillon's avatar tguillon
Browse files

Ajout configuration sur les utilisateurs de notification par e-mail.

Correction envoie d'e-mail à chaque demande d'action.
parent f1601f46
......@@ -18,6 +18,7 @@ CREATE TABLE users (
email VARCHAR(100) NOT NULL,
telephonefixe VARCHAR(15),
telephoneportable VARCHAR(15),
notification BOOLEAN NOT NULL DEFAULT FALSE,
createdby INT DEFAULT NULL REFERENCES users(id) ON DELETE SET NULL ON UPDATE CASCADE,
created timestamp without time zone NOT NULL,
modified timestamp without time zone NOT NULL
......
......@@ -159,4 +159,6 @@ ALTER TABLE organisations RENAME COLUMN cil TO dpo;
ALTER TABLE organisations RENAME COLUMN numerocil TO numerodpo;
UPDATE etats SET libelle = 'Validée par le DPO' WHERE id = 5;
ALTER TABLE users ADD COLUMN notification BOOLEAN NOT NULL DEFAULT FALSE;
COMMIT;
\ No newline at end of file
......@@ -39,56 +39,26 @@
*/
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $smtp = array(
'transport' => 'Smtp',
'from' => array('site@localhost' => 'My Site'),
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $fast = array(
'from' => 'you@localhost',
'sender' => null,
'to' => null,
'cc' => null,
'bcc' => null,
'replyTo' => null,
'readReceipt' => null,
'returnPath' => null,
'messageId' => true,
'subject' => null,
'message' => null,
'headers' => null,
'viewRender' => null,
'template' => false,
'layout' => false,
'viewVars' => null,
'attachments' => null,
'emailFormat' => null,
'transport' => 'Smtp',
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'log' => true,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $default = [
'transport' => 'Mail',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
];
public $email = [
'transport' => 'Mail',
'from' => 'ne-pas-repondre@web-dpo.fr',
//'replyTo' => 'noreply@collectivite',
'host' => 'mail',
'port' => 25,
'timeout' => 30,
// 'username' => '',
// 'password' => '',
'client' => 'smtp_helo_hostname',
'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8'
];
}
......@@ -63,6 +63,29 @@ class NotificationsComponent extends Component {
return false;
}
}
/**
* Envoi un mail de notification si l'utilisateur a autoriser les notifs
*
* @param type $user_id
*/
public function sendEmail($user_id) {
$user = ClassRegistry::init('User');
$userInfo = $user->find('first', [
'conditions' => [
'id' => $user_id
]
]);
if ($userInfo['User']['notification'] === true) {
$Email = new CakeEmail();
$Email->config('email');
$Email->to($userInfo['User']['email']);
$Email->subject('Nouvelle notification');
$Email->send('Vous avez reçu une nouvelle notification sur web-DPO');
}
}
/**
* @param type $content
......@@ -74,10 +97,10 @@ class NotificationsComponent extends Component {
*/
public function del($content, $id) {
$notification = ClassRegistry::init('Notification');
$notification->deleteAll(array(
$notification->deleteAll([
'content' => $content,
'fiche_id' => $id
));
]);
}
}
......@@ -113,6 +113,10 @@ class EtatFichesController extends AppController {
]
]);
$success = $success && false !== $this->Notification->save();
if ($success === true) {
$this->Notifications->sendEmail($this->request->data['EtatFiche']['destinataire']);
}
if ($success == true) {
$destinataire = $this->User->find('first', [
......@@ -352,7 +356,7 @@ class EtatFichesController extends AppController {
}
/**
* Gère l'envoie de la demande d'avis
* Gère l'envoie en consultation
*
* @access public
* @created 29/04/2015
......@@ -411,7 +415,6 @@ class EtatFichesController extends AppController {
}
if ($success == true) {
if (empty($reorientationDemandeAvis)) {
$this->EtatFiche->create([
'EtatFiche' => [
......@@ -472,6 +475,10 @@ class EtatFichesController extends AppController {
]
]);
$success = $success && false !== $this->Notification->save();
if ($success === true) {
$this->Notifications->sendEmail($this->request->data['EtatFiche']['destinataire']);
}
}
}
}
......@@ -652,6 +659,9 @@ class EtatFichesController extends AppController {
}
}
/**
* Fonction permettant de répondre à la demande de consultation
*/
public function repondreCommentaire() {
if ($this->request->is('POST')) {
$success = true;
......@@ -795,11 +805,11 @@ class EtatFichesController extends AppController {
]);
$success = $success && $this->EtatFiche->updateAll([
'actif' => false
], [
'id' => $traitement['EtatFiche']['id']
]
) !== false;
'actif' => false
], [
'id' => $traitement['EtatFiche']['id']
]
) !== false;
if ($success == true) {
$dpo = $this->Organisation->find('first', [
......@@ -863,6 +873,10 @@ class EtatFichesController extends AppController {
]
]);
$success = $success && false !== $this->Notification->save();
if ($success === true) {
$this->Notifications->sendEmail($dpo['Organisation']['dpo']);
}
}
}
}
......
......@@ -756,4 +756,25 @@ class PannelController extends AppController {
return ($this->Norme->enums());
}
public function checkEmail(){
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('email');
//$Email->from('noreply@adullact.org');
$Email->subject("email test web-DPO");
$Email->to("theo.guillon@libriciel.coop");
$result = null;
debug("envoie de l'e-mail");
try {
$result = $Email->send("contenu du mail de test");
} catch (Exception $e) {
debug($e->getMessage());
}
debug($result);
$this->autoRender = false;
}
}
......@@ -247,6 +247,9 @@ msgstr " "
msgid "user.champNumerodpo"
msgstr "Numéro d'enregistrement du DPO"
msgid "user.champNotification"
msgstr "Notification par e-mail ?"
###############################################################################
......
......@@ -118,6 +118,13 @@
],
'telephoneportable' => [
'id' => 'telephoneportable'
],
'notification' => [
'id' => 'notification',
'options' => [false => 'Non', true => 'Oui'],
'empty' => false,
'required' => true,
'placeholder' => false
]
]);
?>
......
......@@ -122,6 +122,14 @@
],
'User.telephoneportable' => [
'id' => 'telephoneportable'
],
'User.notification' => [
'id' => 'notification',
'options' => [false => 'Non', true => 'Oui'],
'empty' => false,
'required' => true,
'default' => false,
'placeholder' => false
]
]);
?>
......
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