Skip to content

Commit 86de8c0

Browse files
authored
Merge pull request #315 from nextcloud/fix/public-header-title
2 parents 66fc429 + 5b9f65f commit 86de8c0

6 files changed

Lines changed: 106 additions & 174 deletions

File tree

css/flex.scss

Lines changed: 0 additions & 19 deletions
This file was deleted.

css/icons.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11

2+
/**
3+
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
4+
*
5+
* @author John Molakvoæ <skjnldsv@protonmail.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
224
// Icon definitions
325
@include icon-black-white('forms', 'forms', 3);
426
@include icon-black-white('clone', 'forms', 1);

css/main.scss

Lines changed: 0 additions & 46 deletions
This file was deleted.

css/public.scss

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
#header {
2-
#appmenu,
3-
.header-right,
4-
nav {
5-
display: none;
6-
}
7-
}
8-
9-
div.crumb {
10-
background-image: none;
1+
/**
2+
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
3+
*
4+
* @author John Molakvoæ <skjnldsv@protonmail.com>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#header .header-shared-by {
24+
color: var(--color-primary-text);
25+
position: relative;
26+
font-weight: 300;
27+
font-size: 11px;
28+
line-height: 11px;
29+
overflow: hidden;
30+
text-overflow: ellipsis;
1131
}

css/submit.scss

Lines changed: 0 additions & 73 deletions
This file was deleted.

lib/Controller/PageController.php

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@
2828

2929
use OCA\Forms\Db\Form;
3030
use OCA\Forms\Db\FormMapper;
31-
use OCA\Forms\Db\OptionMapper;
32-
use OCA\Forms\Db\QuestionMapper;
3331
use OCA\Forms\Service\FormsService;
3432

33+
use OCP\Accounts\IAccountManager;
3534
use OCP\AppFramework\Controller;
3635
use OCP\AppFramework\Db\DoesNotExistException;
36+
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
3737
use OCP\AppFramework\Http\TemplateResponse;
3838
use OCP\IGroupManager;
3939
use OCP\IInitialStateService;
40+
use OCP\IL10N;
4041
use OCP\IRequest;
41-
use OCP\IURLGenerator;
42+
use OCP\IUser;
43+
use OCP\IUserManager;
4244
use OCP\IUserSession;
4345
use OCP\Util;
4446

@@ -47,22 +49,28 @@ class PageController extends Controller {
4749

4850
/** @var FormMapper */
4951
private $formMapper;
52+
53+
/** @var FormsService */
54+
private $formsService;
5055

51-
/** @var IURLGenerator */
52-
private $urlGenerator;
56+
/** @var IAccountManager */
57+
protected $accountManager;
5358

5459
/** @var IGroupManager */
5560
private $groupManager;
5661

57-
/** @var IUserSession */
58-
private $userSession;
59-
6062
/** @var IInitialStateService */
6163
private $initialStateService;
62-
63-
/** @var FormsService */
64-
private $formService;
6564

65+
/** @var IL10N */
66+
private $l10n;
67+
68+
/** @var IUserManager */
69+
private $userManager;
70+
71+
/** @var IUserSession */
72+
private $userSession;
73+
6674
/** @var Array
6775
*
6876
* Maximum String lengths, the database is set to store.
@@ -77,25 +85,27 @@ class PageController extends Controller {
7785

7886
public function __construct(string $appName,
7987
IRequest $request,
80-
IGroupManager $groupManager,
81-
IURLGenerator $urlGenerator,
8288
FormMapper $formMapper,
83-
QuestionMapper $questionMapper,
84-
OptionMapper $optionMapper,
85-
IUserSession $userSession,
89+
FormsService $formsService,
90+
IAccountManager $accountManager,
91+
IGroupManager $groupManager,
8692
IInitialStateService $initialStateService,
87-
FormsService $formsService) {
93+
IL10N $l10n,
94+
IUserManager $userManager,
95+
IUserSession $userSession) {
8896
parent::__construct($appName, $request);
8997

90-
$this->groupManager = $groupManager;
91-
$this->urlGenerator = $urlGenerator;
9298
$this->appName = $appName;
99+
93100
$this->formMapper = $formMapper;
94-
$this->questionMapper = $questionMapper;
95-
$this->optionMapper = $optionMapper;
96-
$this->userSession = $userSession;
97-
$this->initialStateService = $initialStateService;
98101
$this->formsService = $formsService;
102+
103+
$this->accountManager = $accountManager;
104+
$this->groupManager = $groupManager;
105+
$this->initialStateService = $initialStateService;
106+
$this->l10n = $l10n;
107+
$this->userManager = $userManager;
108+
$this->userSession = $userSession;
99109
}
100110

101111
/**
@@ -198,11 +208,29 @@ public function gotoForm($hash): ?TemplateResponse {
198208
return new TemplateResponse('forms', 'expired');
199209
}
200210

201-
$renderAs = $this->userSession->isLoggedIn() ? 'user' : 'public';
202-
203211
Util::addScript($this->appName, 'submit');
204212
$this->initialStateService->provideInitialState($this->appName, 'form', $this->formsService->getPublicForm($form->getId()));
205213
$this->initialStateService->provideInitialState($this->appName, 'maxStringLengths', $this->maxStringLengths);
206-
return new TemplateResponse($this->appName, 'main', [], $renderAs);
214+
215+
if (!$this->userSession->isLoggedIn()) {
216+
Util::addStyle($this->appName, 'public');
217+
$response = new PublicTemplateResponse($this->appName, 'main');
218+
$response->setHeaderTitle($form->getTitle());
219+
220+
// Get owner and check display name privacy settings
221+
$owner = $this->userManager->get($form->getOwnerId());
222+
if ($owner instanceof IUser) {
223+
$ownerAccount = $this->accountManager->getAccount($owner);
224+
225+
$ownerName = $ownerAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME);
226+
if ($ownerName->getScope() === IAccountManager::VISIBILITY_PUBLIC) {
227+
$response->setHeaderDetails($this->l10n->t('Shared by %s', [$ownerName->getValue()]));
228+
}
229+
}
230+
231+
return $response;
232+
}
233+
234+
return new TemplateResponse($this->appName, 'main');
207235
}
208236
}

0 commit comments

Comments
 (0)