2024-07-16 06:39:29 -04:00
< ? php
declare ( strict_types = 1 );
/**
2024-10-15 14:35:30 -04:00
* SPDX - FileCopyrightText : 2024 Nextcloud GmbH and Nextcloud contributors
2024-07-16 06:39:29 -04:00
* SPDX - License - Identifier : AGPL - 3.0 - or - later
*/
2024-10-15 14:35:30 -04:00
namespace OCA\Files\Settings ;
2024-07-16 06:39:29 -04:00
2024-10-15 14:35:30 -04:00
use OCA\Files\Service\SettingsService ;
2024-07-16 06:39:29 -04:00
use OCP\IL10N ;
2024-10-15 14:35:30 -04:00
use OCP\IUser ;
2024-07-16 06:39:29 -04:00
use OCP\Settings\DeclarativeSettingsTypes ;
2024-10-15 14:35:30 -04:00
use OCP\Settings\IDeclarativeSettingsFormWithHandlers ;
2024-07-16 06:39:29 -04:00
2024-10-15 14:35:30 -04:00
class DeclarativeAdminSettings implements IDeclarativeSettingsFormWithHandlers {
2024-07-16 06:39:29 -04:00
public function __construct (
private IL10N $l ,
2024-10-15 14:35:30 -04:00
private SettingsService $service ,
2024-07-16 06:39:29 -04:00
) {
}
2024-10-15 14:35:30 -04:00
public function getValue ( string $fieldId , IUser $user ) : mixed {
return match ( $fieldId ) {
'windows_support' => $this -> service -> hasFilesWindowsSupport (),
default => throw new \InvalidArgumentException ( 'Unexpected field id ' . $fieldId ),
};
}
public function setValue ( string $fieldId , mixed $value , IUser $user ) : void {
switch ( $fieldId ) {
case 'windows_support' :
$this -> service -> setFilesWindowsSupport (( bool ) $value );
break ;
2024-07-16 06:39:29 -04:00
}
2024-10-15 14:35:30 -04:00
}
2024-07-16 06:39:29 -04:00
2024-10-15 14:35:30 -04:00
public function getSchema () : array {
return [
2024-07-16 06:39:29 -04:00
'id' => 'files-filename-support' ,
'priority' => 10 ,
'section_type' => DeclarativeSettingsTypes :: SECTION_TYPE_ADMIN ,
'section_id' => 'server' ,
'storage_type' => DeclarativeSettingsTypes :: STORAGE_TYPE_EXTERNAL ,
'title' => $this -> l -> t ( 'Files compatibility' ),
'description' => $this -> l -> t ( 'Allow to restrict filenames to ensure files can be synced with all clients. By default all filenames valid on POSIX (e.g. Linux or macOS) are allowed.' ),
'fields' => [
[
'id' => 'windows_support' ,
'title' => $this -> l -> t ( 'Enforce Windows compatibility' ),
'description' => $this -> l -> t ( 'This will block filenames not valid on Windows systems, like using reserved names or special characters. But this will not enforce compatibility of case sensitivity.' ),
'type' => DeclarativeSettingsTypes :: CHECKBOX ,
'default' => false ,
],
],
2024-10-15 14:35:30 -04:00
];
2024-07-16 06:39:29 -04:00
}
}