From d1468114c358986457abb8021e4f5afe0320d04a Mon Sep 17 00:00:00 2001 From: ingalls Date: Fri, 16 Feb 2024 08:53:45 -0700 Subject: [PATCH] Wire up roles --- api/lib/api/mission.ts | 26 ++++++++- api/routes/marti-mission.ts | 53 ++++++++++++++++--- .../components/CloudTAK/Mission/Mission.vue | 31 +++++------ 3 files changed, 85 insertions(+), 25 deletions(-) diff --git a/api/lib/api/mission.ts b/api/lib/api/mission.ts index d4842daa3..7051e8c79 100644 --- a/api/lib/api/mission.ts +++ b/api/lib/api/mission.ts @@ -108,15 +108,37 @@ export default class { } /** - * List users subscribed to a mission + * Return UIDs associated with any subscribed users */ async subscriptions(name: string): Promise> { - const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/subscription`, this.api.url); + const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/subscriptions`, this.api.url); + return await this.api.fetch(url, { + method: 'GET' + }); + } + + /** + * Return permissions associated with any subscribed users + */ + async subscriptionRoles(name: string): Promise> { + const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/subscriptions/roles`, this.api.url); return await this.api.fetch(url, { method: 'GET' }); } + /** + * Return permissions associated with a given mission if subscribed + */ + async subscription(name: string): Promise { + const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/subscription`, this.api.url); + const res = await this.api.fetch(url, { + method: 'GET' + }); + + return res.data; + } + /** * Subscribe to a mission */ diff --git a/api/routes/marti-mission.ts b/api/routes/marti-mission.ts index 809def9c0..cebae67ac 100644 --- a/api/routes/marti-mission.ts +++ b/api/routes/marti-mission.ts @@ -175,18 +175,36 @@ export default async function router(schema: any, config: Config) { } }); + await schema.get('/marti/missions/:name/subscription', { + name: 'Mission Subscription', + group: 'MartiMissions', + auth: 'user', + ':name': 'string', + description: 'Return subscriptions associated with your user', + res: { type: 'object' } + }, async (req: AuthRequest, res: Response) => { + try { + await Auth.is_auth(config.models, req); + + const user = await Auth.as_user(config.models, req); + const auth = (await config.models.Profile.from(user.email)).auth; + const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key)); + + const sub = await api.Mission.subscription(String(req.params.name)); + + return res.json(sub); + } catch (err) { + return Err.respond(err, res); + } + }); + await schema.get('/marti/missions/:name/subscriptions', { name: 'Mission Subscriptions', group: 'MartiMissions', auth: 'user', ':name': 'string', description: 'List subscriptions associated with a mission', - res: { - type: 'array', - items: { - type: 'object', - } - } + res: 'res.Marti.json' }, async (req: AuthRequest, res: Response) => { try { await Auth.is_auth(config.models, req); @@ -203,6 +221,29 @@ export default async function router(schema: any, config: Config) { } }); + await schema.get('/marti/missions/:name/subscriptions/roles', { + name: 'Mission Subscriptions', + group: 'MartiMissions', + auth: 'user', + ':name': 'string', + description: 'List subscriptions associated with a mission', + res: 'res.Marti.json' + }, async (req: AuthRequest, res: Response) => { + try { + await Auth.is_auth(config.models, req); + + const user = await Auth.as_user(config.models, req); + const auth = (await config.models.Profile.from(user.email)).auth; + const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key)); + + const roles = await api.Mission.subscriptionRoles(String(req.params.name)); + + return res.json(roles); + } catch (err) { + return Err.respond(err, res); + } + }); + await schema.get('/marti/missions/:name/contacts', { name: 'Mission Contacts', group: 'MartiMissions', diff --git a/api/web/src/components/CloudTAK/Mission/Mission.vue b/api/web/src/components/CloudTAK/Mission/Mission.vue index 5e96baa32..77f711e51 100644 --- a/api/web/src/components/CloudTAK/Mission/Mission.vue +++ b/api/web/src/components/CloudTAK/Mission/Mission.vue @@ -94,8 +94,18 @@