Use allow/deny

This commit is contained in:
Erik Johnston 2018-10-25 15:25:21 +01:00
parent 47a9ba435d
commit e5481b22aa
3 changed files with 11 additions and 11 deletions

View file

@ -35,13 +35,13 @@ class RoomDirectoryConfig(Config):
# The format of this option is a list of rules that contain globs that # The format of this option is a list of rules that contain globs that
# match against user_id and the new alias (fully qualified with server # match against user_id and the new alias (fully qualified with server
# name). The action in the first rule that matches is taken, which can # name). The action in the first rule that matches is taken, which can
# currently either be "allowed" or "denied". # currently either be "allow" or "deny".
# #
# If no rules match the request is denied. # If no rules match the request is denied.
alias_creation_rules: alias_creation_rules:
- user_id: "*" - user_id: "*"
alias: "*" alias: "*"
action: allowed action: allow
""" """
def is_alias_creation_allowed(self, user_id, alias): def is_alias_creation_allowed(self, user_id, alias):
@ -56,7 +56,7 @@ class RoomDirectoryConfig(Config):
""" """
for rule in self._alias_creation_rules: for rule in self._alias_creation_rules:
if rule.matches(user_id, alias): if rule.matches(user_id, alias):
return rule.action == "allowed" return rule.action == "allow"
return False return False
@ -67,12 +67,12 @@ class _AliasRule(object):
user_id = rule["user_id"] user_id = rule["user_id"]
alias = rule["alias"] alias = rule["alias"]
if action in ("allowed", "denied"): if action in ("allow", "deny"):
self.action = action self.action = action
else: else:
raise ConfigError( raise ConfigError(
"alias_creation_rules rules can only have action of 'allowed'" "alias_creation_rules rules can only have action of 'allow'"
" or 'denied'" " or 'deny'"
) )
try: try:

View file

@ -26,16 +26,16 @@ class RoomDirectoryConfigTestCase(unittest.TestCase):
alias_creation_rules: alias_creation_rules:
- user_id: "*bob*" - user_id: "*bob*"
alias: "*" alias: "*"
action: "denied" action: "deny"
- user_id: "*" - user_id: "*"
alias: "#unofficial_*" alias: "#unofficial_*"
action: "allowed" action: "allow"
- user_id: "@foo*:example.com" - user_id: "@foo*:example.com"
alias: "*" alias: "*"
action: "allowed" action: "allow"
- user_id: "@gah:example.com" - user_id: "@gah:example.com"
alias: "#goo:example.com" alias: "#goo:example.com"
action: "allowed" action: "allow"
""") """)
rd_config = RoomDirectoryConfig() rd_config = RoomDirectoryConfig()

View file

@ -118,7 +118,7 @@ class TestCreateAliasACL(unittest.HomeserverTestCase):
{ {
"user_id": "*", "user_id": "*",
"alias": "#unofficial_*", "alias": "#unofficial_*",
"action": "allowed", "action": "allow",
} }
] ]