Skip to content

Commit

Permalink
Set Readonly on Mission Diff
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Jun 13, 2024
1 parent 7a5073f commit 6792351
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

### Pending Release

- :rocket: `API` Ensure `mission_groups` is set if `All Groups` function is used when creating Data Sync
- :rocket: `UI` Disable Mission Role and set value to READONLY

### v2.39.0 - 2024-06-13

- :rocket: `API` Add indexes to Iconsets & Basemaps for user based lookup
Expand Down
10 changes: 8 additions & 2 deletions api/lib/api/mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ export default class {
});

if (!missions.data.length) throw new Err(404, null, `No Mission for Name: ${name}`);

return missions.data[0];
}

Expand All @@ -594,14 +595,19 @@ export default class {
async create(
name: string,
query: Static<typeof CreateInput>
): Promise<TAKList<Static<typeof Mission>>> {
): Promise<Static<typeof Mission>> {
const url = new URL(`/Marti/api/missions/${this.#encodeName(name)}`, this.api.url);

if (query.group && Array.isArray(query.group)) query.group = query.group.join(',');
for (const q in query) url.searchParams.append(q, String(query[q]));
return await this.api.fetch(url, {
const missions = await this.api.fetch(url, {
method: 'POST'
});

if (!missions.data.length) throw new Error('Create Mission didn\'t return a mission or an error');
const mission = missions.data[0];

return mission;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions api/lib/data-mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ export default class DataMission {
data.mission_groups = groups.data.map((group) => { return group.name });
}

const missions = await api.Mission.create(data.name, {
let mission = await api.Mission.create(data.name, {
creatorUid: `connection-${data.connection}-data-${data.id}`,
description: data.description,
defaultRole: data.mission_role,
group: data.mission_groups,
});

if (!missions.data.length) throw new Error('Create Mission didn\'t return a mission or an error');
mission = missions.data[0];
// The groups property isn't returned by Create
// Make this second call to get the groups - TODO Talk to Josh
mission = await api.Mission.get(data.name, {}, {
token: data.mission_token
});

await config.models.Data.commit(data.id, {
mission_token: mission.token
Expand Down
2 changes: 2 additions & 0 deletions api/routes/connection-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export default async function router(schema: Schema, config: Config) {
throw new Err(400, null, 'MissionDiff can only be enabled with a single layer')
}

// TODO: Don't allow mission_diff to be turned on if there are non MISSION_READONLY subscribers

let data = await config.models.Data.from(req.params.dataid);
if (data.connection !== connection.id) throw new Err(400, null, 'Data Sync does not belong to given Connection');

Expand Down
3 changes: 2 additions & 1 deletion api/routes/marti-mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default async function router(schema: Schema, config: Config) {
inviteOnly: Type.Optional(Type.Boolean()),
allowDupe: Type.Optional(Type.Boolean()),
}),
res: GenericMartiResponse
res: Mission
}, async (req, res) => {
try {
const user = await Auth.as_user(config, req);
Expand All @@ -163,6 +163,7 @@ export default async function router(schema: Schema, config: Config) {
bbox: req.query.bbox ? req.query.bbox.split(',') : req.query.bbox,
creatorUid: user.email
});

return res.json(mission);
} catch (err) {
return Err.respond(err, res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default {
method: 'POST',
});
this.$emit('mission', res.data[0]);
this.$emit('mission', res);
} catch (err) {
this.err = err;
}
Expand Down
7 changes: 6 additions & 1 deletion api/web/src/components/DataEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<TablerEnum
v-model='data.mission_role'
label='Mission Default Role'
:disabled='$route.params.dataid'
:disabled='$route.params.dataid || data.mission_diff'
description='The Default role assigned to subscribers to the mission'
:options='["MISSION_OWNER", "MISSION_SUBSCRIBER", "MISSION_READONLY_SUBSCRIBER"]'
/>
Expand Down Expand Up @@ -193,6 +193,11 @@ export default {
handler: function() {
this.mission_groups = this.data.mission_groups.length === 0 ? "All Groups" : this.data.mission_groups.join(",");
}
},
'data.mission_diff': function() {
if (!this.data.id && this.data.mission_diff) {
this.data.mission_role = 'MISSION_READONLY_SUBSCRIBER';
}
}
},
mounted: async function() {
Expand Down

0 comments on commit 6792351

Please sign in to comment.