Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
This commit is contained in:
Jonas Rittershofer 2022-05-08 17:29:16 +02:00
Родитель ca4917a1db
Коммит 35d2197fdb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: A865740F334316E0
6 изменённых файлов: 112 добавлений и 45 удалений

Просмотреть файл

@ -29,9 +29,13 @@ class Constants {
/**
* Used AppConfig Keys
*/
public const CONFIG_KEY_ALLOWPERMITALL = 'allowPermitAll';
public const CONFIG_KEY_ALLOWPUBLICLINK = 'allowPublicLink';
public const CONFIG_KEY_CREATIONALLOWEDGROUPS = 'creationAllowedGroups';
public const CONFIG_KEY_RESTRICTCREATION = 'restrictCreation';
public const CONFIG_KEYS = [
self::CONFIG_KEY_ALLOWPERMITALL,
self::CONFIG_KEY_ALLOWPUBLICLINK,
self::CONFIG_KEY_CREATIONALLOWEDGROUPS,
self::CONFIG_KEY_RESTRICTCREATION
];

Просмотреть файл

@ -31,6 +31,7 @@ use OCA\Forms\Db\Form;
use OCA\Forms\Db\FormMapper;
use OCA\Forms\Db\Share;
use OCA\Forms\Db\ShareMapper;
use OCA\Forms\Service\ConfigService;
use OCA\Forms\Service\FormsService;
use OCP\AppFramework\OCSController;
@ -59,6 +60,9 @@ class ShareApiController extends OCSController {
/** @var ShareMapper */
private $shareMapper;
/** @var ConfigService */
private $configService;
/** @var FormsService */
private $formsService;
@ -80,6 +84,7 @@ class ShareApiController extends OCSController {
public function __construct(string $appName,
FormMapper $formMapper,
ShareMapper $shareMapper,
ConfigService $configService,
FormsService $formsService,
IGroupManager $groupManager,
ILogger $logger,
@ -91,6 +96,7 @@ class ShareApiController extends OCSController {
$this->appName = $appName;
$this->formMapper = $formMapper;
$this->shareMapper = $shareMapper;
$this->configService = $configService;
$this->formsService = $formsService;
$this->groupManager = $groupManager;
$this->logger = $logger;
@ -125,6 +131,12 @@ class ShareApiController extends OCSController {
throw new OCSBadRequestException('Invalid shareType');
}
// Block LinkShares if not allowed
if ($shareType === IShare::TYPE_LINK && !$this->configService->getAllowPublicLink()) {
$this->logger->debug('Link Share not allowed.');
throw new OCSForbiddenException('Link Share not allowed.');
}
try {
$form = $this->formMapper->findById($formId);
} catch (IMapperException $e) {

Просмотреть файл

@ -65,6 +65,12 @@ class ConfigService {
/**
* Load the single values, decode, have default values
*/
public function getAllowPermitAll(): bool {
return json_decode($this->config->getAppValue($this->appName, Constants::CONFIG_KEY_ALLOWPERMITALL, "true"));
}
public function getAllowPublicLink(): bool {
return json_decode($this->config->getAppValue($this->appName, Constants::CONFIG_KEY_ALLOWPUBLICLINK, "true"));
}
private function getUnformattedCreationAllowedGroups(): array {
return json_decode($this->config->getAppValue($this->appName, Constants::CONFIG_KEY_CREATIONALLOWEDGROUPS, "[]"));
}
@ -80,6 +86,8 @@ class ConfigService {
*/
public function getAppConfig(): array {
return [
Constants::CONFIG_KEY_ALLOWPERMITALL => $this->getAllowPermitAll(),
Constants::CONFIG_KEY_ALLOWPUBLICLINK => $this->getAllowPublicLink(),
Constants::CONFIG_KEY_CREATIONALLOWEDGROUPS => $this->getCreationAllowedGroups(),
Constants::CONFIG_KEY_RESTRICTCREATION => $this->getRestrictCreation(),

Просмотреть файл

@ -33,6 +33,7 @@ use OCA\Forms\Db\QuestionMapper;
use OCA\Forms\Db\Share;
use OCA\Forms\Db\ShareMapper;
use OCA\Forms\Db\SubmissionMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\IMapperException;
use OCP\IGroup;
@ -66,6 +67,9 @@ class FormsService {
/** @var SubmissionMapper */
private $submissionMapper;
/** @var ConfigService */
private $configService;
/** @var IGroupManager */
private $groupManager;
@ -84,6 +88,7 @@ class FormsService {
QuestionMapper $questionMapper,
ShareMapper $shareMapper,
SubmissionMapper $submissionMapper,
ConfigService $configService,
IGroupManager $groupManager,
ILogger $logger,
IUserManager $userManager,
@ -94,6 +99,7 @@ class FormsService {
$this->questionMapper = $questionMapper;
$this->shareMapper = $shareMapper;
$this->submissionMapper = $submissionMapper;
$this->configService = $configService;
$this->groupManager = $groupManager;
$this->logger = $logger;
$this->userManager = $userManager;
@ -322,7 +328,7 @@ class FormsService {
}
// Now all remaining users are allowed, if permitAll is set.
if ($access['permitAllUsers']) {
if ($access['permitAllUsers'] && $this->configService->getAllowPermitAll()) {
return true;
}
@ -356,7 +362,9 @@ class FormsService {
}
// Shown if permitall and showntoall are both set.
if ($access['permitAllUsers'] && $access['showToAllUsers']) {
if ($access['permitAllUsers'] &&
$access['showToAllUsers'] &&
$this->configService->getAllowPermitAll()) {
return true;
}

Просмотреть файл

@ -21,24 +21,40 @@
-->
<template>
<SettingsSection :title="t('forms', 'Form creation')">
<CheckboxRadioSwitch ref="switchRestrictCreation"
:checked.sync="appConfig.restrictCreation"
class="forms-settings__creation__switch"
type="switch"
@update:checked="onRestrictCreationChange">
{{ t('forms', 'Restrict form creation to selected groups') }}
</CheckboxRadioSwitch>
<Multiselect v-model="appConfig.creationAllowedGroups"
:disabled="!appConfig.restrictCreation"
:multiple="true"
:options="availableGroups"
:placeholder="t('forms', 'Select groups')"
class="forms-settings__creation__multiselect"
label="displayName"
track-by="groupId"
@update:value="onCreationAllowedGroupsChange" />
</SettingsSection>
<div>
<SettingsSection :title="t('forms', 'Form creation')">
<CheckboxRadioSwitch ref="switchRestrictCreation"
:checked.sync="appConfig.restrictCreation"
class="forms-settings__creation__switch"
type="switch"
@update:checked="onRestrictCreationChange">
{{ t('forms', 'Restrict form creation to selected groups') }}
</CheckboxRadioSwitch>
<Multiselect v-model="appConfig.creationAllowedGroups"
:disabled="!appConfig.restrictCreation"
:multiple="true"
:options="availableGroups"
:placeholder="t('forms', 'Select groups')"
class="forms-settings__creation__multiselect"
label="displayName"
track-by="groupId"
@update:value="onCreationAllowedGroupsChange" />
</SettingsSection>
<SettingsSection :title="t('forms', 'Form sharing')">
<CheckboxRadioSwitch ref="switchAllowPublicLink"
:checked.sync="appConfig.allowPublicLink"
type="switch"
@update:checked="onAllowPublicLinkChange">
{{ t('forms', 'Allow sharing by link') }}
</CheckboxRadioSwitch>
<CheckboxRadioSwitch ref="switchAllowPermitAll"
:checked.sync="appConfig.allowPermitAll"
type="switch"
@update:checked="onAllowPermitAllChange">
{{ t('forms', 'Allow sharing to all logged in accounts') }}
</CheckboxRadioSwitch>
</SettingsSection>
</div>
</template>
<script>
@ -88,6 +104,18 @@ export default {
await this.saveAppConfig('creationAllowedGroups', newVal.map(group => group.groupId))
el.loading = false
},
async onAllowPublicLinkChange(newVal) {
const el = this.$refs.switchAllowPublicLink
el.loading = true
await this.saveAppConfig('allowPublicLink', newVal)
el.loading = false
},
async onAllowPermitAllChange(newVal) {
const el = this.$refs.switchAllowPermitAll
el.loading = true
await this.saveAppConfig('allowPermitAll', newVal)
el.loading = false
},
/**
* Save a key-value pair to the appConfig.

Просмотреть файл

@ -42,12 +42,12 @@
</div>
<!-- Public Link -->
<div v-if="!hasPublicLink" class="share-div share-div--link">
<div v-if="!hasPublicLink && appConfig.allowPublicLink" class="share-div share-div--link">
<div class="share-div__avatar icon-public-white" />
<span class="share-div__desc">{{ t('forms', 'Public share link') }}</span>
<span class="share-div__desc">{{ t('forms', 'Share link') }}</span>
<Actions>
<ActionButton icon="icon-add" @click="addPublicLink">
{{ t('forms', 'Add public link') }}
{{ t('forms', 'Add link') }}
</ActionButton>
</Actions>
</div>
@ -56,7 +56,7 @@
:key="'share-' + share.shareType + '-' + share.shareWith"
class="share-div share-div--link">
<div class="share-div__avatar icon-public-white" />
<span class="share-div__desc">{{ t('forms', 'Public Share Link') }}</span>
<span class="share-div__desc">{{ t('forms', 'Share link') }}</span>
<Actions>
<ActionButton icon="icon-clippy" @click="copyPublicShareLink($event, share.shareWith)">
{{ t('forms', 'Copy to clipboard') }}
@ -66,8 +66,11 @@
<ActionButton icon="icon-delete" @click="removeShare(share)">
{{ t('forms', 'Remove link') }}
</ActionButton>
<ActionButton :close-after-click="true" icon="icon-add" @click="addPublicLink">
{{ t('forms', 'Add public link') }}
<ActionButton v-if="appConfig.allowPublicLink"
:close-after-click="true"
icon="icon-add"
@click="addPublicLink">
{{ t('forms', 'Add link') }}
</ActionButton>
</Actions>
</div>
@ -90,25 +93,27 @@
</div>
<!-- All users on Instance -->
<div class="share-div">
<div class="share-div__avatar icon-group" />
<label for="share-switch__permit-all" class="share-div__desc">
{{ t('forms', 'Permit access to all logged in users') }}
</label>
<CheckboxRadioSwitch id="share-switch__permit-all"
:checked="form.access.permitAllUsers"
type="switch"
@update:checked="onPermitAllUsersChange" />
</div>
<div v-if="form.access.permitAllUsers" class="share-div share-div--indent">
<div class="share-div__avatar icon-forms" />
<label for="share-switch__show-to-all" class="share-div__desc">
{{ t('forms', 'Show to all users on sidebar') }}
</label>
<CheckboxRadioSwitch id="share-switch__show-to-all"
:checked="form.access.showToAllUsers"
type="switch"
@update:checked="onShowToAllUsersChange" />
<div v-if="appConfig.allowPermitAll">
<div class="share-div">
<div class="share-div__avatar icon-group" />
<label for="share-switch__permit-all" class="share-div__desc">
{{ t('forms', 'Permit access to all logged in users') }}
</label>
<CheckboxRadioSwitch id="share-switch__permit-all"
:checked="form.access.permitAllUsers"
type="switch"
@update:checked="onPermitAllUsersChange" />
</div>
<div v-if="form.access.permitAllUsers" class="share-div share-div--indent">
<div class="share-div__avatar icon-forms" />
<label for="share-switch__show-to-all" class="share-div__desc">
{{ t('forms', 'Show to all users on sidebar') }}
</label>
<CheckboxRadioSwitch id="share-switch__show-to-all"
:checked="form.access.showToAllUsers"
type="switch"
@update:checked="onShowToAllUsersChange" />
</div>
</div>
<!-- Single shares -->
@ -123,6 +128,7 @@
<script>
import { generateOcsUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
import Actions from '@nextcloud/vue/dist/Components/Actions'
@ -155,6 +161,7 @@ export default {
data() {
return {
isLoading: false,
appConfig: loadState(appName, 'appConfig'),
}
},