Skip to content

Commit 7cdf800

Browse files
committed
feat(updater): Allow to defined locked apps
Signed-off-by: Git'Fellow <[email protected]>
1 parent b5b3207 commit 7cdf800

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

apps/settings/lib/Controller/AppSettingsController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,12 @@ public function uninstallApp(string $appId): JSONResponse {
650650
public function updateApp(string $appId): JSONResponse {
651651
$appId = $this->appManager->cleanAppId($appId);
652652

653+
// Don't try to update locked apps
654+
$appsLocked = $this->config->getSystemValue('apps_locked', []);
655+
if (in_array($app, $appsLocked, true)) {
656+
return new JSONResponse(['data' => ['message' => $this->l10n->t('App is locked, update skipped.')]], Http::STATUS_FORBIDDEN);
657+
}
658+
653659
$this->config->setSystemValue('maintenance', true);
654660
try {
655661
$result = $this->installer->updateAppstoreApp($appId);

core/Command/App/Update.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use OC\Installer;
1212
use OCP\App\AppPathNotFoundException;
1313
use OCP\App\IAppManager;
14+
use OCP\IConfig;
15+
use OCP\Server;
1416
use Psr\Log\LoggerInterface;
1517
use Symfony\Component\Console\Command\Command;
1618
use Symfony\Component\Console\Input\InputArgument;
@@ -77,13 +79,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7779
}
7880

7981
$return = 0;
82+
83+
$config = Server::get(IConfig::class);
84+
$appsLocked = $config->getSystemValue('apps_locked', []);
85+
8086
foreach ($apps as $appId) {
8187
$newVersion = $this->installer->isUpdateAvailable($appId, $input->getOption('allow-unstable'));
8288
if ($newVersion) {
8389
$updateFound = true;
8490
$output->writeln($appId . ' new version available: ' . $newVersion);
8591

8692
if (!$input->getOption('showonly')) {
93+
// Don't try to update locked apps
94+
if (in_array($appId, $appsLocked, true)) {
95+
$output->writeln('Update skipped for locked app ' . $appId);
96+
continue;
97+
}
98+
8799
try {
88100
$result = $this->installer->updateAppstoreApp($appId, $input->getOption('allow-unstable'));
89101
} catch (\Exception $e) {

lib/private/Updater.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,14 @@ private function isCodeUpgrade(): bool {
373373
* @throws \Exception
374374
*/
375375
private function upgradeAppStoreApps(array $apps, array $previousEnableStates = []): void {
376+
$appsLocked = $this->config->getSystemValue('apps_locked', []);
377+
376378
foreach ($apps as $app) {
379+
// Don't try to update locked apps
380+
if (in_array($app, $appsLocked, true)) {
381+
$this->log->info('Update skipped for locked app' . $app, ['app' => 'updater']);
382+
continue;
383+
}
377384
try {
378385
$this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]);
379386
if ($this->installer->isUpdateAvailable($app)) {

0 commit comments

Comments
 (0)