From fc1d6f4c3cd2882c22d71c060c8ffef8c4a44b7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas.mueller@tmit.eu>
Date: Wed, 4 Jun 2014 15:01:36 +0200
Subject: [PATCH] fixes during test

---
 .../controller/adminsettingscontroller.php    | 33 ++++++++++------
 apps/files_sharing/js/settings-admin.js       | 17 ++++-----
 apps/files_sharing/lib/mailtemplate.php       |  3 +-
 core/templates/mail.html                      | 38 -------------------
 4 files changed, 32 insertions(+), 59 deletions(-)
 delete mode 100644 core/templates/mail.html

diff --git a/apps/files_sharing/controller/adminsettingscontroller.php b/apps/files_sharing/controller/adminsettingscontroller.php
index 7125641617d..fed3147a99c 100644
--- a/apps/files_sharing/controller/adminsettingscontroller.php
+++ b/apps/files_sharing/controller/adminsettingscontroller.php
@@ -15,35 +15,46 @@ class AdminSettingsController extends ApiController {
 	/**
 	 * @param string $theme
 	 * @param string $template
-	 * @return type Description
 	 * @return \OCA\Files_Sharing\Http\MailTemplateResponse
 	 */
 	public function render( $theme, $template ) {
-		$template = new \OCA\Files_Sharing\MailTemplate( $theme, $template );
-		return $template->getResponse();
+		try {
+			$template = new \OCA\Files_Sharing\MailTemplate( $theme, $template );
+			return $template->getResponse();
+		} catch (\Exception $ex) {
+			return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode());
+		}
 	}
 
 	/**
 	 * @param string $theme
 	 * @param string $template
 	 * @param string $content
-	 * @return array
+	 * @return JSONResponse
 	 */
 	public function update( $theme, $template, $content ) {
-		$template = new \OCA\Files_Sharing\MailTemplate( $theme, $template );
-		$template->setContent( $content );
-		return new JSONResponse();
+		try {
+			$template = new \OCA\Files_Sharing\MailTemplate( $theme, $template );
+			$template->setContent( $content );
+			return new JSONResponse();
+		} catch (\Exception $ex) {
+			return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode());
+		}
 	}
 
 	/**
 	 * @param string $theme
 	 * @param string $template
-	 * @return array
+	 * @return JSONResponse
 	 */
 	public function reset( $theme, $template ) {
-		$template = new \OCA\Files_Sharing\MailTemplate( $theme, $template );
-		$template->reset();
-		return new JSONResponse();
+		try {
+			$template = new \OCA\Files_Sharing\MailTemplate( $theme, $template );
+			$template->reset();
+			return new JSONResponse();
+		} catch (\Exception $ex) {
+			return new JSONResponse(array('message' => $ex->getMessage()), $ex->getCode());
+		}
 	}
 
 }
diff --git a/apps/files_sharing/js/settings-admin.js b/apps/files_sharing/js/settings-admin.js
index 0362af0232b..fa9b236ea98 100644
--- a/apps/files_sharing/js/settings-admin.js
+++ b/apps/files_sharing/js/settings-admin.js
@@ -7,9 +7,9 @@ $(document).ready(function() {
 		).done(function( result ) {
 			$( '#mailTemplateSettings textarea' ).val(result);
 		}).fail(function( result ) {
-			alert(result);
+			OC.dialogs.alert(result.message, t('files_sharing', 'Could not load template'));
 		});
-	}
+	};
 
 	// load default template
 	var theme = $( '#mts-theme' ).val();
