Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nextcloud mail - PostGuard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Kolijn
Nextcloud mail - PostGuard
Commits
2b861f24
Unverified
Commit
2b861f24
authored
8 years ago
by
Christoph Wurst
Browse files
Options
Downloads
Patches
Plain Diff
inject prefilled data
parent
c258423c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/controller/pagecontroller.php
+11
-5
11 additions, 5 deletions
lib/controller/pagecontroller.php
templates/index.php
+2
-2
2 additions, 2 deletions
templates/index.php
tests/controller/pagecontrollertest.php
+36
-18
36 additions, 18 deletions
tests/controller/pagecontrollertest.php
with
49 additions
and
25 deletions
lib/controller/pagecontroller.php
+
11
−
5
View file @
2b861f24
...
...
@@ -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
);
});
...
...
This diff is collapsed.
Click to expand it.
templates/index.php
+
2
−
2
View file @
2b861f24
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
tests/controller/pagecontrollertest.php
+
36
−
18
View file @
2b861f24
...
...
@@ -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
->
getMock
Builder
(
'\OCP\IRequest'
)
->
getMock
()
;
$this
->
urlGenerator
=
$this
->
getMock
Builder
(
'OCP\IURLGenerator'
)
->
getMock
()
;
$this
->
config
=
$this
->
getMock
Builder
(
'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
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment