Closed Gocnak closed 3 weeks ago
Sounds very doable.
I think we could use an NestJS guard here and custom decorator, e.g. decorate an endpoint with
@KillswitchGuard(Killswitch.MAP_SUBMISSION)
That guard would inject a small KillswitchService
with some method like
checkKillswitch(Killswitch switch): boolean {
return this.switches[switch];
}
where switches
is a Record<Killswitch, boolean>
.
In future, after multi-deploy, it'd be stored in Redis.
A single admin-only endpoint would take the entire Record<Killswitch, boolean>
to update the object/redis hash. Frontend would just be a bunch of checkboxes reflecting those.
For testing, might want to generate a test util that takes an array of switches and tests a certain endpoint against all of them (or all possible switches, and check that unapplied ones don't apply). Then it'd be 1-2 lines per endpoint to test.
This is a very good first issue for someone wanting to learn some more Nest. If you don't know Angular and only want to do the backend, ask someone else to do frontend, is a very easy job,
Oh and for frontend, make sure to just generate a bunch of <input type="checkbox">
s using the Killswitch enum - we should never need to use any individual values.
Okay so currently we have these switches
enum KillswitchType {
NEW_SIGNUPS = 'NEW_SIGNUPS',
RUN_SUBMISSION = 'RUN_SUBMISSION',
MAP_SUBMISSION = 'MAP_SUBMISSION',
MAP_REVIEWS = 'MAP_REVIEWS'
}
NEW_SIGNUPS
This is complicated, rather than using a guard it should be a check inside the authentication logic somewhere, would need to re-read up on all that
RUN_SUBMISSION
/sessions/run POST
/sessions/run DELETE
Others I think we can skip, since we'll going to port this endpoints to WS in the future anyway and don't think it's worth the faff with tests, and probably harmless to let players finish a run they've startedMAP_SUBMISSION
/maps POST
/maps/:mapID POST
/maps/:mapID/credits PUT
/maps/:mapI/images PUT
MAP_REVIEWS
/maps/:mapID/reviews POST
/map-review/:reviewID PATCH
/map-review/:reviewID DELETE
/map-review/:reviewID/comments POST
/map-review/:reviewID/comments PATCH
/map-review/:reviewID/comments DELETE
A great admin tool we should have by 1.0.0 is killswitches; being able to "toggle off" core functionality of the backend.
E.g. a game-breaking bug is discovered and we need to shut off run submissions for a bit while we get a patch out.
Ideally the endpoint that would be tied to this killswitch would then return a 503 so it can be handled by the clients.
Kill switches I can think of:
This list can be expanded upon with sub-level switches, e.g. turning off comments on map submission vs turning off map submission entirely.
In the future we could make the switches have 3 modes: ON, OFF, OFF for public, where just admins can still do things as to test if fixes are in place.