Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 27 additions & 8 deletions apps/theming/lib/Controller/ThemingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ public function updateStylesheet($setting, $value) {
if (strlen($value) > 500) {
$error = $this->l10n->t('The given web address is too long');
}
if (!$this->isValidUrl($value)) {
if ($value !== '' && !$this->isValidUrl($value)) {
$error = $this->l10n->t('The given web address is not a valid URL');
}
break;
case 'legalNoticeUrl':
$setting = 'imprintUrl';
// no break
case 'imprintUrl':
if (strlen($value) > 500) {
$error = $this->l10n->t('The given legal notice address is too long');
Expand All @@ -93,6 +96,9 @@ public function updateStylesheet($setting, $value) {
$error = $this->l10n->t('The given legal notice address is not a valid URL');
}
break;
case 'privacyPolicyUrl':
$setting = 'privacyUrl';
// no break
case 'privacyUrl':
if (strlen($value) > 500) {
$error = $this->l10n->t('The given privacy policy address is too long');
Expand All @@ -106,30 +112,38 @@ public function updateStylesheet($setting, $value) {
$error = $this->l10n->t('The given slogan is too long');
}
break;
case 'primaryColor':
$setting = 'primary_color';
// no break
case 'primary_color':
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
$error = $this->l10n->t('The given color is invalid');
} else {
$this->appConfig->setAppValueString('primary_color', $value);
$saved = true;
}
break;
case 'backgroundColor':
$setting = 'background_color';
// no break
case 'background_color':
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
$error = $this->l10n->t('The given color is invalid');
} else {
$this->appConfig->setAppValueString('background_color', $value);
$saved = true;
}
break;
case 'disableUserTheming':
case 'disable-user-theming':
if (!in_array($value, ['yes', 'true', 'no', 'false'])) {
$error = $this->l10n->t('Disable-user-theming should be true or false');
$error = $this->l10n->t('%1$s should be true or false', ['disable-user-theming']);
} else {
$this->appConfig->setAppValueBool('disable-user-theming', $value === 'yes' || $value === 'true');
$saved = true;
}
break;
case 'backgroundMime':
if ($value !== 'backgroundColor') {
$error = $this->l10n->t('%1$s can only be set to %2$s through the API', ['backgroundMime', 'backgroundColor']);
}
break;
default:
$error = $this->l10n->t('Invalid setting key');
}
if ($error !== null) {
return new DataResponse([
Expand Down Expand Up @@ -291,6 +305,11 @@ public function uploadImage(): DataResponse {
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
public function undo(string $setting): DataResponse {
$setting = match ($setting) {
'primaryColor' => 'primary_color',
'backgroundColor' => 'background_color',
default => $setting,
};
$value = $this->themingDefaults->undo($setting);

return new DataResponse(
Expand Down
34 changes: 18 additions & 16 deletions apps/theming/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
class Admin implements IDelegatedSettings {

public function __construct(
private string $appName,
private IConfig $config,
private IL10N $l,
private ThemingDefaults $themingDefaults,
Expand All @@ -38,11 +37,11 @@ public function __construct(
* @return TemplateResponse
*/
public function getForm(): TemplateResponse {
$themable = true;
$themeable = true;
$errorMessage = '';
$theme = $this->config->getSystemValue('theme', '');
if ($theme !== '') {
$themable = false;
$themeable = false;
$errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
}

Expand All @@ -51,9 +50,17 @@ public function getForm(): TemplateResponse {
return $carry;
}, []);

$this->initialState->provideInitialState('adminThemingInfo', [
'isThemeable' => $themeable,
'notThemeableErrorMessage' => $errorMessage,
'defaultBackgroundURL' => $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE),
'defaultBackgroundColor' => BackgroundService::DEFAULT_BACKGROUND_COLOR,
'docUrl' => $this->urlGenerator->linkToDocs('admin-theming'),
'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
]);

$this->initialState->provideInitialState('adminThemingParameters', [
'isThemable' => $themable,
'notThemableErrorMessage' => $errorMessage,
'name' => $this->themingDefaults->getEntity(),
'url' => $this->themingDefaults->getBaseUrl(),
'slogan' => $this->themingDefaults->getSlogan(),
Expand All @@ -62,30 +69,25 @@ public function getForm(): TemplateResponse {
'logoMime' => $this->config->getAppValue(Application::APP_ID, 'logoMime', ''),
'allowedMimeTypes' => $allowedMimeTypes,
'backgroundURL' => $this->imageManager->getImageUrl('background'),
'defaultBackgroundURL' => $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE),
'defaultBackgroundColor' => BackgroundService::DEFAULT_BACKGROUND_COLOR,
'backgroundMime' => $this->config->getAppValue(Application::APP_ID, 'backgroundMime', ''),
'logoheaderMime' => $this->config->getAppValue(Application::APP_ID, 'logoheaderMime', ''),
'faviconMime' => $this->config->getAppValue(Application::APP_ID, 'faviconMime', ''),
'legalNoticeUrl' => $this->themingDefaults->getImprintUrl(),
'privacyPolicyUrl' => $this->themingDefaults->getPrivacyUrl(),
'docUrl' => $this->urlGenerator->linkToDocs('admin-theming'),
'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
'disableUserTheming' => $this->themingDefaults->isUserThemingDisabled(),
'defaultApps' => $this->navigationManager->getDefaultEntryIds(),
]);

Util::addScript($this->appName, 'admin-theming');

return new TemplateResponse($this->appName, 'settings-admin');
Util::addStyle(Application::APP_ID, 'settings-admin');
Util::addScript(Application::APP_ID, 'settings-admin');
return new TemplateResponse(Application::APP_ID, 'settings-admin');
}

/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection(): string {
return $this->appName;
return Application::APP_ID;
}

/**
Expand All @@ -105,7 +107,7 @@ public function getName(): ?string {

public function getAuthorizedAppConfig(): array {
return [
$this->appName => '/.*/',
Application::APP_ID => '/.*/',
];
}
}
10 changes: 5 additions & 5 deletions apps/theming/lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace OCA\Theming\Settings;

use OCA\Theming\AppInfo\Application;
use OCA\Theming\ITheme;
use OCA\Theming\Service\BackgroundService;
use OCA\Theming\Service\ThemesService;
Expand All @@ -20,7 +21,6 @@
class Personal implements ISettings {

public function __construct(
protected string $appName,
private string $userId,
private IConfig $config,
private ThemesService $themesService,
Expand Down Expand Up @@ -82,17 +82,17 @@ public function getForm(): TemplateResponse {
'enforcedDefaultApp' => $forcedDefaultEntry
]);

Util::addScript($this->appName, 'personal-theming');

return new TemplateResponse($this->appName, 'settings-personal');
Util::addStyle(Application::APP_ID, 'settings-personal');
Util::addScript(Application::APP_ID, 'settings-personal');
return new TemplateResponse(Application::APP_ID, 'settings-personal');
}

/**
* @return string the section ID, e.g. 'sharing'
* @since 9.1
*/
public function getSection(): string {
return $this->appName;
return Application::APP_ID;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions apps/theming/lib/Settings/PersonalSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace OCA\Theming\Settings;

use OCA\Theming\AppInfo\Application;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
Expand All @@ -20,7 +21,6 @@ class PersonalSection implements IIconSection {
* @param IL10N $l
*/
public function __construct(
protected string $appName,
private IURLGenerator $urlGenerator,
private IL10N $l,
) {
Expand All @@ -34,7 +34,7 @@ public function __construct(
* @since 13.0.0
*/
public function getIcon() {
return $this->urlGenerator->imagePath($this->appName, 'accessibility-dark.svg');
return $this->urlGenerator->imagePath(Application::APP_ID, 'accessibility-dark.svg');
}

/**
Expand All @@ -45,7 +45,7 @@ public function getIcon() {
* @since 9.1
*/
public function getID() {
return $this->appName;
return Application::APP_ID;
}

/**
Expand Down
Loading
Loading