Skip to content
Snippets Groups Projects
Unverified Commit 2b861f24 authored by Christoph Wurst's avatar Christoph Wurst
Browse files

inject prefilled data

parent c258423c
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
class PageController extends Controller {
......@@ -51,6 +52,9 @@ class PageController extends Controller {
/** @var string */
private $currentUserId;
/** @var IUserSession */
private $userSession;
/**
* @param string $appName
* @param IRequest $request
......@@ -62,13 +66,14 @@ class PageController extends Controller {
*/
public function __construct($appName, IRequest $request,
IURLGenerator $urlGenerator, IConfig $config, AccountService $accountService,
AliasesService $aliasesService, $UserId) {
AliasesService $aliasesService, $UserId, IUserSession $userSession) {
parent::__construct($appName, $request);
$this->urlGenerator = $urlGenerator;
$this->config = $config;
$this->accountService = $accountService;
$this->aliasesService = $aliasesService;
$this->currentUserId = $UserId;
$this->userSession = $userSession;
}
/**
......@@ -83,15 +88,17 @@ class PageController extends Controller {
$accountsJson = [];
foreach ($mailAccounts as $mailAccount) {
$conf = $mailAccount->getConfiguration();
$conf['aliases'] = $this->aliasesService->findAll($conf['accountId'],
$this->currentUserId);
$conf['aliases'] = $this->aliasesService->findAll($conf['accountId'], $this->currentUserId);
$accountsJson[] = $conf;
}
$user = $this->userSession->getUser();
$response = new TemplateResponse($this->appName, 'index', [
'debug' => $this->config->getSystemValue('debug', false),
'app-version' => $this->config->getAppValue('mail', 'installed_version'),
'accounts' => base64_encode(json_encode($accountsJson)),
'prefill_displayName' => $user->getDisplayName(),
'prefill_email' => $this->config->getUserValue($user->getUID(), 'settings', 'email', ''),
]);
// set csp rules for ownCloud 8.1
......@@ -122,8 +129,7 @@ class PageController extends Controller {
}
}
array_walk($params,
function (&$value, $key) {
array_walk($params, function (&$value, $key) {
$value = "$key=" . urlencode($value);
});
......
......@@ -43,9 +43,9 @@ if ($_['debug']) {
<input type="hidden" id="serialized-accounts" value="<?php p($_['accounts']); ?>">
<div id="user-displayname"
style="display: none"><?php p(\OCP\User::getDisplayName(\OCP\User::getUser())); ?></div>
style="display: none"><?php p($_['prefill_displayName']); ?></div>
<div id="user-email"
style="display: none"><?php p(\OCP\Config::getUserValue(\OCP\User::getUser(), 'settings', 'email', '')); ?></div>
style="display: none"><?php p($_['prefill_email']); ?></div>
<div id="app">
<div id="app-navigation" class="icon-loading">
<div id="mail-new-message-fixed"></div>
......
......@@ -18,10 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
use OCA\Mail\Controller\PageController;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use Test\TestCase;
use OCA\Mail\Controller\PageController;
class PageControllerTest extends TestCase {
......@@ -34,24 +35,26 @@ class PageControllerTest extends TestCase {
private $controller;
private $accountService;
private $aliasesService;
private $userSession;
protected function setUp() {
parent::setUp();
$this->appName = 'mail';
$this->userId = 'george';
$this->request = $this->getMock('\OCP\IRequest');
$this->urlGenerator = $this->getMock('OCP\IURLGenerator');
$this->config = $this->getMock('OCP\IConfig');
$this->request = $this->getMockBuilder('\OCP\IRequest')->getMock();
$this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')->getMock();
$this->config = $this->getMockBuilder('OCP\IConfig')->getMock();
$this->accountService = $this->getMockBuilder('OCA\Mail\Service\AccountService')
->disableOriginalConstructor()
->getMock();
$this->aliasesService = $this->getMockBuilder('\OCA\Mail\Service\AliasesService')
->disableOriginalConstructor()
->getMock();
$this->userSession = $this->getMockBuilder('OCP\IUserSession')->getMock();
$this->controller = new PageController($this->appName, $this->request,
$this->urlGenerator, $this->config, $this->accountService,
$this->aliasesService, $this->userId);
$this->aliasesService, $this->userId, $this->userSession);
}
public function testIndex() {
......@@ -62,25 +65,25 @@ class PageControllerTest extends TestCase {
->method('findByUserId')
->with($this->userId)
->will($this->returnValue([
$account1,
$account2,
]));
$account1,
$account2,
]));
$account1->expects($this->once())
->method('getConfiguration')
->will($this->returnValue([
'accountId' => 1,
]));
'accountId' => 1,
]));
$account2->expects($this->once())
->method('getConfiguration')
->will($this->returnValue([
'accountId' => 2,
]));
'accountId' => 2,
]));
$this->aliasesService->expects($this->exactly(2))
->method('findAll')
->will($this->returnValueMap([
[1, $this->userId, ['a11', 'a12']],
[2, $this->userId, ['a21', 'a22']],
]));
[1, $this->userId, ['a11', 'a12']],
[2, $this->userId, ['a21', 'a22']],
]));
$accountsJson = [
[
'accountId' => 1,
......@@ -98,6 +101,10 @@ class PageControllerTest extends TestCase {
],
];
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$this->userSession->expects($this->once())
->method('getUser')
->will($this->returnValue($user));
$this->config->expects($this->once())
->method('getSystemValue')
->with('debug', false)
......@@ -106,16 +113,27 @@ class PageControllerTest extends TestCase {
->method('getAppValue')
->with('mail', 'installed_version')
->will($this->returnValue('1.2.3'));
$user->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('Jane Doe'));
$user->expects($this->once())
->method('getUID')
->will($this->returnValue('jane'));
$this->config->expects($this->once())
->method('getUserValue')
->with($this->equalTo('jane'), $this->equalTo('settings'), $this->equalTo('email'), $this->equalTo(''))
->will($this->returnValue('jane@doe.cz'));
$expected = new TemplateResponse($this->appName, 'index',
[
$expected = new TemplateResponse($this->appName, 'index', [
'debug' => true,
'app-version' => '1.2.3',
'accounts' => base64_encode(json_encode($accountsJson)),
'prefill_displayName' => 'Jane Doe',
'prefill_email' => 'jane@doe.cz',
]);
// set csp rules for ownCloud 8.1
if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) {
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
$csp = new ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
$expected->setContentSecurityPolicy($csp);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment