Skip to content

Single active app theme with no magic fallbacks to inactive app themes - #29747

Merged
VicDeo merged 6 commits into
masterfrom
fix-28167
Dec 14, 2017
Merged

VicDeo merged 6 commits into
masterfrom
fix-28167

Conversation

@VicDeo

@VicDeo VicDeo commented Dec 1, 2017 •

Copy link
Copy Markdown
Contributor

Description

Fixes custom translations inside app-themes.

TODO:

  • Remove undocumented fallback to the app-theme with default_enabled attribute
  • Fallback to the legacy theme only in case there is no app-theme active
  • Allow only one app-theme to be active (CLI/Web)

A migration step that

  • resets legacy theme if app-theme is enabled ->setSystemValue('theme', '')
  • disables extra app-themes in case there is more than one active app-theme
    currently the last (alphabetically) app-theme wins. So the latest theme should stay active.

Related Issue

Fixes
#28167
https://github.com/owncloud/theme-enterprise/issues/16

Motivation and Context

How Has This Been Tested?

Test 1

  1. Activate app-theme. e.g. theme-example
  2. Switch to British English
  3. mkdir -p apps/theme-example/core/l10n
  4. cp core/l10n/en_GB.json apps/theme-example/core/l10n/en_GB.json
  5. Change
    "Log out" : "Log out",
    to
    "Log out" : "Go away!",

Expected

Log out is renamed in menu

Actual

it is not

Tested as a guest

Please note that guest user uses a language based on browser locale settings.
You'll need to override another file (es.json, de.json, whatever...) instead of en_GB.json if your browser is not in en_GB

  • "File not found" changed to "File not found and never will be"
    Accessing an unexisting share - translation works
  • "Password" changed to "Password 123"
    Accessing a login page - translation works

Test 2

  1. Activate another app-theme

Expected

It can't be enabled until the current theme is active

Actual

Both themes are enabled, theme that is the last according to the alphabet is loaded.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@VicDeo VicDeo added this to the development milestone Dec 1, 2017
@VicDeo VicDeo changed the title Preload active app themes. Override translations from app-themes WIP Preload active app themes. Override translations from app-themes Dec 1, 2017
@codecov

codecov Bot commented Dec 4, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #29747 into master will increase coverage by 0.05%.
The diff coverage is 88.76%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #29747      +/-   ##
============================================
+ Coverage     60.46%   60.51%   +0.05%     
- Complexity    18360    18370      +10     
============================================
  Files          1089     1090       +1     
  Lines         60893    60931      +38     
============================================
+ Hits          36818    36872      +54     
+ Misses        24075    24059      -16
Impacted Files Coverage Δ Complexity Δ
lib/private/legacy/app.php 59.48% <ø> (+1.15%) 197 <0> (-5) ⬇️
core/Command/App/Enable.php 100% <ø> (ø) 5 <0> (ø) ⬇️
lib/public/Util.php 52.72% <ø> (-0.29%) 68 <0> (ø)
index.php 0% <ø> (ø) 0 <0> (ø) ⬇️
lib/private/Repair.php 27.84% <0%> (-1.49%) 21 <0> (ø)
lib/base.php 2.7% <0%> (+0.02%) 154 <0> (-2) ⬇️
lib/private/Server.php 82.63% <100%> (+0.45%) 128 <0> (ø) ⬇️
lib/private/Theme/ThemeService.php 59.01% <100%> (-3.68%) 28 <4> (-3)
lib/private/App/AppManager.php 84.24% <83.33%> (-0.08%) 61 <7> (+7)
lib/private/Repair/DisableExtraThemes.php 93.1% <93.1%> (ø) 10 <10> (?)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1df409...81d3ff5. Read the comment docs.

@VicDeo

VicDeo commented Dec 4, 2017

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 in the current state it works and passes all the tests.
I tried to inject a ThemeService as a next step but it leads to the error 500 when any app-theme is active:

