-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
theming: handle not being in the serverroot #8463
Merged
MorrisJobke
merged 3 commits into
nextcloud:master
from
kyrofa:bugfix/8462/theming_app_outside_root
Feb 26, 2018
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
use OCA\Theming\Util; | ||
use OCP\ITempManager; | ||
use OCP\IURLGenerator; | ||
use OCP\App\IAppManager; | ||
|
||
/** | ||
* Class ThemingController | ||
|
@@ -78,6 +79,8 @@ class ThemingController extends Controller { | |
private $scssCacher; | ||
/** @var IURLGenerator */ | ||
private $urlGenerator; | ||
/** @var IAppManager */ | ||
private $appManager; | ||
|
||
/** | ||
* ThemingController constructor. | ||
|
@@ -93,6 +96,7 @@ class ThemingController extends Controller { | |
* @param IAppData $appData | ||
* @param SCSSCacher $scssCacher | ||
* @param IURLGenerator $urlGenerator | ||
* @param IAppManager $appManager | ||
*/ | ||
public function __construct( | ||
$appName, | ||
|
@@ -105,7 +109,8 @@ public function __construct( | |
ITempManager $tempManager, | ||
IAppData $appData, | ||
SCSSCacher $scssCacher, | ||
IURLGenerator $urlGenerator | ||
IURLGenerator $urlGenerator, | ||
IAppManager $appManager = NULL | ||
) { | ||
parent::__construct($appName, $request); | ||
|
||
|
@@ -118,6 +123,12 @@ public function __construct( | |
$this->appData = $appData; | ||
$this->scssCacher = $scssCacher; | ||
$this->urlGenerator = $urlGenerator; | ||
|
||
if (!is_null($appManager)) { | ||
$this->appManager = $appManager; | ||
} else { | ||
$this->appManager = \OC::$server->getAppManager(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -409,12 +420,13 @@ public function getLoginBackground() { | |
* @return FileDisplayResponse|NotFoundResponse | ||
*/ | ||
public function getStylesheet() { | ||
$appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1); | ||
$appPath = $this->appManager->getAppPath('theming'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙈 👍 |
||
|
||
/* SCSSCacher is required here | ||
* We cannot rely on automatic caching done by \OC_Util::addStyle, | ||
* since we need to add the cacheBuster value to the url | ||
*/ | ||
$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming'); | ||
$cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); | ||
if(!$cssCached) { | ||
return new NotFoundResponse(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no need for such a check. The AppManager will be injected automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, only in this test case, right? If it's not injected (like the other test cases, or in typical usage) it should default back to the server's app manager. Perhaps I misunderstand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock should just be added to the controller here: https://github.com/kyrofa/server/blob/a1f18241166f335b89a6cf3d002efd3d825fde19/apps/theming/tests/Controller/ThemingControllerTest.php#L109
Then of course the method need to be configured to the other tests as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can do that, although we'll still need the null check for the real system. Eventually this parameter could become non-optional and the callers could all start passing it in, but that's a larger change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the tests to add the mock in setUp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, great. Then you can get rid of the is_null check since the appManager will be injected automatically, just like the other constructor arguments. So it will always be
\OC::$server->getAppManager()
except for the tests where we call the constructor ourselfs and it will be mocked then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, indeed, I'm not sure how the other constructor arguments are handed off. There must be some sort of introspection magic happening there that I haven't seen, because you're right-- removing the null check works! I've pushed that up, but can you show me where this magic is happening so I can further my understanding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can read more about the dependency injection here: https://docs.nextcloud.com/server/13/developer_manual/app/container.html#how-does-automatic-assembly-work
This is basically where the "magic" happens: 😉
server/lib/private/AppFramework/Utility/SimpleContainer.php
Line 50 in 0eebff1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh and the puzzle pieces come together! Thank you for helping me understand this :) .