Send comments by email

This commit is contained in:
Frederic Guillot 2017-02-18 18:25:46 -05:00
parent 5710bab971
commit b4dc602381
36 changed files with 230 additions and 70 deletions

View File

@ -3,6 +3,7 @@ Version 1.0.40 (unreleased)
New features:
* Send comments by email
* Upload Sqlite database from user interface
Improvements:

View File

@ -0,0 +1,74 @@
<?php
namespace Kanboard\Controller;
/**
* Class CommentMailController
*
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class CommentMailController extends BaseController
{
public function create(array $values = array(), array $errors = array())
{
$project = $this->getProject();
$task = $this->getTask();
$this->response->html($this->helper->layout->task('comment_mail/create', array(
'values' => $values,
'errors' => $errors,
'task' => $task,
'project' => $project,
)));
}
public function save()
{
$task = $this->getTask();
$values = $this->request->getValues();
$values['task_id'] = $task['id'];
$values['user_id'] = $this->userSession->getId();
list($valid, $errors) = $this->commentValidator->validateEmailCreation($values);
if ($valid) {
$this->sendByEmail($values);
$values = $this->prepareComment($values);
if ($this->commentModel->create($values) !== false) {
$this->flash->success(t('Comment sent by email successfully.'));
} else {
$this->flash->failure(t('Unable to create your comment.'));
}
$this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments'), true);
} else {
$this->create($values, $errors);
}
}
protected function sendByEmail(array $values)
{
$html = $this->template->render('comment_mail/email', array(
'email' => $values,
));
$this->emailClient->send(
$values['email'],
$values['email'],
$values['subject'],
$html
);
}
protected function prepareComment(array $values)
{
$values['comment'] .= "\n\n_".t('Sent by email to [%s](mailto:%s) (%s)', $values['email'], $values['email'], $values['subject']).'_';
unset($values['subject']);
unset($values['email']);
return $values;
}
}

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Dodaj',
'Replace' => 'Zamijeni',
'Import' => 'Uvoz',
'change sorting' => 'Promijeni sortiranje',
'Change sorting' => 'Promijeni sortiranje',
'Tasks Importation' => 'Uvoz zadataka',
'Delimiter' => 'Djelilac',
'Enclosure' => 'Prilog',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Anhängen',
'Replace' => 'Ersetzen',
'Import' => 'Import',
'change sorting' => 'Sortierung ändern',
'Change sorting' => 'Sortierung ändern',
'Tasks Importation' => 'Aufgaben Import',
'Delimiter' => 'Trennzeichen',
'Enclosure' => 'Textbegrenzer',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Προσθήκη',
'Replace' => 'Αντικατάσταση',
'Import' => 'Εισαγωγή',
'change sorting' => 'Αλλαγή ταξινόμησης',
'Change sorting' => 'Αλλαγή ταξινόμησης',
'Tasks Importation' => 'Εισαγωγή εργασιών',
'Delimiter' => 'Delimiter',
'Enclosure' => 'Enclosure',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Añadir',
'Replace' => 'Reemplazar',
'Import' => 'Importar',
'change sorting' => 'Cambiar orden',
'Change sorting' => 'Cambiar orden',
'Tasks Importation' => 'Importación de tareas',
'Delimiter' => 'Delimitador',
'Enclosure' => 'Recinto',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Ajouter',
'Replace' => 'Remplaçer',
'Import' => 'Importation',
'change sorting' => 'changer l\'ordre',
'Change sorting' => 'changer l\'ordre',
'Tasks Importation' => 'Importation des tâches',
'Delimiter' => 'Délimiteur',
'Enclosure' => 'Caractère d\'encadrement',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Hozzáfűz',
'Replace' => 'Helyettesít',
'Import' => 'Importál',
'change sorting' => 'rendezési sorrend megváltoztatása',
'Change sorting' => 'rendezési sorrend megváltoztatása',
'Tasks Importation' => 'Feladat importálás',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Tambahkan',
'Replace' => 'Ganti',
'Import' => 'Impor',
'change sorting' => 'ubah pengurutan',
'Change sorting' => 'ubah pengurutan',
'Tasks Importation' => 'Importasi Tugas',
'Delimiter' => 'Pembatas',
'Enclosure' => 'Lampiran',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Aggiungi',
'Replace' => 'Sostituisci',
'Import' => 'Importa',
'change sorting' => 'cambia ordinamento',
'Change sorting' => 'cambia ordinamento',
'Tasks Importation' => 'Importazione task',
'Delimiter' => 'Delimitatore',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
'Append' => '추가',
'Replace' => '변경',
'Import' => '가져오기',
'change sorting' => '정렬 변경',
'Change sorting' => '정렬 변경',
'Tasks Importation' => '할일 가져오기',
'Delimiter' => '구분자',
'Enclosure' => '동봉',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Dołącz',
'Replace' => 'Zastąp',
'Import' => 'Importuj',
'change sorting' => 'odwróć sortowanie',
'Change sorting' => 'odwróć sortowanie',
'Tasks Importation' => 'Import zadań',
'Delimiter' => 'Separator pola',
'Enclosure' => 'Separator tekstu',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Adicionar',
'Replace' => 'Substituir',
'Import' => 'Importar',
'change sorting' => 'alterar ordenação',
'Change sorting' => 'alterar ordenação',
'Tasks Importation' => 'Importação de Tarefas',
'Delimiter' => 'Separador',
'Enclosure' => 'Delimitador de campos',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Acrescentar',
'Replace' => 'Substituir',
'Import' => 'Importar',
'change sorting' => 'alterar ordernação',
'Change sorting' => 'alterar ordernação',
'Tasks Importation' => 'Importação de Tarefas',
'Delimiter' => 'Delimitador',
'Enclosure' => 'Clausura',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Добавление',
'Replace' => 'Замена',
'Import' => 'Импорт',
'change sorting' => 'изменить сортировку',
'Change sorting' => 'изменить сортировку',
'Tasks Importation' => 'Импортирование задач',
'Delimiter' => 'Разделитель',
'Enclosure' => 'Тип кавычек',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
// 'Append' => '',
// 'Replace' => '',
// 'Import' => '',
// 'change sorting' => '',
// 'Change sorting' => '',
// 'Tasks Importation' => '',
// 'Delimiter' => '',
// 'Enclosure' => '',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'เพิ่มเติม',
'Replace' => 'แทนที่',
'Import' => 'นำเข้า',
'change sorting' => 'เปลี่ยนการเรียง',
'Change sorting' => 'เปลี่ยนการเรียง',
'Tasks Importation' => 'การนำเข้างาน',
'Delimiter' => 'คั่น',
'Enclosure' => 'กำหนดข้อความ',

View File

@ -844,7 +844,7 @@ return array(
'Append' => 'Ekle',
'Replace' => 'Üzerine yaz',
'Import' => 'İçeri aktar',
'change sorting' => 'sıralamayı değiştir',
'Change sorting' => 'sıralamayı değiştir',
'Tasks Importation' => 'Görevleri içeri aktar',
'Delimiter' => 'Ayırıcı',
'Enclosure' => 'Enclosure',

View File

@ -844,7 +844,7 @@ return array(
'Append' => '追加',
'Replace' => '替换',
'Import' => '导入',
'change sorting' => '改变排序',
'Change sorting' => '改变排序',
'Tasks Importation' => '任务重要性',
'Delimiter' => '分隔符',
'Enclosure' => '附件',

View File

@ -8,26 +8,28 @@
<?php endif ?>
<small class="comment-date"><?= t('Created at:') ?> <?= $this->dt->datetime($comment['date_creation']) ?></small>
<small class="comment-date"><?= t('Updated at:')?> <?= $this->dt->datetime($comment['date_modification']) ?></small>
<small class="comment-date"><?= t('Updated at:') ?> <?= $this->dt->datetime($comment['date_modification']) ?></small>
</div>
<?php if (! isset($hide_actions)): ?>
<div class="comment-actions">
<div class="comment-actions">
<div class="dropdown">
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog"></i><i class="fa fa-caret-down"></i></a>
<ul>
<li>
<i class="fa fa-link fa-fw"></i>
<a href="#comment-<?= $comment['id'] ?>"><?= t('link') ?></a>
<?= $this->url->icon('link', t('Link'), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', '', $this->app->isAjax(), 'comment-'.$comment['id']) ?>
</li>
<?php if ($editable && ($this->user->isAdmin() || $this->user->isCurrentUser($comment['user_id']))): ?>
<li>
<?= $this->modal->medium('edit', t('edit'), 'CommentController', 'edit', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'comment_id' => $comment['id'])) ?>
<?= $this->modal->medium('edit', t('Edit'), 'CommentController', 'edit', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'comment_id' => $comment['id'])) ?>
</li>
<li>
<?= $this->modal->confirm('trash-o', t('remove'), 'CommentController', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'comment_id' => $comment['id'])) ?>
<?= $this->modal->confirm('trash-o', t('Remove'), 'CommentController', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'comment_id' => $comment['id'])) ?>
</li>
<?php endif ?>
</ul>
</div>
</div>
<?php endif ?>
<div class="comment-content">

View File

@ -1,20 +1,25 @@
<div class="page-header">
<h2><?= $this->text->e($task['title']) ?> &gt; <?= t('Comments') ?></h2>
<h2><?= $this->text->e($task['title']) ?></h2>
<?php if (!isset($is_public) || !$is_public): ?>
<div class="comment-sorting">
<small>
<?= $this->url->icon('sort', t('change sorting'), 'CommentListController', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'js-modal-replace') ?>
</small>
</div>
<ul>
<li>
<?= $this->url->icon('sort', t('Change sorting'), 'CommentListController', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'js-modal-replace') ?>
</li>
<?php if ($editable): ?>
<li>
<?= $this->modal->medium('paper-plane', t('Send by email'), 'CommentMailController', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
</li>
<?php endif ?>
</ul>
<?php endif ?>
</div>
<div class="comments">
<?php foreach ($comments as $comment): ?>
<?= $this->render('comment/show', array(
'comment' => $comment,
'task' => $task,
'project' => $project,
'editable' => $editable,
'comment' => $comment,
'task' => $task,
'project' => $project,
'editable' => $editable,
'is_public' => isset($is_public) && $is_public,
)) ?>
<?php endforeach ?>

View File

@ -0,0 +1,21 @@
<div class="page-header">
<h2><?= t('Create and send comment by email') ?></h2>
</div>
<form method="post" action="<?= $this->url->href('CommentMailController', 'save', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->hidden('task_id', $values) ?>
<?= $this->form->hidden('user_id', $values) ?>
<?= $this->form->label(t('Email'), 'email') ?>
<?= $this->form->email('email', $values, $errors, array('autofocus', 'required', 'tabindex="1"')) ?>
<?= $this->form->label(t('Subject'), 'subject') ?>
<?= $this->form->text('subject', $values, $errors, array('required', 'tabindex="2"')) ?>
<?= $this->form->textEditor('comment', $values, $errors, array('required' => true, 'tabindex' => 3)) ?>
<?= $this->modal->submitButtons(array(
'submitLabel' => t('Send by email'),
'tabindex' => 4,
)) ?>
</form>

View File

@ -0,0 +1 @@
<?= $this->text->markdown($email['comment'], true) ?>

View File

@ -6,25 +6,28 @@
<?php if (!isset($is_public) || !$is_public): ?>
<div class="comment-sorting">
<small>
<?= $this->url->icon('sort', t('change sorting'), 'CommentController', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
<?= $this->url->icon('sort', t('Change sorting'), 'CommentController', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
<?php if ($editable): ?>
<?= $this->modal->medium('paper-plane', t('Send by email'), 'CommentMailController', 'create', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
<?php endif ?>
</small>
</div>
<?php endif ?>
<?php foreach ($comments as $comment): ?>
<?= $this->render('comment/show', array(
'comment' => $comment,
'task' => $task,
'project' => $project,
'editable' => $editable,
'comment' => $comment,
'task' => $task,
'project' => $project,
'editable' => $editable,
'is_public' => isset($is_public) && $is_public,
)) ?>
<?php endforeach ?>
<?php if ($editable): ?>
<?= $this->render('task_comments/create', array(
'values' => array(),
'errors' => array(),
'task' => $task,
'values' => array(),
'errors' => array(),
'task' => $task,
)) ?>
<?php endif ?>
</div>

View File

@ -13,6 +13,31 @@ use SimpleValidator\Validators;
*/
class CommentValidator extends BaseValidator
{
/**
* Validate comment email creation
*
* @access public
* @param array $values Required parameters to save an action
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
*/
public function validateEmailCreation(array $values)
{
$rules = array(
new Validators\Required('task_id', t('This value is required')),
new Validators\Required('user_id', t('This value is required')),
new Validators\Required('subject', t('This field is required')),
new Validators\Required('email', t('This field is required')),
new Validators\Email('email', t('Email address invalid')),
);
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
return array(
$v->execute(),
$v->getErrors()
);
}
/**
* Validate comment creation
*

File diff suppressed because one or more lines are too long

View File

@ -12,16 +12,6 @@
.comment
padding: 5px
margin-bottom: 15px
&:hover
background: #fafafa
.comment-highlighted
background-color: map-get($highlight-colors, 'background')
border: 2px solid map-get($highlight-colors, 'background')
border-left: 2px solid map-get($highlight-colors, 'border')
&:hover
background-color: map-get($highlight-colors, 'background')
border: 2px solid map-get($highlight-colors, 'border')
.comment-title
border-bottom: 1px dotted #eee
@ -32,17 +22,7 @@
font-weight: 200
.comment-actions
font-size: size('small')
margin-bottom: 10px
text-align: right
li
display: inline
a
color: color('light')
text-decoration: none
&:focus, &:hover
color: color('primary')
text-decoration: underline
.comment-content
margin-left: 55px
@ -53,3 +33,17 @@
height: 90px
.text-editor-preview-area
height: 90px
.comment-highlighted
background-color: map-get($highlight-colors, 'background')
border: 2px solid map-get($highlight-colors, 'border')
&:hover
background-color: map-get($highlight-colors, 'background')
.comment
&:hover
background: map-get($highlight-colors, 'background')
&:nth-child(even):not(.comment-highlighted)
background: bg-color('primary')
&:hover
background: map-get($highlight-colors, 'background')

View File

@ -6,6 +6,40 @@ use Kanboard\Validator\CommentValidator;
class CommentValidatorTest extends Base
{
public function testValidateMailCreation()
{
$commentValidator = new CommentValidator($this->container);
$result = $commentValidator->validateEmailCreation(array(
'user_id' => 1,
'task_id' => 1,
'comment' => 'blah',
'email' => 'test@localhost',
'subject' => 'something',
));
$this->assertTrue($result[0]);
$result = $commentValidator->validateEmailCreation(array(
'user_id' => 1,
'task_id' => 1,
'comment' => 'blah',
'email' => 'invalid',
'subject' => 'something',
));
$this->assertFalse($result[0]);
$result = $commentValidator->validateEmailCreation(array(
'user_id' => 1,
'task_id' => 1,
'comment' => 'bla',
'email' => 'test@localhost',
));
$this->assertFalse($result[0]);
}
public function testValidateCreation()
{
$commentValidator = new CommentValidator($this->container);