Skip to content

Commit

Permalink
Wire up roles
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Feb 16, 2024
1 parent 60494bb commit d146811
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 25 deletions.
26 changes: 24 additions & 2 deletions api/lib/api/mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TAKList<MissionSubscriber>> {
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<TAKList<any>> {
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<MissionSubscriber> {
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
*/
Expand Down
53 changes: 47 additions & 6 deletions api/routes/marti-mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand Down
31 changes: 14 additions & 17 deletions api/web/src/components/CloudTAK/Mission/Mission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,18 @@
</div>
</template>
<template v-else-if='mode === "users"'>
<div v-for='contact of contacts'>
<Contact @chat='$emit("chat", $event)' :contact='contact'/>
<div v-for='sub of subscriptions'>
<div class='col-12 py-2 d-flex hover-dark'>
<div class='row col-12 align-items-center'>
<div class='col-auto mx-2'>
<div v-text='sub.username'></div>
<div v-text='sub.username' class='subheader'></div>
</div>
<div class='col-auto ms-auto btn-list'>
<span v-text='sub.role.type'/>
</div>
</div>
</div>
</div>
</template>
<template v-else-if='mode === "contents"'>
Expand Down Expand Up @@ -193,7 +203,6 @@ import {
TablerInput,
TablerLoading
} from '@tak-ps/vue-tabler';
import Contact from '../partial/Contact.vue';
import { useOverlayStore } from '/src/stores/overlays.js';
import { useMapStore } from '/src/stores/map.js';
const overlayStore = useOverlayStore();
Expand Down Expand Up @@ -231,7 +240,6 @@ export default {
passwordProtected: this.initial.passwordProtected,
},
imports: [],
contacts: [],
subscriptions: []
}
},
Expand Down Expand Up @@ -323,18 +331,8 @@ export default {
},
fetchSubscriptions: async function() {
try {
const url = await window.stdurl(`/api/marti/missions/${this.mission.name}/subscriptions`);
this.subscriptions = await window.std(url);
} catch (err) {
this.err = err;
}
this.loading.users = false;
},
fetchContacts: async function() {
try {
this.loading.users = true;
const url = await window.stdurl(`/api/marti/missions/${this.mission.name}/contacts`);
this.contacts = await window.std(url);
const url = await window.stdurl(`/api/marti/missions/${this.mission.name}/subscriptions/roles`);
this.subscriptions = (await window.std(url)).data;
} catch (err) {
this.err = err;
}
Expand Down Expand Up @@ -370,7 +368,6 @@ export default {
},
components: {
Status,
Contact,
TablerNone,
UploadImport,
Alert,
Expand Down

0 comments on commit d146811

Please sign in to comment.