fix(settings): Do not use `null` on `string` parameter for sharing disclaimer

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/48864/head
Ferdinand Thiessen 2024-10-23 20:12:32 +07:00
parent c00d49bb55
commit 6d2c63ecff
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
4 changed files with 112 additions and 111 deletions

@ -62,7 +62,7 @@ class Sharing implements IDelegatedSettings {
'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'), 'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'),
'excludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no'), 'excludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no'),
'excludeGroupsList' => json_decode($excludedGroups, true) ?? [], 'excludeGroupsList' => json_decode($excludedGroups, true) ?? [],
'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext'),
'enableLinkPasswordByDefault' => $this->getHumanBooleanConfig('core', 'shareapi_enable_link_password_by_default'), 'enableLinkPasswordByDefault' => $this->getHumanBooleanConfig('core', 'shareapi_enable_link_password_by_default'),
'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL), 'defaultPermissions' => (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL),
'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'), 'defaultInternalExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_internal_expire_date'),

@ -170,7 +170,7 @@
<NcCheckboxRadioSwitch type="switch" :checked.sync="publicShareDisclaimerEnabled"> <NcCheckboxRadioSwitch type="switch" :checked.sync="publicShareDisclaimerEnabled">
{{ t('settings', 'Show disclaimer text on the public link upload page (only shown when the file list is hidden)') }} {{ t('settings', 'Show disclaimer text on the public link upload page (only shown when the file list is hidden)') }}
</NcCheckboxRadioSwitch> </NcCheckboxRadioSwitch>
<div v-if="typeof settings.publicShareDisclaimerText === 'string'" <div v-if="publicShareDisclaimerEnabled"
aria-describedby="settings-sharing-privary-related-disclaimer-hint" aria-describedby="settings-sharing-privary-related-disclaimer-hint"
class="sharing__sub-section"> class="sharing__sub-section">
<NcTextArea class="sharing__input" <NcTextArea class="sharing__input"
@ -231,7 +231,7 @@ interface IShareSettings {
enforceExpireDate: boolean enforceExpireDate: boolean
excludeGroups: string excludeGroups: string
excludeGroupsList: string[] excludeGroupsList: string[]
publicShareDisclaimerText?: string publicShareDisclaimerText: string
enableLinkPasswordByDefault: boolean enableLinkPasswordByDefault: boolean
defaultPermissions: number defaultPermissions: number
defaultInternalExpireDate: boolean defaultInternalExpireDate: boolean
@ -252,8 +252,10 @@ export default defineComponent({
SelectSharingPermissions, SelectSharingPermissions,
}, },
data() { data() {
const settingsData = loadState<IShareSettings>('settings', 'sharingSettings')
return { return {
settingsData: loadState<IShareSettings>('settings', 'sharingSettings'), settingsData,
publicShareDisclaimerEnabled: settingsData.publicShareDisclaimerText !== '',
} }
}, },
computed: { computed: {
@ -272,26 +274,24 @@ export default defineComponent({
}, },
}) })
}, },
publicShareDisclaimerEnabled: { },
get() {
return typeof this.settingsData.publicShareDisclaimerText === 'string' watch: {
}, publicShareDisclaimerEnabled() {
set(value) { // When disabled we just remove the disclaimer content
if (value) { if (this.publicShareDisclaimerEnabled === false) {
this.settingsData.publicShareDisclaimerText = '' this.onUpdateDisclaimer('')
} else { }
this.onUpdateDisclaimer()
}
},
}, },
}, },
methods: { methods: {
t, t,
onUpdateDisclaimer: debounce(function(value?: string) { onUpdateDisclaimer: debounce(function(value: string) {
const options = { const options = {
success() { success() {
if (value) { if (value !== '') {
showSuccess(t('settings', 'Changed disclaimer text')) showSuccess(t('settings', 'Changed disclaimer text'))
} else { } else {
showSuccess(t('settings', 'Deleted disclaimer text')) showSuccess(t('settings', 'Deleted disclaimer text'))
@ -301,7 +301,7 @@ export default defineComponent({
showError(t('settings', 'Could not set disclaimer text')) showError(t('settings', 'Could not set disclaimer text'))
}, },
} }
if (!value) { if (value === '') {
window.OCP.AppConfig.deleteKey('core', 'shareapi_public_link_disclaimertext', options) window.OCP.AppConfig.deleteKey('core', 'shareapi_public_link_disclaimertext', options)
} else { } else {
window.OCP.AppConfig.setValue('core', 'shareapi_public_link_disclaimertext', value, options) window.OCP.AppConfig.setValue('core', 'shareapi_public_link_disclaimertext', value, options)

@ -20,9 +20,9 @@ use Test\TestCase;
class SharingTest extends TestCase { class SharingTest extends TestCase {
/** @var Sharing */ /** @var Sharing */
private $admin; private $admin;
/** @var IConfig */ /** @var IConfig&MockObject */
private $config; private $config;
/** @var IL10N|MockObject */ /** @var IL10N&MockObject */
private $l10n; private $l10n;
/** @var IManager|MockObject */ /** @var IManager|MockObject */
private $shareManager; private $shareManager;
@ -35,9 +35,7 @@ class SharingTest extends TestCase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
/** @var IConfig|MockObject */
$this->config = $this->getMockBuilder(IConfig::class)->getMock(); $this->config = $this->getMockBuilder(IConfig::class)->getMock();
/** @var IL10N|MockObject */
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock(); $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
/** @var IManager|MockObject */ /** @var IManager|MockObject */
@ -82,7 +80,7 @@ class SharingTest extends TestCase {
['core', 'shareapi_expire_after_n_days', '7', '7'], ['core', 'shareapi_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_expire_date', 'no', 'no'], ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
['core', 'shareapi_exclude_groups', 'no', 'no'], ['core', 'shareapi_exclude_groups', 'no', 'no'],
['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'], ['core', 'shareapi_public_link_disclaimertext', '', 'Lorem ipsum'],
['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'], ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL], ['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
['core', 'shareapi_default_internal_expire_date', 'no', 'no'], ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
@ -98,50 +96,53 @@ class SharingTest extends TestCase {
->willReturn(false); ->willReturn(false);
$this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false); $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(false);
$initialStateCalls = [];
$this->initialState $this->initialState
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('provideInitialState') ->method('provideInitialState')
->withConsecutive( ->willReturnCallback(function (string $key) use (&$initialStateCalls) {
['sharingAppEnabled', false], $initialStateCalls[$key] = func_get_args();
['sharingDocumentation', ''], });
[
'sharingSettings', $expectedInitialStateCalls = [
[ 'sharingAppEnabled' => false,
'allowGroupSharing' => true, 'sharingDocumentation' => '',
'allowLinks' => true, 'sharingSettings' => [
'allowPublicUpload' => true, 'allowGroupSharing' => true,
'allowResharing' => true, 'allowLinks' => true,
'allowShareDialogUserEnumeration' => true, 'allowPublicUpload' => true,
'restrictUserEnumerationToGroup' => false, 'allowResharing' => true,
'restrictUserEnumerationToPhone' => false, 'allowShareDialogUserEnumeration' => true,
'restrictUserEnumerationFullMatch' => true, 'restrictUserEnumerationToGroup' => false,
'restrictUserEnumerationFullMatchUserId' => true, 'restrictUserEnumerationToPhone' => false,
'restrictUserEnumerationFullMatchEmail' => true, 'restrictUserEnumerationFullMatch' => true,
'restrictUserEnumerationFullMatchIgnoreSecondDN' => false, 'restrictUserEnumerationFullMatchUserId' => true,
'enforceLinksPassword' => false, 'restrictUserEnumerationFullMatchEmail' => true,
'onlyShareWithGroupMembers' => false, 'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
'enabled' => true, 'enforceLinksPassword' => false,
'defaultExpireDate' => false, 'onlyShareWithGroupMembers' => false,
'expireAfterNDays' => '7', 'enabled' => true,
'enforceExpireDate' => false, 'defaultExpireDate' => false,
'excludeGroups' => 'no', 'expireAfterNDays' => '7',
'excludeGroupsList' => [], 'enforceExpireDate' => false,
'publicShareDisclaimerText' => 'Lorem ipsum', 'excludeGroups' => 'no',
'enableLinkPasswordByDefault' => true, 'excludeGroupsList' => [],
'defaultPermissions' => Constants::PERMISSION_ALL, 'publicShareDisclaimerText' => 'Lorem ipsum',
'defaultInternalExpireDate' => false, 'enableLinkPasswordByDefault' => true,
'internalExpireAfterNDays' => '7', 'defaultPermissions' => Constants::PERMISSION_ALL,
'enforceInternalExpireDate' => false, 'defaultInternalExpireDate' => false,
'defaultRemoteExpireDate' => false, 'internalExpireAfterNDays' => '7',
'remoteExpireAfterNDays' => '7', 'enforceInternalExpireDate' => false,
'enforceRemoteExpireDate' => false, 'defaultRemoteExpireDate' => false,
'allowLinksExcludeGroups' => [], 'remoteExpireAfterNDays' => '7',
'onlyShareWithGroupMembersExcludeGroupList' => [], 'enforceRemoteExpireDate' => false,
'enforceLinksPasswordExcludedGroups' => [], 'allowLinksExcludeGroups' => [],
'enforceLinksPasswordExcludedGroupsEnabled' => false, 'onlyShareWithGroupMembersExcludeGroupList' => [],
] 'enforceLinksPasswordExcludedGroups' => [],
], 'enforceLinksPasswordExcludedGroupsEnabled' => false,
); ]
];
$expected = new TemplateResponse( $expected = new TemplateResponse(
'settings', 'settings',
@ -151,6 +152,7 @@ class SharingTest extends TestCase {
); );
$this->assertEquals($expected, $this->admin->getForm()); $this->assertEquals($expected, $this->admin->getForm());
$this->assertEquals(sort($expectedInitialStateCalls), sort($initialStateCalls), 'Provided initial state does not match');
} }
public function testGetFormWithExcludedGroups(): void { public function testGetFormWithExcludedGroups(): void {
@ -175,7 +177,7 @@ class SharingTest extends TestCase {
['core', 'shareapi_expire_after_n_days', '7', '7'], ['core', 'shareapi_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_expire_date', 'no', 'no'], ['core', 'shareapi_enforce_expire_date', 'no', 'no'],
['core', 'shareapi_exclude_groups', 'no', 'yes'], ['core', 'shareapi_exclude_groups', 'no', 'yes'],
['core', 'shareapi_public_link_disclaimertext', null, 'Lorem ipsum'], ['core', 'shareapi_public_link_disclaimertext', '', 'Lorem ipsum'],
['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'], ['core', 'shareapi_enable_link_password_by_default', 'no', 'yes'],
['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL], ['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],
['core', 'shareapi_default_internal_expire_date', 'no', 'no'], ['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
@ -191,50 +193,53 @@ class SharingTest extends TestCase {
->willReturn(false); ->willReturn(false);
$this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true); $this->appManager->method('isEnabledForUser')->with('files_sharing')->willReturn(true);
$initialStateCalls = [];
$this->initialState $this->initialState
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('provideInitialState') ->method('provideInitialState')
->withConsecutive( ->willReturnCallback(function (string $key) use (&$initialStateCalls) {
['sharingAppEnabled', true], $initialStateCalls[$key] = func_get_args();
['sharingDocumentation', ''], });
[
'sharingSettings', $expectedInitialStateCalls = [
[ 'sharingAppEnabled' => true,
'allowGroupSharing' => true, 'sharingDocumentation' => '',
'allowLinks' => true, 'sharingSettings' => [
'allowPublicUpload' => true, 'allowGroupSharing' => true,
'allowResharing' => true, 'allowLinks' => true,
'allowShareDialogUserEnumeration' => true, 'allowPublicUpload' => true,
'restrictUserEnumerationToGroup' => false, 'allowResharing' => true,
'restrictUserEnumerationToPhone' => false, 'allowShareDialogUserEnumeration' => true,
'restrictUserEnumerationFullMatch' => true, 'restrictUserEnumerationToGroup' => false,
'restrictUserEnumerationFullMatchUserId' => true, 'restrictUserEnumerationToPhone' => false,
'restrictUserEnumerationFullMatchEmail' => true, 'restrictUserEnumerationFullMatch' => true,
'restrictUserEnumerationFullMatchIgnoreSecondDN' => false, 'restrictUserEnumerationFullMatchUserId' => true,
'enforceLinksPassword' => false, 'restrictUserEnumerationFullMatchEmail' => true,
'onlyShareWithGroupMembers' => false, 'restrictUserEnumerationFullMatchIgnoreSecondDN' => false,
'enabled' => true, 'enforceLinksPassword' => false,
'defaultExpireDate' => false, 'onlyShareWithGroupMembers' => false,
'expireAfterNDays' => '7', 'enabled' => true,
'enforceExpireDate' => false, 'defaultExpireDate' => false,
'excludeGroups' => 'yes', 'expireAfterNDays' => '7',
'excludeGroupsList' => ['NoSharers','OtherNoSharers'], 'enforceExpireDate' => false,
'publicShareDisclaimerText' => 'Lorem ipsum', 'excludeGroups' => 'yes',
'enableLinkPasswordByDefault' => true, 'excludeGroupsList' => ['NoSharers','OtherNoSharers'],
'defaultPermissions' => Constants::PERMISSION_ALL, 'publicShareDisclaimerText' => 'Lorem ipsum',
'defaultInternalExpireDate' => false, 'enableLinkPasswordByDefault' => true,
'internalExpireAfterNDays' => '7', 'defaultPermissions' => Constants::PERMISSION_ALL,
'enforceInternalExpireDate' => false, 'defaultInternalExpireDate' => false,
'defaultRemoteExpireDate' => false, 'internalExpireAfterNDays' => '7',
'remoteExpireAfterNDays' => '7', 'enforceInternalExpireDate' => false,
'enforceRemoteExpireDate' => false, 'defaultRemoteExpireDate' => false,
'allowLinksExcludeGroups' => [], 'remoteExpireAfterNDays' => '7',
'onlyShareWithGroupMembersExcludeGroupList' => [], 'enforceRemoteExpireDate' => false,
'enforceLinksPasswordExcludedGroups' => [], 'allowLinksExcludeGroups' => [],
'enforceLinksPasswordExcludedGroupsEnabled' => false, 'onlyShareWithGroupMembersExcludeGroupList' => [],
] 'enforceLinksPasswordExcludedGroups' => [],
], 'enforceLinksPasswordExcludedGroupsEnabled' => false,
); ],
];
$expected = new TemplateResponse( $expected = new TemplateResponse(
'settings', 'settings',
@ -244,6 +249,7 @@ class SharingTest extends TestCase {
); );
$this->assertEquals($expected, $this->admin->getForm()); $this->assertEquals($expected, $this->admin->getForm());
$this->assertEquals(sort($expectedInitialStateCalls), sort($initialStateCalls), 'Provided initial state does not match');
} }
public function testGetSection(): void { public function testGetSection(): void {

@ -1041,11 +1041,6 @@
<code><![CDATA[isReady]]></code> <code><![CDATA[isReady]]></code>
</UndefinedInterfaceMethod> </UndefinedInterfaceMethod>
</file> </file>
<file src="apps/settings/lib/Settings/Admin/Sharing.php">
<NullArgument>
<code><![CDATA[null]]></code>
</NullArgument>
</file>
<file src="apps/sharebymail/lib/ShareByMailProvider.php"> <file src="apps/sharebymail/lib/ShareByMailProvider.php">
<InvalidArgument> <InvalidArgument>
<code><![CDATA[$share->getId()]]></code> <code><![CDATA[$share->getId()]]></code>