Skip to content

Commit 0740c93

Browse files
alexander-rebelloChartman123
authored andcommitted
Update ConfigService and add/update related tests
Signed-off-by: Alexander Rebello <me@alexander-rebello.de>
1 parent 5a54f52 commit 0740c93

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

lib/Constants.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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';
@@ -24,6 +25,7 @@ class Constants {
2425
public const CONFIG_KEYS = [
2526
self::CONFIG_KEY_ALLOWPERMITALL,
2627
self::CONFIG_KEY_ALLOWPUBLICLINK,
28+
self::CONFIG_KEY_ALLOWCUSTOMPUBLICTOKEN,
2729
self::CONFIG_KEY_ALLOWSHOWTOALL,
2830
self::CONFIG_KEY_CREATIONALLOWEDGROUPS,
2931
self::CONFIG_KEY_RESTRICTCREATION,
@@ -41,6 +43,10 @@ class Constants {
4143
self::CONFIG_KEY_CONFIRMATIONEMAILRATELIMIT => 'int',
4244
];
4345

46+
public const PUBLIC_SHARE_TOKEN_MIN_LENGTH = 8;
47+
public const PUBLIC_SHARE_TOKEN_MAX_LENGTH = 256;
48+
public const PUBLIC_SHARE_HASH_REQUIREMENT = '[a-zA-Z0-9]{' . self::PUBLIC_SHARE_TOKEN_MIN_LENGTH . ',' . self::PUBLIC_SHARE_TOKEN_MAX_LENGTH . '}';
49+
4450
/**
4551
* Maximum String lengths, the database is set to store.
4652
*/

lib/Service/ConfigService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public function getAllowPermitAll(): bool {
3838
public function getAllowPublicLink(): bool {
3939
return $this->appConfig->getAppValueBool(Constants::CONFIG_KEY_ALLOWPUBLICLINK, true);
4040
}
41-
public function getAllowShowToAll() : bool {
41+
public function getAllowCustomPublicToken(): bool {
42+
return json_decode($this->config->getAppValue($this->appName, Constants::CONFIG_KEY_ALLOWCUSTOMPUBLICTOKEN, 'false'));
43+
}
44+
public function getAllowShowToAll(): bool {
4245
return $this->appConfig->getAppValueBool(Constants::CONFIG_KEY_ALLOWSHOWTOALL, true);
4346
}
4447
private function getUnformattedCreationAllowedGroups(): array {
@@ -74,6 +77,7 @@ public function getAppConfig(): array {
7477
return [
7578
Constants::CONFIG_KEY_ALLOWPERMITALL => $this->getAllowPermitAll(),
7679
Constants::CONFIG_KEY_ALLOWPUBLICLINK => $this->getAllowPublicLink(),
80+
Constants::CONFIG_KEY_ALLOWCUSTOMPUBLICTOKEN => $this->getAllowCustomPublicToken(),
7781
Constants::CONFIG_KEY_ALLOWSHOWTOALL => $this->getAllowShowToAll(),
7882
Constants::CONFIG_KEY_CREATIONALLOWEDGROUPS => $this->getCreationAllowedGroups(),
7983
Constants::CONFIG_KEY_RESTRICTCREATION => $this->getRestrictCreation(),

tests/Unit/Controller/ConfigControllerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public static function dataUpdateAppConfig() {
6868
'configValue' => true,
6969
'strConfig' => 'true'
7070
],
71+
'booleanConfigAllowCustomPublicShareTokens' => [
72+
'configKey' => 'allowCustomPublicShareTokens',
73+
'configValue' => true,
74+
'strConfig' => 'true'
75+
],
7176
'arrayCreationAllowedGroups' => [
7277
'configKey' => 'creationAllowedGroups',
7378
'configValue' => [

tests/Unit/Service/ConfigServiceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public static function dataGetAppConfig() {
5757
'strConfig' => [
5858
'allowPermitAll' => 'false',
5959
'allowPublicLink' => 'false',
60+
'allowCustomPublicShareTokens' => 'true',
6061
'allowShowToAll' => 'false',
6162
'creationAllowedGroups' => '["group1", "group2", "nonExisting"]',
6263
'restrictCreation' => 'true',
@@ -71,6 +72,7 @@ public static function dataGetAppConfig() {
7172
'expected' => [
7273
'allowPermitAll' => false,
7374
'allowPublicLink' => false,
75+
'allowCustomPublicShareTokens' => true,
7476
'allowShowToAll' => false,
7577
'creationAllowedGroups' => [
7678
[
@@ -160,6 +162,7 @@ public static function dataGetAppConfig_Default() {
160162
'expected' => [
161163
'allowPermitAll' => true,
162164
'allowPublicLink' => true,
165+
'allowCustomPublicShareTokens' => false,
163166
'allowShowToAll' => true,
164167
'creationAllowedGroups' => [],
165168
'restrictCreation' => false,

0 commit comments

Comments
 (0)