From 42c83678a8563c1b787e85407362158386d5ae70 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:18:54 +0300 Subject: [PATCH] do not disable ExApp on lower version Signed-off-by: Alexander Piskun --- .github/workflows/tests-special.yml | 114 +--------------------------- lib/Service/AppAPIService.php | 36 ++------- lib/Service/ExAppService.php | 2 +- tests/app_version_higher.py | 26 ------- 4 files changed, 7 insertions(+), 171 deletions(-) delete mode 100644 tests/app_version_higher.py diff --git a/.github/workflows/tests-special.yml b/.github/workflows/tests-special.yml index b8c7d319..461eb200 100644 --- a/.github/workflows/tests-special.yml +++ b/.github/workflows/tests-special.yml @@ -21,118 +21,6 @@ env: APP_SECRET: "tC6vkwPhcppjMykD1r0n9NlI95uJMBYjs5blpIcA1PAdoPDmc5qoAjaBAkyocZ6E" jobs: - app-version-higher: - runs-on: ubuntu-22.04 - name: ExApp version higher - - services: - postgres: - image: ghcr.io/nextcloud/continuous-integration-postgres-14:latest - ports: - - 4444:5432/tcp - env: - POSTGRES_USER: root - POSTGRES_PASSWORD: rootpassword - POSTGRES_DB: nextcloud - options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5 - - steps: - - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Set app env - run: echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV - - - name: Checkout server - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - with: - submodules: true - repository: nextcloud/server - ref: 'stable28' - - - name: Checkout Notifications - uses: actions/checkout@v3 - with: - repository: nextcloud/notifications - ref: 'stable28' - path: apps/notifications - - - name: Checkout AppAPI - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - with: - path: apps/${{ env.APP_NAME }} - - - name: Set up php - uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # v2 - with: - php-version: '8.1' - extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, pgsql, pdo_pgsql - coverage: none - ini-file: development - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Check composer file existence - id: check_composer - uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2 - with: - files: apps/${{ env.APP_NAME }}/composer.json - - - name: Set up dependencies - if: steps.check_composer.outputs.files_exists == 'true' - working-directory: apps/${{ env.APP_NAME }} - run: composer i - - - name: Set up Nextcloud - env: - DB_PORT: 4444 - run: | - mkdir data - ./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 \ - --database-port=$DB_PORT --database-user=root --database-pass=rootpassword \ - --admin-user admin --admin-pass admin - ./occ app:enable notifications - ./occ app:enable --force ${{ env.APP_NAME }} - - - name: Run Nextcloud - run: PHP_CLI_SERVER_WORKERS=2 php -S 127.0.0.1:8080 & - - - name: Checkout NcPyApi - uses: actions/checkout@v3 - with: - path: nc_py_api - repository: cloud-py-api/nc_py_api - - - name: Install NcPyApi - working-directory: nc_py_api - run: python3 -m pip -v install ".[dev]" - - - name: Register NcPyApi - run: | - cd nc_py_api - python3 tests/_install.py & - echo $! > /tmp/_install.pid - cd .. - sleep 5s - php occ app_api:daemon:register manual_install "Manual Install" manual-install http localhost 0 - php occ app_api:app:register $APP_ID manual_install --json-info \ - "{\"appid\":\"$APP_ID\",\"name\":\"$APP_ID\",\"daemon_config_name\":\"manual_install\",\"version\":\"$APP_VERSION\",\"secret\":\"$APP_SECRET\",\"port\":$APP_PORT,\"scopes\":[\"SYSTEM\", \"NOTIFICATIONS\", \"USER_INFO\"],\"system_app\":1}" \ - --force-scopes --wait-finish - kill -15 $(cat /tmp/_install.pid) - timeout 3m tail --pid=$(cat /tmp/_install.pid) -f /dev/null - - - name: Run Manual App Update test - working-directory: apps/${{ env.APP_NAME }} - run: python3 tests/app_version_higher.py - - - name: Upload NC logs - if: always() - uses: actions/upload-artifact@v3 - with: - name: app_version_higher_nextcloud.log - path: data/nextcloud.log - if-no-files-found: warn auth-tests-no-init: runs-on: ubuntu-22.04 @@ -258,7 +146,7 @@ jobs: permissions: contents: none runs-on: ubuntu-22.04 - needs: [app-version-higher, auth-tests-no-init] + needs: [auth-tests-no-init] name: TestsSpecial-OK steps: - run: echo "Tests special passed successfully" diff --git a/lib/Service/AppAPIService.php b/lib/Service/AppAPIService.php index 84e3bf0e..277b7482 100644 --- a/lib/Service/AppAPIService.php +++ b/lib/Service/AppAPIService.php @@ -9,7 +9,6 @@ use OCA\AppAPI\Db\ExApp; use OCA\AppAPI\DeployActions\DockerActions; use OCA\AppAPI\DeployActions\ManualActions; -use OCA\AppAPI\Notifications\ExNotificationsManager; use OCP\AppFramework\Http; use OCP\DB\Exception; use OCP\Http\Client\IClient; @@ -36,7 +35,6 @@ public function __construct( private readonly ISession $session, private readonly IUserManager $userManager, private readonly IFactory $l10nFactory, - private readonly ExNotificationsManager $exNotificationsManager, private readonly ExAppService $exAppService, private readonly ExAppApiScopeService $exAppApiScopeService, private readonly DockerActions $dockerActions, @@ -400,42 +398,18 @@ public function passesScopeCheck(ExApp $exApp, int $apiScope): bool { } /** - * Check if ExApp version changed and update it in database. - * Immediately disable ExApp and send notifications to the administrators (users of admins group). - * This handling only intentional case of manual ExApp update - * so the administrator must re-enable ExApp in UI or CLI after that. - * - * Ref: https://github.com/cloud-py-api/app_api/pull/29 - * TODO: Add link to docs with warning and mark as not-recommended - * + * Checks if the ExApp version changed and if it is higher, updates it in the database. */ public function handleExAppVersionChange(IRequest $request, ExApp $exApp): bool { $requestExAppVersion = $request->getHeader('EX-APP-VERSION'); - $versionValid = $exApp->getVersion() === $requestExAppVersion; - if (!$versionValid) { - // Update ExApp version - $oldVersion = $exApp->getVersion(); + if ($requestExAppVersion === '') { + return false; + } + if (version_compare($requestExAppVersion, $exApp->getVersion(), '>')) { $exApp->setVersion($requestExAppVersion); if (!$this->exAppService->updateExApp($exApp, ['version'])) { return false; } - $this->disableExApp($exApp); - $this->exNotificationsManager->sendAdminsNotification($exApp->getAppid(), [ - 'object' => 'ex_app_update', - 'object_id' => $exApp->getAppid(), - 'subject_type' => 'ex_app_version_update', - 'subject_params' => [ - 'rich_subject' => 'ExApp updated, action required!', - 'rich_subject_params' => [], - 'rich_message' => sprintf( - 'ExApp %s disabled due to update from %s to %s. Manual re-enable required.', - $exApp->getAppid(), - $oldVersion, - $exApp->getVersion()), - 'rich_message_params' => [], - ], - ]); - return false; } return true; } diff --git a/lib/Service/ExAppService.php b/lib/Service/ExAppService.php index 9283948b..bfa2dbc0 100644 --- a/lib/Service/ExAppService.php +++ b/lib/Service/ExAppService.php @@ -202,7 +202,7 @@ public function updateExApp(ExApp $exApp, array $fields = ['version', 'name', 'p try { $this->exAppMapper->updateExApp($exApp, $fields); $this->cache->remove('/ex_apps'); - if (in_array('enabled', $fields)) { + if (in_array('enabled', $fields) || in_array('version', $fields)) { $this->resetCaches(); } return true; diff --git a/tests/app_version_higher.py b/tests/app_version_higher.py deleted file mode 100644 index bf28f6b7..00000000 --- a/tests/app_version_higher.py +++ /dev/null @@ -1,26 +0,0 @@ -import pytest - -from nc_py_api import Nextcloud, NextcloudApp, NextcloudException - - -if __name__ == "__main__": - nc_client = Nextcloud(nc_auth_user="admin", nc_auth_pass="admin") - assert nc_client.apps.ex_app_is_disabled("nc_py_api") is False - nc_client.users.create("second_admin", password="2Very3Strong4", groups=["admin"]) - - nc_application = NextcloudApp(user="admin") - assert nc_application.users.get_user() # OCS call works - assert not nc_application.notifications.get_all() # there are no notifications - nc_application._session.adapter.headers.update({"EX-APP-VERSION": "99.0.0"}) # change ExApp version - with pytest.raises(NextcloudException) as exc_info: - nc_application.users.get_user() # this call should be rejected by AppAPI - assert exc_info.value.status_code == 401 - - assert nc_client.apps.ex_app_is_disabled("nc_py_api") is True - notifications = nc_client.notifications.get_all() - notification = [i for i in notifications if i.object_type == "ex_app_update"] - assert len(notification) == 1 # only one notification for each admin - nc_client = Nextcloud(nc_auth_user="second_admin", nc_auth_pass="2Very3Strong4") - notifications = nc_client.notifications.get_all() - notification = [i for i in notifications if i.object_type == "ex_app_update"] - assert len(notification) == 1 # only one notification for each admin