[Mon Dec 04 22:52:41.765941 2017] Fatal error: Cannot declare class OC_Theme, because the name is already in use in /ocpath/apps/theme-enterprise/defaults.php on line 16
[Mon Dec 04 22:52:41.765971 2017] Stack trace:
[Mon Dec 04 22:52:41.765986 2017]  1. {main}() /ocpath/index.php:0
[Mon Dec 04 22:52:41.765994 2017]  2. OC_Template::printExceptionErrorPage($exception = *uninitialized*, $fetchPage = *uninitialized*) /ocpath/index.php:84
[Mon Dec 04 22:52:41.766001 2017]  3. OC_Template->__construct($app = *uninitialized*, $name = *uninitialized*, $renderAs = *uninitialized*, $registerCall = *uninitialized*) /ocpath/lib/private/legacy/template.php:358
[Mon Dec 04 22:52:41.766007 2017]  4. OC_Defaults->__construct() /ocpath/lib/private/legacy/template.php:93
[Mon Dec 04 22:52:41.766012 2017]  5. require_once() /ocpath/lib/private/legacy/defaults.php:76

@VicDeo

VicDeo commented Dec 4, 2017

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 plz disregard the previous comment.
I didn't noticed that running test from CLI killed files directory for my user. What I broke is an output for error message informing about that. Fixing...

@VicDeo VicDeo changed the title WIP Preload active app themes. Override translations from app-themes Preload active app themes. Override translations from app-themes Dec 4, 2017
@VicDeo

VicDeo commented Dec 6, 2017

Copy link
Copy Markdown
Contributor Author

@PVince81 IMHO it's better to disable the currently active theme instead of blocking a new one.

