diff options
Diffstat (limited to 'app')
28 files changed, 228 insertions, 4 deletions
diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php index ef79379f..afa0543a 100644 --- a/app/Controller/Webhook.php +++ b/app/Controller/Webhook.php @@ -100,4 +100,20 @@ class Webhook extends Base echo $result ? 'PARSED' : 'IGNORED'; } + + /** + * Handle Postmark webhooks + * + * @access public + */ + public function postmark() + { + if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { + $this->response->text('Not Authorized', 401); + } + + $result = $this->postmarkWebhook->parsePayload($this->request->getJson() ?: array()); + + echo $result ? 'PARSED' : 'IGNORED'; + } } diff --git a/app/Integration/PostmarkWebhook.php b/app/Integration/PostmarkWebhook.php new file mode 100644 index 00000000..6387ba20 --- /dev/null +++ b/app/Integration/PostmarkWebhook.php @@ -0,0 +1,67 @@ +<?php + +namespace Integration; + +use HTML_To_Markdown; + +/** + * Postmark Webhook + * + * @package integration + * @author Frederic Guillot + */ +class PostmarkWebhook extends Base +{ + /** + * Parse incoming email + * + * @access public + * @param array $payload Incoming email + * @return boolean + */ + public function parsePayload(array $payload) + { + if (empty($payload['From']) || empty($payload['Subject']) || empty($payload['MailboxHash']) || empty($payload['TextBody'])) { + return false; + } + + // The user must exists in Kanboard + $user = $this->user->getByEmail($payload['From']); + + if (empty($user)) { + $this->container['logger']->debug('PostmarkWebhook: ignored => user not found'); + return false; + } + + // The project must have a short name + $project = $this->project->getByIdentifier($payload['MailboxHash']); + + if (empty($project)) { + $this->container['logger']->debug('PostmarkWebhook: ignored => project not found'); + return false; + } + + // The user must be member of the project + if (! $this->projectPermission->isMember($project['id'], $user['id'])) { + $this->container['logger']->debug('PostmarkWebhook: ignored => user is not member of the project'); + return false; + } + + // Get the Markdown contents + if (empty($payload['HtmlBody'])) { + $description = $payload['TextBody']; + } + else { + $markdown = new HTML_To_Markdown($payload['HtmlBody'], array('strip_tags' => true)); + $description = $markdown->output(); + } + + // Finally, we create the task + return (bool) $this->taskCreation->create(array( + 'project_id' => $project['id'], + 'title' => $payload['Subject'], + 'description' => $description, + 'creator_id' => $user['id'], + )); + } +} diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index cc602ef4..f021ea34 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index 6a589cdd..f58e4630 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index d230d845..3160e6f6 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index badb7d88..934f90f4 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index 3bc3e7df..cdb9045b 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -860,4 +860,8 @@ return array( 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => 'Prenez une capture d\'écran et appuyez sur CTRL+V ou ⌘+V pour coller ici.', 'Screenshot uploaded successfully.' => 'Capture d\'écran téléchargée avec succès.', 'SEK - Swedish Krona' => 'SEK - Couronne suédoise', + 'The project identifier is an optional alphanumeric code used to identify your project.' => 'L\'identificateur du projet est un code alpha-numérique optionnel pour identifier votre projet.', + 'Identifier' => 'Identificateur', + 'Postmark (incoming emails)' => 'Postmark (emails entrants)', + 'Help on Postmark integration' => 'Aide sur l\'intégration avec Postmark', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index 558bb25e..38bed1a2 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index c8df81ab..59f057b3 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 11af3feb..9fa0a723 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php index 37c7c69d..5f57937c 100644 --- a/app/Locale/nl_NL/translations.php +++ b/app/Locale/nl_NL/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 366c6371..42b2865e 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index 87845f77..4dd237ec 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index 18fd6dfe..e3039db9 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php index cb2d7287..6e4a8228 100644 --- a/app/Locale/sr_Latn_RS/translations.php +++ b/app/Locale/sr_Latn_RS/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index e67402b2..abdb2b70 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', 'SEK - Swedish Krona' => 'SEK - Svensk Krona', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 024b211a..b6c140d6 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php index c5c1c79e..7457e0b1 100644 --- a/app/Locale/tr_TR/translations.php +++ b/app/Locale/tr_TR/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index e6166335..63570ca2 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -858,4 +858,8 @@ return array( // 'Take a screenshot and press CTRL+V or ⌘+V to paste here.' => '', // 'Screenshot uploaded successfully.' => '', // 'SEK - Swedish Krona' => '', + // 'The project identifier is an optional alphanumeric code used to identify your project.' => '', + // 'Identifier' => '', + // 'Postmark (incoming emails)' => '', + // 'Help on Postmark integration' => '', ); diff --git a/app/Model/Project.php b/app/Model/Project.php index dbb9db1b..231d57e7 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -60,6 +60,18 @@ class Project extends Base } /** + * Get a project by the identifier (code) + * + * @access public + * @param string $identifier + * @return array + */ + public function getByIdentifier($identifier) + { + return $this->db->table(self::TABLE)->eq('identifier', strtoupper($identifier))->findOne(); + } + + /** * Fetch project data by using the token * * @access public @@ -276,6 +288,10 @@ class Project extends Base $values['last_modified'] = time(); $values['is_private'] = empty($values['is_private']) ? 0 : 1; + if (! empty($values['identifier'])) { + $values['identifier'] = strtoupper($values['identifier']); + } + if (! $this->db->table(self::TABLE)->save($values)) { $this->db->cancelTransaction(); return false; @@ -338,6 +354,10 @@ class Project extends Base */ public function update(array $values) { + if (! empty($values['identifier'])) { + $values['identifier'] = strtoupper($values['identifier']); + } + return $this->exists($values['id']) && $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); } @@ -443,7 +463,10 @@ class Project extends Base new Validators\Integer('is_active', t('This value must be an integer')), new Validators\Required('name', t('The project name is required')), new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50), + new Validators\MaxLength('identifier', t('The maximum length is %d characters', 50), 50), + new Validators\AlphaNumeric('identifier', t('This value must be alphanumeric')) , new Validators\Unique('name', t('This project must be unique'), $this->db->getConnection(), self::TABLE), + new Validators\Unique('identifier', t('The identifier must be unique'), $this->db->getConnection(), self::TABLE), ); } @@ -456,6 +479,10 @@ class Project extends Base */ public function validateCreation(array $values) { + if (! empty($values['identifier'])) { + $values['identifier'] = strtoupper($values['identifier']); + } + $v = new Validator($values, $this->commonValidationRules()); return array( @@ -473,6 +500,10 @@ class Project extends Base */ public function validateModification(array $values) { + if (! empty($values['identifier'])) { + $values['identifier'] = strtoupper($values['identifier']); + } + $rules = array( new Validators\Required('id', t('This value is required')), ); diff --git a/app/Model/User.php b/app/Model/User.php index 6c348caa..d9f174bd 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -142,6 +142,18 @@ class User extends Base } /** + * Get a specific user by the email address + * + * @access public + * @param string $email Email + * @return array + */ + public function getByEmail($email) + { + return $this->db->table(self::TABLE)->eq('email', $email)->findOne(); + } + + /** * Get all users * * @access public diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 3e67387d..22f8c1b0 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -6,7 +6,12 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 65; +const VERSION = 66; + +function version_66($pdo) +{ + $pdo->exec("ALTER TABLE projects ADD COLUMN identifier VARCHAR(50) DEFAULT ''"); +} function version_65($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 6973b266..db30af67 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -6,7 +6,12 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 46; +const VERSION = 47; + +function version_47($pdo) +{ + $pdo->exec("ALTER TABLE projects ADD COLUMN identifier VARCHAR(50) DEFAULT ''"); +} function version_46($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index c4ebd98a..79c50458 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -6,7 +6,12 @@ use Core\Security; use PDO; use Model\Link; -const VERSION = 64; +const VERSION = 65; + +function version_65($pdo) +{ + $pdo->exec("ALTER TABLE projects ADD COLUMN identifier TEXT DEFAULT ''"); +} function version_64($pdo) { diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index b08d506c..0c02058e 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -78,6 +78,7 @@ class ClassProvider implements ServiceProviderInterface 'BitbucketWebhook', 'Hipchat', 'SlackWebhook', + 'PostmarkWebhook', ) ); diff --git a/app/Template/config/integrations.php b/app/Template/config/integrations.php index e11b62f8..b7dab2b4 100644 --- a/app/Template/config/integrations.php +++ b/app/Template/config/integrations.php @@ -6,7 +6,13 @@ <?= $this->formCsrf() ?> - <h3><?= t('Gravatar') ?></h3> + <h3><img src="assets/img/postmark-icon.png"/> <?= t('Postmark (incoming emails)') ?></h3> + <div class="listing"> + <input type="text" class="auto-select" readonly="readonly" value="<?= $this->getCurrentBaseUrl().$this->u('webhook', 'postmark', array('token' => $values['webhook_token'])) ?>"/><br/> + <p class="form-help"><a href="http://kanboard.net/documentation/postmark" target="_blank"><?= t('Help on Postmark integration') ?></a></p> + </div> + + <h3><img src="assets/img/gravatar-icon.png"/> <?= t('Gravatar') ?></h3> <div class="listing"> <?= $this->formCheckbox('integration_gravatar', t('Enable Gravatar images'), 1, $values['integration_gravatar'] == 1) ?> </div> diff --git a/app/Template/project/edit.php b/app/Template/project/edit.php index c1f98315..ffd9be00 100644 --- a/app/Template/project/edit.php +++ b/app/Template/project/edit.php @@ -9,6 +9,10 @@ <?= $this->formLabel(t('Name'), 'name') ?> <?= $this->formText('name', $values, $errors, array('required', 'maxlength="50"')) ?> + <?= $this->formLabel(t('Identifier'), 'identifier') ?> + <?= $this->formText('identifier', $values, $errors, array('maxlength="50"')) ?> + <p class="form-help"><?= t('The project identifier is an optional alphanumeric code used to identify your project.') ?></p> + <?= $this->formLabel(t('Description'), 'description') ?> <div class="form-tabs"> diff --git a/app/Template/project/index.php b/app/Template/project/index.php index 05a7d955..8d2bc30b 100644 --- a/app/Template/project/index.php +++ b/app/Template/project/index.php @@ -15,6 +15,7 @@ <tr> <th class="column-8"><?= $paginator->order(t('Id'), 'id') ?></th> <th class="column-8"><?= $paginator->order(t('Status'), 'is_active') ?></th> + <th class="column-8"><?= $paginator->order(t('Identifier'), 'identifier') ?></th> <th class="column-20"><?= $paginator->order(t('Project'), 'name') ?></th> <th><?= t('Columns') ?></th> </tr> @@ -31,6 +32,9 @@ <?php endif ?> </td> <td> + <?= $this->e($project['identifier']) ?> + </td> + <td> <?= $this->a('<i class="fa fa-table"></i>', 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Board')) ?> <?php if ($project['is_public']): ?> |