Streamline can_run access control method
authorJeremy Stanley <fungi@yuggoth.org>
Wed, 30 Sep 2020 18:07:46 +0000 (18:07 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Wed, 30 Sep 2020 18:07:46 +0000 (18:07 +0000)
Minor rework of can_run() to replace the chain of elifs with simple
short-circuiting conditions each with its own return() so that it's
clearer this operates in a "first match" model.

mudpy/misc.py

index 044614f..fd4e0ac 100644 (file)
@@ -189,22 +189,18 @@ class Element:
 
         # has to be in the commands group
         if command not in self.universe.groups["command"].values():
-            result = False
+            return(False)
 
         # avatars of administrators can run any command
-        elif self.owner and self.owner.account.get("administrator"):
-            result = True
+        if self.owner and self.owner.account.get("administrator"):
+            return(True)
 
         # everyone can run non-administrative commands
-        elif not command.get("administrative"):
-            result = True
+        if not command.get("administrative"):
+            return(True)
 
         # otherwise the command cannot be run by this actor
-        else:
-            result = False
-
-        # pass back the result
-        return result
+        return(False)
 
     def update_location(self):
         """Make sure the location's contents contain this element."""