Skip to content

Commit

Permalink
Merge pull request #36348 from nextcloud/bugfix/noid/fix-primary-colo…
Browse files Browse the repository at this point in the history
…r-usage-in-emails-and-federation

Fix primary color usage in emails and federation
  • Loading branch information
nickvergessen authored Jan 30, 2023
2 parents 97e6fe4 + 959e2aa commit de415fb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
36 changes: 13 additions & 23 deletions apps/federatedfilesharing/lib/Settings/Personal.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
Expand Down Expand Up @@ -29,30 +32,27 @@
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IL10N;
use OCP\Defaults;
use OCP\IUserSession;
use OCP\IURLGenerator;
use OCP\Settings\ISettings;

class Personal implements ISettings {
private FederatedShareProvider $federatedShareProvider;
private IUserSession $userSession;
private IL10N $l;
private \OC_Defaults $defaults;
private Defaults $defaults;
private IInitialState $initialState;
private IURLGenerator $urlGenerator;

public function __construct(
FederatedShareProvider $federatedShareProvider, #
FederatedShareProvider $federatedShareProvider,
IUserSession $userSession,
IL10N $l,
\OC_Defaults $defaults,
Defaults $defaults,
IInitialState $initialState,
IURLGenerator $urlGenerator
) {
$this->federatedShareProvider = $federatedShareProvider;
$this->userSession = $userSession;
$this->l = $l;
$this->defaults = $defaults;
$this->initialState = $initialState;
$this->urlGenerator = $urlGenerator;
Expand All @@ -62,35 +62,25 @@ public function __construct(
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
* @since 9.1
*/
public function getForm() {
public function getForm(): TemplateResponse {
$cloudID = $this->userSession->getUser()->getCloudId();
$url = 'https://nextcloud.com/sharing#' . $cloudID;

$parameters = [
'message_with_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID, see %s', [$url]),
'message_without_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID', [$cloudID]),
'logoPath' => $this->defaults->getLogo(),
'reference' => $url,
'cloudId' => $cloudID,
'color' => $this->defaults->getColorPrimary(),
'textColor' => "#ffffff",
];

$this->initialState->provideInitialState('color', $this->defaults->getColorPrimary());
$this->initialState->provideInitialState('textColor', '#fffff');
$this->initialState->provideInitialState('color', $this->defaults->getDefaultColorPrimary());
$this->initialState->provideInitialState('textColor', $this->defaults->getDefaultTextColorPrimary());
$this->initialState->provideInitialState('logoPath', $this->defaults->getLogo());
$this->initialState->provideInitialState('reference', $url);
$this->initialState->provideInitialState('cloudId', $cloudID);
$this->initialState->provideInitialState('docUrlFederated', $this->urlGenerator->linkToDocs('user-sharing-federated'));

return new TemplateResponse('federatedfilesharing', 'settings-personal', $parameters, '');
return new TemplateResponse('federatedfilesharing', 'settings-personal', [], TemplateResponse::RENDER_AS_BLANK);
}

/**
* @return string the section ID, e.g. 'sharing'
* @since 9.1
*/
public function getSection() {
public function getSection(): ?string {
if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() ||
$this->federatedShareProvider->isIncomingServer2serverGroupShareEnabled()) {
return 'sharing';
Expand All @@ -106,7 +96,7 @@ public function getSection() {
* E.g.: 70
* @since 9.1
*/
public function getPriority() {
public function getPriority(): int {
return 40;
}
}
9 changes: 9 additions & 0 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,15 @@ public function getTextColorPrimary() {
return $this->util->invertTextColor($this->getColorPrimary()) ? '#000000' : '#ffffff';
}

/**
* Color of text in the header and primary buttons
*
* @return string
*/
public function getDefaultTextColorPrimary() {
return $this->util->invertTextColor($this->getDefaultColorPrimary()) ? '#000000' : '#ffffff';
}

/**
* Has the admin disabled user customization
*/
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Mail/EMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public function addHeader() {
$this->headerAdded = true;

$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
}

/**
Expand Down Expand Up @@ -555,7 +555,7 @@ public function addBodyButtonGroup(string $textLeft,
$this->ensureBodyIsOpened();
$this->ensureBodyListClosed();

$color = $this->themingDefaults->getColorPrimary();
$color = $this->themingDefaults->getDefaultColorPrimary();
$textColor = $this->themingDefaults->getTextColorPrimary();

$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
Expand Down Expand Up @@ -586,7 +586,7 @@ public function addBodyButton(string $text, string $url, $plainText = '') {
$text = htmlspecialchars($text);
}

$color = $this->themingDefaults->getColorPrimary();
$color = $this->themingDefaults->getDefaultColorPrimary();
$textColor = $this->themingDefaults->getTextColorPrimary();
$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);

Expand Down
24 changes: 24 additions & 0 deletions lib/public/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ public function getColorPrimary(): string {
return $this->defaults->getColorPrimary();
}

/**
* Return the default color primary
* @return string
* @since 25.0.4
*/
public function getDefaultColorPrimary(): string {
if (method_exists($this->defaults, 'getDefaultColorPrimary')) {
return $this->defaults->getDefaultColorPrimary();
}
return $this->defaults->getColorPrimary();
}

/**
* @param string $key
* @return string URL to doc with key
Expand All @@ -231,4 +243,16 @@ public function getTitle(): string {
public function getTextColorPrimary(): string {
return $this->defaults->getTextColorPrimary();
}

/**
* Returns primary color
* @return string
* @since 25.0.4
*/
public function getDefaultTextColorPrimary(): string {
if (method_exists($this->defaults, 'getDefaultTextColorPrimary')) {
return $this->defaults->getDefaultTextColorPrimary();
}
return $this->defaults->getTextColorPrimary();
}
}
8 changes: 4 additions & 4 deletions tests/lib/Mail/EMailTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function setUp(): void {
public function testEMailTemplateCustomFooter() {
$this->defaults
->expects($this->any())
->method('getColorPrimary')
->method('getDefaultColorPrimary')
->willReturn('#0082c9');
$this->defaults
->expects($this->any())
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testEMailTemplateCustomFooter() {
public function testEMailTemplateDefaultFooter() {
$this->defaults
->expects($this->any())
->method('getColorPrimary')
->method('getDefaultColorPrimary')
->willReturn('#0082c9');
$this->defaults
->expects($this->any())
Expand Down Expand Up @@ -147,7 +147,7 @@ public function testEMailTemplateDefaultFooter() {
public function testEMailTemplateSingleButton() {
$this->defaults
->expects($this->any())
->method('getColorPrimary')
->method('getDefaultColorPrimary')
->willReturn('#0082c9');
$this->defaults
->expects($this->any())
Expand Down Expand Up @@ -192,7 +192,7 @@ public function testEMailTemplateSingleButton() {
public function testEMailTemplateAlternativePlainTexts() {
$this->defaults
->expects($this->any())
->method('getColorPrimary')
->method('getDefaultColorPrimary')
->willReturn('#0082c9');
$this->defaults
->expects($this->any())
Expand Down

0 comments on commit de415fb

Please sign in to comment.