Skip to content

Commit 557abb5

Browse files
Add admin flag for custom public tokens
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
1 parent 7c61071 commit 557abb5

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

lib/Constants.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ class Constants {
1515
*/
1616
public const CONFIG_KEY_ALLOWPERMITALL = 'allowPermitAll';
1717
public const CONFIG_KEY_ALLOWPUBLICLINK = 'allowPublicLink';
18+
public const CONFIG_KEY_ALLOWCUSTOMPUBLICTOKEN = 'allowCustomPublicShareTokens';
1819
public const CONFIG_KEY_ALLOWSHOWTOALL = 'allowShowToAll';
1920
public const CONFIG_KEY_CREATIONALLOWEDGROUPS = 'creationAllowedGroups';
2021
public const CONFIG_KEY_RESTRICTCREATION = 'restrictCreation';
2122
public const CONFIG_KEYS = [
2223
self::CONFIG_KEY_ALLOWPERMITALL,
2324
self::CONFIG_KEY_ALLOWPUBLICLINK,
25+
self::CONFIG_KEY_ALLOWCUSTOMPUBLICTOKEN,
2426
self::CONFIG_KEY_ALLOWSHOWTOALL,
2527
self::CONFIG_KEY_CREATIONALLOWEDGROUPS,
2628
self::CONFIG_KEY_RESTRICTCREATION
2729
];
2830

31+
public const PUBLIC_SHARE_TOKEN_MIN_LENGTH = 8;
32+
public const PUBLIC_SHARE_TOKEN_MAX_LENGTH = 256;
33+
2934
/**
3035
* Maximum String lengths, the database is set to store.
3136
*/

lib/Service/ConfigService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public function getAllowPermitAll(): bool {
3737
public function getAllowPublicLink(): bool {
3838
return json_decode($this->config->getAppValue($this->appName, Constants::CONFIG_KEY_ALLOWPUBLICLINK, 'true'));
3939
}
40-
public function getAllowShowToAll() : bool {
40+
public function getAllowCustomPublicToken(): bool {
41+
return json_decode($this->config->getAppValue($this->appName, Constants::CONFIG_KEY_ALLOWCUSTOMPUBLICTOKEN, 'false'));
42+
}
43+
public function getAllowShowToAll(): bool {
4144
return json_decode($this->config->getAppValue($this->appName, Constants::CONFIG_KEY_ALLOWSHOWTOALL, 'true'));
4245
}
4346
private function getUnformattedCreationAllowedGroups(): array {
@@ -57,6 +60,7 @@ public function getAppConfig(): array {
5760
return [
5861
Constants::CONFIG_KEY_ALLOWPERMITALL => $this->getAllowPermitAll(),
5962
Constants::CONFIG_KEY_ALLOWPUBLICLINK => $this->getAllowPublicLink(),
63+
Constants::CONFIG_KEY_ALLOWCUSTOMPUBLICTOKEN => $this->getAllowCustomPublicToken(),
6064
Constants::CONFIG_KEY_ALLOWSHOWTOALL => $this->getAllowShowToAll(),
6165
Constants::CONFIG_KEY_CREATIONALLOWEDGROUPS => $this->getCreationAllowedGroups(),
6266
Constants::CONFIG_KEY_RESTRICTCREATION => $this->getRestrictCreation(),

src/FormsSettings.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
@update:modelValue="onAllowPublicLinkChange">
3333
{{ t('forms', 'Allow sharing by link') }}
3434
</NcCheckboxRadioSwitch>
35+
<NcCheckboxRadioSwitch
36+
ref="switchAllowCustomPublicShareTokens"
37+
v-model="appConfig.allowCustomPublicShareTokens"
38+
type="switch"
39+
@update:modelValue="onAllowCustomPublicShareTokensChange">
40+
{{ t('forms', 'Allow custom public share tokens') }}
41+
</NcCheckboxRadioSwitch>
3542
<NcCheckboxRadioSwitch
3643
ref="switchAllowPermitAll"
3744
v-model="appConfig.allowPermitAll"
@@ -115,6 +122,13 @@ export default {
115122
el.loading = false
116123
},
117124
125+
async onAllowCustomPublicShareTokensChange(newVal) {
126+
const el = this.$refs.switchAllowCustomPublicShareTokens
127+
el.loading = true
128+
await this.saveAppConfig('allowCustomPublicShareTokens', newVal)
129+
el.loading = false
130+
},
131+
118132
async onAllowPermitAllChange(newVal) {
119133
const el = this.$refs.switchAllowPermitAll
120134
el.loading = true

tests/Unit/Controller/ConfigControllerTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,21 @@ public function testGetAppConfig() {
6969

7070
public static function dataUpdateAppConfig() {
7171
return [
72-
'booleanConfig' => [
72+
'booleanConfigAllowPermitAll' => [
7373
'configKey' => 'allowPermitAll',
7474
'configValue' => true,
7575
'strConfig' => 'true'
7676
],
77-
'booleanConfig' => [
77+
'booleanConfigAllowShowToAll' => [
7878
'configKey' => 'allowShowToAll',
7979
'configValue' => true,
8080
'strConfig' => 'true'
8181
],
82+
'booleanConfigAllowCustomPublicShareTokens' => [
83+
'configKey' => 'allowCustomPublicShareTokens',
84+
'configValue' => true,
85+
'strConfig' => 'true'
86+
],
8287
'arrayConfig' => [
8388
'configKey' => 'allowPermitAll',
8489
'configValue' => [

tests/Unit/Service/ConfigServiceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static function dataGetAppConfig() {
6262
'strConfig' => [
6363
'allowPermitAll' => 'false',
6464
'allowPublicLink' => 'false',
65+
'allowCustomPublicShareTokens' => 'true',
6566
'allowShowToAll' => 'false',
6667
'creationAllowedGroups' => '["group1", "group2", "nonExisting"]',
6768
'restrictCreation' => 'true',
@@ -73,6 +74,7 @@ public static function dataGetAppConfig() {
7374
'expected' => [
7475
'allowPermitAll' => false,
7576
'allowPublicLink' => false,
77+
'allowCustomPublicShareTokens' => true,
7678
'allowShowToAll' => false,
7779
'creationAllowedGroups' => [
7880
[
@@ -136,6 +138,7 @@ public static function dataGetAppConfig_Default() {
136138
'expected' => [
137139
'allowPermitAll' => true,
138140
'allowPublicLink' => true,
141+
'allowCustomPublicShareTokens' => false,
139142
'allowShowToAll' => true,
140143
'creationAllowedGroups' => [],
141144
'restrictCreation' => false,

0 commit comments

Comments
 (0)