From: Ian Jackson Date: Sun, 26 Jul 2020 22:04:27 +0000 (+0100) Subject: list all games X-Git-Tag: otter-0.2.0~1237 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f31565455f6377d02a2de79198a80d06be5ae9f9;p=otter.git list all games --- diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index bfbe90d5..452b24a5 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -106,9 +106,16 @@ impl CommandStream<'_> { } } -#[throws(AuthorisationError)] +#[throws(MgmtError)] fn authorise_scope(cs: &CommandStream, wanted: &ManagementScope) -> AuthorisedSatisfactory { + do_authorise_scope(cs, wanted) + .map_err(|e| cs.map_auth_err(e))? +} + +#[throws(AuthorisationError)] +fn do_authorise_scope(cs: &CommandStream, wanted: &ManagementScope) + -> AuthorisedSatisfactory { type AS = (T, ManagementScope); match &wanted { @@ -194,9 +201,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { SetScope{ scope: wanted_scope } => { let authorised : AuthorisedSatisfactory = - authorise_scope(cs, &wanted_scope) - .map_err(|e| cs.map_auth_err(e)) - ?; + authorise_scope(cs, &wanted_scope)?; cs.scope = Some(authorised.into_inner()); Fine { } }, @@ -227,15 +232,20 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { Fine { } }, - ListGames { } => { - let scope = cs.scope.as_ref().ok_or(NoScope)?; - let mut games = list_games(Some(scope)); + ListGames { all } => { + let scope = if all == Some(true) { + let _authorise : AuthorisedSatisfactory = + authorise_scope(cs, &ManagementScope::Server)?; + None + } else { + let scope = cs.scope.as_ref().ok_or(NoScope)?; + Some(scope) + }; + let mut games = list_games(scope); games.sort_unstable(); GamesList { games } }, -// let game = cs.lookup_game(&game)?; - } } diff --git a/src/commands.rs b/src/commands.rs index 064c89b3..b935d25c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -6,7 +6,7 @@ pub enum MgmtCommand { Noop { }, SetScope { scope: ManagementScope }, CreateGame { name: String, insns: Vec }, - ListGames { }, + ListGames { all: Option, }, } #[derive(Debug,Serialize,Deserialize)]