Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/api/v1/apps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Debug from 'debug'
import { Response } from 'express'
import { OpenApiRequestExt } from 'src/otomi-models'

const debug = Debug('otomi:api:v1:apps')

/**
* GET /v1/apps
* Get all apps across all teams
* Returns list of all apps with their ids and enabled status
*/
export const getApps = (req: OpenApiRequestExt, res: Response): void => {
debug('getAllApps')
res.json(req.otomi.getApps())
}
6 changes: 4 additions & 2 deletions src/api/v1/apps/{teamId}.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ const debug = Debug('otomi:api:v1:apps')
/**
* GET /v1/apps/{teamId}
* Get apps for a team
* Returns list of team apps with their ids and enabled status
*/
export const getApps = (req: OpenApiRequestExt, res: Response): void => {
export const getTeamApps = (req: OpenApiRequestExt, res: Response): void => {
const { teamId } = req.params
res.json(req.otomi.getApps(teamId))
debug('getTeamApps', teamId)
res.json(req.otomi.getTeamApps(teamId))
}

/**
Expand Down
31 changes: 22 additions & 9 deletions src/openapi/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,22 @@ paths:
'200':
description: Successfully edited settings.

/v1/apps:
get:
operationId: getApps
x-eov-operation-handler: v1/apps
description: Get list of all apps ids and their enabled status
x-aclSchema: AppEnabled
responses:
'200':
description: The request is successful.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/AppEnabled'

/v1/apps/{teamId}:
parameters:
- in: path
Expand All @@ -2590,10 +2606,10 @@ paths:
schema:
type: string
get:
operationId: getApps
operationId: getTeamApps
x-eov-operation-handler: v1/apps/{teamId}
description: Get list of apps for a team
x-aclSchema: App
description: Get list of team apps ids and their enabled status
x-aclSchema: AppEnabled
responses:
'200':
description: The request is successful.
Expand All @@ -2602,12 +2618,7 @@ paths:
schema:
type: array
items:
type: object
properties:
id:
$ref: '#/components/schemas/App/properties/id'
enabled:
$ref: '#/components/schemas/App/properties/enabled'
$ref: '#/components/schemas/AppEnabled'
put:
operationId: toggleApps
x-eov-operation-handler: v1/apps/{teamId}
Expand Down Expand Up @@ -3092,6 +3103,8 @@ components:
$ref: 'agent.yaml#/Agent'
App:
$ref: 'app.yaml#/App'
AppEnabled:
$ref: 'app.yaml#/AppEnabled'
AppList:
$ref: 'app.yaml#/AppList'
Build:
Expand Down
12 changes: 12 additions & 0 deletions src/openapi/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ App:
type: object
additionalProperties: true
required: [id]

AppEnabled:
x-acl:
platformAdmin: [read-any]
teamAdmin: [read-any]
teamMember: [read-any]
type: object
properties:
id:
$ref: 'definitions.yaml#/idName'
enabled:
type: boolean
1 change: 1 addition & 0 deletions src/otomi-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { components, operations, paths } from 'src/generated-schema'
import OtomiStack from 'src/otomi-stack'

export type App = components['schemas']['App']
export type AppEnabled = components['schemas']['AppEnabled']
export type AppList = components['schemas']['AppList']
export type AplKnowledgeBaseRequest = components['schemas']['AplKnowledgeBaseRequest']
export type AplKnowledgeBaseResponse = components['schemas']['AplKnowledgeBaseResponse']
Expand Down
23 changes: 14 additions & 9 deletions src/otomi-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export default class OtomiStack {
return { values: content.spec, id: content.metadata.name } as App
}

getApps(teamId: string): Array<App> {
getApps(): Array<App> {
const appList = this.getAppList()

const allApps = appList.map((id) => {
Expand All @@ -574,16 +574,21 @@ export default class OtomiStack {

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

if (teamId === 'admin')
return providerSpecificApps.map((app) => {
return {
id: app.id,
enabled: Boolean(app.values?.enabled ?? true),
}
})
return providerSpecificApps.map((app) => {
return {
id: app.id,
enabled: Boolean(app.values?.enabled ?? true),
}
})
}

getTeamApps(teamId: string): Array<App> {
const allApps = this.getApps()

if (teamId === 'admin') return allApps

const core = this.getCore()
const teamApps = providerSpecificApps
const teamApps = allApps
.map((app: App) => {
const isShared = !!core.adminApps.find((a) => a.name === app.id)?.isShared
const inTeamApps = !!core.teamApps.find((a) => a.name === app.id)
Expand Down
Loading