Skip to content

Commit d94246e

Browse files
committed
fix(settings): save the guest allowlist again and add a default quota selector
- the allowlist NcSelect used @input, which @nextcloud/vue 9 no longer emits, so editing the allowed apps was never saved - rework the allowlist into a read-only chip list with an edit (pencil) button and a confirm (check) button that applies and saves; editing uses a draft, so closing the dropdown no longer saves - add a "Default quota for new guest accounts" selector (the preset-derived default shown with its value, Unlimited, common sizes, or a custom size with a required unit) - add Config getters/setters and SettingsController plumbing for guest_quota, reading the preset default via IAppConfig::getDetails() - cover the new quota config methods with unit tests - document the default quota and its Quick presets source in the README - fix three README links that still pointed to the removed `master` branch (now `main`) Signed-off-by: ernolf <raphael.gradenwitz@googlemail.com>
1 parent 9315c89 commit d94246e

5 files changed

Lines changed: 339 additions & 17 deletions

File tree

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The app is published in the [app store](https://apps.nextcloud.com/apps/guests).
2323

2424
## Development
2525

26-
Development is ongoing. A [CHANGELOG](https://github.com/nextcloud/guests/blob/master/CHANGELOG.md) covers the highlights. [New releases are also published](https://github.com/nextcloud-releases/guests/releases) on GitHub.
26+
Development is ongoing. A [CHANGELOG](https://github.com/nextcloud/guests/blob/main/CHANGELOG.md) covers the highlights. [New releases are also published](https://github.com/nextcloud-releases/guests/releases) on GitHub.
2727

2828
## Usage
2929

@@ -43,12 +43,12 @@ Optionally, when creating a guest the following values may also be specified:
4343

4444
Admins/Group admins also may:
4545

46-
* specify the group(s) to put the guest user in (see [Guest specific behavior and configuration](https://github.com/nextcloud/guests/blob/master/README.md#guest-specific-behavior-and-configuration) for details).
46+
* specify the group(s) to put the guest user in (see [Guest specific behavior and configuration](https://github.com/nextcloud/guests/blob/main/README.md#guest-specific-behavior-and-configuration) for details).
4747

4848
![image](https://github.com/nextcloud/guests/assets/1731941/68edbd4f-fedc-45f0-8241-2e1cd12d04de)
4949

5050
> [!WARNING]
51-
> While it is easy to create a new Guest, it's important to understand the default behavior and how guests interact with other features in Nextcloud. See [Guest specific behavior and configuration](https://github.com/nextcloud/guests/blob/master/README.md#guest-specific-behavior-and-configuration) for details.
51+
> While it is easy to create a new Guest, it's important to understand the default behavior and how guests interact with other features in Nextcloud. See [Guest specific behavior and configuration](https://github.com/nextcloud/guests/blob/main/README.md#guest-specific-behavior-and-configuration) for details.
5252
5353
### Deleting a guest
5454

@@ -150,6 +150,24 @@ to list users within that group (and, for example, share files with those users)
150150

151151
As a result, guests will be able to see each other as they are part of the same `guest` group. To prevent that behavior, you can add the `guest` group to the "Exclude groups from sharing" settings. You can find more information in [our documentation about sharing](https://docs.nextcloud.com/server/21/admin_manual/configuration_files/file_sharing_configuration.html).
152152

153+
### Default quota for new guests
154+
155+
New guest accounts are created with a default storage quota. This default comes from the **Quick presets** configuration (*Administration → Quick presets*), where it is listed as *"set default disk quota assigned to guest account at its creation"* (`guest_quota`). Its value depends on the selected preset: the **Default** preset uses `0 B`, while organization or family presets use a non-zero quota such as `1 GB` or `10 GB`. As a result, on many instances guests no longer receive `0 B` automatically.
156+
157+
Administrators can review and override this default under **Administration settings → Guests → "Default quota for new guest accounts"**: pick a preset (the *Default* entry shows the current preset value), *Unlimited*, or enter a custom size such as `500 MB`.
158+
159+
It can also be set on the command line:
160+
161+
```
162+
occ config:app:set guests guest_quota --value "500 MB"
163+
```
164+
165+
Remove the override to fall back to the Quick presets default again:
166+
167+
```
168+
occ config:app:delete guests guest_quota
169+
```
170+
153171
### Converting guest users to full users
154172

155173
Guest users can be automatically converted into full users (provided by any other user back end like SAML, LDAP, OAuth, database...) on their **first** login. When this happens they will retain their shares.

lib/Config.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OCA\Guests;
1111

12+
use OCA\Guests\AppInfo\Application;
1213
use OCP\AppFramework\Services\IAppConfig;
1314
use OCP\Group\ISubAdmin;
1415
use OCP\IAppConfig as IGlobalAppConfig;
@@ -51,6 +52,47 @@ public function setHideOtherUsers(bool $hide): void {
5152
$this->appConfig->setAppValueBool(ConfigLexicon::HIDE_OTHER_ACCOUNTS, $hide);
5253
}
5354

55+
/**
56+
* Currently configured default quota for new guest accounts. Returns the
57+
* explicit override if one is set, otherwise the preset-derived default.
58+
*/
59+
public function getGuestQuota(): string {
60+
return $this->appConfig->getAppValueString(ConfigLexicon::GUEST_DISK_QUOTA);
61+
}
62+
63+
/**
64+
* Whether an explicit default quota is stored, as opposed to falling back
65+
* to the preset-derived default from the config lexicon.
66+
*/
67+
public function hasGuestQuotaOverride(): bool {
68+
return $this->globalAppConfig->hasKey(Application::APP_ID, ConfigLexicon::GUEST_DISK_QUOTA);
69+
}
70+
71+
/**
72+
* The preset-derived default quota, regardless of any override. This is the
73+
* value the instance's configuration preset assigns to guests.
74+
*/
75+
public function getGuestQuotaDefault(): string {
76+
// getDetails() only works once a value is stored; when no override is
77+
// set, the app config already returns the preset-derived lexicon default.
78+
if (!$this->hasGuestQuotaOverride()) {
79+
return $this->appConfig->getAppValueString(ConfigLexicon::GUEST_DISK_QUOTA);
80+
}
81+
return (string)($this->globalAppConfig->getDetails(Application::APP_ID, ConfigLexicon::GUEST_DISK_QUOTA)['default'] ?? '0 B');
82+
}
83+
84+
/**
85+
* Store the default guest quota. An empty value or 'default' removes the
86+
* override so the preset-derived default applies again.
87+
*/
88+
public function setGuestQuota(?string $quota): void {
89+
if ($quota === null || $quota === '' || $quota === 'default') {
90+
$this->appConfig->deleteAppValue(ConfigLexicon::GUEST_DISK_QUOTA);
91+
return;
92+
}
93+
$this->appConfig->setAppValueString(ConfigLexicon::GUEST_DISK_QUOTA, $quota);
94+
}
95+
5496
public function getHome(string $uid): string {
5597
return $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid;
5698
}

lib/Controller/SettingsController.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\AppFramework\Http\DataResponse;
1919
use OCP\AppFramework\Services\IAppConfig;
2020
use OCP\IRequest;
21+
use OCP\Util;
2122

2223
/**
2324
* Class SettingsController is used to handle configuration changes on the
@@ -55,13 +56,15 @@ public function getConfig(): DataResponse {
5556
'whiteListableApps' => $this->appWhitelist->getWhitelistAbleApps(),
5657
'sharingRestrictedToGroup' => $this->config->isSharingRestrictedToGroup(),
5758
'createRestrictedToGroup' => $this->config->getCreateRestrictedToGroup(),
59+
'guestQuota' => $this->config->hasGuestQuotaOverride() ? $this->config->getGuestQuota() : 'default',
60+
'guestQuotaDefault' => $this->config->getGuestQuotaDefault(),
5861
]);
5962
}
6063

6164
/**
6265
* @param list<string> $whitelist
6366
*/
64-
public function setConfig(bool $useWhitelist, array $whitelist, bool $allowExternalStorage, bool $useHashedEmailAsUserID, bool $hideUsers, array $createRestrictedToGroup): DataResponse {
67+
public function setConfig(bool $useWhitelist, array $whitelist, bool $allowExternalStorage, bool $useHashedEmailAsUserID, bool $hideUsers, array $createRestrictedToGroup, string $guestQuota = 'default'): DataResponse {
6568
$newWhitelist = [];
6669
foreach ($whitelist as $app) {
6770
$newWhitelist[] = trim((string)$app);
@@ -73,10 +76,26 @@ public function setConfig(bool $useWhitelist, array $whitelist, bool $allowExter
7376
$this->config->setUseHashedEmailAsUserID($useHashedEmailAsUserID);
7477
$this->config->setHideOtherUsers($hideUsers);
7578
$this->config->setCreateRestrictedToGroup($createRestrictedToGroup);
79+
if ($this->isValidQuota($guestQuota)) {
80+
$this->config->setGuestQuota($guestQuota);
81+
}
7682

7783
return new DataResponse();
7884
}
7985

86+
/**
87+
* A quota value is acceptable if it is the "default" sentinel, "none"
88+
* (unlimited) or a human-readable size such as "500 MB".
89+
*/
90+
private function isValidQuota(string $quota): bool {
91+
if ($quota === 'default' || $quota === 'none') {
92+
return true;
93+
}
94+
// Require an explicit unit so the stored value is unambiguous (e.g. "500 MB").
95+
return preg_match('/^\d+(\.\d+)?\s*[KMGTP]?B$/i', trim($quota)) === 1
96+
&& Util::computerFileSize($quota) !== false;
97+
}
98+
8099
/**
81100
* AJAX handler for getting the whitelisted apps
82101
* We do not set the whitelist to null when it is unused. This is by design.

0 commit comments

Comments
 (0)