-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add dedicated API for apps' bootstrapping process #20865
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
69571fb
Add dedicated API for apps' bootstrapping process
ChristophWurst 0a24d1f
Migrate Comments to the new bootstrap mechanism
ChristophWurst 0587010
Migrate Accessibility app to new bootstrap mechanism
ChristophWurst 16ab798
Migrate Admin Audit app to new bootstrap mechanism
ChristophWurst c5d2958
Migrate Settings to new bootstrap mechanism
ChristophWurst a2c8bfa
Migrate Two-Factor Backup Codes to new bootstrap mechanism
ChristophWurst 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2018 John Molakvoæ <[email protected]> | ||
| * | ||
|
|
@@ -27,14 +30,21 @@ | |
| namespace OCA\Accessibility\AppInfo; | ||
|
|
||
| use OCP\AppFramework\App; | ||
| use OCP\AppFramework\Bootstrap\IBootContext; | ||
| use OCP\AppFramework\Bootstrap\IBootstrap; | ||
| use OCP\AppFramework\Bootstrap\IRegistrationContext; | ||
| use OCP\IConfig; | ||
| use OCP\IServerContainer; | ||
| use OCP\IURLGenerator; | ||
| use OCP\IUserSession; | ||
| use function count; | ||
| use function implode; | ||
| use function md5; | ||
|
|
||
| class Application extends App { | ||
| class Application extends App implements IBootstrap { | ||
|
|
||
| /** @var string */ | ||
| public const APP_NAME = 'accessibility'; | ||
| public const APP_ID = 'accessibility'; | ||
|
|
||
| /** @var IConfig */ | ||
| private $config; | ||
|
|
@@ -46,39 +56,56 @@ class Application extends App { | |
| private $urlGenerator; | ||
|
|
||
| public function __construct() { | ||
| parent::__construct(self::APP_NAME); | ||
| $this->config = \OC::$server->getConfig(); | ||
| $this->userSession = \OC::$server->getUserSession(); | ||
| $this->urlGenerator = \OC::$server->getURLGenerator(); | ||
| parent::__construct(self::APP_ID); | ||
| } | ||
|
|
||
| public function register(IRegistrationContext $context): void { | ||
| } | ||
|
|
||
| public function boot(IBootContext $context): void { | ||
| $this->injectCss( | ||
| $context->getAppContainer()->query(IUserSession::class), | ||
| $context->getAppContainer()->query(IConfig::class), | ||
| $context->getAppContainer()->query(IURLGenerator::class) | ||
| ); | ||
| $this->injectJavascript( | ||
| $context->getAppContainer()->query(IURLGenerator::class), | ||
| $context->getAppContainer()->query(IConfig::class), | ||
| $context->getServerContainer() | ||
| ); | ||
| } | ||
|
|
||
| public function injectCss() { | ||
| private function injectCss(IUserSession $userSession, | ||
| IConfig $config, | ||
| IURLGenerator $urlGenerator) { | ||
| // Inject the fake css on all pages if enabled and user is logged | ||
| $loggedUser = $this->userSession->getUser(); | ||
| if (!is_null($loggedUser)) { | ||
| $userValues = $this->config->getUserKeys($loggedUser->getUID(), self::APP_NAME); | ||
| $loggedUser = $userSession->getUser(); | ||
| if ($loggedUser !== null) { | ||
| $userValues = $config->getUserKeys($loggedUser->getUID(), self::APP_ID); | ||
| // we want to check if any theme or font is enabled. | ||
| if (count($userValues) > 0) { | ||
| $hash = $this->config->getUserValue($loggedUser->getUID(), self::APP_NAME, 'icons-css', md5(implode('-', $userValues))); | ||
| $linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME . '.accessibility.getCss', ['md5' => $hash]); | ||
| $hash = $config->getUserValue($loggedUser->getUID(), self::APP_ID, 'icons-css', md5(implode('-', $userValues))); | ||
| $linkToCSS = $urlGenerator->linkToRoute(self::APP_ID . '.accessibility.getCss', ['md5' => $hash]); | ||
| \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public function injectJavascript() { | ||
| $linkToJs = $this->urlGenerator->linkToRoute( | ||
| self::APP_NAME . '.accessibility.getJavascript', | ||
| private function injectJavascript(IURLGenerator $urlGenerator, | ||
| IConfig $config, | ||
| IServerContainer $serverContainer) { | ||
| $linkToJs = $urlGenerator->linkToRoute( | ||
| self::APP_ID . '.accessibility.getJavascript', | ||
| [ | ||
| 'v' => \OC::$server->getConfig()->getAppValue('accessibility', 'cachebuster', '0'), | ||
| 'v' => $config->getAppValue(self::APP_ID, 'cachebuster', '0'), | ||
| ] | ||
| ); | ||
|
|
||
| \OCP\Util::addHeader( | ||
| 'script', | ||
| [ | ||
| 'src' => $linkToJs, | ||
| 'nonce' => \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() | ||
| 'nonce' => $serverContainer->getContentSecurityPolicyNonceManager()->getNonce() | ||
| ], | ||
| '' | ||
| ); | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.