Skip to content

Commit 4172472

Browse files
committed
fix: apps enabled status (#897)
* fix: apps enabled status * fix: split get apps * chore: add debug line * fix: apps enabled permission (cherry picked from commit d280dcf)
1 parent 207301c commit 4172472

6 files changed

Lines changed: 68 additions & 20 deletions

File tree

src/api/v1/apps.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Debug from 'debug'
2+
import { Response } from 'express'
3+
import { OpenApiRequestExt } from 'src/otomi-models'
4+
5+
const debug = Debug('otomi:api:v1:apps')
6+
7+
/**
8+
* GET /v1/apps
9+
* Get all apps across all teams
10+
* Returns list of all apps with their ids and enabled status
11+
*/
12+
export const getApps = (req: OpenApiRequestExt, res: Response): void => {
13+
debug('getAllApps')
14+
res.json(req.otomi.getApps())
15+
}

src/api/v1/apps/{teamId}.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ const debug = Debug('otomi:api:v1:apps')
77
/**
88
* GET /v1/apps/{teamId}
99
* Get apps for a team
10+
* Returns list of team apps with their ids and enabled status
1011
*/
11-
export const getApps = (req: OpenApiRequestExt, res: Response): void => {
12+
export const getTeamApps = (req: OpenApiRequestExt, res: Response): void => {
1213
const { teamId } = req.params
13-
res.json(req.otomi.getApps(teamId))
14+
debug('getTeamApps', teamId)
15+
res.json(req.otomi.getTeamApps(teamId))
1416
}
1517

1618
/**

src/openapi/api.yaml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,22 @@ paths:
25792579
'200':
25802580
description: Successfully edited settings.
25812581

2582+
/v1/apps:
2583+
get:
2584+
operationId: getApps
2585+
x-eov-operation-handler: v1/apps
2586+
description: Get list of all apps ids and their enabled status
2587+
x-aclSchema: AppEnabled
2588+
responses:
2589+
'200':
2590+
description: The request is successful.
2591+
content:
2592+
application/json:
2593+
schema:
2594+
type: array
2595+
items:
2596+
$ref: '#/components/schemas/AppEnabled'
2597+
25822598
/v1/apps/{teamId}:
25832599
parameters:
25842600
- in: path
@@ -2587,10 +2603,10 @@ paths:
25872603
schema:
25882604
type: string
25892605
get:
2590-
operationId: getApps
2606+
operationId: getTeamApps
25912607
x-eov-operation-handler: v1/apps/{teamId}
2592-
description: Get list of apps for a team
2593-
x-aclSchema: App
2608+
description: Get list of team apps ids and their enabled status
2609+
x-aclSchema: AppEnabled
25942610
responses:
25952611
'200':
25962612
description: The request is successful.
@@ -2599,12 +2615,7 @@ paths:
25992615
schema:
26002616
type: array
26012617
items:
2602-
type: object
2603-
properties:
2604-
id:
2605-
$ref: '#/components/schemas/App/properties/id'
2606-
enabled:
2607-
$ref: '#/components/schemas/App/properties/enabled'
2618+
$ref: '#/components/schemas/AppEnabled'
26082619
put:
26092620
operationId: toggleApps
26102621
x-eov-operation-handler: v1/apps/{teamId}
@@ -3298,6 +3309,8 @@ components:
32983309
$ref: 'agent.yaml#/Agent'
32993310
App:
33003311
$ref: 'app.yaml#/App'
3312+
AppEnabled:
3313+
$ref: 'app.yaml#/AppEnabled'
33013314
AppList:
33023315
$ref: 'app.yaml#/AppList'
33033316
Build:

src/openapi/app.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,15 @@ App:
6060
type: object
6161
additionalProperties: true
6262
required: [id]
63+
64+
AppEnabled:
65+
x-acl:
66+
platformAdmin: [read-any]
67+
teamAdmin: [read-any]
68+
teamMember: [read-any]
69+
type: object
70+
properties:
71+
id:
72+
$ref: 'definitions.yaml#/idName'
73+
enabled:
74+
type: boolean

src/otomi-models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { components, operations, paths } from 'src/generated-schema'
44
import OtomiStack from 'src/otomi-stack'
55

66
export type App = components['schemas']['App']
7+
export type AppEnabled = components['schemas']['AppEnabled']
78
export type AppList = components['schemas']['AppList']
89
export type AplKnowledgeBaseRequest = components['schemas']['AplKnowledgeBaseRequest']
910
export type AplKnowledgeBaseResponse = components['schemas']['AplKnowledgeBaseResponse']

src/otomi-stack.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ export default class OtomiStack {
559559
return { values: content.spec, id: content.metadata.name } as App
560560
}
561561

562-
getApps(teamId: string): Array<App> {
562+
getApps(): Array<App> {
563563
const appList = this.getAppList()
564564

565565
const allApps = appList.map((id) => {
@@ -568,16 +568,21 @@ export default class OtomiStack {
568568

569569
const providerSpecificApps = this.filterExcludedApp(allApps) as App[]
570570

571-
if (teamId === 'admin')
572-
return providerSpecificApps.map((app) => {
573-
return {
574-
id: app.id,
575-
enabled: Boolean(app.values?.enabled ?? true),
576-
}
577-
})
571+
return providerSpecificApps.map((app) => {
572+
return {
573+
id: app.id,
574+
enabled: Boolean(app.values?.enabled ?? true),
575+
}
576+
})
577+
}
578+
579+
getTeamApps(teamId: string): Array<App> {
580+
const allApps = this.getApps()
581+
582+
if (teamId === 'admin') return allApps
578583

579584
const core = this.getCore()
580-
const teamApps = providerSpecificApps
585+
const teamApps = allApps
581586
.map((app: App) => {
582587
const isShared = !!core.adminApps.find((a) => a.name === app.id)?.isShared
583588
const inTeamApps = !!core.teamApps.find((a) => a.name === app.id)

0 commit comments

Comments
 (0)