Skip to content

Commit 6510bbc

Browse files
committed
feat: Add OpenAPI
Signed-off-by: provokateurin <[email protected]>
1 parent ba58601 commit 6510bbc

29 files changed

+3358
-221
lines changed

.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@ module.exports = {
66
extends: [
77
'@nextcloud/eslint-config/typescript',
88
],
9+
overrides: [
10+
{
11+
files: ['src/types/openapi/*.ts'],
12+
rules: {
13+
'@typescript-eslint/no-explicit-any': 'off',
14+
quotes: 'off',
15+
'no-multiple-empty-lines': 'off',
16+
'no-use-before-define': 'off',
17+
},
18+
},
19+
],
920
}

.github/workflows/openapi.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# This workflow is provided via the organization template repository
2+
#
3+
# https://github.com/nextcloud/.github
4+
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5+
#
6+
# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
# SPDX-FileCopyrightText: 2024 Arthur Schiwon <[email protected]>
8+
# SPDX-License-Identifier: MIT
9+
10+
name: OpenAPI
11+
12+
on: pull_request
13+
14+
permissions:
15+
contents: read
16+
17+
concurrency:
18+
group: openapi-${{ github.head_ref || github.run_id }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
openapi:
23+
runs-on: ubuntu-latest
24+
25+
if: ${{ github.repository_owner != 'nextcloud-gmbh' }}
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
30+
31+
- name: Get php version
32+
id: php_versions
33+
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1
34+
35+
- name: Set up php
36+
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
37+
with:
38+
php-version: ${{ steps.php_versions.outputs.php-available }}
39+
extensions: xml
40+
coverage: none
41+
ini-file: development
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Check Typescript OpenApi types
46+
id: check_typescript_openapi
47+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
48+
with:
49+
files: "src/types/openapi/openapi*.ts"
50+
51+
- name: Read package.json node and npm engines version
52+
if: steps.check_typescript_openapi.outputs.files_exists == 'true'
53+
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
54+
id: node_versions
55+
# Continue if no package.json
56+
continue-on-error: true
57+
with:
58+
fallbackNode: '^20'
59+
fallbackNpm: '^10'
60+
61+
- name: Set up node ${{ steps.node_versions.outputs.nodeVersion }}
62+
if: ${{ steps.node_versions.outputs.nodeVersion }}
63+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
64+
with:
65+
node-version: ${{ steps.node_versions.outputs.nodeVersion }}
66+
67+
- name: Set up npm ${{ steps.node_versions.outputs.npmVersion }}
68+
if: ${{ steps.node_versions.outputs.nodeVersion }}
69+
run: npm i -g 'npm@${{ steps.node_versions.outputs.npmVersion }}'
70+
71+
- name: Install dependencies & build
72+
if: ${{ steps.node_versions.outputs.nodeVersion }}
73+
env:
74+
CYPRESS_INSTALL_BINARY: 0
75+
PUPPETEER_SKIP_DOWNLOAD: true
76+
run: |
77+
npm ci
78+
79+
- name: Set up dependencies
80+
run: composer i
81+
82+
- name: Regenerate OpenAPI
83+
run: composer run openapi
84+
85+
- name: Check openapi*.json and typescript changes
86+
run: |
87+
bash -c "[[ ! \"`git status --porcelain `\" ]] || (echo 'Please run \"composer run openapi\" and commit the openapi*.json files and (if applicable) src/types/openapi/openapi*.ts, see the section \"Show changes on failure\" for details' && exit 1)"
88+
89+
- name: Show changes on failure
90+
if: failure()
91+
run: |
92+
git status
93+
git --no-pager diff
94+
exit 1 # make it red to grab attention

README.md

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,35 +126,7 @@ To disable the advanced permissions feature for a group folder, use `occ groupfo
126126

127127
### REST API
128128

129-
Group folders can be configured externally through REST APIs.
130-
131-
The following REST API's are supported:
132-
133-
- `GET apps/groupfolders/folders`: Returns a list of all configured folders and their settings
134-
- `POST apps/groupfolders/folders`: Create a new group folder
135-
- `mountpoint`: The name for the new folder
136-
- `GET apps/groupfolders/folders/$folderId`: Return a specific configured folder and its settings
137-
- `DELETE apps/groupfolders/folders/$folderId`: Delete a group folder
138-
- `POST apps/groupfolders/folders/$folderId/groups`: Give a group access to a folder
139-
- `group`: The id of the group to be given access to the folder
140-
- `DELETE apps/groupfolders/folders/$folderId/groups/$groupId`: Remove access from a group to a folder
141-
- `POST apps/groupfolders/folders/$folderId/acl`: Enable/Disable folder advanced permissions
142-
- `acl` 1 for enable, 0 for disable.
143-
- `POST apps/groupfolders/folders/$folderId/manageACL`: Grants/Removes a group or user the ability to manage a groupfolders' advanced permissions
144-
- `$mappingId`: the id of the group/user to be granted/removed access to/from the folder
145-
- `$mappingType`: 'group' or 'user'
146-
- `$manageAcl`: true to grants ability to manage a groupfolders' advanced permissions, false to remove
147-
- `POST apps/groupfolders/folders/$folderId/groups/$groupId`: Set the permissions a group has in a folder
148-
- `permissions` The new permissions for the group as bitmask of [permissions constants](https://github.com/nextcloud/server/blob/b4f36d44c43aac0efdc6c70ff8e46473341a9bfe/lib/public/Constants.php#L65)
149-
- `POST apps/groupfolders/folders/$folderId/quota`: Set the quota for a folder
150-
- `quota`: The new quota for the folder in bytes, user `-3` for unlimited
151-
- `POST apps/groupfolders/folders/$folderId/mountpoint`: Change the name of a folder
152-
- `mountpoint`: The new name for the folder
153-
154-
For all `POST` calls the required parameters are listed.
155-
156-
Non-admins can access the `GET` requests to retrieve info about group folders they have access to.
157-
Admins can add `applicable=1` as a parameter to the group folder list request to get the same filtered results of only folders they have direct access to.
129+
See the [OpenAPI specification](openapi.json) to learn about all available API endpoints: https://petstore.swagger.io/?url=https://raw.githubusercontent.com/nextcloud/groupfolders/master/openapi.json
158130

159131
### WebDAV API
160132

REUSE.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,9 @@ path = ["img/app-dark.svg", "img/app.svg", "img/deny.svg", "img/folder-group.svg
4646
precedence = "aggregate"
4747
SPDX-FileCopyrightText = "2018-2024 Google LLC"
4848
SPDX-License-Identifier = "Apache-2.0"
49+
50+
[[annotations]]
51+
path = ["openapi.json", "src/types/openapi/openapi.ts"]
52+
precedence = "aggregate"
53+
SPDX-FileCopyrightText = "2024 Nextcloud GmbH and Nextcloud contributors"
54+
SPDX-License-Identifier = "AGPL-3.0-or-later"

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
1919
"psalm:clear": "psalm.phar --clear-cache && psalm.phar --clear-global-cache",
2020
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
21-
"test:unit": "vendor/bin/phpunit -c tests/phpunit.xml"
21+
"test:unit": "vendor/bin/phpunit -c tests/phpunit.xml",
22+
"openapi": "generate-spec && npm run typescript:generate"
2223
},
2324
"config": {
2425
"allow-plugins": {

lib/AppInfo/Capabilities.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace OCA\GroupFolders\AppInfo;
99

1010
use OCA\GroupFolders\Folder\FolderManager;
11+
use OCP\App\IAppManager;
1112
use OCP\Capabilities\ICapability;
1213
use OCP\IUser;
1314
use OCP\IUserSession;
14-
use OCP\App\IAppManager;
1515

1616
class Capabilities implements ICapability {
1717
private IUserSession $userSession;
@@ -24,6 +24,14 @@ public function __construct(IUserSession $userSession, FolderManager $folderMana
2424
$this->appManager = $appManager;
2525
}
2626

27+
/**
28+
* @return array{
29+
* groupfolders?: array{
30+
* appVersion: string,
31+
* hasGroupFolders: bool,
32+
* },
33+
* }
34+
*/
2735
public function getCapabilities(): array {
2836
$user = $this->userSession->getUser();
2937
if (!$user) {

lib/Command/FolderCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
/**
1919
* Base command for commands asking the user for a folder id.
20+
*
21+
* @psalm-import-type InternalFolderOut from FolderManager
2022
*/
2123
abstract class FolderCommand extends Base {
2224
protected FolderManager $folderManager;
@@ -31,7 +33,7 @@ public function __construct(FolderManager $folderManager, IRootFolder $rootFolde
3133
}
3234

3335
/**
34-
* @psalm-return array{id: mixed, mount_point: string, groups: array<empty, empty>|mixed, quota: int, size: int|mixed, acl: bool}|false
36+
* @return InternalFolderOut|false
3537
*/
3638
protected function getFolder(InputInterface $input, OutputInterface $output) {
3739
$folderId = (int)$input->getArgument('folder_id');

lib/Controller/DelegationController.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
namespace OCA\GroupFolders\Controller;
99

1010
use OCA\Circles\CirclesManager;
11+
use OCA\GroupFolders\Attribute\RequireGroupFolderAdmin;
12+
use OCA\GroupFolders\ResponseDefinitions;
1113
use OCA\GroupFolders\Service\DelegationService;
14+
use OCA\GroupFolders\Service\DelegationService;
15+
use OCA\Settings\Service\AuthorizedGroupService;
1216
use OCA\Settings\Service\AuthorizedGroupService;
1317
use OCP\App\IAppManager;
18+
use OCP\App\IAppManager;
19+
use OCP\AppFramework\Http;
20+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1421
use OCP\AppFramework\Http\DataResponse;
1522
use OCP\AppFramework\OCSController;
1623
use OCP\IConfig;
@@ -20,6 +27,10 @@
2027
use Psr\Container\ContainerExceptionInterface;
2128
use Psr\Container\ContainerInterface;
2229

30+
/**
31+
* @psalm-import-type GroupFoldersDelegationGroup from ResponseDefinitions
32+
* @psalm-import-type GroupFoldersDelegationCircle from ResponseDefinitions
33+
*/
2334
class DelegationController extends OCSController {
2435
public function __construct(
2536
string $appName,
@@ -39,6 +50,9 @@ public function __construct(
3950
*
4051
* @NoAdminRequired
4152
* @RequireGroupFolderAdmin
53+
* @return DataResponse<Http::STATUS_OK, list<GroupFoldersDelegationGroup>, array{}>
54+
*
55+
* 200: All groups returned
4256
*/
4357
public function getAllGroups(): DataResponse {
4458
// Get all groups
@@ -61,6 +75,9 @@ public function getAllGroups(): DataResponse {
6175
*
6276
* @NoAdminRequired
6377
* @RequireGroupFolderAdmin
78+
* @return DataResponse<Http::STATUS_OK, list<GroupFoldersDelegationCircle>, array{}>
79+
*
80+
* 200: All circles returned
6481
*/
6582
public function getAllCircles(): DataResponse {
6683
$circlesEnabled = $this->appManager->isEnabledForUser('circles');
@@ -94,12 +111,15 @@ public function getAllCircles(): DataResponse {
94111

95112
/**
96113
* Get the list Groups related to classname.
97-
* If the classname is
98-
* - OCA\GroupFolders\Settings\Admin : It's reference to fields in Admin Priveleges.
99-
* - OCA\GroupFolders\Controller\DelegationController : It's just to specific the subadmins.
100-
* They can only manage groupfolders in which they are added in the Advanced Permissions (groups only)
114+
* @param string $classname If the classname is
115+
* - OCA\GroupFolders\Settings\Admin : It's reference to fields in Admin Privileges.
116+
* - OCA\GroupFolders\Controller\DelegationController : It's just to specific the subadmins.
117+
* They can only manage groupfolders in which they are added in the Advanced Permissions (groups only)
101118
* @NoAdminRequired
102119
* @RequireGroupFolderAdmin
120+
* @return DataResponse<Http::STATUS_OK, list<GroupFoldersDelegationGroup>, array{}>
121+
*
122+
* 200: Authorized groups returned
103123
*/
104124
public function getAuthorizedGroups(string $classname = ""): DataResponse {
105125
$data = [];

0 commit comments

Comments
 (0)