From 9adfe8e7664ec9306d9b63ccf4ca2d7bddb73daa Mon Sep 17 00:00:00 2001 From: Philipp Schaffrath Date: Wed, 26 Apr 2017 09:23:10 +0200 Subject: [PATCH 1/8] added propper support for app and legacy themes, updated namespaces, re-written some code so it is up to date, also used depencency injection, so we can add tests --- appinfo/info.xml | 1 + appinfo/routes.php | 18 +- js/settings-admin.js | 2 +- lib/AdminPanel.php | 45 ++++ .../AppInfo/Application.php | 23 ++- .../Controller/AdminSettingsController.php | 51 +++-- .../Http/MailTemplateResponse.php | 1 - lib/MailTemplate.php | 108 ++++++++++ lib/TemplateEditor.php | 80 +++++++ lib/adminpanel.php | 28 --- lib/mailtemplate.php | 195 ------------------ templates/settings-admin.php | 23 +-- 12 files changed, 284 insertions(+), 291 deletions(-) create mode 100644 lib/AdminPanel.php rename app/templateeditor.php => lib/AppInfo/Application.php (73%) rename controller/adminsettingscontroller.php => lib/Controller/AdminSettingsController.php (66%) rename http/mailtemplateresponse.php => lib/Http/MailTemplateResponse.php (99%) create mode 100644 lib/MailTemplate.php create mode 100644 lib/TemplateEditor.php delete mode 100644 lib/adminpanel.php delete mode 100644 lib/mailtemplate.php diff --git a/appinfo/info.xml b/appinfo/info.xml index aa258af..4179fbb 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -8,6 +8,7 @@ While it is possible to manually change email templates within ownCloud, this ap AGPL Jörn Dreyer 0.1 + TemplateEditor diff --git a/appinfo/routes.php b/appinfo/routes.php index e666e73..645377f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -1,5 +1,4 @@ registerRoutes($this, array('routes' => array( - - // mailTemplate settings - array('name' => 'admin_settings#renderTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'GET'), - - array('name' => 'admin_settings#updateTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'POST'), - - array('name' => 'admin_settings#resetTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'DELETE') - -))); +return [ + ['name' => 'admin_settings#renderTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'GET'], + ['name' => 'admin_settings#updateTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'POST'], + ['name' => 'admin_settings#resetTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'DELETE'], +]; \ No newline at end of file diff --git a/js/settings-admin.js b/js/settings-admin.js index 32e8c5d..70736b9 100644 --- a/js/settings-admin.js +++ b/js/settings-admin.js @@ -9,7 +9,7 @@ $(document).ready(function() { $( '#mailTemplateSettings .templateEditor + .actions:hidden').show(400); $.get( OC.generateUrl('apps/templateeditor/settings/mailtemplate'), - { theme: theme, template: template } + { themeName: theme, template: template } ).done(function( result ) { $( '#mailTemplateSettings textarea' ).val(result); }).fail(function( result ) { diff --git a/lib/AdminPanel.php b/lib/AdminPanel.php new file mode 100644 index 0000000..6f0b647 --- /dev/null +++ b/lib/AdminPanel.php @@ -0,0 +1,45 @@ +templateEditor = $templateEditor; + } + + /** + * @return Template + */ + public function getPanel() { + $template = new Template('templateeditor', 'settings-admin'); + $template->assign('themeNames', $this->templateEditor->getAllThemeNames()); + $template->assign('editableTemplates', $this->templateEditor->getEditableTemplates()); + return $template; + } + + /** + * @return string + */ + public function getSectionID() { + return 'general'; + } + + /** + * @return int + */ + public function getPriority() { + return 5; + } +} diff --git a/app/templateeditor.php b/lib/AppInfo/Application.php similarity index 73% rename from app/templateeditor.php rename to lib/AppInfo/Application.php index 89ca7f3..7bcbf17 100644 --- a/app/templateeditor.php +++ b/lib/AppInfo/Application.php @@ -1,5 +1,4 @@ getContainer(); - /** - * Controllers - */ + $container->registerService('TemplateEditor', function ($container) { + return new TemplateEditor($container->query('ThemeService')); + }); + $container->registerService('AdminSettingsController', function($c) { return new AdminSettingsController( $c->query('AppName'), - $c->query('Request') + $c->query('Request'), + $c->query('TemplateEditor') ); }); } diff --git a/controller/adminsettingscontroller.php b/lib/Controller/AdminSettingsController.php similarity index 66% rename from controller/adminsettingscontroller.php rename to lib/Controller/AdminSettingsController.php index b6a2214..c4502f1 100644 --- a/controller/adminsettingscontroller.php +++ b/lib/Controller/AdminSettingsController.php @@ -1,5 +1,4 @@ templateEditor = $templateEditor; } /** - * @param string $theme + * @param string $themeName * @param string $template * @return \OCP\AppFramework\Http\Response */ - public function renderTemplate( $theme, $template ) { + public function renderTemplate($themeName, $template) { try { - $template = $this->getMailTemplate($theme, $template); + $template = $this->templateEditor->getMailTemplate($themeName, $template); return $template->getResponse(); } catch (\Exception $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode()); + return new JSONResponse(['message' => $ex->getMessage()], $ex->getCode()); } } @@ -56,10 +66,11 @@ public function renderTemplate( $theme, $template ) { * @param string $content * @return JSONResponse */ - public function updateTemplate( $theme, $template, $content ) { + public function updateTemplate($theme, $template, $content) { try { - $template = $this->getMailTemplate($theme, $template); - $template->setContent( $content ); + // TODO: throw new SecurityException('Template not editable.', 403); if template not editable + $template = $this->templateEditor->getMailTemplate($theme, $template); + $template->setContent($content); return new JSONResponse(); } catch (\Exception $ex) { return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode()); @@ -71,9 +82,9 @@ public function updateTemplate( $theme, $template, $content ) { * @param string $template * @return JSONResponse */ - public function resetTemplate( $theme, $template ) { + public function resetTemplate($theme, $template) { try { - $template = $this->getMailTemplate($theme, $template); + $template = $this->templateEditor->getMailTemplate($theme, $template); if ($template->reset()) { return new JSONResponse(); } else { @@ -83,18 +94,4 @@ public function resetTemplate( $theme, $template ) { return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode()); } } - - /** - * @param string $themeName - * @param string $template - * @return MailTemplate - */ - protected function getMailTemplate($themeName, $template){ - $themeService = new ThemeService($themeName); - return new MailTemplate( - $themeService->getTheme(), - $template - ); - } - } diff --git a/http/mailtemplateresponse.php b/lib/Http/MailTemplateResponse.php similarity index 99% rename from http/mailtemplateresponse.php rename to lib/Http/MailTemplateResponse.php index 16d4f98..8d9668c 100644 --- a/http/mailtemplateresponse.php +++ b/lib/Http/MailTemplateResponse.php @@ -53,5 +53,4 @@ public function __construct($filename, $contentType = 'text/php') { public function render(){ return file_get_contents($this->filename); } - } diff --git a/lib/MailTemplate.php b/lib/MailTemplate.php new file mode 100644 index 0000000..3c08bbf --- /dev/null +++ b/lib/MailTemplate.php @@ -0,0 +1,108 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ + +namespace OCA\TemplateEditor; + +use OC\Theme\Theme; +use OCA\TemplateEditor\Http\MailTemplateResponse; +use OC\AppFramework\Middleware\Security\Exceptions\SecurityException; + +class MailTemplate extends \OC_Template { + + /** @var string */ + private $path; + + /** + * @param Theme $theme + * @param string $path + */ + public function __construct(Theme $theme, $path) { + $this->theme = $theme; + $this->path = $path; + } + + /** + * @return \OCA\TemplateEditor\Http\MailTemplateResponse + * @throws SecurityException + */ + public function getResponse() { + $template = $this->getTemplateDetails(); + return new MailTemplateResponse($template); + } + + /** + * @return string + */ + protected function getTemplateDetails() { + list($app, $filename) = explode('/templates/', $this->path, 2); + $name = substr($filename, 0, -4); + $template = $this->findTemplate($this->theme, $app, $name); + return $template; + } + + /** + * @param string $content + * @return int|false + * @throws \Exception + */ + public function setContent($content) { + $absolutePath = $this->getAbsoluteTemplatePath(); + + // TODO: check what the minimum permissions are. + if (!is_dir(dirname($absolutePath)) ) { + if (!mkdir(dirname($absolutePath), 0777, true)){ + throw new \Exception('Could not create directory.', 500); + } + } + if (is_file($absolutePath) ) { + if (!copy($absolutePath, $absolutePath.'.bak')){ + throw new \Exception('Could not create template backup.', 500); + } + } + + return file_put_contents($absolutePath, $content); + } + + /** + * @return bool + */ + public function reset() { + $absolutePath = $this->getAbsoluteTemplatePath(); + + if (is_file($absolutePath . '.bak')) { + if (rename($absolutePath . '.bak', $absolutePath)) { + return true; + } + } else if (unlink($absolutePath)) { + return true; + } + + return !file_exists($absolutePath); + } + + /** + * @return string + */ + protected function getAbsoluteTemplatePath() { + return \OC::$SERVERROOT . '/' . $this->theme->getDirectory() . '/' . $this->path; + } +} diff --git a/lib/TemplateEditor.php b/lib/TemplateEditor.php new file mode 100644 index 0000000..4386ca4 --- /dev/null +++ b/lib/TemplateEditor.php @@ -0,0 +1,80 @@ +themeService = $themeService; + } + + /** + * @return string[] + */ + public function getAllThemeNames() { + $themes = $this->themeService->getAllThemes(); + $themeNames = []; + + foreach ($themes as $theme) { + $themeNames[] = $theme->getName(); + } + return $themeNames; + } + + /** + * @return array + */ + public function getEditableTemplates() { + $l10n = \OC::$server->getL10NFactory()->get('templateeditor'); + $templates = [ + 'core/templates/mail.php' => $l10n->t('Sharing email - public link shares (HTML)'), + 'core/templates/altmail.php' => $l10n->t('Sharing email - public link shares (plain text fallback)'), + 'core/templates/internalmail.php' => $l10n->t('Sharing email (HTML)'), + 'core/templates/internalaltmail.php' => $l10n->t('Sharing email (plain text fallback)'), + 'core/templates/lostpassword/email.php' => $l10n->t('Lost password mail'), + 'settings/templates/email.new_user.php' => $l10n->t('New user email (HTML)'), + 'settings/templates/email.new_user_plain_text.php' => $l10n->t('New user email (plain text fallback)'), + ]; + + if (App::isEnabled('activity')) { + $tmplPath = \OC_App::getAppPath('activity') . '/templates/email.notification.php'; + $path = substr($tmplPath, strlen(\OC::$SERVERROOT) + 1); + $templates[$path] = $l10n->t('Activity notification mail'); + } + + return $templates; + } + + /** + * @param string $themeName + * @param string $template + * @return MailTemplate + */ + public function getMailTemplate($themeName, $template) { + return new MailTemplate( + $this->themeService->findTheme($themeName), + $template + ); + } + +} \ No newline at end of file diff --git a/lib/adminpanel.php b/lib/adminpanel.php deleted file mode 100644 index 11d3693..0000000 --- a/lib/adminpanel.php +++ /dev/null @@ -1,28 +0,0 @@ -assign('themes', $themes); - $tmpl->assign('editableTemplates', $editableTemplates); - return $tmpl; - } - - public function getPriority() { - return 5; - } - - -} \ No newline at end of file diff --git a/lib/mailtemplate.php b/lib/mailtemplate.php deleted file mode 100644 index 4366554..0000000 --- a/lib/mailtemplate.php +++ /dev/null @@ -1,195 +0,0 @@ - - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see . - * - */ - -namespace OCA\TemplateEditor; - -use OCP\App; -use OCP\Files\NotPermittedException; -use OC\AppFramework\Middleware\Security\Exceptions\SecurityException; -use OCA\TemplateEditor\Http\MailTemplateResponse; -use OC\Theme\Theme; - -class MailTemplate extends \OC_Template { - - /** @var array */ - private $editableThemes; - - /** @var array */ - private $editableTemplates; - - /** @var string */ - private $path; - - /** - * @param Theme $theme - * @param string $path - */ - public function __construct($theme, $path) { - $this->theme = $theme; - $this->path = $path; - - //determine valid theme names - $this->editableThemes = self::getEditableThemes(); - //for now hard code the valid mail template paths - $this->editableTemplates = self::getEditableTemplates(); - } - - /** - * @return \OCA\TemplateEditor\Http\MailTemplateResponse - * @throws SecurityException - */ - public function getResponse() { - if(!$this->isEditable()) { - throw new SecurityException('Template not editable.', 403); - } - $template = $this->getTemplateDetails(); - return new MailTemplateResponse($template); - } - - public function renderContent() { - if(!$this->isEditable()) { - throw new SecurityException('Template not editable.', 403); - } - $template = $this->getTemplateDetails(); - \OC_Response::sendFile($template); - } - - protected function getTemplateDetails(){ - list($app, $filename) = explode('/templates/', $this->path, 2); - $name = substr($filename, 0, -4); - $template = $this->findTemplate($this->theme, $app, $name); - return $template; - } - - /** - * @return string - */ - protected function getAbsoluteTemplatePath(){ - return \OC::$SERVERROOT . '/' . $this->theme->getDirectory() . $this->path; - } - - public function isEditable() { - $themeName = $this->theme->getName(); - if (isset($this->editableThemes[$themeName]) - && isset($this->editableTemplates[$this->path]) - ) { - return true; - } - return false; - } - - public function setContent($data) { - if($this->isEditable()) { - //save default templates in default folder to overwrite core template - $absolutePath = $this->getAbsoluteTemplatePath(); - $parent = dirname($absolutePath); - if ( ! is_dir($parent) ) { - if ( ! mkdir(dirname($absolutePath), 0777, true) ){ - throw new \Exception('Could not create directory.', 500); - } - } - if ( $this->theme->getName() !== 'default' && is_file($absolutePath) ) { - if ( ! copy($absolutePath, $absolutePath.'.bak') ){ - throw new \Exception('Could not overwrite template.', 500); - } - } - //overwrite theme templates? use versions? - return file_put_contents($absolutePath, $data); - } - throw new SecurityException('Template not editable.', 403); - } - - public function reset(){ - if($this->isEditable()) { - $absolutePath = $this->getAbsoluteTemplatePath(); - if ($this->theme->getName() === 'default') { - //templates can simply be deleted in the themes folder - if (unlink($absolutePath)) { - return true; - } - } else { - //if a bak file exists overwrite the template with it - if (is_file($absolutePath.'.bak')) { - if (rename($absolutePath.'.bak', $absolutePath)) { - return true; - } - } else if (unlink($absolutePath)) { - return true; - } - } - return !file_exists($absolutePath); - } - throw new NotPermittedException('Template not editable.', 403); - } - - /** - * @return array with available themes. consists of core and subfolders in the themes folder - */ - public static function getEditableThemes() { - $themes = []; - $theme = \OC::$server->getConfig()->getSystemValue('theme', null); - if (!empty($theme)) { - $themes[$theme] = true; - } - - if ($handle = opendir(\OC::$SERVERROOT.'/themes')) { - while (false !== ($entry = readdir($handle))) { - if ($entry === '.' || $entry === '..') { - continue; - } - if (!is_null($theme) && $entry === $theme) { - continue; - } - if (is_dir(\OC::$SERVERROOT.'/themes/'.$entry)) { - $themes[$entry] = true; - } - } - closedir($handle); - } - return $themes; - } - - /** - * @return array with keys containing the path and values containing the name of a template - */ - public static function getEditableTemplates() { - $l10n = \OC::$server->getL10NFactory()->get('templateeditor'); - $templates = [ - 'core/templates/mail.php' => $l10n->t('Sharing email - public link shares (HTML)'), - 'core/templates/altmail.php' => $l10n->t('Sharing email - public link shares (plain text fallback)'), - 'core/templates/internalmail.php' => $l10n->t('Sharing email (HTML)'), - 'core/templates/internalaltmail.php' => $l10n->t('Sharing email (plain text fallback)'), - 'core/templates/lostpassword/email.php' => $l10n->t('Lost password mail'), - 'settings/templates/email.new_user.php' => $l10n->t('New user email (HTML)'), - 'settings/templates/email.new_user_plain_text.php' => $l10n->t('New user email (plain text fallback)'), - ]; - - if (App::isEnabled('activity')) { - $tmplPath = \OC_App::getAppPath('activity') . '/templates/email.notification.php'; - $path = substr($tmplPath, strlen(\OC::$SERVERROOT) + 1); - $templates[$path] = $l10n->t('Activity notification mail'); - } - - return $templates; - } -} diff --git a/templates/settings-admin.php b/templates/settings-admin.php index 5113910..e317ff8 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -1,23 +1,20 @@

t('Mail Templates'));?>

-
-
-
-
-
-
- - - -
-
From 6d3fdfe0d3ad0b8f66734a90f4319c9926b5cef7 Mon Sep 17 00:00:00 2001 From: Philipp Schaffrath Date: Tue, 16 May 2017 09:31:07 +0200 Subject: [PATCH 2/8] Theme and ThemeService switched to OCP namespace, removed exception annotation that isn't actually been thrown, fixed docblock, removed todo that is unnecessary --- lib/Controller/AdminSettingsController.php | 1 - lib/MailTemplate.php | 4 +--- lib/TemplateEditor.php | 25 ++++++++++++++++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/Controller/AdminSettingsController.php b/lib/Controller/AdminSettingsController.php index c4502f1..2484d74 100644 --- a/lib/Controller/AdminSettingsController.php +++ b/lib/Controller/AdminSettingsController.php @@ -68,7 +68,6 @@ public function renderTemplate($themeName, $template) { */ public function updateTemplate($theme, $template, $content) { try { - // TODO: throw new SecurityException('Template not editable.', 403); if template not editable $template = $this->templateEditor->getMailTemplate($theme, $template); $template->setContent($content); return new JSONResponse(); diff --git a/lib/MailTemplate.php b/lib/MailTemplate.php index 3c08bbf..88837dd 100644 --- a/lib/MailTemplate.php +++ b/lib/MailTemplate.php @@ -22,9 +22,8 @@ namespace OCA\TemplateEditor; -use OC\Theme\Theme; +use OCP\Theme\Theme; use OCA\TemplateEditor\Http\MailTemplateResponse; -use OC\AppFramework\Middleware\Security\Exceptions\SecurityException; class MailTemplate extends \OC_Template { @@ -42,7 +41,6 @@ public function __construct(Theme $theme, $path) { /** * @return \OCA\TemplateEditor\Http\MailTemplateResponse - * @throws SecurityException */ public function getResponse() { $template = $this->getTemplateDetails(); diff --git a/lib/TemplateEditor.php b/lib/TemplateEditor.php index 4386ca4..8927493 100644 --- a/lib/TemplateEditor.php +++ b/lib/TemplateEditor.php @@ -1,15 +1,26 @@ + * + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * */ - namespace OCA\TemplateEditor; - -use OC\Theme\ThemeService; +use OCP\Theme\ThemeService; use OCP\App; class TemplateEditor { From 3ca67fb95803499d59de1162e0e02ac2c27c3069 Mon Sep 17 00:00:00 2001 From: Philipp Schaffrath Date: Thu, 18 May 2017 15:43:26 +0200 Subject: [PATCH 3/8] use ThemeService public api --- lib/AppInfo/Application.php | 12 +++++++----- lib/MailTemplate.php | 6 +++--- lib/TemplateEditor.php | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 7bcbf17..f180202 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -22,9 +22,11 @@ namespace OCA\TemplateEditor\AppInfo; +use OCA\TemplateEditor\AdminPanel; use OCA\TemplateEditor\Controller\AdminSettingsController; use OCA\TemplateEditor\TemplateEditor; use OCP\AppFramework\App; +use OCP\AppFramework\IAppContainer; class Application extends App { @@ -36,15 +38,15 @@ public function __construct(array $urlParams = []) { $container = $this->getContainer(); - $container->registerService('TemplateEditor', function ($container) { + $container->registerService('TemplateEditor', function (IAppContainer $container) { return new TemplateEditor($container->query('ThemeService')); }); - $container->registerService('AdminSettingsController', function($c) { + $container->registerService('AdminSettingsController', function(IAppContainer $container) { return new AdminSettingsController( - $c->query('AppName'), - $c->query('Request'), - $c->query('TemplateEditor') + $container->query('AppName'), + $container->query('Request'), + $container->query('TemplateEditor') ); }); } diff --git a/lib/MailTemplate.php b/lib/MailTemplate.php index 88837dd..a8fd2ca 100644 --- a/lib/MailTemplate.php +++ b/lib/MailTemplate.php @@ -22,7 +22,7 @@ namespace OCA\TemplateEditor; -use OCP\Theme\Theme; +use OCP\Theme\ITheme; use OCA\TemplateEditor\Http\MailTemplateResponse; class MailTemplate extends \OC_Template { @@ -31,10 +31,10 @@ class MailTemplate extends \OC_Template { private $path; /** - * @param Theme $theme + * @param ITheme $theme * @param string $path */ - public function __construct(Theme $theme, $path) { + public function __construct(ITheme $theme, $path) { $this->theme = $theme; $this->path = $path; } diff --git a/lib/TemplateEditor.php b/lib/TemplateEditor.php index 8927493..7c9e11f 100644 --- a/lib/TemplateEditor.php +++ b/lib/TemplateEditor.php @@ -20,22 +20,22 @@ */ namespace OCA\TemplateEditor; -use OCP\Theme\ThemeService; use OCP\App; +use OCP\Theme\IThemeService; class TemplateEditor { /** - * @var ThemeService + * @var IThemeService */ private $themeService; /** * TemplateEditor constructor. * - * @param ThemeService $themeService + * @param IThemeService $themeService */ - public function __construct(ThemeService $themeService) { + public function __construct(IThemeService $themeService) { $this->themeService = $themeService; } From 7f2a647503347910ee2dd6964ff65a078c7699f3 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 11 Aug 2017 11:28:52 +0200 Subject: [PATCH 4/8] Increase version requirement + version. Remove deprecated 'shipped' tag --- appinfo/info.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 4179fbb..7d582c8 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -7,12 +7,11 @@ While it is possible to manually change email templates within ownCloud, this ap AGPL Jörn Dreyer - 0.1 + 0.2 TemplateEditor - + - true OCA\TemplateEditor\AdminPanel From 4f5355c654721c8245db03ad14f496b80b12460a Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 8 Nov 2017 17:09:28 +0300 Subject: [PATCH 5/8] Update legal part --- appinfo/routes.php | 7 ++++--- lib/AdminPanel.php | 21 +++++++++++++++++++++ lib/AppInfo/Application.php | 5 +++-- lib/Controller/AdminSettingsController.php | 5 +++-- lib/Http/MailTemplateResponse.php | 5 +++-- lib/MailTemplate.php | 5 +++-- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 645377f..74c3d62 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -2,8 +2,9 @@ /** * ownCloud - Template Editor * - * @author Jörn Dreyer - * @copyright 2014 Jörn Dreyer + * @author Jörn Dreyer + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -24,4 +25,4 @@ ['name' => 'admin_settings#renderTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'GET'], ['name' => 'admin_settings#updateTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'POST'], ['name' => 'admin_settings#resetTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'DELETE'], -]; \ No newline at end of file +]; diff --git a/lib/AdminPanel.php b/lib/AdminPanel.php index 6f0b647..c8ea95b 100644 --- a/lib/AdminPanel.php +++ b/lib/AdminPanel.php @@ -1,4 +1,25 @@ + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + */ namespace OCA\TemplateEditor; diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f180202..22acbc6 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -2,8 +2,9 @@ /** * ownCloud - Template Editor * - * @author Jörn Dreyer - * @copyright 2014 Jörn Dreyer + * @author Jörn Dreyer + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/lib/Controller/AdminSettingsController.php b/lib/Controller/AdminSettingsController.php index 2484d74..4c92ab6 100644 --- a/lib/Controller/AdminSettingsController.php +++ b/lib/Controller/AdminSettingsController.php @@ -2,8 +2,9 @@ /** * ownCloud - Template Editor * - * @author Jörn Dreyer - * @copyright 2014 Jörn Dreyer + * @author Jörn Dreyer + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/lib/Http/MailTemplateResponse.php b/lib/Http/MailTemplateResponse.php index 8d9668c..fb389bf 100644 --- a/lib/Http/MailTemplateResponse.php +++ b/lib/Http/MailTemplateResponse.php @@ -3,8 +3,9 @@ /** * ownCloud - Template Editor * - * @author Jörn Dreyer - * @copyright 2014 Jörn Dreyer + * @author Jörn Dreyer + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE diff --git a/lib/MailTemplate.php b/lib/MailTemplate.php index a8fd2ca..e3bfe08 100644 --- a/lib/MailTemplate.php +++ b/lib/MailTemplate.php @@ -2,8 +2,9 @@ /** * ownCloud - Template Editor * - * @author Jörn Dreyer - * @copyright 2014 Jörn Dreyer + * @author Jörn Dreyer + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE From 7617f4bb774f34ffd78142544235ad0c2b0e6ec0 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 8 Nov 2017 17:33:52 +0300 Subject: [PATCH 6/8] Minor 'use' cleanup, use short array syntax --- lib/AppInfo/Application.php | 1 - lib/Controller/AdminSettingsController.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 22acbc6..d7c2fe1 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -23,7 +23,6 @@ namespace OCA\TemplateEditor\AppInfo; -use OCA\TemplateEditor\AdminPanel; use OCA\TemplateEditor\Controller\AdminSettingsController; use OCA\TemplateEditor\TemplateEditor; use OCP\AppFramework\App; diff --git a/lib/Controller/AdminSettingsController.php b/lib/Controller/AdminSettingsController.php index 4c92ab6..bc724ef 100644 --- a/lib/Controller/AdminSettingsController.php +++ b/lib/Controller/AdminSettingsController.php @@ -73,7 +73,7 @@ public function updateTemplate($theme, $template, $content) { $template->setContent($content); return new JSONResponse(); } catch (\Exception $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode()); + return new JSONResponse(['message' => $ex->getMessage()], $ex->getCode()); } } @@ -91,7 +91,7 @@ public function resetTemplate($theme, $template) { return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } catch (\Exception $ex) { - return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode()); + return new JSONResponse(['message' => $ex->getMessage()], $ex->getCode()); } } } From 011b06a5ad390171719cd0a2b360f66e0cd9e3b3 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 8 Nov 2017 17:51:52 +0300 Subject: [PATCH 7/8] Fix routes --- appinfo/routes.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 74c3d62..85ad0aa 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -22,7 +22,9 @@ */ return [ - ['name' => 'admin_settings#renderTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'GET'], - ['name' => 'admin_settings#updateTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'POST'], - ['name' => 'admin_settings#resetTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'DELETE'], + 'routes' => [ + ['name' => 'adminSettings#renderTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'GET'], + ['name' => 'adminSettings#updateTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'POST'], + ['name' => 'adminSettings#resetTemplate', 'url' => '/settings/mailtemplate', 'verb' => 'DELETE'], + ] ]; From 138c16ee72f22acf6cc5b5980d7e1821de41394e Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Thu, 9 Nov 2017 21:35:59 +0300 Subject: [PATCH 8/8] Filter only enabled app-themes --- lib/TemplateEditor.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/TemplateEditor.php b/lib/TemplateEditor.php index 7c9e11f..85e6b1c 100644 --- a/lib/TemplateEditor.php +++ b/lib/TemplateEditor.php @@ -44,10 +44,14 @@ public function __construct(IThemeService $themeService) { */ public function getAllThemeNames() { $themes = $this->themeService->getAllThemes(); + $themeNames = []; - foreach ($themes as $theme) { - $themeNames[] = $theme->getName(); + $themeName = $theme->getName(); + if (is_array(App::getAppInfo($themeName)) && !App::isEnabled($themeName)) { + continue; + } + $themeNames[] = $themeName; } return $themeNames; }