forms/lib/Controller/PageController.php
dependabot-preview[bot] e2959be243 Merge
Bumps [sass-loader](https://github.com/webpack-contrib/sass-loader) from 9.0.1 to 9.0.2.
- [Release notes](https://github.com/webpack-contrib/sass-loader/releases)
- [Changelog](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack-contrib/sass-loader/compare/v9.0.1...v9.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Bump @nextcloud/vue from 2.2.0 to 2.2.1

Bumps [@nextcloud/vue](https://github.com/nextcloud/nextcloud-vue) from 2.2.0 to 2.2.1.
- [Release notes](https://github.com/nextcloud/nextcloud-vue/releases)
- [Commits](https://github.com/nextcloud/nextcloud-vue/compare/v2.2.0...v2.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Bump vuedraggable from 2.23.2 to 2.24.0

Bumps [vuedraggable](https://github.com/SortableJS/Vue.Draggable) from 2.23.2 to 2.24.0.
- [Release notes](https://github.com/SortableJS/Vue.Draggable/releases)
- [Commits](https://github.com/SortableJS/Vue.Draggable/compare/v2.23.2...v2.24.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Bump @nextcloud/axios from 1.3.2 to 1.3.3

Bumps [@nextcloud/axios](https://github.com/nextcloud/nextcloud-axios) from 1.3.2 to 1.3.3.
- [Release notes](https://github.com/nextcloud/nextcloud-axios/releases)
- [Changelog](https://github.com/nextcloud/nextcloud-axios/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nextcloud/nextcloud-axios/compare/v1.3.2...v1.3.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

[tx-robot] updated from transifex

Move to webpack vue global config & clean routes

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>

Lint fix

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>

@nextcloud/webpack-vue-config@1.0.3

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>

[tx-robot] updated from transifex

[tx-robot] updated from transifex

Bump @nextcloud/webpack-vue-config from 1.0.3 to 1.1.0

Bumps [@nextcloud/webpack-vue-config](https://github.com/nextcloud/webpack-vue-config) from 1.0.3 to 1.1.0.
- [Release notes](https://github.com/nextcloud/webpack-vue-config/releases)
- [Commits](https://github.com/nextcloud/webpack-vue-config/compare/v1.0.3...v1.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Bump @babel/core from 7.10.4 to 7.10.5

Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.10.4 to 7.10.5.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.10.5/packages/babel-core)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

[tx-robot] updated from transifex

Add screenshot of response visualization, adjust readme

Signed-off-by: Jan C. Borchardt <hey@jancborchardt.net>

[tx-robot] updated from transifex

[tx-robot] updated from transifex

Revert "Allow navigation through edit via Tab-Key"

v2.0.0-rc.1

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>

[tx-robot] updated from transifex

Bump webpack from 4.43.0 to 4.44.0

Bumps [webpack](https://github.com/webpack/webpack) from 4.43.0 to 4.44.0.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v4.43.0...v4.44.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

[tx-robot] updated from transifex

Update stylelint config

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>

Fix actions

Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>

[tx-robot] updated from transifex

Fix dropdown submission insert

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>

2.0.0

Force enable for master

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>

[tx-robot] updated from transifex

Fix substring utf8

Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>

2.0.1

[Security] Bump elliptic from 6.5.0 to 6.5.3

Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.0 to 6.5.3. **This update includes a security fix.**
- [Release notes](https://github.com/indutny/elliptic/releases)
- [Commits](https://github.com/indutny/elliptic/compare/v6.5.0...v6.5.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

[tx-robot] updated from transifex

Increase description length

Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>

2.0.2

Bump webpack from 4.44.0 to 4.44.1

Bumps [webpack](https://github.com/webpack/webpack) from 4.44.0 to 4.44.1.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v4.44.0...v4.44.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Bump @babel/core from 7.10.5 to 7.11.0

Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.10.5 to 7.11.0.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.11.0/packages/babel-core)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Bump @babel/preset-env from 7.10.4 to 7.11.0

Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.10.4 to 7.11.0.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.11.0/packages/babel-preset-env)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

[tx-robot] updated from transifex

[tx-robot] updated from transifex
2020-09-15 16:42:33 +02:00

210 lines
6.1 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author affan98 <affan98@gmail.com>
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
* @author Jonas Rittershofer <jotoeri@users.noreply.github.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Forms\Controller;
use OCA\Forms\Db\Form;
use OCA\Forms\Db\FormMapper;
use OCA\Forms\Service\FormsService;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IGroupManager;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Util;
class PageController extends Controller {
private const TEMPLATE_EXPIRED = 'expired';
private const TEMPLATE_MAIN = 'main';
private const TEMPLATE_NOSUBMIT = 'nosubmit';
private const TEMPLATE_NOTFOUND = 'notfound';
protected $appName;
/** @var FormMapper */
private $formMapper;
/** @var FormsService */
private $formsService;
/** @var IAccountManager */
protected $accountManager;
/** @var IGroupManager */
private $groupManager;
/** @var IInitialStateService */
private $initialStateService;
/** @var IL10N */
private $l10n;
/** @var ILogger */
private $logger;
/** @var IUserManager */
private $userManager;
/** @var IUserSession */
private $userSession;
/** @var Array
*
* Maximum String lengths, the database is set to store.
*/
private $maxStringLengths = [
'formTitle' => 256,
'formDescription' => 8192,
'questionText' => 2048,
'optionText' => 1024,
'answerText' => 4096,
];
public function __construct(string $appName,
IRequest $request,
FormMapper $formMapper,
FormsService $formsService,
IAccountManager $accountManager,
IGroupManager $groupManager,
IInitialStateService $initialStateService,
IL10N $l10n,
ILogger $logger,
IUserManager $userManager,
IUserSession $userSession) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->formMapper = $formMapper;
$this->formsService = $formsService;
$this->accountManager = $accountManager;
$this->groupManager = $groupManager;
$this->initialStateService = $initialStateService;
$this->l10n = $l10n;
$this->logger = $logger;
$this->userManager = $userManager;
$this->userSession = $userSession;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function index(): TemplateResponse {
Util::addScript($this->appName, 'forms-main');
Util::addStyle($this->appName, 'forms');
$this->initialStateService->provideInitialState($this->appName, 'maxStringLengths', $this->maxStringLengths);
return new TemplateResponse($this->appName, self::TEMPLATE_MAIN);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
* @param string $hash
* @return TemplateResponse
*/
public function gotoForm($hash): ?TemplateResponse {
// Inject style on all templates
Util::addStyle($this->appName, 'forms');
try {
$form = $this->formMapper->findByHash($hash);
} catch (DoesNotExistException $e) {
return $this->provideTemplate(self::TEMPLATE_NOTFOUND);
}
// Does the user have access to form
if (!$this->formsService->hasUserAccess($form->getId())) {
return $this->provideTemplate(self::TEMPLATE_NOTFOUND);
}
// Does the user have permissions to submit (resp. submitOnce)
if (!$this->formsService->canSubmit($form->getId())) {
return $this->provideTemplate(self::TEMPLATE_NOSUBMIT, $form);
}
// Has form expired
if ($form->getExpires() !== 0 && time() > $form->getExpires()) {
return $this->provideTemplate(self::TEMPLATE_EXPIRED, $form);
}
// Main Template to fill the form
Util::addScript($this->appName, 'forms-submit');
$this->initialStateService->provideInitialState($this->appName, 'form', $this->formsService->getPublicForm($form->getId()));
$this->initialStateService->provideInitialState($this->appName, 'maxStringLengths', $this->maxStringLengths);
return $this->provideTemplate(self::TEMPLATE_MAIN, $form);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
* @param string $template
* @param Form $form Necessary to set header on public forms, not necessary for 'notfound'-template
* @return TemplateResponse
*/
public function provideTemplate(string $template, Form $form = null): ?TemplateResponse {
// If not logged in, use PublicTemplate
if (!$this->userSession->isLoggedIn()) {
Util::addStyle($this->appName, 'public');
$response = new PublicTemplateResponse($this->appName, $template);
// Set Header
$response->setHeaderTitle($this->l10n->t('Forms'));
if ($template !== self::TEMPLATE_NOTFOUND) {
$response->setHeaderTitle($form->getTitle());
// Get owner and check display name privacy settings
$owner = $this->userManager->get($form->getOwnerId());
if ($owner instanceof IUser) {
$ownerAccount = $this->accountManager->getAccount($owner);
$ownerName = $ownerAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME);
if ($ownerName->getScope() === IAccountManager::VISIBILITY_PUBLIC) {
$response->setHeaderDetails($this->l10n->t('Shared by %s', [$ownerName->getValue()]));
}
}
}
return $response;
}
return new TemplateResponse($this->appName, $template);
}
}