Big commit. We now have a respectable command table with built in permission checking. I've commented this pretty well, so see cmdtable.py and cmdhandler.py for more details. There is also some assorted cleanup and an unrelated fix or two resulting from the new Twisted back-end. Note that for the permissions, you will eventually be able to override the codebase's permissions via the web interface for each command.
This commit is contained in:
parent
9746382614
commit
204ef6d4c5
7 changed files with 151 additions and 69 deletions
|
|
@ -9,17 +9,15 @@ class GenericPerm(models.Model):
|
|||
permissions = (
|
||||
("announce", "May use @wall to make announcements"),
|
||||
("boot", "May use @boot to kick players"),
|
||||
("builder", "May build"),
|
||||
("builder", "Can build and modify objects"),
|
||||
("chown_all", "Can @chown anything to anyone."),
|
||||
("control_all", "May control everything"),
|
||||
("examine_all", "Can examine any object"),
|
||||
("extended_who", "May see extended WHO list"),
|
||||
("free_money", "Has infinite money"),
|
||||
("long_fingers", "May get/look/examine etc. from a distance"),
|
||||
("steal", "May give negative money"),
|
||||
("set_hide", "May set themself invisible"),
|
||||
("shutdown", "May @shutdown the site"),
|
||||
("tel_anywhere", "May @teleport anywhere"),
|
||||
("tel_anyone", "May @teleport anything"),
|
||||
("see_session_data", "May see detailed player session data"),
|
||||
("process_control", "May shutdown/restart/reload the game"),
|
||||
("manage_players", "Can change passwords, siteban, etc."),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -133,6 +133,8 @@ class Object(models.Model):
|
|||
"""
|
||||
Checks to see whether a user has the specified permission or is a super
|
||||
user.
|
||||
|
||||
perm: (string) A string representing the desired permission.
|
||||
"""
|
||||
if not self.is_player():
|
||||
return False
|
||||
|
|
@ -145,6 +147,28 @@ class Object(models.Model):
|
|||
else:
|
||||
return False
|
||||
|
||||
def user_has_perm_list(self, perm_list):
|
||||
"""
|
||||
Checks to see whether a user has the specified permission or is a super
|
||||
user. This form accepts an iterable of strings representing permissions,
|
||||
if the user has any of them return true.
|
||||
|
||||
perm: (iterable) An iterable of strings of permissions.
|
||||
"""
|
||||
if not self.is_player():
|
||||
return False
|
||||
|
||||
if self.is_superuser():
|
||||
return True
|
||||
|
||||
for perm in perm_list:
|
||||
# Stop searching perms on the first match.
|
||||
if self.get_user_account().has_perm(perm):
|
||||
return True
|
||||
|
||||
# Fall through to failure
|
||||
return False
|
||||
|
||||
def owns_other(self, other_obj):
|
||||
"""
|
||||
See if the envoked object owns another object.
|
||||
|
|
@ -170,10 +194,9 @@ class Object(models.Model):
|
|||
if self.owns_other(other_obj):
|
||||
# If said object owns the target, then give it the green.
|
||||
return True
|
||||
else:
|
||||
# Still pending more stuff here, for now assume we have
|
||||
# dominance. Bad assumption.
|
||||
return True
|
||||
|
||||
# They've failed to meet any of the above conditions.
|
||||
return False
|
||||
|
||||
def set_home(self, new_home):
|
||||
"""
|
||||
|
|
@ -643,6 +666,9 @@ class CommChannel(models.Model):
|
|||
|
||||
class Meta:
|
||||
ordering = ['-name']
|
||||
permissions = (
|
||||
("emit_commchannel", "May @cemit over channels."),
|
||||
)
|
||||
|
||||
class Admin:
|
||||
list_display = ('name', 'owner')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue