chiark / gitweb /
list all games
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jul 2020 22:04:27 +0000 (23:04 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jul 2020 22:04:27 +0000 (23:04 +0100)
src/cmdlistener.rs
src/commands.rs

index bfbe90d58ee5877f24f88753dd455176fe15e078..452b24a57fade7de3353f8b77799ade5aab1eb13 100644 (file)
@@ -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> = (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)?;
-
   }
 }
 
index 064c89b30267b5f859ebe23e8876f0cc9f28da9c..b935d25ceb1454960fe484c40ab85cb543e05c50 100644 (file)
@@ -6,7 +6,7 @@ pub enum MgmtCommand {
   Noop { },
   SetScope { scope: ManagementScope },
   CreateGame { name: String, insns: Vec<MgmtGameInstruction> },
-  ListGames { },
+  ListGames { all: Option<bool>, },
 }
 
 #[derive(Debug,Serialize,Deserialize)]