momentum-mod / website

Momentum Mod's main website.
https://momentum-mod.org
MIT License
55 stars 60 forks source link

Killswitches For Core Functionality #943

Closed Gocnak closed 3 weeks ago

Gocnak commented 1 month ago

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.

tsa96 commented 1 month 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,

tsa96 commented 1 month ago

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.

tsa96 commented 1 month ago

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

MAP_SUBMISSION

MAP_REVIEWS