@@ -41,11 +41,11 @@ $(document).ready(function() {
 			$.post(
 				OC.generateUrl('apps/files_sharing/settings/mailtemplate'),
 				{ theme: theme, template: template, content: content }
-			).done(function( result ) {
+			).done(function() {
 				var data = { status:'success', data:{message:t('files_sharing', 'Saved')} };
 				OC.msg.finishedSaving('#mts-msg', data);
-			}).fail(function( result ) {
-				var data = { status:'error', data:{message:t('files_sharing', 'Error')} };
+			}).fail(function(result) {
+				var data = { status: 'error', data:{message:result.responseJSON.message} };
 				OC.msg.finishedSaving('#mts-msg', data);
 			});
 		}
@@ -55,13 +55,12 @@ $(document).ready(function() {
 		function() {
 			var theme = $( '#mts-theme' ).val();
 			var template = $( '#mts-template' ).val();
-			var content = $( '#mailTemplateSettings textarea' ).val();
 			OC.msg.startSaving('#mts-msg');
 			$.ajax({
 				type: "DELETE",
 				url: OC.generateUrl('apps/files_sharing/settings/mailtemplate'),
 				data: { theme: theme, template: template }
-			}).done(function( result ) {
+			}).done(function() {
 				var data = { status:'success', data:{message:t('files_sharing', 'Reset')} };
 				OC.msg.finishedSaving('#mts-msg', data);
 
@@ -69,8 +68,8 @@ $(document).ready(function() {
 				var theme = $( '#mts-theme' ).val();
 				var template = $( '#mts-template' ).val();
 				loadTemplate(theme, template);
-			}).fail(function( result ) {
-				var data = { status:'error', data:{message:t('files_sharing', 'Error')} };
+			}).fail(function(result) {
+				var data = { status: 'error', data:{message:result.responseJSON.message} };
 				OC.msg.finishedSaving('#mts-msg', data);
 			});
 		}
diff --git a/apps/files_sharing/lib/mailtemplate.php b/apps/files_sharing/lib/mailtemplate.php
index cb08b534d6f..ca1b0234ccf 100644
--- a/apps/files_sharing/lib/mailtemplate.php
+++ b/apps/files_sharing/lib/mailtemplate.php
@@ -19,7 +19,7 @@ class MailTemplate extends \OC_Template {
 
 		//determine valid theme names
 		$this->editableThemes = self::getEditableThemes();
-		//for now hardcode the valid mail template paths
+		//for now hard code the valid mail template paths
 		$this->editableTemplates = self::getEditableTemplates();
 	}
 	
@@ -34,6 +34,7 @@ class MailTemplate extends \OC_Template {
 			list($path, $template) = $this->findTemplate($this->theme, $app, $name, '');
 			return new MailTemplateResponse($template);
 		}
+		throw new SecurityException('Template not editable.', 403);
 	}
 
 	public function renderContent() {
diff --git a/core/templates/mail.html b/core/templates/mail.html
deleted file mode 100644
index 3382dbf81d5..00000000000
--- a/core/templates/mail.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<table cellspacing="0" cellpadding="0" border="0" width="100%">
-<tr><td>
-<table cellspacing="0" cellpadding="0" border="0" width="600px">
-<tr>
-<td bgcolor="#1d2d44" width="20px">&nbsp;</td>
-<td bgcolor="#1d2d44">
-<img src="<?php print_unescaped(OC_Helper::makeURLAbsolute(image_path('', 'logo-mail.gif'))); ?>" alt="{{theme.name}}"/>
-</td>
-</tr>
-<tr><td bgcolor="#f8f8f8" colspan="2">&nbsp;</td></tr>
-<tr>
-<td bgcolor="#f8f8f8" width="20px">&nbsp;</td>
-<td bgcolor="#f8f8f8" style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
-<?php
-print_unescaped($l->t('Hey there,<br><br>just letting you know that %s shared <strong>%s</strong> with you.<br><a href="%s">View it!</a><br><br>', array($_['user_displayname'], $_['filename'], $_['link'])));
-if ( isset($_['expiration']) ) {
-	p($l->t("The share will expire on %s.", array($_['expiration'])));
-	print_unescaped('<br><br>');
-}
-p($l->t('Cheers!'));
-?>
-</td>
-</tr>
-<tr><td bgcolor="#f8f8f8" colspan="2">&nbsp;</td></tr>
-<tr>
-<td bgcolor="#f8f8f8" width="20px">&nbsp;</td>
-<td bgcolor="#f8f8f8" style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br>
-{{theme.name}} -
-{{theme.slogan}}
-<br><a href="{{theme.baseurl}}">{{theme.baseurl}}</a>
-</td>
-</tr>
-<tr>
-<td bgcolor="#f8f8f8" colspan="2">&nbsp;</td>
-</tr>
-</table>
-</td></tr>
-</table>
-- 
GitLab