GrafeasGroup / blossom

The website. The app. The everything.
6 stars 3 forks source link

Add generic Permission structure #196

Open itsthejoker opened 3 years ago

itsthejoker commented 3 years ago

Thankfully, this is really easy and is just extending a little bit of the BlossomUser class: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#custom-permissions

Example:

class BlossomUser(...):
    class Meta:
        permissions = [
            ("tor_expert", "Is recognized as an Expert and has extra abilities on the subreddit")
        ]

usage:

me = BlossomUser.objects.get(username="me")
if me.has_perm("user.tor_expert"):
    do_stuff()