Skip to content

Commit

Permalink
Add Fetch Subs endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Feb 16, 2024
1 parent 0f6a363 commit c493d6c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
22 changes: 22 additions & 0 deletions api/lib/api/mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export type Mission = {
missionChanges?: Array<unknown>; // Only present on Mission.get()
}

export type MissionSubscriber = {
token?: string;
clientUid: string;
username: string;
createTime: string;
role: {
permissions: Array<string>;
hibernateLazyInitializer: object;
type: string;
}
}

/**
* @class
*/
Expand Down Expand Up @@ -95,6 +107,16 @@ export default class {
});
}

/**
* List users subscribed to a mission
*/
async subscriptions(name: string): Promise<TAKList<MissionSubscriber>> {
const url = new URL(`/Marti/api/missions/${encodeURIComponent(name)}/subscription`, this.api.url);
return await this.api.fetch(url, {
method: 'GET'
});
}

/**
* Subscribe to a mission
*/
Expand Down
30 changes: 29 additions & 1 deletion api/routes/marti-mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,34 @@ export default async function router(schema: any, config: Config) {
}
});

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',
}
}
}, 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 subs = await api.Mission.subscriptions(String(req.params.name));

return res.json(subs);
} catch (err) {
return Err.respond(err, res);
}
});

await schema.get('/marti/missions/:name/contacts', {
name: 'Mission Contacts',
group: 'MartiMissions',
Expand Down Expand Up @@ -265,7 +293,7 @@ export default async function router(schema: any, config: Config) {
});

await schema.delete('/marti/missions/:name/upload/:hash', {
name: 'Mission Upload Delete',
nMissionSubscriptioname: 'Mission Upload Delete',
group: 'MartiMissions',
auth: 'user',
':name': 'string',
Expand Down
20 changes: 12 additions & 8 deletions api/web/src/components/CloudTAK/Mission/Mission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ const mapStore = useMapStore();
export default {
name: 'Mission',
props: {
connection: {
type: Number
},
initial: {
type: Object
},
Expand Down Expand Up @@ -234,7 +231,8 @@ export default {
passwordProtected: this.initial.passwordProtected,
},
imports: [],
contacts: []
contacts: [],
subscriptions: []
}
},
mounted: async function() {
Expand Down Expand Up @@ -275,7 +273,7 @@ export default {
await this.fetchMission();
await Promise.all([
this.fetchContacts(),
this.fetchSubscriptions(),
this.fetchImports()
]);
},
Expand Down Expand Up @@ -323,11 +321,19 @@ export default {
}
this.loading.users = false;
},
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`);
if (this.connection) url.searchParams.append('connection', this.connection);
this.contacts = await window.std(url);
} catch (err) {
this.err = err;
Expand All @@ -338,7 +344,6 @@ export default {
try {
this.loading.delete = true;
const url = window.stdurl(`/api/marti/missions/${this.mission.name}`);
if (this.connection) url.searchParams.append('connection', this.connection);
const list = await window.std(url, {
method: 'DELETE'
});
Expand All @@ -355,7 +360,6 @@ export default {
const url = window.stdurl(`/api/marti/missions/${this.mission.name}`);
url.searchParams.append('changes', 'true');
url.searchParams.append('logs', 'true');
if (this.connection) url.searchParams.append('connection', this.connection);
this.mission = await window.std(url);
} catch (err) {
this.err = err;
Expand Down

0 comments on commit c493d6c

Please sign in to comment.