summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
347ddf4)
Switch account elements to the new data model, and fix some
old-style assumptions in Element creation and destruction. Also use
(and coerce to) boolean values for the administrator facet, and be
more clear in logs when accounts authenticating are admins or not.
# parse out appropriate category and subkey names, add to list
if self.key.find(":") > 0:
# parse out appropriate category and subkey names, add to list
if self.key.find(":") > 0:
+ # TODO(fungi) this can be removed once old_style Elements
+ # are no longer needed
self.category, self.subkey = self.key.split(":", 1)
self.category, self.subkey = self.key.split(":", 1)
+ elif self.key.find(".") > 0:
+ self.category, self.subkey = self.key.split(".", 1)[-2:]
else:
self.category = "other"
self.subkey = self.key
else:
self.category = "other"
self.subkey = self.key
# record or reset a pointer to the origin file
self.origin = self.universe.files[origin.source]
# record or reset a pointer to the origin file
self.origin = self.universe.files[origin.source]
- # add a data section to the origin if necessary
- if self.key not in self.origin.data:
- self.origin.data[self.key] = {}
-
# add or replace this element in the universe
self.universe.contents[self.key] = self
self.universe.categories[self.category][self.subkey] = self
# add or replace this element in the universe
self.universe.contents[self.key] = self
self.universe.categories[self.category][self.subkey] = self
def destroy(self):
"""Remove an element from the universe and destroy it."""
def destroy(self):
"""Remove an element from the universe and destroy it."""
- del(self.origin.data[self.key])
+ if self.old_style:
+ del self.origin.data[self.key]
+ else:
+ for facet in self.facethash:
+ del self.origin.data[".".join((self.key, facet))]
del self.universe.categories[self.category][self.subkey]
del self.universe.contents[self.key]
del self
del self.universe.categories[self.category][self.subkey]
del self.universe.contents[self.key]
del self
"disallowed")
if facet in ["loglevel"]:
value = int(value)
"disallowed")
if facet in ["loglevel"]:
value = int(value)
+ elif facet in ["administrator"]:
+ value = bool(value)
if not self.has_facet(facet) or not self.get(facet) == value:
if self.old_style:
if self.key not in self.origin.data:
if not self.has_facet(facet) or not self.get(facet) == value:
if self.old_style:
if self.key not in self.origin.data:
def authenticate(self):
"""Flag the user as authenticated and disconnect duplicates."""
if self.state is not "authenticated":
def authenticate(self):
"""Flag the user as authenticated and disconnect duplicates."""
if self.state is not "authenticated":
- log("User " + self.account.get("name") + " logged in.", 2)
self.authenticated = True
if ("mudpy.limit" in universe.contents and self.account.subkey in
universe.contents["mudpy.limit"].get("admins")):
self.authenticated = True
if ("mudpy.limit" in universe.contents and self.account.subkey in
universe.contents["mudpy.limit"].get("admins")):
- self.account.set("administrator", "True")
+ self.account.set("administrator", True)
+ log("Administrator %s authenticated." %
+ self.account.get("name"), 2)
+ else:
+ # log("User %s authenticated." % self.account.get("name"), 2)
+ log("User %s authenticated." % self.account.subkey, 2)
def show_menu(self):
"""Send the user their current menu."""
def show_menu(self):
"""Send the user their current menu."""
# otherwise, this could be a brand new user
else:
# otherwise, this could be a brand new user
else:
- user.account = Element("account:" + name, universe, old_style=True)
+ user.account = Element("account.%s" % name, universe)
user.account.set("name", name)
log("New user: " + name, 2)
user.state = "checking_new_account_name"
user.account.set("name", name)
log("New user: " + name, 2)
user.state = "checking_new_account_name"
)
test_custom_loglevel = (
)
test_custom_loglevel = (
- (2, "> ", "set account:admin loglevel 2"),
+ (2, "> ", "set account.admin loglevel 2"),
(2, "You have successfully .*> ", "show log"),
(2, r"There are [0-9]+ log lines in memory and [0-9]+ at or above level "
r"[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""),
)
test_invalid_loglevel = (
(2, "You have successfully .*> ", "show log"),
(2, r"There are [0-9]+ log lines in memory and [0-9]+ at or above level "
r"[0-9]+\. The matching lines\r\nfrom [0-9]+ to [0-9]+ are:", ""),
)
test_invalid_loglevel = (
- (2, "> ", "set account:admin loglevel two"),
+ (2, "> ", "set account.admin loglevel two"),
(2, r'''Value "two" of type "<class 'str'>" cannot be coerced .*> ''', ""),
)
(2, r'''Value "two" of type "<class 'str'>" cannot be coerced .*> ''', ""),
)