Another thing: as soon as it is not possible to have multiple themes, we should consider adding theme type into the list of protected apps (that can't be enabled for certain groups only) https://github.com/owncloud/core/blob/master/lib/private/App/AppManager.php#L49

@VicDeo VicDeo added 3 - To Review p1-urgent Critical issue, need to consider hotfix with just that issue and removed 2 - Developing labels Dec 7, 2017
@PVince81

PVince81 commented Dec 8, 2017

Copy link
Copy Markdown
Contributor

IMHO it's better to disable the currently active theme instead of blocking a new one.

@VicDeo in any case we need a warning to tell the admin whatever happened.

@VicDeo VicDeo changed the title Preload active app themes. Override translations from app-themes Single active app theme with no magic fallbacks to inactive app themes Dec 8, 2017
@VicDeo

VicDeo commented Dec 8, 2017

Copy link
Copy Markdown
Contributor Author

@PVince81

we need a warning to tell the admin whatever happened.

it's done. For now I did it as suggested: second theme can't be enabled with a warning.

@VicDeo

VicDeo commented Dec 8, 2017

Copy link
Copy Markdown
Contributor Author

Failing tests are related to CI itself:

General error: 2006 MySQL server has gone away
+ wait-for-it mysqlmb4:3306
wait-for-it: waiting 15 seconds for mysqlmb4:3306
wait-for-it: timeout occurred after waiting 15 seconds for mysqlmb4:3306

@PVince81 PVince81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, see comments for a few minor things.

Great to see so many tests!

Comment thread core/Command/App/Enable.php Outdated
$output->writeln($appId . ' enabled for groups: ' . implode(', ', $groups));
}
} catch (\Exception $e) {
$output->writeln($e->getMessage());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log the stack trace to avoid future headaches ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 Possible. But is t really needed for CLI command?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once people start reporting bugs and you don't have the stack trace at all, this will become painful...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just dont catch the exception then - afaik the symfony console will print the stack ...

Comment thread index.php
OC::handleRequest();

} catch(\OC\ServiceUnavailableException $ex) {
\OC::loadDefaultEnabledAppTheme();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad to see these go!

if(OC_App::getAppPath($appId) === false) {
throw new \Exception("$appId can't be enabled since it is not installed.");
}
$this->canEnableTheme($appId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return boolean and throw here ? just reading this line makes it look like a mistake as it asks can but doesn't check the result.

Since you're using this function only once I think it's better to do the boolean thing.

@VicDeo VicDeo Dec 12, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 This is what I was going to do initially. TBH I don't remember why I decided to do it this way finally.
May be due to Scrutinizer's pessimization for methods with too many decision points. (Yes, I look into the code analisys results :) )

@VicDeo VicDeo Dec 12, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 a-ha. It allows to produce more descriptive exception message (with the blocking app-theme appid). Just by returning false this appid would be lost

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the current message contains both blocking and blocked appIds: new-shiny-theme can't be enabled until old-bloody-theme is disabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine by me

Comment thread lib/private/App/AppManager.php Outdated
$apps = $this->getInstalledApps();
foreach ($apps as $installedAppId) {
if ($this->isTheme($installedAppId)) {
throw new \Exception("$appId can't be enabled until $installedAppId is disabled.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have some fantastic app manager specific exceptions, maybe one would suit here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 There is no specific subclass. Would generic AppManagerException be enough?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would already be better

@VicDeo
VicDeo force-pushed the fix-28167 branch 2 times, most recently from 587eae2 to 1ac6f9e Compare December 12, 2017 16:49
@VicDeo

VicDeo commented Dec 12, 2017

Copy link
Copy Markdown
Contributor Author

@PVince81 all except canEnableTheme addressed

@VicDeo VicDeo self-assigned this Dec 12, 2017
Comment thread core/Command/App/Enable.php Outdated
* @param ILogger $logger
*/
public function __construct(IAppManager $manager) {
public function __construct(IAppManager $manager, ILogger $logger) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my pov a occ command shall not use the logger but print anything to the console

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DeepDiver1975 please discuss this with @PVince81 as he requested logging :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 whats the background here? its actually easier for the user to see any error/exception in the console and not to look it up in the log file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as the stack trace appears somewhere we're fine

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, removing logging along with try/catch

protected function canEnableTheme($appId) {
$info = $this->getAppInfo($appId);
if (
isset($info['types'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isset($info['types']['theme']) - keep is simple

@VicDeo VicDeo Dec 13, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DeepDiver1975 it'snot possible this way because 'theme' is not a key but a value:

array(20) {
  'id' =>  string(16) "theme-enterprise"
  'name' =>  string(27) "ownCloud X Enterprise Theme"
'types' =>
  array(1) {
    [0] =>     string(5) "theme"
  }

$info['types'][0] = 'theme', not $info['types']['theme'] = 'something'

protected function canEnableTheme($appId) {
$info = $this->getAppInfo($appId);
if (
isset($info['types'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isset($info['types']['theme']) - keep is simple

$relativePath = substr($dir, strlen($this->serverRoot));
$themeDir = $this->getActiveThemeDirectory();
if ($themeDir !== '') {
$themeDir .= $relativePath;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ is guaranteed to be in place here?

@VicDeo VicDeo Dec 13, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep $relativePath = substr($dir, strlen($this->serverRoot)); where $this->serverRoot is actually OC::$SERVERROOT. As soon as OC::$SERVERROOT has no trailing slash $relativePath always starts with a slash.

In addition it is covered by a newly added FactoryTest::testFindAvailableLanguagesWithAppThemes test.

protected $config;

/** @var IAppConfig */
protected $appConfig;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you already have IConfig - there is not need for appConfig

@VicDeo VicDeo Dec 13, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DeepDiver1975 I do need appConfig to get all appIds along with their types (appIds are filtered by type theme afterwards) https://github.com/owncloud/core/pull/29747/files#diff-cdbcd54405a2b5684c9aed2c1824d7f8R94
$appTypes = $this->appConfig->getValues(false, 'types');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not exist in IConfig? brilliant ...

@VicDeo

VicDeo commented Dec 13, 2017

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 thanks, addressed/responded

@VicDeo

VicDeo commented Dec 14, 2017

Copy link
Copy Markdown
Contributor Author

Stable10: #29854

@lock

lock Bot commented Aug 1, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3 - To Review p1-urgent Critical issue, need to consider hotfix with just that issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants