diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 5d232cdf5..d4378f1e8 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -3,20 +3,18 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ module.exports = { - extends: [ - '@nextcloud/eslint-config/vue3', - 'prettier', - ], - plugins: [ - 'promise', - ], + extends: ['@nextcloud/eslint-config/vue3', 'prettier'], + plugins: ['promise'], rules: { 'arrow-body-style': 'error', - "jsdoc/require-jsdoc": ["error" | "warn", { - "publicOnly": { - "ancestorsOnly": true, + 'jsdoc/require-jsdoc': [ + 'error' | 'warn', + { + publicOnly: { + ancestorsOnly: true, + }, }, - }], + ], 'no-array-constructor': 'error', 'no-continue': 'error', 'no-else-return': ['error', { allowElseIf: false }], @@ -24,15 +22,18 @@ module.exports = { 'no-negated-condition': 'error', 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], 'prefer-template': 'error', - 'vue/script-indent': ['error', 'tab', { - baseIndent: 1, - switchCase: 1, - }], + 'vue/first-attribute-linebreak': [ + 'error', + { multiline: 'below', singleline: 'ignore' }, + ], 'vue/no-v-model-argument': 'off', - 'vue/no-unused-properties': ['error', { - groups: ['props', 'data', 'computed', 'methods'], - deepData: true, - ignorePublicMembers: true, - }], + 'vue/no-unused-properties': [ + 'error', + { + groups: ['props', 'data', 'computed', 'methods'], + deepData: true, + ignorePublicMembers: true, + }, + ], }, } diff --git a/.github/ISSUE_TEMPLATE/ANNOUNCEMENT.yml b/.github/ISSUE_TEMPLATE/ANNOUNCEMENT.yml index 94f1f30a4..24680a0ad 100644 --- a/.github/ISSUE_TEMPLATE/ANNOUNCEMENT.yml +++ b/.github/ISSUE_TEMPLATE/ANNOUNCEMENT.yml @@ -1,6 +1,6 @@ -name: "Announcement" -description: "Used for announcements" -labels: ["announcement"] +name: 'Announcement' +description: 'Used for announcements' +labels: ['announcement'] body: - type: textarea diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml index c9991ba63..8ebeed118 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml @@ -1,6 +1,6 @@ -name: "Bug report: Nextcloud Polls" -description: "Submit a report and help us improve Polls" -labels: ["bug"] +name: 'Bug report: Nextcloud Polls' +description: 'Submit a report and help us improve Polls' +labels: ['bug'] body: - type: markdown @@ -11,7 +11,7 @@ body: - type: checkboxes id: before-posting attributes: - label: "⚠️ This issue respects the following points: ⚠️" + label: '⚠️ This issue respects the following points: ⚠️' description: All conditions are **required**. Your issue can be closed if these are checked incorrectly. options: - label: This is a **bug**, not a question or a configuration/webserver/proxy issue. @@ -71,9 +71,9 @@ body: description: | How did you install the Polls version, you are referring to, especially when experiencing update errors options: - - "Installed/updated from the appstore (Apps section of your site)" - - "Installed/updated using occ" - - "Installed/updated via extracting downloaded package to the apps folder" + - 'Installed/updated from the appstore (Apps section of your site)' + - 'Installed/updated using occ' + - 'Installed/updated via extracting downloaded package to the apps folder' validations: required: true - type: dropdown @@ -83,10 +83,10 @@ body: description: | Was it an update or a first time installation options: - - "First time installation" - - "Updated from a minor version within same major version (i.e. 4.0.0 to 4.1.1)" - - "Updated from previous major version (i.e. 3.x.x to 4.x.x)" - - "Updated from a much older version (more than one major version)" + - 'First time installation' + - 'Updated from a minor version within same major version (i.e. 4.0.0 to 4.1.1)' + - 'Updated from previous major version (i.e. 3.x.x to 4.x.x)' + - 'Updated from a much older version (more than one major version)' validations: required: true - type: input @@ -111,11 +111,11 @@ body: description: | Select **all** browsers you used, where the bug appeared. options: - - label: "Firefox" - - label: "Chrome" - - label: "Chromium/Chromium based (i.e. Edge)" - - label: "Safari" - - label: "Other/Don't know" + - label: 'Firefox' + - label: 'Chrome' + - label: 'Chromium/Chromium based (i.e. Edge)' + - label: 'Safari' + - label: "Other/Don't know" - type: input id: client-browser-other attributes: @@ -151,11 +151,11 @@ body: description: | Which Nextcloud Server version are you running. options: - - "Nextcloud 27" - - "Nextcloud 28" - - "Nextcloud 29" - - "Nextcloud 30" - - "Nextcloud 31" + - 'Nextcloud 27' + - 'Nextcloud 28' + - 'Nextcloud 29' + - 'Nextcloud 30' + - 'Nextcloud 31' - "Other/Don't know" validations: required: true @@ -172,10 +172,10 @@ body: description: | Select PHP engine version serving Nextcloud Server. options: - - "PHP 8.0" - - "PHP 8.1" - - "PHP 8.2" - - "PHP 8.3" + - 'PHP 8.0' + - 'PHP 8.1' + - 'PHP 8.2' + - 'PHP 8.3' - "Other/Don't know" validations: required: true @@ -193,11 +193,11 @@ body: description: | Select Database engine serving Nextcloud Server. options: - - "MySQL" - - "MariaDB" - - "PostgreSQL" - - "SQlite" - - "Oracle" + - 'MySQL' + - 'MariaDB' + - 'PostgreSQL' + - 'SQlite' + - 'Oracle' - "Other/Don't know" validations: required: true @@ -216,10 +216,10 @@ body: Select **all** user-backends Enabled on your Nextcloud Server. _Describe in the "Additional info" section if you chose "Other"._ options: - - label: "Default user-backend _(database)_" - - label: "LDAP/ Active Directory" - - label: "SSO - SAML" - - label: "Other/Don't know" + - label: 'Default user-backend _(database)_' + - label: 'LDAP/ Active Directory' + - label: 'SSO - SAML' + - label: "Other/Don't know" - type: textarea id: server-nextcloud-log diff --git a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml index 1043368c4..7f38b94ff 100644 --- a/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml +++ b/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml @@ -1,6 +1,6 @@ -name: "Feature request: Nextcloud Polls" -description: "Suggest your idea for the improvement of Polls" -labels: ["enhancement"] +name: 'Feature request: Nextcloud Polls' +description: 'Suggest your idea for the improvement of Polls' +labels: ['enhancement'] body: - type: markdown @@ -11,7 +11,7 @@ body: - type: checkboxes id: before-posting attributes: - label: "⚠️ This issue respects the following points: ⚠️" + label: '⚠️ This issue respects the following points: ⚠️' description: All conditions are **required**. Your issue can be closed if these are checked incorrectly. options: - label: I agree to follow Nextcloud's [Code of Conduct](https://nextcloud.com/contribute/code-of-conduct/). @@ -35,6 +35,6 @@ body: - type: textarea id: additional-context attributes: - label: Additional context + label: Additional context description: | Add a screenshot or a mockup for your UI suggestion or add more context to understand the reason, why you think this is a valuable request. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index c4cd16618..45f8344e5 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,5 @@ -blank_issues_enabled: false -contact_links: - - name: ❓ Polls Community Support and Help - url: https://help.nextcloud.com/c/apps/polls/94 - about: Configuration or usage questions regarding Polls \ No newline at end of file +blank_issues_enabled: false +contact_links: + - name: ❓ Polls Community Support and Help + url: https://help.nextcloud.com/c/apps/polls/94 + about: Configuration or usage questions regarding Polls diff --git a/.github/actions/get-polls-version/action.yml b/.github/actions/get-polls-version/action.yml index 9ea28fe36..67706892f 100644 --- a/.github/actions/get-polls-version/action.yml +++ b/.github/actions/get-polls-version/action.yml @@ -1,23 +1,23 @@ # SPDX-FileCopyrightText: 2022 Nextcloud contributors # SPDX-License-Identifier: AGPL-3.0-or-later name: Read polls version from info.xml -inputs: +inputs: skip-check: description: Do not check tag against version required: false - type: boolean + type: boolean default: false outputs: - app-version: + app-version: description: 'Version string from app' value: ${{ steps.appinfo.outputs.info }} - tag-version: + tag-version: description: 'Version string from tag' value: ${{ steps.gettag.outputs.VERSION }} runs: - using: "composite" + using: 'composite' steps: - name: Get app version from appinfo/info.xml id: appinfo diff --git a/.github/actions/setup-composer/action.yml b/.github/actions/setup-composer/action.yml index 39b11a875..db3b01f14 100644 --- a/.github/actions/setup-composer/action.yml +++ b/.github/actions/setup-composer/action.yml @@ -26,12 +26,12 @@ inputs: default: '' outputs: - cache-hit: + cache-hit: description: 'Return cache hit' value: ${{ steps.cache-composer.outputs.cache-hit }} runs: - using: "composite" + using: 'composite' steps: - name: Use or setup caching composer packages (${{ inputs.mode }}) uses: actions/cache@v4 diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index 7da1e9463..4d00f297d 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -8,12 +8,12 @@ inputs: description: 'Node version to use' outputs: - cache-hit: + cache-hit: description: 'Return cache hit' value: ${{ steps.cache-modules.outputs.cache-hit }} runs: - using: "composite" + using: 'composite' steps: - name: Use or setup caching npm modules uses: actions/cache@v4 @@ -36,4 +36,4 @@ runs: - name: Install dependencies if: steps.cache-modules.outputs.cache-hit != 'true' run: npm ci - shell: bash \ No newline at end of file + shell: bash diff --git a/.github/actions/setup-server/action.yml b/.github/actions/setup-server/action.yml index fa1149a47..e654f0906 100644 --- a/.github/actions/setup-server/action.yml +++ b/.github/actions/setup-server/action.yml @@ -52,7 +52,7 @@ inputs: desrcription: 'Password of the admin user (Default: password)' runs: - using: "composite" + using: 'composite' steps: - name: Checkout server ${{ inputs.server-version }} uses: actions/checkout@v4 diff --git a/.github/dependabot.yml b/.github/dependabot.yml index af70bcf3f..23e9b8dca 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,27 +2,27 @@ # SPDX-License-Identifier: AGPL-3.0-or-later version: 2 updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "03:00" - timezone: Europe/Paris - open-pull-requests-limit: 10 - ignore: - - dependency-name: linkify-urls - versions: - - ">= 3.0.a" - - "< 3.1" - - dependency-name: linkify-urls - versions: - - ">= 3.1.a" - - "< 3.2" -- package-ecosystem: composer - directory: "/" - schedule: - interval: weekly - day: saturday - time: "03:00" - timezone: Europe/Paris - open-pull-requests-limit: 10 + - package-ecosystem: npm + directory: '/' + schedule: + interval: daily + time: '03:00' + timezone: Europe/Paris + open-pull-requests-limit: 10 + ignore: + - dependency-name: linkify-urls + versions: + - '>= 3.0.a' + - '< 3.1' + - dependency-name: linkify-urls + versions: + - '>= 3.1.a' + - '< 3.2' + - package-ecosystem: composer + directory: '/' + schedule: + interval: weekly + day: saturday + time: '03:00' + timezone: Europe/Paris + open-pull-requests-limit: 10 diff --git a/.github/release.yml b/.github/release.yml index bdd386788..52b0260ae 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -36,4 +36,4 @@ changelog: - performance - title: Other Changes labels: - - "*" + - '*' diff --git a/.github/workflows/lint-eslint.yml b/.github/workflows/lint-eslint.yml new file mode 100644 index 000000000..e25d8ec26 --- /dev/null +++ b/.github/workflows/lint-eslint.yml @@ -0,0 +1,98 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Lint eslint + +on: pull_request + +permissions: + contents: read + +concurrency: + group: lint-eslint-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'src/**' + - 'appinfo/info.xml' + - 'package.json' + - 'package-lock.json' + - 'tsconfig.json' + - '.eslintrc.*' + - '.eslintignore' + - '**.js' + - '**.ts' + - '**.vue' + + lint: + runs-on: ubuntu-latest + + needs: changes + if: needs.changes.outputs.src != 'false' + + name: NPM lint + + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Read package.json node and npm engines version + uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3 + id: versions + with: + fallbackNode: '^20' + fallbackNpm: '^10' + + - name: Set up node ${{ steps.versions.outputs.nodeVersion }} + uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + with: + node-version: ${{ steps.versions.outputs.nodeVersion }} + + - name: Set up npm ${{ steps.versions.outputs.npmVersion }} + run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}' + + - name: Install dependencies + env: + CYPRESS_INSTALL_BINARY: 0 + PUPPETEER_SKIP_DOWNLOAD: true + run: npm ci + + - name: Lint + run: npm run lint + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes, lint] + + if: always() + + # This is the summary, we just avoid to rename it so that branch protection rules still match + name: eslint + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.lint.result != 'success' }}; then exit 1; fi \ No newline at end of file diff --git a/.github/workflows/lint-info-xml.yml b/.github/workflows/lint-info-xml.yml new file mode 100644 index 000000000..5781613fa --- /dev/null +++ b/.github/workflows/lint-info-xml.yml @@ -0,0 +1,36 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Lint info.xml + +on: pull_request + +permissions: + contents: read + +concurrency: + group: lint-info-xml-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + xml-linters: + runs-on: ubuntu-latest-low + + name: info.xml lint + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Download schema + run: wget https://raw.githubusercontent.com/nextcloud/appstore/master/nextcloudappstore/api/v1/release/info.xsd + + - name: Lint info.xml + uses: ChristophWurst/xmllint-action@36f2a302f84f8c83fceea0b9c59e1eb4a616d3c1 # v1.2 + with: + xml-file: ./appinfo/info.xml + xml-schema-file: ./info.xsd \ No newline at end of file diff --git a/.github/workflows/lint-php-cs.yml b/.github/workflows/lint-php-cs.yml new file mode 100644 index 000000000..29fc919b0 --- /dev/null +++ b/.github/workflows/lint-php-cs.yml @@ -0,0 +1,48 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Lint php-cs + +on: pull_request + +permissions: + contents: read + +concurrency: + group: lint-php-cs-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + + name: php-cs + + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Get php version + id: versions + uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1 + + - name: Set up php${{ steps.versions.outputs.php-available }} + uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 + with: + php-version: ${{ steps.versions.outputs.php-available }} + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite + coverage: none + ini-file: development + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: composer i + + - name: Lint + run: composer run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 ) \ No newline at end of file diff --git a/.github/workflows/lint-php.yml b/.github/workflows/lint-php.yml new file mode 100644 index 000000000..734c286f4 --- /dev/null +++ b/.github/workflows/lint-php.yml @@ -0,0 +1,70 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Lint php + +on: pull_request + +permissions: + contents: read + +concurrency: + group: lint-php-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + matrix: + runs-on: ubuntu-latest-low + outputs: + php-versions: ${{ steps.versions.outputs.php-versions }} + steps: + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Get version matrix + id: versions + uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.0.0 + + php-lint: + runs-on: ubuntu-latest + needs: matrix + strategy: + matrix: + php-versions: ${{fromJson(needs.matrix.outputs.php-versions)}} + + name: php-lint + + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 + with: + php-version: ${{ matrix.php-versions }} + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite + coverage: none + ini-file: development + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Lint + run: composer run lint + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: php-lint + + if: always() + + name: php-lint-summary + + steps: + - name: Summary status + run: if ${{ needs.php-lint.result != 'success' && needs.php-lint.result != 'skipped' }}; then exit 1; fi \ No newline at end of file diff --git a/.github/workflows/lint-prettier.yml b/.github/workflows/lint-prettier.yml new file mode 100644 index 000000000..e2d47400d --- /dev/null +++ b/.github/workflows/lint-prettier.yml @@ -0,0 +1,91 @@ +# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Lint prettier + +on: pull_request + +permissions: + contents: read + +concurrency: + group: lint-prettier-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes: + runs-on: ubuntu-latest + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'lib/**' + - 'appinfo/info.xml' + - 'package.json' + - 'package-lock.json' + - 'tsconfig.json' + - '.prettierignore' + - '**.js' + - '**.ts' + - '**.vue' + - '**.yml' + - '**.md' + + lint: + runs-on: ubuntu-latest + + needs: changes + if: needs.changes.outputs.src != 'false' + + name: NPM format + + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Read package.json node and npm engines version + uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3 + id: versions + with: + fallbackNode: '^20' + fallbackNpm: '^10' + + - name: Set up node ${{ steps.versions.outputs.nodeVersion }} + uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v3 + with: + node-version: ${{ steps.versions.outputs.nodeVersion }} + + - name: Set up npm ${{ steps.versions.outputs.npmVersion }} + run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}" + + - name: Install dependencies + env: + CYPRESS_INSTALL_BINARY: 0 + PUPPETEER_SKIP_DOWNLOAD: true + run: npm ci + + - name: Format + run: npm run format + + summary: + permissions: + contents: none + runs-on: ubuntu-latest + needs: [changes, lint] + + if: always() + + # This is the summary, we just avoid to rename it so that branch protection rules still match + name: prettier + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.lint.result != 'success' }}; then exit 1; fi \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index a1430efa8..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,66 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Nextcloud contributors -# SPDX-License-Identifier: AGPL-3.0-or-later -name: Lint - -on: - pull_request: - push: - branches: - - main - - master* - - next - - stable* - -jobs: - php-cs: - runs-on: ubuntu-latest - - strategy: - matrix: - php-versions: ['8.1', '8.2', '8.3'] - - name: PHP-CS - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup composer and PHP - uses: ./.github/actions/setup-composer - with: - php-version: ${{ matrix.php-versions }} - php-tools: composer - - - name: Run coding standards check - run: composer run cs:check - - eslint: - runs-on: ubuntu-latest - - name: ESLint - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup node - uses: ./.github/actions/setup-node - - - name: Run eslint - run: npm run lint - - stylelint: - runs-on: ubuntu-latest - - name: Stylelint - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup node - uses: ./.github/actions/setup-node - - - name: Run stylelint - run: npm run stylelint - diff --git a/.github/workflows/phpunit-mariadb.yml b/.github/workflows/phpunit-mariadb.yml new file mode 100644 index 000000000..42a8466b4 --- /dev/null +++ b/.github/workflows/phpunit-mariadb.yml @@ -0,0 +1,195 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit MariaDB + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-mariadb-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + matrix: + runs-on: ubuntu-latest-low + outputs: + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + steps: + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Get version matrix + id: versions + uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1 + + changes: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + phpunit-mariadb: + runs-on: ubuntu-latest + + needs: [changes, matrix] + if: needs.changes.outputs.src != 'false' + + strategy: + matrix: + php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }} + mariadb-versions: ['10.6', '10.11'] + + name: MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + services: + mariadb: + image: ghcr.io/nextcloud/continuous-integration-mariadb-${{ matrix.mariadb-versions }}:latest + ports: + - 4444:3306/tcp + env: + MYSQL_ROOT_PASSWORD: rootpassword + options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5 + + steps: + - name: Set app env + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + path: apps/${{ env.APP_NAME }} + + - name: Checkout teams dependency + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: nextcloud/circles + ref: ${{ matrix.server-versions }} + path: apps/circles + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql + coverage: none + ini-file: development + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Set up dependencies + # Only run if phpunit config file exists + 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=mysql --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 --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes, phpunit-mariadb] + + if: always() + + name: phpunit-mariadb-summary + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-mariadb.result != 'success' }}; then exit 1; fi \ No newline at end of file diff --git a/.github/workflows/phpunit-mysql.yml b/.github/workflows/phpunit-mysql.yml new file mode 100644 index 000000000..eb3d9dabf --- /dev/null +++ b/.github/workflows/phpunit-mysql.yml @@ -0,0 +1,198 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit MySQL + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-mysql-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + matrix: + runs-on: ubuntu-latest-low + outputs: + matrix: ${{ steps.versions.outputs.sparse-matrix }} + steps: + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Get version matrix + id: versions + uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1 + with: + matrix: '{"mysql-versions": ["8.4"]}' + + changes: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + phpunit-mysql: + runs-on: ubuntu-latest + + needs: [changes, matrix] + if: needs.changes.outputs.src != 'false' + + strategy: + matrix: ${{ fromJson(needs.matrix.outputs.matrix) }} + + name: MySQL ${{ matrix.mysql-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + services: + mysql: + image: ghcr.io/nextcloud/continuous-integration-mysql-${{ matrix.mysql-versions }}:latest + ports: + - 4444:3306/tcp + env: + MYSQL_ROOT_PASSWORD: rootpassword + options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10 + + steps: + - name: Set app env + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + path: apps/${{ env.APP_NAME }} + + - name: Checkout teams dependency + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: nextcloud/circles + ref: ${{ matrix.server-versions }} + path: apps/circles + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql + coverage: none + ini-file: development + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Enable ONLY_FULL_GROUP_BY MySQL option + run: | + echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword + echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Set up dependencies + # Only run if phpunit config file exists + 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=mysql --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 --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes, phpunit-mysql] + + if: always() + + name: phpunit-mysql-summary + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-mysql.result != 'success' }}; then exit 1; fi \ No newline at end of file diff --git a/.github/workflows/phpunit-pgsql.yml b/.github/workflows/phpunit-pgsql.yml new file mode 100644 index 000000000..4ce284d7d --- /dev/null +++ b/.github/workflows/phpunit-pgsql.yml @@ -0,0 +1,196 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit PostgreSQL + +on: pull_request + +permissions: + contents: read + +concurrency: + group: phpunit-pgsql-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + matrix: + runs-on: ubuntu-latest-low + outputs: + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + steps: + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Get version matrix + id: versions + uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1 + + changes: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src }} + + steps: + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + phpunit-pgsql: + runs-on: ubuntu-latest + + needs: [changes, matrix] + if: needs.changes.outputs.src != 'false' + + strategy: + matrix: + php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }} + + name: PostgreSQL PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + 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: + - name: Set app env + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + path: apps/${{ env.APP_NAME }} + + - name: Checkout teams dependency + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: nextcloud/circles + ref: ${{ matrix.server-versions }} + path: apps/circles + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + 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@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Set up dependencies + # Only run if phpunit config file exists + 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 --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes, phpunit-pgsql] + + if: always() + + name: phpunit-pgsql-summary + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-pgsql.result != 'success' }}; then exit 1; fi diff --git a/.github/workflows/phpunit-sqlite.yml b/.github/workflows/phpunit-sqlite.yml new file mode 100644 index 000000000..8d3417297 --- /dev/null +++ b/.github/workflows/phpunit-sqlite.yml @@ -0,0 +1,196 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: PHPUnit SQLite + +on: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +concurrency: + group: phpunit-sqlite-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + matrix: + runs-on: ubuntu-latest-low + outputs: + php-version: ${{ steps.versions.outputs.php-available-list }} + server-max: ${{ steps.versions.outputs.branches-max-list }} + steps: + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Get version matrix + id: versions + uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1 + + changes: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + phpunit-sqlite: + runs-on: ubuntu-latest + + needs: [changes, matrix] + if: needs.changes.outputs.src != 'false' + + strategy: + matrix: + php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }} + server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }} + + name: SQLite PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }} + + steps: + - name: Set app env + run: | + # Split and keep last + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV + + - name: Checkout server + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + submodules: true + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + path: apps/${{ env.APP_NAME }} + + - name: Checkout teams app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: nextcloud/circles + ref: ${{ matrix.server-versions }} + path: apps/circles + + - name: Checkout analytics app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: rello/analytics + ref: master + path: apps/analytics + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 + with: + php-version: ${{ matrix.php-versions }} + # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite + coverage: xdebug + ini-file: development + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check composer file existence + id: check_composer + uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0 + with: + files: apps/${{ env.APP_NAME }}/composer.json + + - name: Set up dependencies + # Only run if phpunit config file exists + 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=sqlite --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 --force ${{ env.APP_NAME }} + + - name: Check PHPUnit script is defined + id: check_phpunit + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:unit ' | wc -l | grep 1 + + - name: PHPUnit + # Only run if phpunit config file exists + if: steps.check_phpunit.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:unit + + - name: Check PHPUnit integration script is defined + id: check_integration + continue-on-error: true + working-directory: apps/${{ env.APP_NAME }} + run: | + composer run --list | grep '^ test:integration ' | wc -l | grep 1 + + - name: Run Nextcloud + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + run: php -S localhost:8080 & + + - name: PHPUnit integration + # Only run if phpunit integration config file exists + if: steps.check_integration.outcome == 'success' + working-directory: apps/${{ env.APP_NAME }} + run: composer run test:integration + + - name: Print logs + if: always() + run: | + cat data/nextcloud.log + + - name: Skipped + # Fail the action when neither unit nor integration tests ran + if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure' + run: | + echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts' + exit 1 + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes, phpunit-sqlite] + + if: always() + + name: phpunit-sqlite-summary + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-sqlite.result != 'success' }}; then exit 1; fi \ No newline at end of file diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml deleted file mode 100644 index f45222ae7..000000000 --- a/.github/workflows/phpunit.yml +++ /dev/null @@ -1,137 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Nextcloud contributors -# SPDX-License-Identifier: AGPL-3.0-or-later -name: PHPUnit - -on: - pull_request: - push: - branches: - - main - - master* - - next - - stable* - -env: - APP_NAME: polls - SERVER_PATH: server - DB_USER: root - DB_PASSWORD: rootpassword - DB_NAME: nextcloud - -jobs: - sqlite: - runs-on: ubuntu-latest - - strategy: - # do not stop on another job's failure - fail-fast: false - matrix: - php-versions: ['8.1'] - server-versions: ['master'] - - name: SQLite - - steps: - - uses: actions/checkout@v4 - with: - path: src - - - name: Setup server - uses: ./src/.github/actions/setup-server - with: - server-version: ${{ matrix.server-versions }} - php-version: ${{ matrix.php-versions }} - server-path: ${{ env.SERVER_PATH }} - db-engine: sqlite - - - name: PHPUnit - working-directory: ${{ env.SERVER_PATH }}/apps/${{ env.APP_NAME }} - run: composer run phpunit:unit - - - name: PHPUnit integration - working-directory: ${{ env.SERVER_PATH }}/apps/${{ env.APP_NAME }} - run: composer run phpunit:integration - - mysql: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - php-versions: ['8.2'] - server-versions: ['master'] - - name: MySQL - - services: - mysql: - image: mysql:8.0 - # map port fix to 4444 for mysql - ports: - - 4444:3306/tcp - env: - MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }} - options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5 - - steps: - - uses: actions/checkout@v4 - with: - path: src - - - name: Setup server - uses: ./src/.github/actions/setup-server - with: - server-version: ${{ matrix.server-versions }} - php-version: ${{ matrix.php-versions }} - server-path: ${{ env.SERVER_PATH }} - db-engine: 'mysql' - - - name: PHPUnit - working-directory: ${{ env.SERVER_PATH }}/apps/${{ env.APP_NAME }} - run: composer run phpunit:unit - - - name: PHPUnit integration - working-directory: ${{ env.SERVER_PATH }}/apps/${{ env.APP_NAME }} - run: composer run phpunit:integration - - pgsql: - runs-on: ubuntu-latest - strategy: - # do not stop on another job's failure - fail-fast: false - matrix: - php-versions: ['8.3'] - server-versions: ['master'] - - name: PostgreSQL - - services: - postgres: - image: postgres:14.5-bullseye - # map port fix to 4445 for pgsql - ports: - - 4445:5432/tcp - env: - POSTGRES_USER: ${{ env.DB_USER }} - POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }} - POSTGRES_DB: ${{ env.DB_NAME }} - options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5 - - steps: - - uses: actions/checkout@v4 - with: - path: src - - name: Prepare server - uses: ./src/.github/actions/setup-server - with: - server-version: ${{ matrix.server-versions }} - php-version: ${{ matrix.php-versions }} - server-path: ${{ env.SERVER_PATH }} - db-engine: 'pgsql' - - - name: PHPUnit - working-directory: ${{ env.SERVER_PATH }}/apps/${{ env.APP_NAME }} - run: composer run phpunit:unit - - - name: PHPUnit integration - working-directory: ${{ env.SERVER_PATH }}/apps/${{ env.APP_NAME }} - run: composer run phpunit:integration diff --git a/.github/workflows/psalm-matrix.yml b/.github/workflows/psalm-matrix.yml new file mode 100644 index 000000000..2b273d0e3 --- /dev/null +++ b/.github/workflows/psalm-matrix.yml @@ -0,0 +1,78 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization +# +# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Static analysis + +on: + pull_request: + push: + branches: + - main + +concurrency: + group: psalm-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + matrix: + runs-on: ubuntu-latest-low + outputs: + ocp-matrix: ${{ steps.versions.outputs.ocp-matrix }} + steps: + - name: Checkout app + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Get version matrix + id: versions + uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1 + + static-analysis: + runs-on: ubuntu-latest + needs: matrix + strategy: + # do not stop on another job's failure + fail-fast: false + matrix: ${{ fromJson(needs.matrix.outputs.ocp-matrix) }} + + name: static-psalm-analysis ${{ matrix.ocp-version }} + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Set up php${{ matrix.php-versions }} + uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 + with: + php-version: ${{ matrix.php-versions }} + extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite + coverage: none + ini-file: development + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: | + composer remove nextcloud/ocp --dev + composer i + + + - name: Install dependencies + run: composer require --dev 'nextcloud/ocp:${{ matrix.ocp-version }}' --ignore-platform-reqs --with-dependencies + + - name: Run coding standards check + run: composer run psalm + + summary: + runs-on: ubuntu-latest-low + needs: static-analysis + + if: always() + + name: static-psalm-analysis-summary + + steps: + - name: Summary status + run: if ${{ needs.static-analysis.result != 'success' }}; then exit 1; fi \ No newline at end of file diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index b685274ba..000000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,40 +0,0 @@ -# SPDX-FileCopyrightText: 2021 Nextcloud contributors -# SPDX-License-Identifier: AGPL-3.0-or-later -name: Static analysis - -on: - pull_request: - push: - branches: - - main - - master* - - next - - stable* - -jobs: - psalm-master: - runs-on: ubuntu-latest - strategy: - matrix: - ocp-version: ['stable29'] - php-versions: ['8.1', '8.2', '8.3'] - - name: Psalm - - steps: - - uses: actions/checkout@v4 - - - name: Setup composer and PHP - uses: ./.github/actions/setup-composer - with: - php-version: ${{ matrix.php-versions }} - php-tools: composer - - - name: Install Nextcloud API - run: composer require --dev -W nextcloud/ocp:dev-${{ matrix.ocp-version }} - - - name: Install symfony/console - run: composer require -W symfony/console - - - name: Run coding standards check - run: composer run psalm diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index c6771ea03..403098675 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -5,14 +5,12 @@ * SPDX-FileCopyrightText: 2021 Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -require_once 'vendor/autoload.php'; +require_once './vendor-bin/php-cs-fixer/vendor/autoload.php'; use Nextcloud\CodingStandard\Config; -use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; $config = new Config(); $config - ->setParallelConfig(ParallelConfigFactory::detect()) ->getFinder() ->ignoreVCSIgnored(true) ->notPath('build') diff --git a/.prettierignore b/.prettierignore index 925aa6610..87eb508ed 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,6 +5,9 @@ **/.svn **/.hg +# Github workflows +.github/workflows/ + # 3rdparty dependencies **/node_modules **/vendor @@ -13,12 +16,20 @@ # Compiled JS output js/ +# Handled by transifex +l10n/ + +# OpenAPI +openapi.json + # PHP appinfo/ lib/ tests/ templates/ **/*.php +composer.json +composer.lock # individual files screenshots/ diff --git a/.prettierrc.json b/.prettierrc.json index 309109c68..68b03a97b 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1 +1 @@ -"@nextcloud/prettier-config" \ No newline at end of file +"@nextcloud/prettier-config" diff --git a/_config.yml b/_config.yml index d635e43cd..14e49d15d 100644 --- a/_config.yml +++ b/_config.yml @@ -1,3 +1,3 @@ # SPDX-FileCopyrightText: 2018 Nextcloud contributors # SPDX-License-Identifier: AGPL-3.0-or-later -theme: jekyll-theme-slate \ No newline at end of file +theme: jekyll-theme-slate diff --git a/appinfo/info.xml b/appinfo/info.xml index 6dde386bc..721a617db 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,56 +6,39 @@ A polls app, similar to Doodle/Dudle with the possibility to restrict access (members, certain groups/users, hidden and public). 8.0.0-alpha13 agpl + Vinzenz Rosenkranz René Gieling Kai Schröer + https://github.com/nextcloud/polls/blob/master/README.md + tools social organization + https://github.com/nextcloud/polls https://help.nextcloud.com/tag/polls-app https://github.com/nextcloud/polls/issues https://github.com/nextcloud/polls.git + https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/overview.png https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/vote.png https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/edit-poll.png + - + - - - OCA\Polls\Provider\ActivityProvider - - - OCA\Polls\Filter\ActivityFilter - - + OCA\Polls\Cron\NotificationCron OCA\Polls\Cron\JanitorCron OCA\Polls\Cron\AutoReminderCron - - OCA\Polls\Command\Share\Add - OCA\Polls\Command\Share\Remove - OCA\Polls\Command\Db\Purge - OCA\Polls\Command\Db\RemoveIndices - OCA\Polls\Command\Db\Rebuild - OCA\Polls\Command\Db\CreateIndices - OCA\Polls\Command\Db\CleanMigrations - OCA\Polls\Command\Db\ResetWatch - OCA\Polls\Command\Poll\TransferOwnership - - - OCA\Polls\Settings\AdminSection - OCA\Polls\Settings\PersonalSection - OCA\Polls\Settings\AdminSettings - OCA\Polls\Settings\PersonalSettings - + OCA\Polls\Migration\RepairSteps\RemoveObsoleteMigrations @@ -71,6 +54,35 @@ OCA\Polls\Migration\RepairSteps\Install + + + OCA\Polls\Command\Share\Add + OCA\Polls\Command\Share\Remove + OCA\Polls\Command\Db\Purge + OCA\Polls\Command\Db\RemoveIndices + OCA\Polls\Command\Db\Rebuild + OCA\Polls\Command\Db\CreateIndices + OCA\Polls\Command\Db\CleanMigrations + OCA\Polls\Command\Db\ResetWatch + OCA\Polls\Command\Poll\TransferOwnership + + + + OCA\Polls\Settings\AdminSettings + OCA\Polls\Settings\AdminSection + OCA\Polls\Settings\PersonalSettings + OCA\Polls\Settings\PersonalSection + + + + + OCA\Polls\Filter\ActivityFilter + + + OCA\Polls\Provider\ActivityProvider + + + Polls @@ -79,4 +91,5 @@ 77 + \ No newline at end of file diff --git a/composer.json b/composer.json index eb1c5e4cf..2f7fb0364 100644 --- a/composer.json +++ b/composer.json @@ -39,15 +39,15 @@ "doctrine/dbal": "3.8.6", "league/factory-muffin": "^3.0", "league/factory-muffin-faker": "^2.0", - "nextcloud/coding-standard": "^1.0", "nextcloud/ocp": "dev-stable29" }, "scripts": { + "lint": "find . -name \\*.php -not -path './vendor*/*' -print0 | xargs -0 -n1 php -l", "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", "psalm": "psalm --no-diff", - "phpunit:unit": "phpunit -c tests/phpunit.xml", - "phpunit:integration": "phpunit -c tests/phpunit.xml", + "test:unit": "phpunit -c tests/phpunit.xml", + "test:integration": "phpunit -c tests/phpunit.xml", "psalm:fix": "psalm --alter --php-version=8.0 --issues=MissingReturnType,InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType", "psalm:info": "psalm --no-diff --show-info=true", "psalm:baseline": "psalm --set-baseline=psalm-baseline.xml", diff --git a/composer.lock b/composer.lock index a239a7f14..a4838288c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "16e53d6f3032c0ab17cb801f8854843d", + "content-hash": "9dce06701b18a98189711a5f91af4828", "packages": [ { "name": "dflydev/dot-access-data", @@ -1128,52 +1128,6 @@ }, "time": "2024-11-21T13:46:39+00:00" }, - { - "name": "kubawerlos/php-cs-fixer-custom-fixers", - "version": "v3.22.0", - "source": { - "type": "git", - "url": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers.git", - "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/8701394f0c7cd450ac4fa577d24589122c1d5d5e", - "reference": "8701394f0c7cd450ac4fa577d24589122c1d5d5e", - "shasum": "" - }, - "require": { - "ext-filter": "*", - "ext-tokenizer": "*", - "friendsofphp/php-cs-fixer": "^3.61.1", - "php": "^7.4 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.6.4 || ^10.5.29" - }, - "type": "library", - "autoload": { - "psr-4": { - "PhpCsFixerCustomFixers\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kuba Werłos", - "email": "werlos@gmail.com" - } - ], - "description": "A set of custom fixers for PHP CS Fixer", - "support": { - "issues": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/issues", - "source": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/tree/v3.22.0" - }, - "time": "2024-08-16T20:44:35+00:00" - }, { "name": "league/factory-muffin", "version": "v3.3.0", @@ -1317,60 +1271,18 @@ ], "time": "2020-12-13T15:53:28+00:00" }, - { - "name": "nextcloud/coding-standard", - "version": "v1.3.2", - "source": { - "type": "git", - "url": "https://github.com/nextcloud/coding-standard.git", - "reference": "9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d", - "reference": "9c719c4747fa26efc12f2e8b21c14a9a75c6ba6d", - "shasum": "" - }, - "require": { - "kubawerlos/php-cs-fixer-custom-fixers": "^3.22", - "php": "^7.3|^8.0", - "php-cs-fixer/shim": "^3.17" - }, - "type": "library", - "autoload": { - "psr-4": { - "Nextcloud\\CodingStandard\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christoph Wurst", - "email": "christoph@winzerhof-wurst.at" - } - ], - "description": "Nextcloud coding standards for the php cs fixer", - "support": { - "issues": "https://github.com/nextcloud/coding-standard/issues", - "source": "https://github.com/nextcloud/coding-standard/tree/v1.3.2" - }, - "time": "2024-10-14T16:49:05+00:00" - }, { "name": "nextcloud/ocp", "version": "dev-stable29", "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "e73c73fdcc8d174e5c6fe5f591d561030d41c0a3" + "reference": "709320d453740d62b8d355b42da6704e993836bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/e73c73fdcc8d174e5c6fe5f591d561030d41c0a3", - "reference": "e73c73fdcc8d174e5c6fe5f591d561030d41c0a3", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/709320d453740d62b8d355b42da6704e993836bb", + "reference": "709320d453740d62b8d355b42da6704e993836bb", "shasum": "" }, "require": { @@ -1401,59 +1313,7 @@ "issues": "https://github.com/nextcloud-deps/ocp/issues", "source": "https://github.com/nextcloud-deps/ocp/tree/stable29" }, - "time": "2024-11-26T00:46:04+00:00" - }, - { - "name": "php-cs-fixer/shim", - "version": "v3.65.0", - "source": { - "type": "git", - "url": "https://github.com/PHP-CS-Fixer/shim.git", - "reference": "4983ec79b9dee926695ac324ea6e8d291935525d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/4983ec79b9dee926695ac324ea6e8d291935525d", - "reference": "4983ec79b9dee926695ac324ea6e8d291935525d", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-tokenizer": "*", - "php": "^7.4 || ^8.0" - }, - "replace": { - "friendsofphp/php-cs-fixer": "self.version" - }, - "suggest": { - "ext-dom": "For handling output formats in XML", - "ext-mbstring": "For handling non-UTF8 characters." - }, - "bin": [ - "php-cs-fixer", - "php-cs-fixer.phar" - ], - "type": "application", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Dariusz Rumiński", - "email": "dariusz.ruminski@gmail.com" - } - ], - "description": "A tool to automatically fix PHP code style", - "support": { - "issues": "https://github.com/PHP-CS-Fixer/shim/issues", - "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.65.0" - }, - "time": "2024-11-25T00:39:41+00:00" + "time": "2025-03-05T00:45:45+00:00" }, { "name": "psr/cache", @@ -1668,5 +1528,5 @@ "platform-overrides": { "php": "8.1" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/jsconfig.json b/jsconfig.json index f7df6e8f5..815ea28af 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,12 +1,8 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es6" - }, - "exclude": [ - "node_modules" - ], - "include": [ - "src/**/*" - ] -} \ No newline at end of file +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6" + }, + "exclude": ["node_modules"], + "include": ["src/**/*"] +} diff --git a/lib/Db/Poll.php b/lib/Db/Poll.php index 8e9534042..0ae874f43 100644 --- a/lib/Db/Poll.php +++ b/lib/Db/Poll.php @@ -175,31 +175,31 @@ class Poll extends EntityWithUser implements JsonSerializable { protected int $participantsCount = 0; public function __construct() { - $this->addType('created', 'int'); - $this->addType('expire', 'int'); - $this->addType('deleted', 'int'); - $this->addType('anonymous', 'int'); - $this->addType('allowComment', 'int'); - $this->addType('allowMaybe', 'int'); - $this->addType('proposalsExpire', 'int'); - $this->addType('voteLimit', 'int'); - $this->addType('optionLimit', 'int'); - $this->addType('adminAccess', 'int'); - $this->addType('hideBookedUp', 'int'); - $this->addType('useNo', 'int'); - $this->addType('lastInteraction', 'int'); + $this->addType('created', 'integer'); + $this->addType('expire', 'integer'); + $this->addType('deleted', 'integer'); + $this->addType('anonymous', 'integer'); + $this->addType('allowComment', 'integer'); + $this->addType('allowMaybe', 'integer'); + $this->addType('proposalsExpire', 'integer'); + $this->addType('voteLimit', 'integer'); + $this->addType('optionLimit', 'integer'); + $this->addType('adminAccess', 'integer'); + $this->addType('hideBookedUp', 'integer'); + $this->addType('useNo', 'integer'); + $this->addType('lastInteraction', 'integer'); // joined columns - $this->addType('isCurrentUserLocked', 'int'); - $this->addType('maxDate', 'int'); - $this->addType('minDate', 'int'); - $this->addType('countOptions', 'int'); + $this->addType('isCurrentUserLocked', 'integer'); + $this->addType('maxDate', 'integer'); + $this->addType('minDate', 'integer'); + $this->addType('countOptions', 'integer'); // subqueried columns - $this->addType('currentUserVotes', 'int'); - $this->addType('currentUserVotesYes', 'int'); - $this->addType('currentUserOrphanedVotes', 'int'); - $this->addType('participantsCount', 'int'); + $this->addType('currentUserVotes', 'integer'); + $this->addType('currentUserVotesYes', 'integer'); + $this->addType('currentUserOrphanedVotes', 'integer'); + $this->addType('participantsCount', 'integer'); $this->urlGenerator = Container::queryClass(IURLGenerator::class); $this->systemSettings = Container::queryClass(SystemSettings::class); diff --git a/package.json b/package.json index a2ee50bd5..dcb78ac7a 100644 --- a/package.json +++ b/package.json @@ -12,16 +12,19 @@ "url": "git+https://github.com/nextcloud/polls.git" }, "license": "AGPL-3.0", + "type": "module", "main": "src/main.js", "scripts": { + "build": "vite --mode production build", + "dev": "NODE_ENV=development vite --mode development build", + "dev:win": "set NODE_ENV=development && vite --mode development build", + "format": "prettier --check .", + "format:fix": "prettier --write .", "lint": "eslint --ext .js,.vue src", "lint:fix": "eslint --ext .js,.vue src --fix", "stylelint": "stylelint src/**/*{.scss,.vue,.css}", "stylelint:fix": "stylelint src --fix", "version": "node update-app-version.mjs && git add ./appinfo/info.xml", - "build": "vite --mode production build", - "dev": "NODE_ENV=development vite --mode development build", - "dev:win": "set NODE_ENV=development && vite --mode development build", "watch": "NODE_ENV=development vite --mode development build --watch" }, "browserslist": [ @@ -74,7 +77,6 @@ "node": "^20.0.0", "npm": "^10.0.0" }, - "type": "module", "authors": [ { "name": "Vinzenz Rosenkranz", diff --git a/src/Api/modules/HttpApi.js b/src/Api/modules/HttpApi.js index 9940edf23..9d1939a3b 100644 --- a/src/Api/modules/HttpApi.js +++ b/src/Api/modules/HttpApi.js @@ -1,56 +1,59 @@ -/** - * SPDX-FileCopyrightText: 2023 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import axios from '@nextcloud/axios' -import { generateUrl, generateOcsUrl } from '@nextcloud/router' - -const clientSessionId = Math.random().toString(36).substring(2) - -const axiosConfig = { - baseURL: generateUrl('apps/polls/'), - headers: { - Accept: 'application/json', - 'Nc-Polls-Client-Id': clientSessionId, - 'Nc-Polls-Client-Time-Zone': Intl.DateTimeFormat().resolvedOptions().timeZone, - }, -} - -const axiosOcsConfig = { - baseURL: generateOcsUrl('apps/'), - headers: { - Accept: 'application/json', - }, -} - -const CancelToken = axios.CancelToken -const httpInstance = axios.create(axiosConfig) -const ocsInstance = axios.create(axiosOcsConfig) - -/** - * Description - * - * @param {any} apiObject apiObject - * @return {any} - */ -const createCancelTokenHandler = (apiObject) => { - const cancelTokenHandler = {} - Object.getOwnPropertyNames(apiObject) - .forEach((propertyName) => { - const cancelTokenRequestHandler = { - cancelToken: undefined, - } - - cancelTokenHandler[propertyName] = { - handleRequestCancellation: () => { - cancelTokenRequestHandler.cancelToken && cancelTokenRequestHandler.cancelToken.cancel(`${propertyName} canceled`) - cancelTokenRequestHandler.cancelToken = CancelToken.source() - return cancelTokenRequestHandler.cancelToken - }, - } - }) - - return cancelTokenHandler -} - -export { ocsInstance, httpInstance, createCancelTokenHandler } +/** + * SPDX-FileCopyrightText: 2023 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import axios from '@nextcloud/axios' +import { generateUrl, generateOcsUrl } from '@nextcloud/router' + +const clientSessionId = Math.random().toString(36).substring(2) + +const axiosConfig = { + baseURL: generateUrl('apps/polls/'), + headers: { + Accept: 'application/json', + 'Nc-Polls-Client-Id': clientSessionId, + 'Nc-Polls-Client-Time-Zone': + Intl.DateTimeFormat().resolvedOptions().timeZone, + }, +} + +const axiosOcsConfig = { + baseURL: generateOcsUrl('apps/'), + headers: { + Accept: 'application/json', + }, +} + +const CancelToken = axios.CancelToken +const httpInstance = axios.create(axiosConfig) +const ocsInstance = axios.create(axiosOcsConfig) + +/** + * Description + * + * @param {any} apiObject apiObject + * @return {any} + */ +const createCancelTokenHandler = (apiObject) => { + const cancelTokenHandler = {} + Object.getOwnPropertyNames(apiObject).forEach((propertyName) => { + const cancelTokenRequestHandler = { + cancelToken: undefined, + } + + cancelTokenHandler[propertyName] = { + handleRequestCancellation: () => { + cancelTokenRequestHandler.cancelToken && + cancelTokenRequestHandler.cancelToken.cancel( + `${propertyName} canceled`, + ) + cancelTokenRequestHandler.cancelToken = CancelToken.source() + return cancelTokenRequestHandler.cancelToken + }, + } + }) + + return cancelTokenHandler +} + +export { ocsInstance, httpInstance, createCancelTokenHandler } diff --git a/src/Api/modules/activity.js b/src/Api/modules/activity.js index 57addf4a5..d1fe5ada7 100644 --- a/src/Api/modules/activity.js +++ b/src/Api/modules/activity.js @@ -1,27 +1,30 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { ocsInstance, createCancelTokenHandler } from './HttpApi.js' - -const activity = { - getActivities(pollId) { - const response = ocsInstance.request({ - method: 'GET', - url: 'activity/api/v2/activity/polls', - params: { - format: 'json', - since: 0, - limit: 50, - object_type: 'poll', - object_id: pollId, - }, - cancelToken: cancelTokenHandlerObject[this.getActivities.name].handleRequestCancellation().token, - }) - return response - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(activity) - -export default activity +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { ocsInstance, createCancelTokenHandler } from './HttpApi.js' + +const activity = { + getActivities(pollId) { + const response = ocsInstance.request({ + method: 'GET', + url: 'activity/api/v2/activity/polls', + params: { + format: 'json', + since: 0, + limit: 50, + object_type: 'poll', + object_id: pollId, + }, + cancelToken: + cancelTokenHandlerObject[ + this.getActivities.name + ].handleRequestCancellation().token, + }) + return response + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(activity) + +export default activity diff --git a/src/Api/modules/admin.js b/src/Api/modules/admin.js index 0477a4d37..1a6fb7417 100644 --- a/src/Api/modules/admin.js +++ b/src/Api/modules/admin.js @@ -1,34 +1,43 @@ -/** - * SPDX-FileCopyrightText: 2024 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const adminJobs = { - runAutoReminder() { - return httpInstance.request({ - method: 'GET', - url: 'administration/autoreminder/run', - cancelToken: cancelTokenHandlerObject[this.runAutoReminder.name].handleRequestCancellation().token, - }) - }, - runJanitor() { - return httpInstance.request({ - method: 'GET', - url: 'administration/janitor/run', - cancelToken: cancelTokenHandlerObject[this.runJanitor.name].handleRequestCancellation().token, - }) - }, - runNotification() { - return httpInstance.request({ - method: 'GET', - url: 'administration/notification/run', - cancelToken: cancelTokenHandlerObject[this.runNotification.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(adminJobs) - -export default adminJobs +/** + * SPDX-FileCopyrightText: 2024 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const adminJobs = { + runAutoReminder() { + return httpInstance.request({ + method: 'GET', + url: 'administration/autoreminder/run', + cancelToken: + cancelTokenHandlerObject[ + this.runAutoReminder.name + ].handleRequestCancellation().token, + }) + }, + runJanitor() { + return httpInstance.request({ + method: 'GET', + url: 'administration/janitor/run', + cancelToken: + cancelTokenHandlerObject[ + this.runJanitor.name + ].handleRequestCancellation().token, + }) + }, + runNotification() { + return httpInstance.request({ + method: 'GET', + url: 'administration/notification/run', + cancelToken: + cancelTokenHandlerObject[ + this.runNotification.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(adminJobs) + +export default adminJobs diff --git a/src/Api/modules/appSettings.js b/src/Api/modules/appSettings.js index 0a4e685f0..5cfa86e0a 100644 --- a/src/Api/modules/appSettings.js +++ b/src/Api/modules/appSettings.js @@ -1,45 +1,57 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const appSettings = { - getAppSettings() { - return httpInstance.request({ - method: 'GET', - url: 'settings/app', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getAppSettings.name].handleRequestCancellation().token, - }) - }, - - writeAppSettings(appSettings) { - return httpInstance.request({ - method: 'POST', - url: 'settings/app', - data: { appSettings }, - cancelToken: cancelTokenHandlerObject[this.writeAppSettings.name].handleRequestCancellation().token, - }) - }, - - getGroups(query) { - return httpInstance.request({ - method: 'GET', - url: `groups${query.trim() ? `/${query.trim()}` : ''}`, - cancelToken: cancelTokenHandlerObject[this.getGroups.name].handleRequestCancellation().token, - }) - }, - - getUsers(query) { - return httpInstance.request({ - method: 'GET', - url: `search/users${query.trim() ? `/${query.trim()}` : ''}`, - cancelToken: cancelTokenHandlerObject[this.getUsers.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(appSettings) - -export default appSettings +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const appSettings = { + getAppSettings() { + return httpInstance.request({ + method: 'GET', + url: 'settings/app', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getAppSettings.name + ].handleRequestCancellation().token, + }) + }, + + writeAppSettings(appSettings) { + return httpInstance.request({ + method: 'POST', + url: 'settings/app', + data: { appSettings }, + cancelToken: + cancelTokenHandlerObject[ + this.writeAppSettings.name + ].handleRequestCancellation().token, + }) + }, + + getGroups(query) { + return httpInstance.request({ + method: 'GET', + url: `groups${query.trim() ? `/${query.trim()}` : ''}`, + cancelToken: + cancelTokenHandlerObject[ + this.getGroups.name + ].handleRequestCancellation().token, + }) + }, + + getUsers(query) { + return httpInstance.request({ + method: 'GET', + url: `search/users${query.trim() ? `/${query.trim()}` : ''}`, + cancelToken: + cancelTokenHandlerObject[ + this.getUsers.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(appSettings) + +export default appSettings diff --git a/src/Api/modules/calendar.js b/src/Api/modules/calendar.js index 8bc9a31fe..63eda6877 100644 --- a/src/Api/modules/calendar.js +++ b/src/Api/modules/calendar.js @@ -1,31 +1,37 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const calendar = { - getCalendars() { - return httpInstance.request({ - method: 'GET', - url: 'calendars', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getCalendars.name].handleRequestCancellation().token, - }) - }, - getEvents(optionId) { - return httpInstance.request({ - method: 'GET', - url: `option/${optionId}/events`, - params: { - tz: Intl.DateTimeFormat().resolvedOptions().timeZone, - time: +new Date(), - }, - cancelToken: cancelTokenHandlerObject[this.getEvents.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(calendar) - -export default calendar +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const calendar = { + getCalendars() { + return httpInstance.request({ + method: 'GET', + url: 'calendars', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getCalendars.name + ].handleRequestCancellation().token, + }) + }, + getEvents(optionId) { + return httpInstance.request({ + method: 'GET', + url: `option/${optionId}/events`, + params: { + tz: Intl.DateTimeFormat().resolvedOptions().timeZone, + time: +new Date(), + }, + cancelToken: + cancelTokenHandlerObject[ + this.getEvents.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(calendar) + +export default calendar diff --git a/src/Api/modules/comments.js b/src/Api/modules/comments.js index 87bfa8576..e9a4c528a 100644 --- a/src/Api/modules/comments.js +++ b/src/Api/modules/comments.js @@ -1,48 +1,60 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const comments = { - getComments(pollId) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}/comments`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getComments.name].handleRequestCancellation().token, - }) - }, - addComment(pollId, message) { - return httpInstance.request({ - method: 'POST', - url: `poll/${pollId}/comment`, - data: { message }, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.addComment.name].handleRequestCancellation().token, - }) - }, - - deleteComment(commentId) { - return httpInstance.request({ - method: 'DELETE', - url: `comment/${commentId}`, - params: { time: +new Date() }, - - cancelToken: cancelTokenHandlerObject[this.deleteComment.name].handleRequestCancellation().token, - }) - }, - restoreComment(commentId) { - return httpInstance.request({ - method: 'PUT', - url: `comment/${commentId}/restore`, - params: { time: +new Date() }, - - cancelToken: cancelTokenHandlerObject[this.restoreComment.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(comments) - -export default comments +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const comments = { + getComments(pollId) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}/comments`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getComments.name + ].handleRequestCancellation().token, + }) + }, + addComment(pollId, message) { + return httpInstance.request({ + method: 'POST', + url: `poll/${pollId}/comment`, + data: { message }, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.addComment.name + ].handleRequestCancellation().token, + }) + }, + + deleteComment(commentId) { + return httpInstance.request({ + method: 'DELETE', + url: `comment/${commentId}`, + params: { time: +new Date() }, + + cancelToken: + cancelTokenHandlerObject[ + this.deleteComment.name + ].handleRequestCancellation().token, + }) + }, + restoreComment(commentId) { + return httpInstance.request({ + method: 'PUT', + url: `comment/${commentId}/restore`, + params: { time: +new Date() }, + + cancelToken: + cancelTokenHandlerObject[ + this.restoreComment.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(comments) + +export default comments diff --git a/src/Api/modules/options.js b/src/Api/modules/options.js index 29325e259..989a61153 100644 --- a/src/Api/modules/options.js +++ b/src/Api/modules/options.js @@ -1,113 +1,142 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const options = { - getOptions(pollId) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}/options`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getOptions.name].handleRequestCancellation().token, - }) - }, - - addOption(option) { - return httpInstance.request({ - method: 'POST', - url: 'option', - data: { ...option }, - cancelToken: cancelTokenHandlerObject[this.addOption.name].handleRequestCancellation().token, - }) - }, - - updateOption(option) { - return httpInstance.request({ - method: 'PUT', - url: `option/${option.id}`, - // TODO: replace text with timestamp - data: { ...option }, - cancelToken: cancelTokenHandlerObject[this.updateOption.name].handleRequestCancellation().token, - }) - }, - - deleteOption(optionId) { - return httpInstance.request({ - method: 'DELETE', - url: `option/${optionId}`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.deleteOption.name].handleRequestCancellation().token, - }) - }, - - restoreOption(optionId) { - return httpInstance.request({ - method: 'PUT', - url: `option/${optionId}/restore`, - params: { time: +new Date() }, - - cancelToken: cancelTokenHandlerObject[this.restoreOption.name].handleRequestCancellation().token, - }) - }, - - addOptions(pollId, optionsBatch) { - return httpInstance.request({ - method: 'POST', - url: 'option/bulk', - data: { - pollId, - text: optionsBatch, - }, - cancelToken: cancelTokenHandlerObject[this.addOptions.name].handleRequestCancellation().token, - }) - }, - - confirmOption(optionId) { - return httpInstance.request({ - method: 'PUT', - url: `option/${optionId}/confirm`, - cancelToken: cancelTokenHandlerObject[this.confirmOption.name].handleRequestCancellation().token, - }) - }, - - reorderOptions(pollId, options) { - return httpInstance.request({ - method: 'POST', - url: `poll/${pollId}/options/reorder`, - data: { options }, - cancelToken: cancelTokenHandlerObject[this.reorderOptions.name].handleRequestCancellation().token, - }) - }, - - addOptionsSequence(optionId, step, unit, amount) { - return httpInstance.request({ - method: 'POST', - url: `option/${optionId}/sequence`, - data: { - step, - unit, - amount, - }, - cancelToken: cancelTokenHandlerObject[this.addOptionsSequence.name].handleRequestCancellation().token, - }) - }, - - shiftOptions(pollId, step, unit) { - return httpInstance.request({ - method: 'POST', - url: `poll/${pollId}/shift`, - data: { - step, - unit, - }, - cancelToken: cancelTokenHandlerObject[this.shiftOptions.name].handleRequestCancellation().token, - }) - }, - -} - -const cancelTokenHandlerObject = createCancelTokenHandler(options) - -export default options +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const options = { + getOptions(pollId) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}/options`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getOptions.name + ].handleRequestCancellation().token, + }) + }, + + addOption(option) { + return httpInstance.request({ + method: 'POST', + url: 'option', + data: { ...option }, + cancelToken: + cancelTokenHandlerObject[ + this.addOption.name + ].handleRequestCancellation().token, + }) + }, + + updateOption(option) { + return httpInstance.request({ + method: 'PUT', + url: `option/${option.id}`, + // TODO: replace text with timestamp + data: { ...option }, + cancelToken: + cancelTokenHandlerObject[ + this.updateOption.name + ].handleRequestCancellation().token, + }) + }, + + deleteOption(optionId) { + return httpInstance.request({ + method: 'DELETE', + url: `option/${optionId}`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.deleteOption.name + ].handleRequestCancellation().token, + }) + }, + + restoreOption(optionId) { + return httpInstance.request({ + method: 'PUT', + url: `option/${optionId}/restore`, + params: { time: +new Date() }, + + cancelToken: + cancelTokenHandlerObject[ + this.restoreOption.name + ].handleRequestCancellation().token, + }) + }, + + addOptions(pollId, optionsBatch) { + return httpInstance.request({ + method: 'POST', + url: 'option/bulk', + data: { + pollId, + text: optionsBatch, + }, + cancelToken: + cancelTokenHandlerObject[ + this.addOptions.name + ].handleRequestCancellation().token, + }) + }, + + confirmOption(optionId) { + return httpInstance.request({ + method: 'PUT', + url: `option/${optionId}/confirm`, + cancelToken: + cancelTokenHandlerObject[ + this.confirmOption.name + ].handleRequestCancellation().token, + }) + }, + + reorderOptions(pollId, options) { + return httpInstance.request({ + method: 'POST', + url: `poll/${pollId}/options/reorder`, + data: { options }, + cancelToken: + cancelTokenHandlerObject[ + this.reorderOptions.name + ].handleRequestCancellation().token, + }) + }, + + addOptionsSequence(optionId, step, unit, amount) { + return httpInstance.request({ + method: 'POST', + url: `option/${optionId}/sequence`, + data: { + step, + unit, + amount, + }, + cancelToken: + cancelTokenHandlerObject[ + this.addOptionsSequence.name + ].handleRequestCancellation().token, + }) + }, + + shiftOptions(pollId, step, unit) { + return httpInstance.request({ + method: 'POST', + url: `poll/${pollId}/shift`, + data: { + step, + unit, + }, + cancelToken: + cancelTokenHandlerObject[ + this.shiftOptions.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(options) + +export default options diff --git a/src/Api/modules/polls.js b/src/Api/modules/polls.js index 99e4d7884..25054b7b6 100644 --- a/src/Api/modules/polls.js +++ b/src/Api/modules/polls.js @@ -1,165 +1,219 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const polls = { - getPolls() { - return httpInstance.request({ - method: 'GET', - url: 'polls', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getPolls.name].handleRequestCancellation().token, - }) - }, - - getPollsForAdmin() { - return httpInstance.request({ - method: 'GET', - url: 'administration/polls', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getPollsForAdmin.name].handleRequestCancellation().token, - }) - }, - - getPoll(pollId) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}/poll`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getPoll.name].handleRequestCancellation().token, - }) - }, - - getFullPoll(pollId) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getPoll.name].handleRequestCancellation().token, - }) - }, - - watchPoll(pollId = 0, lastUpdated) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}/watch`, - params: { offset: lastUpdated }, - cancelToken: cancelTokenHandlerObject[this.watchPoll.name].handleRequestCancellation().token, - }) - }, - - takeOver(pollId) { - return httpInstance.request({ - method: 'PUT', - url: `administration/poll/${pollId}/takeover`, - cancelToken: cancelTokenHandlerObject[this.takeOver.name].handleRequestCancellation().token, - }) - }, - - addPoll(type, title) { - return httpInstance.request({ - method: 'POST', - url: 'poll/add', - data: { - type, - title, - }, - cancelToken: cancelTokenHandlerObject[this.addPoll.name].handleRequestCancellation().token, - }) - }, - - writePoll(pollId, poll) { - return httpInstance.request({ - method: 'PUT', - url: `poll/${pollId}`, - data: { poll }, - cancelToken: cancelTokenHandlerObject[this.writePoll.name].handleRequestCancellation().token, - }) - }, - - lockAnonymous(pollId) { - return httpInstance.request({ - method: 'PUT', - url: `poll/${pollId}/lockAnonymous`, - cancelToken: cancelTokenHandlerObject[this.lockAnonymous.name].handleRequestCancellation().token, - }) - }, - - deletePoll(pollId) { - return httpInstance.request({ - method: 'DELETE', - url: `poll/${pollId}`, - cancelToken: cancelTokenHandlerObject[this.deletePoll.name].handleRequestCancellation().token, - }) - }, - - closePoll(pollId) { - return httpInstance.request({ - method: 'PUT', - url: `poll/${pollId}/close`, - cancelToken: cancelTokenHandlerObject[this.closePoll.name].handleRequestCancellation().token, - }) - }, - - reopenPoll(pollId) { - return httpInstance.request({ - method: 'PUT', - url: `poll/${pollId}/reopen`, - cancelToken: cancelTokenHandlerObject[this.reopenPoll.name].handleRequestCancellation().token, - }) - }, - - toggleArchive(pollId) { - return httpInstance.request({ - method: 'PUT', - url: `poll/${pollId}/toggleArchive`, - cancelToken: cancelTokenHandlerObject[this.toggleArchive.name].handleRequestCancellation().token, - }) - }, - - clonePoll(pollId) { - return httpInstance.request({ - method: 'POST', - url: `poll/${pollId}/clone`, - cancelToken: cancelTokenHandlerObject[this.clonePoll.name].handleRequestCancellation().token, - }) - }, - - sendConfirmation(pollId) { - return httpInstance.request({ - method: 'POST', - url: `poll/${pollId}/confirmation`, - cancelToken: cancelTokenHandlerObject[this.sendConfirmation.name].handleRequestCancellation().token, - }) - }, - - getParticipantsEmailAddresses(pollId) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}/addresses`, - cancelToken: cancelTokenHandlerObject[this.getParticipantsEmailAddresses.name].handleRequestCancellation().token, - }) - }, - - getSubscription(pollId) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}/subscription`, - cancelToken: cancelTokenHandlerObject[this.getSubscription.name].handleRequestCancellation().token, - }) - }, - - setSubscription(pollId, subscription) { - return httpInstance.request({ - method: 'PUT', - url: `poll/${pollId}${subscription ? '/subscribe' : '/unsubscribe'}`, - cancelToken: cancelTokenHandlerObject[this.setSubscription.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(polls) - -export default polls +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const polls = { + getPolls() { + return httpInstance.request({ + method: 'GET', + url: 'polls', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getPolls.name + ].handleRequestCancellation().token, + }) + }, + + getPollsForAdmin() { + return httpInstance.request({ + method: 'GET', + url: 'administration/polls', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getPollsForAdmin.name + ].handleRequestCancellation().token, + }) + }, + + getPoll(pollId) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}/poll`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getPoll.name + ].handleRequestCancellation().token, + }) + }, + + getFullPoll(pollId) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getPoll.name + ].handleRequestCancellation().token, + }) + }, + + watchPoll(pollId = 0, lastUpdated) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}/watch`, + params: { offset: lastUpdated }, + cancelToken: + cancelTokenHandlerObject[ + this.watchPoll.name + ].handleRequestCancellation().token, + }) + }, + + takeOver(pollId) { + return httpInstance.request({ + method: 'PUT', + url: `administration/poll/${pollId}/takeover`, + cancelToken: + cancelTokenHandlerObject[ + this.takeOver.name + ].handleRequestCancellation().token, + }) + }, + + addPoll(type, title) { + return httpInstance.request({ + method: 'POST', + url: 'poll/add', + data: { + type, + title, + }, + cancelToken: + cancelTokenHandlerObject[ + this.addPoll.name + ].handleRequestCancellation().token, + }) + }, + + writePoll(pollId, poll) { + return httpInstance.request({ + method: 'PUT', + url: `poll/${pollId}`, + data: { poll }, + cancelToken: + cancelTokenHandlerObject[ + this.writePoll.name + ].handleRequestCancellation().token, + }) + }, + + lockAnonymous(pollId) { + return httpInstance.request({ + method: 'PUT', + url: `poll/${pollId}/lockAnonymous`, + cancelToken: + cancelTokenHandlerObject[ + this.lockAnonymous.name + ].handleRequestCancellation().token, + }) + }, + + deletePoll(pollId) { + return httpInstance.request({ + method: 'DELETE', + url: `poll/${pollId}`, + cancelToken: + cancelTokenHandlerObject[ + this.deletePoll.name + ].handleRequestCancellation().token, + }) + }, + + closePoll(pollId) { + return httpInstance.request({ + method: 'PUT', + url: `poll/${pollId}/close`, + cancelToken: + cancelTokenHandlerObject[ + this.closePoll.name + ].handleRequestCancellation().token, + }) + }, + + reopenPoll(pollId) { + return httpInstance.request({ + method: 'PUT', + url: `poll/${pollId}/reopen`, + cancelToken: + cancelTokenHandlerObject[ + this.reopenPoll.name + ].handleRequestCancellation().token, + }) + }, + + toggleArchive(pollId) { + return httpInstance.request({ + method: 'PUT', + url: `poll/${pollId}/toggleArchive`, + cancelToken: + cancelTokenHandlerObject[ + this.toggleArchive.name + ].handleRequestCancellation().token, + }) + }, + + clonePoll(pollId) { + return httpInstance.request({ + method: 'POST', + url: `poll/${pollId}/clone`, + cancelToken: + cancelTokenHandlerObject[ + this.clonePoll.name + ].handleRequestCancellation().token, + }) + }, + + sendConfirmation(pollId) { + return httpInstance.request({ + method: 'POST', + url: `poll/${pollId}/confirmation`, + cancelToken: + cancelTokenHandlerObject[ + this.sendConfirmation.name + ].handleRequestCancellation().token, + }) + }, + + getParticipantsEmailAddresses(pollId) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}/addresses`, + cancelToken: + cancelTokenHandlerObject[ + this.getParticipantsEmailAddresses.name + ].handleRequestCancellation().token, + }) + }, + + getSubscription(pollId) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}/subscription`, + cancelToken: + cancelTokenHandlerObject[ + this.getSubscription.name + ].handleRequestCancellation().token, + }) + }, + + setSubscription(pollId, subscription) { + return httpInstance.request({ + method: 'PUT', + url: `poll/${pollId}${subscription ? '/subscribe' : '/unsubscribe'}`, + cancelToken: + cancelTokenHandlerObject[ + this.setSubscription.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(polls) + +export default polls diff --git a/src/Api/modules/public.js b/src/Api/modules/public.js index 05ca3d42d..26f118f97 100644 --- a/src/Api/modules/public.js +++ b/src/Api/modules/public.js @@ -1,223 +1,292 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const publicPoll = { - getPoll(shareToken) { - return httpInstance.request({ - method: 'GET', - url: `/s/${shareToken}/poll`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getPoll.name].handleRequestCancellation().token, - }) - }, - - getSession(shareToken) { - return httpInstance.request({ - method: 'GET', - url: `/s/${shareToken}/session`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getSession.name].handleRequestCancellation().token, - }) - }, - - watchPoll(shareToken, lastUpdated) { - return httpInstance.request({ - method: 'GET', - url: `s/${shareToken}/watch`, - params: { offset: lastUpdated }, - cancelToken: cancelTokenHandlerObject[this.watchPoll.name].handleRequestCancellation().token, - }) - }, - - getOptions(shareToken) { - return httpInstance.request({ - method: 'GET', - url: `/s/${shareToken}/options`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getOptions.name].handleRequestCancellation().token, - }) - }, - - addOption(shareToken, option) { - return httpInstance.request({ - method: 'POST', - url: `/s/${shareToken}/option`, - data: { ...option }, - cancelToken: cancelTokenHandlerObject[this.addOption.name].handleRequestCancellation().token, - }) - }, - - deleteOption(shareToken, optionId) { - return httpInstance.request({ - method: 'DELETE', - url: `s/${shareToken}/option/${optionId}`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.deleteOption.name].handleRequestCancellation().token, - }) - }, - - restoreOption(shareToken, optionId) { - return httpInstance.request({ - method: 'PUT', - url: `s/${shareToken}/option/${optionId}/restore`, - params: { time: +new Date() }, - - cancelToken: cancelTokenHandlerObject[this.restoreOption.name].handleRequestCancellation().token, - }) - }, - - getVotes(shareToken) { - return httpInstance.request({ - method: 'GET', - url: `/s/${shareToken}/votes`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getVotes.name].handleRequestCancellation().token, - }) - }, - - setVote(shareToken, optionId, setTo) { - return httpInstance.request({ - method: 'PUT', - url: `s/${shareToken}/vote`, - data: { optionId, setTo }, - cancelToken: cancelTokenHandlerObject[this.setVote.name].handleRequestCancellation().token, - }) - }, - - removeVotes(shareToken) { - return httpInstance.request({ - method: 'DELETE', - url: `s/${shareToken}/user`, - cancelToken: cancelTokenHandlerObject[this.removeVotes.name].handleRequestCancellation().token, - }) - }, - - removeOrphanedVotes(shareToken) { - return httpInstance.request({ - method: 'DELETE', - url: `s/${shareToken}/votes/orphaned`, - cancelToken: cancelTokenHandlerObject[this.removeOrphanedVotes.name].handleRequestCancellation().token, - }) - }, - - getComments(shareToken) { - return httpInstance.request({ - method: 'GET', - url: `/s/${shareToken}/comments`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getComments.name].handleRequestCancellation().token, - }) - }, - - addComment(shareToken, message) { - return httpInstance.request({ - method: 'POST', - url: `s/${shareToken}/comment`, - data: { message }, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.addComment.name].handleRequestCancellation().token, - }) - }, - - deleteComment(shareToken, commentId) { - return httpInstance.request({ - method: 'DELETE', - url: `s/${shareToken}/comment/${commentId}`, - params: { time: +new Date() }, - - cancelToken: cancelTokenHandlerObject[this.deleteComment.name].handleRequestCancellation().token, - }) - }, - - restoreComment(shareToken, commentId) { - return httpInstance.request({ - method: 'PUT', - url: `s/${shareToken}/comment/${commentId}/restore`, - params: { time: +new Date() }, - - cancelToken: cancelTokenHandlerObject[this.restoreComment.name].handleRequestCancellation().token, - }) - }, - - getShare(shareToken) { - return httpInstance.request({ - method: 'GET', - url: `s/${shareToken}/share`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getShare.name].handleRequestCancellation().token, - }) - }, - - setEmailAddress(shareToken, emailAddress) { - return httpInstance.request({ - method: 'PUT', - url: `s/${shareToken}/email/${emailAddress}`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.setEmailAddress.name].handleRequestCancellation().token, - }) - }, - - deleteEmailAddress(shareToken) { - return httpInstance.request({ - method: 'DELETE', - url: `s/${shareToken}/email`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.deleteEmailAddress.name].handleRequestCancellation().token, - }) - }, - - setDisplayName(shareToken, displayName) { - return httpInstance.request({ - method: 'PUT', - url: `s/${shareToken}/name/${displayName}`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.setDisplayName.name].handleRequestCancellation().token, - }) - }, - - resendInvitation(shareToken) { - return httpInstance.request({ - method: 'POST', - url: `s/${shareToken}/resend`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.resendInvitation.name].handleRequestCancellation().token, - }) - }, - - getSubscription(shareToken) { - return httpInstance.request({ - method: 'GET', - url: `s/${shareToken}/subscription`, - cancelToken: cancelTokenHandlerObject[this.getSubscription.name].handleRequestCancellation().token, - }) - }, - - setSubscription(shareToken, subscription) { - return httpInstance.request({ - method: 'PUT', - url: `s/${shareToken}${subscription ? '/subscribe' : '/unsubscribe'}`, - cancelToken: cancelTokenHandlerObject[this.setSubscription.name].handleRequestCancellation().token, - }) - }, - - register(shareToken, displayName, emailAddress, timeZone) { - return httpInstance.request({ - method: 'POST', - url: `s/${shareToken}/register`, - data: { - displayName, - emailAddress, - timeZone, - }, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.register.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(publicPoll) - -export default publicPoll +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const publicPoll = { + getPoll(shareToken) { + return httpInstance.request({ + method: 'GET', + url: `/s/${shareToken}/poll`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getPoll.name + ].handleRequestCancellation().token, + }) + }, + + getSession(shareToken) { + return httpInstance.request({ + method: 'GET', + url: `/s/${shareToken}/session`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getSession.name + ].handleRequestCancellation().token, + }) + }, + + watchPoll(shareToken, lastUpdated) { + return httpInstance.request({ + method: 'GET', + url: `s/${shareToken}/watch`, + params: { offset: lastUpdated }, + cancelToken: + cancelTokenHandlerObject[ + this.watchPoll.name + ].handleRequestCancellation().token, + }) + }, + + getOptions(shareToken) { + return httpInstance.request({ + method: 'GET', + url: `/s/${shareToken}/options`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getOptions.name + ].handleRequestCancellation().token, + }) + }, + + addOption(shareToken, option) { + return httpInstance.request({ + method: 'POST', + url: `/s/${shareToken}/option`, + data: { ...option }, + cancelToken: + cancelTokenHandlerObject[ + this.addOption.name + ].handleRequestCancellation().token, + }) + }, + + deleteOption(shareToken, optionId) { + return httpInstance.request({ + method: 'DELETE', + url: `s/${shareToken}/option/${optionId}`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.deleteOption.name + ].handleRequestCancellation().token, + }) + }, + + restoreOption(shareToken, optionId) { + return httpInstance.request({ + method: 'PUT', + url: `s/${shareToken}/option/${optionId}/restore`, + params: { time: +new Date() }, + + cancelToken: + cancelTokenHandlerObject[ + this.restoreOption.name + ].handleRequestCancellation().token, + }) + }, + + getVotes(shareToken) { + return httpInstance.request({ + method: 'GET', + url: `/s/${shareToken}/votes`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getVotes.name + ].handleRequestCancellation().token, + }) + }, + + setVote(shareToken, optionId, setTo) { + return httpInstance.request({ + method: 'PUT', + url: `s/${shareToken}/vote`, + data: { optionId, setTo }, + cancelToken: + cancelTokenHandlerObject[ + this.setVote.name + ].handleRequestCancellation().token, + }) + }, + + removeVotes(shareToken) { + return httpInstance.request({ + method: 'DELETE', + url: `s/${shareToken}/user`, + cancelToken: + cancelTokenHandlerObject[ + this.removeVotes.name + ].handleRequestCancellation().token, + }) + }, + + removeOrphanedVotes(shareToken) { + return httpInstance.request({ + method: 'DELETE', + url: `s/${shareToken}/votes/orphaned`, + cancelToken: + cancelTokenHandlerObject[ + this.removeOrphanedVotes.name + ].handleRequestCancellation().token, + }) + }, + + getComments(shareToken) { + return httpInstance.request({ + method: 'GET', + url: `/s/${shareToken}/comments`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getComments.name + ].handleRequestCancellation().token, + }) + }, + + addComment(shareToken, message) { + return httpInstance.request({ + method: 'POST', + url: `s/${shareToken}/comment`, + data: { message }, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.addComment.name + ].handleRequestCancellation().token, + }) + }, + + deleteComment(shareToken, commentId) { + return httpInstance.request({ + method: 'DELETE', + url: `s/${shareToken}/comment/${commentId}`, + params: { time: +new Date() }, + + cancelToken: + cancelTokenHandlerObject[ + this.deleteComment.name + ].handleRequestCancellation().token, + }) + }, + + restoreComment(shareToken, commentId) { + return httpInstance.request({ + method: 'PUT', + url: `s/${shareToken}/comment/${commentId}/restore`, + params: { time: +new Date() }, + + cancelToken: + cancelTokenHandlerObject[ + this.restoreComment.name + ].handleRequestCancellation().token, + }) + }, + + getShare(shareToken) { + return httpInstance.request({ + method: 'GET', + url: `s/${shareToken}/share`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getShare.name + ].handleRequestCancellation().token, + }) + }, + + setEmailAddress(shareToken, emailAddress) { + return httpInstance.request({ + method: 'PUT', + url: `s/${shareToken}/email/${emailAddress}`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.setEmailAddress.name + ].handleRequestCancellation().token, + }) + }, + + deleteEmailAddress(shareToken) { + return httpInstance.request({ + method: 'DELETE', + url: `s/${shareToken}/email`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.deleteEmailAddress.name + ].handleRequestCancellation().token, + }) + }, + + setDisplayName(shareToken, displayName) { + return httpInstance.request({ + method: 'PUT', + url: `s/${shareToken}/name/${displayName}`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.setDisplayName.name + ].handleRequestCancellation().token, + }) + }, + + resendInvitation(shareToken) { + return httpInstance.request({ + method: 'POST', + url: `s/${shareToken}/resend`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.resendInvitation.name + ].handleRequestCancellation().token, + }) + }, + + getSubscription(shareToken) { + return httpInstance.request({ + method: 'GET', + url: `s/${shareToken}/subscription`, + cancelToken: + cancelTokenHandlerObject[ + this.getSubscription.name + ].handleRequestCancellation().token, + }) + }, + + setSubscription(shareToken, subscription) { + return httpInstance.request({ + method: 'PUT', + url: `s/${shareToken}${subscription ? '/subscribe' : '/unsubscribe'}`, + cancelToken: + cancelTokenHandlerObject[ + this.setSubscription.name + ].handleRequestCancellation().token, + }) + }, + + register(shareToken, displayName, emailAddress, timeZone) { + return httpInstance.request({ + method: 'POST', + url: `s/${shareToken}/register`, + data: { + displayName, + emailAddress, + timeZone, + }, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.register.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(publicPoll) + +export default publicPoll diff --git a/src/Api/modules/session.js b/src/Api/modules/session.js index 025b3e156..581e75e83 100644 --- a/src/Api/modules/session.js +++ b/src/Api/modules/session.js @@ -1,20 +1,23 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const session = { - getSession() { - return httpInstance.request({ - method: 'GET', - url: '/session', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getSession.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(session) - -export default session +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const session = { + getSession() { + return httpInstance.request({ + method: 'GET', + url: '/session', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getSession.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(session) + +export default session diff --git a/src/Api/modules/shares.js b/src/Api/modules/shares.js index 0c0c70fb8..0d18803ee 100644 --- a/src/Api/modules/shares.js +++ b/src/Api/modules/shares.js @@ -1,121 +1,160 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const shares = { - getShares(pollId) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}/shares`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getShares.name].handleRequestCancellation().token, - }) - }, - - addUserShare(pollId, user) { - return httpInstance.request({ - method: 'POST', - url: `poll/${pollId}/share`, - data: user, - cancelToken: cancelTokenHandlerObject[this.addUserShare.name].handleRequestCancellation().token, - }) - }, - - addPublicShare(pollId) { - return httpInstance.request({ - method: 'POST', - url: `poll/${pollId}/publicshare`, - cancelToken: cancelTokenHandlerObject[this.addPublicShare.name].handleRequestCancellation().token, - }) - }, - - writeLabel(shareToken, label) { - return httpInstance.request({ - method: 'PUT', - url: `share/${shareToken}/setlabel`, - data: { - label, - }, - cancelToken: cancelTokenHandlerObject[this.writeLabel.name].handleRequestCancellation().token, - }) - }, - - switchAdmin(shareToken, setTo) { - return httpInstance.request({ - method: 'PUT', - url: `share/${shareToken}/${setTo}`, - cancelToken: cancelTokenHandlerObject[this.switchAdmin.name].handleRequestCancellation().token, - }) - }, - - setEmailAddressConstraint(shareToken, setTo) { - return httpInstance.request({ - method: 'PUT', - url: `share/${shareToken}/publicpollemail/${setTo}`, - cancelToken: cancelTokenHandlerObject[this.setEmailAddressConstraint.name].handleRequestCancellation().token, - }) - }, - - sendInvitation(shareToken) { - return httpInstance.request({ - method: 'POST', - url: `share/${shareToken}/invite`, - cancelToken: cancelTokenHandlerObject[this.sendInvitation.name].handleRequestCancellation().token, - }) - }, - - resolveShare(shareToken) { - return httpInstance.request({ - method: 'GET', - url: `share/${shareToken}/resolve`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.resolveShare.name].handleRequestCancellation().token, - }) - }, - - deleteShare(shareToken) { - return httpInstance.request({ - method: 'DELETE', - url: `share/${shareToken}`, - cancelToken: cancelTokenHandlerObject[this.deleteShare.name].handleRequestCancellation().token, - }) - }, - - restoreShare(shareToken) { - return httpInstance.request({ - method: 'PUT', - url: `share/${shareToken}/restore`, - cancelToken: cancelTokenHandlerObject[this.restoreShare.name].handleRequestCancellation().token, - }) - }, - - lockShare(shareToken) { - return httpInstance.request({ - method: 'PUT', - url: `share/${shareToken}/lock`, - cancelToken: cancelTokenHandlerObject[this.lockShare.name].handleRequestCancellation().token, - }) - }, - - unlockShare(shareToken) { - return httpInstance.request({ - method: 'PUT', - url: `share/${shareToken}/unlock`, - cancelToken: cancelTokenHandlerObject[this.unlockShare.name].handleRequestCancellation().token, - }) - }, - - inviteAll(pollId) { - return httpInstance.request({ - method: 'PUT', - url: `poll/${pollId}/inviteAll`, - cancelToken: cancelTokenHandlerObject[this.inviteAll.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(shares) - -export default shares +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const shares = { + getShares(pollId) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}/shares`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getShares.name + ].handleRequestCancellation().token, + }) + }, + + addUserShare(pollId, user) { + return httpInstance.request({ + method: 'POST', + url: `poll/${pollId}/share`, + data: user, + cancelToken: + cancelTokenHandlerObject[ + this.addUserShare.name + ].handleRequestCancellation().token, + }) + }, + + addPublicShare(pollId) { + return httpInstance.request({ + method: 'POST', + url: `poll/${pollId}/publicshare`, + cancelToken: + cancelTokenHandlerObject[ + this.addPublicShare.name + ].handleRequestCancellation().token, + }) + }, + + writeLabel(shareToken, label) { + return httpInstance.request({ + method: 'PUT', + url: `share/${shareToken}/setlabel`, + data: { + label, + }, + cancelToken: + cancelTokenHandlerObject[ + this.writeLabel.name + ].handleRequestCancellation().token, + }) + }, + + switchAdmin(shareToken, setTo) { + return httpInstance.request({ + method: 'PUT', + url: `share/${shareToken}/${setTo}`, + cancelToken: + cancelTokenHandlerObject[ + this.switchAdmin.name + ].handleRequestCancellation().token, + }) + }, + + setEmailAddressConstraint(shareToken, setTo) { + return httpInstance.request({ + method: 'PUT', + url: `share/${shareToken}/publicpollemail/${setTo}`, + cancelToken: + cancelTokenHandlerObject[ + this.setEmailAddressConstraint.name + ].handleRequestCancellation().token, + }) + }, + + sendInvitation(shareToken) { + return httpInstance.request({ + method: 'POST', + url: `share/${shareToken}/invite`, + cancelToken: + cancelTokenHandlerObject[ + this.sendInvitation.name + ].handleRequestCancellation().token, + }) + }, + + resolveShare(shareToken) { + return httpInstance.request({ + method: 'GET', + url: `share/${shareToken}/resolve`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.resolveShare.name + ].handleRequestCancellation().token, + }) + }, + + deleteShare(shareToken) { + return httpInstance.request({ + method: 'DELETE', + url: `share/${shareToken}`, + cancelToken: + cancelTokenHandlerObject[ + this.deleteShare.name + ].handleRequestCancellation().token, + }) + }, + + restoreShare(shareToken) { + return httpInstance.request({ + method: 'PUT', + url: `share/${shareToken}/restore`, + cancelToken: + cancelTokenHandlerObject[ + this.restoreShare.name + ].handleRequestCancellation().token, + }) + }, + + lockShare(shareToken) { + return httpInstance.request({ + method: 'PUT', + url: `share/${shareToken}/lock`, + cancelToken: + cancelTokenHandlerObject[ + this.lockShare.name + ].handleRequestCancellation().token, + }) + }, + + unlockShare(shareToken) { + return httpInstance.request({ + method: 'PUT', + url: `share/${shareToken}/unlock`, + cancelToken: + cancelTokenHandlerObject[ + this.unlockShare.name + ].handleRequestCancellation().token, + }) + }, + + inviteAll(pollId) { + return httpInstance.request({ + method: 'PUT', + url: `poll/${pollId}/inviteAll`, + cancelToken: + cancelTokenHandlerObject[ + this.inviteAll.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(shares) + +export default shares diff --git a/src/Api/modules/user.js b/src/Api/modules/user.js index 84eeab692..92b81856a 100644 --- a/src/Api/modules/user.js +++ b/src/Api/modules/user.js @@ -1,38 +1,47 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const userSettings = { - getUserSettings() { - return httpInstance.request({ - method: 'GET', - url: 'preferences', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getUserSettings.name].handleRequestCancellation().token, - }) - }, - - getSession() { - return httpInstance.request({ - method: 'GET', - url: 'session', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getSession.name].handleRequestCancellation().token, - }) - }, - - writeUserSettings(preferences) { - return httpInstance.request({ - method: 'POST', - url: 'preferences', - data: { preferences }, - cancelToken: cancelTokenHandlerObject[this.writeUserSettings.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(userSettings) - -export default userSettings +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const userSettings = { + getUserSettings() { + return httpInstance.request({ + method: 'GET', + url: 'preferences', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getUserSettings.name + ].handleRequestCancellation().token, + }) + }, + + getSession() { + return httpInstance.request({ + method: 'GET', + url: 'session', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getSession.name + ].handleRequestCancellation().token, + }) + }, + + writeUserSettings(preferences) { + return httpInstance.request({ + method: 'POST', + url: 'preferences', + data: { preferences }, + cancelToken: + cancelTokenHandlerObject[ + this.writeUserSettings.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(userSettings) + +export default userSettings diff --git a/src/Api/modules/userSettings.js b/src/Api/modules/userSettings.js index 705d77af2..63120f4f0 100644 --- a/src/Api/modules/userSettings.js +++ b/src/Api/modules/userSettings.js @@ -1,40 +1,47 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const userSettings = { - getUserSettings() { - return httpInstance.request({ - method: 'GET', - url: 'preferences', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getUserSettings.name].handleRequestCancellation().token, - }) - }, - - writeUserSettings(preferences) { - return httpInstance.request({ - method: 'POST', - url: 'preferences', - data: { preferences }, - cancelToken: cancelTokenHandlerObject[this.writeUserSettings.name].handleRequestCancellation().token, - }) - }, - - getSession() { - return httpInstance.request({ - method: 'GET', - url: 'session', - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getSession.name].handleRequestCancellation().token, - }) - }, - - -} - -const cancelTokenHandlerObject = createCancelTokenHandler(userSettings) - -export default userSettings +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const userSettings = { + getUserSettings() { + return httpInstance.request({ + method: 'GET', + url: 'preferences', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getUserSettings.name + ].handleRequestCancellation().token, + }) + }, + + writeUserSettings(preferences) { + return httpInstance.request({ + method: 'POST', + url: 'preferences', + data: { preferences }, + cancelToken: + cancelTokenHandlerObject[ + this.writeUserSettings.name + ].handleRequestCancellation().token, + }) + }, + + getSession() { + return httpInstance.request({ + method: 'GET', + url: 'session', + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getSession.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(userSettings) + +export default userSettings diff --git a/src/Api/modules/validators.js b/src/Api/modules/validators.js index b3660f46d..10d774620 100644 --- a/src/Api/modules/validators.js +++ b/src/Api/modules/validators.js @@ -1,34 +1,40 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const validators = { - validateEmailAddress(emailAddress) { - return httpInstance.request({ - method: 'GET', - url: `check/emailaddress/${emailAddress}`, - cancelToken: cancelTokenHandlerObject[this.validateEmailAddress.name].handleRequestCancellation().token, - }) - }, - - validateName(pollToken, name) { - return httpInstance.request({ - method: 'POST', - url: 'check/username', - cancelToken: cancelTokenHandlerObject[this.validateName.name].handleRequestCancellation().token, - data: { - displayName: name, - token: pollToken, - }, - headers: { - 'Nc-Polls-Share-Token': pollToken, - } - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(validators) - -export default validators +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const validators = { + validateEmailAddress(emailAddress) { + return httpInstance.request({ + method: 'GET', + url: `check/emailaddress/${emailAddress}`, + cancelToken: + cancelTokenHandlerObject[ + this.validateEmailAddress.name + ].handleRequestCancellation().token, + }) + }, + + validateName(pollToken, name) { + return httpInstance.request({ + method: 'POST', + url: 'check/username', + cancelToken: + cancelTokenHandlerObject[ + this.validateName.name + ].handleRequestCancellation().token, + data: { + displayName: name, + token: pollToken, + }, + headers: { + 'Nc-Polls-Share-Token': pollToken, + }, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(validators) + +export default validators diff --git a/src/Api/modules/votes.js b/src/Api/modules/votes.js index 5dad9640f..89ffa1682 100644 --- a/src/Api/modules/votes.js +++ b/src/Api/modules/votes.js @@ -1,45 +1,57 @@ -/** - * SPDX-FileCopyrightText: 2022 Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { httpInstance, createCancelTokenHandler } from './HttpApi.js' - -const votes = { - getVotes(pollId) { - return httpInstance.request({ - method: 'GET', - url: `poll/${pollId}/votes`, - params: { time: +new Date() }, - cancelToken: cancelTokenHandlerObject[this.getVotes.name].handleRequestCancellation().token, - }) - }, - - setVote(optionId, setTo) { - return httpInstance.request({ - method: 'PUT', - url: 'vote', - data: { optionId, setTo }, - cancelToken: cancelTokenHandlerObject[this.setVote.name].handleRequestCancellation().token, - }) - }, - - removeUser(pollId, userId = null) { - return httpInstance.request({ - method: 'DELETE', - url: userId ? `poll/${pollId}/user/${userId}` : `poll/${pollId}/user`, - cancelToken: cancelTokenHandlerObject[this.removeUser.name].handleRequestCancellation().token, - }) - }, - - removeOrphanedVotes(pollId) { - return httpInstance.request({ - method: 'DELETE', - url: `poll/${pollId}/votes/orphaned`, - cancelToken: cancelTokenHandlerObject[this.removeOrphanedVotes.name].handleRequestCancellation().token, - }) - }, -} - -const cancelTokenHandlerObject = createCancelTokenHandler(votes) - -export default votes +/** + * SPDX-FileCopyrightText: 2022 Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { httpInstance, createCancelTokenHandler } from './HttpApi.js' + +const votes = { + getVotes(pollId) { + return httpInstance.request({ + method: 'GET', + url: `poll/${pollId}/votes`, + params: { time: +new Date() }, + cancelToken: + cancelTokenHandlerObject[ + this.getVotes.name + ].handleRequestCancellation().token, + }) + }, + + setVote(optionId, setTo) { + return httpInstance.request({ + method: 'PUT', + url: 'vote', + data: { optionId, setTo }, + cancelToken: + cancelTokenHandlerObject[ + this.setVote.name + ].handleRequestCancellation().token, + }) + }, + + removeUser(pollId, userId = null) { + return httpInstance.request({ + method: 'DELETE', + url: userId ? `poll/${pollId}/user/${userId}` : `poll/${pollId}/user`, + cancelToken: + cancelTokenHandlerObject[ + this.removeUser.name + ].handleRequestCancellation().token, + }) + }, + + removeOrphanedVotes(pollId) { + return httpInstance.request({ + method: 'DELETE', + url: `poll/${pollId}/votes/orphaned`, + cancelToken: + cancelTokenHandlerObject[ + this.removeOrphanedVotes.name + ].handleRequestCancellation().token, + }) + }, +} + +const cancelTokenHandlerObject = createCancelTokenHandler(votes) + +export default votes diff --git a/src/App.vue b/src/App.vue index 7bdb2c61f..a88db0142 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,117 +4,118 @@ -->