From f31565455f6377d02a2de79198a80d06be5ae9f9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 26 Jul 2020 23:04:27 +0100 Subject: [PATCH] list all games --- src/cmdlistener.rs | 28 +++++++++++++++++++--------- src/commands.rs | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) 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)] -- 2.30.2