Change permission strings so Immortals->Developer, Wizards->Admin, Builders->Builder, PlayerHelper->Helper, Players->Player, Guests->Guest. Made perm() and pperm() lock function accept both the plural and singular form (so both Admin and Admins work). Still lacking a data migration for updating an existing database to the new setup.

This commit is contained in:
Griatch 2017-02-17 23:25:00 +01:00
parent edc092bfc4
commit 0bd47f0c52
23 changed files with 119 additions and 118 deletions

View file

@ -168,7 +168,8 @@ def perm(accessing_obj, accessed_obj, *args, **kwargs):
if utils.inherits_from(accessing_obj, "evennia.objects.objects.DefaultObject") and accessing_obj.player:
player = accessing_obj.player
perms_player = [p.lower() for p in player.permissions.all()]
# we strip eventual plural forms, so Builders == Builder
perms_player = [p.lower().rstrip("s") for p in player.permissions.all()]
is_quell = player.attributes.get("_quell")
if permission in _PERMISSION_HIERARCHY:

View file

@ -56,21 +56,21 @@ Example:
We want to limit who may edit a particular object (let's call this access_type
for 'edit', it depends on what the command is looking for). We want this to
only work for those with the Permission 'Builders'. So we use our lock
only work for those with the Permission 'Builder'. So we use our lock
function above and define it like this:
'edit:perm(Builders)'
'edit:perm(Builder)'
Here, the lock-function perm() will be called with the string
'Builders' (accessing_obj and accessed_obj are added automatically,
'Builder' (accessing_obj and accessed_obj are added automatically,
you only need to add the args/kwargs, if any).
If we wanted to make sure the accessing object was BOTH a Builders and a
If we wanted to make sure the accessing object was BOTH a Builder and a
GoodGuy, we could use AND:
'edit:perm(Builders) AND perm(GoodGuy)'
'edit:perm(Builder) AND perm(GoodGuy)'
To allow EITHER Builders and GoodGuys, we replace AND with OR. perm() is just
To allow EITHER Builder and GoodGuys, we replace AND with OR. perm() is just
one example, the lock function can do anything and compare any properties of
the calling object to decide if the lock is passed or not.
@ -79,7 +79,7 @@ the calling object to decide if the lock is passed or not.
To make these work, add the string to the lockhandler of the object you want
to apply the lock to:
obj.lockhandler.add('edit:perm(Builders)')
obj.lockhandler.add('edit:perm(Builder)')
From then on, a command that wants to check for 'edit' access on this
object would do something like this:
@ -541,13 +541,13 @@ def _test():
obj1 = TestObj()
obj2 = TestObj()
#obj1.lock_storage = "owner:dbref(#4);edit:dbref(#5) or perm(Wizards);examine:perm(Builders);delete:perm(Wizards);get:all()"
#obj1.lock_storage = "owner:dbref(#4);edit:dbref(#5) or perm(Admin);examine:perm(Builder);delete:perm(Admin);get:all()"
#obj1.lock_storage = "cmd:all();admin:id(1);listen:all();send:all()"
obj1.lock_storage = "listen:perm(Immortals)"
obj1.lock_storage = "listen:perm(Developer)"
pdb.set_trace()
obj1.locks = LockHandler(obj1)
obj2.permissions.add("Immortals")
obj2.permissions.add("Developer")
obj2.id = 4
#obj1.locks.add("edit:attr(test)")

View file

@ -25,8 +25,8 @@ from evennia.locks import lockfuncs
class TestLockCheck(EvenniaTest):
def testrun(self):
dbref = self.obj2.dbref
self.obj1.locks.add("owner:dbref(%s);edit:dbref(%s) or perm(Wizards);examine:perm(Builders) and id(%s);delete:perm(Wizards);get:all()" % (dbref, dbref, dbref))
self.obj2.permissions.add('Wizards')
self.obj1.locks.add("owner:dbref(%s);edit:dbref(%s) or perm(Admin);examine:perm(Builder) and id(%s);delete:perm(Admin);get:all()" % (dbref, dbref, dbref))
self.obj2.permissions.add('Admin')
self.assertEquals(True, self.obj1.locks.check(self.obj2, 'owner'))
self.assertEquals(True, self.obj1.locks.check(self.obj2, 'edit'))
self.assertEquals(True, self.obj1.locks.check(self.obj2, 'examine'))
@ -39,11 +39,11 @@ class TestLockCheck(EvenniaTest):
class TestLockfuncs(EvenniaTest):
def testrun(self):
self.obj2.permissions.add('Wizards')
self.obj2.permissions.add('Admin')
self.assertEquals(True, lockfuncs.true(self.obj2, self.obj1))
self.assertEquals(False, lockfuncs.false(self.obj2, self.obj1))
self.assertEquals(True, lockfuncs.perm(self.obj2, self.obj1, 'Wizards'))
self.assertEquals(True, lockfuncs.perm_above(self.obj2, self.obj1, 'Builders'))
self.assertEquals(True, lockfuncs.perm(self.obj2, self.obj1, 'Admin'))
self.assertEquals(True, lockfuncs.perm_above(self.obj2, self.obj1, 'Builder'))
dbref = self.obj2.dbref
self.assertEquals(True, lockfuncs.dbref(self.obj2, self.obj1, '%s' % dbref))
self.obj2.db.testattr = 45