Do permissions in Pyramid always have to be strings, or can you use an enum?
Currently we use this enum-like class to store all our permission strings as
namespaced constants:
class Permission:
class User:
READ = "user:read"
CREATE = "user:create"
UPDATE = "user:update"
class Admin:
FOO = "admin:foo"
This is just as an alternative to always duplicating the literal strings
everywhere. It works nicely with autocomplete, allows PyLint to catch typos,
etc.
It *seems* to work fine if we use enums:
from enum import Enum
class Permission:
class User(Enum):
READ = "user:read"
CREATE = "user:create"
UPDATE = "user:update"
class Admin(Enum):
FOO = "admin:foo"
The reason is just so that we can get some of the functionality of Enum, like
being able to iterate over them.
>From what I can tell from the Pyramid docs permissions are usually strings,
>but I don't see any concrete reason why arbitrary values can't be used for
>permissions. Built-in permissions like security.Authenticated are strings but
>I don't think that will cause any problems if our own permissions are enums.
This seems to be fine?
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/b87825cb-be39-4a51-adb4-7eb20788ecc1%40www.fastmail.com.