Skip to content

v0.2.0 - Expression Syntax

Choose a tag to compare

@meinsoft meinsoft released this 21 Jan 02:59
· 6 commits to main since this release

馃帀 Expression Syntax Release

New Features

  • Class-based View support - @ guard now works on CBV classes
  • Expression syntax - Write permissions as strings
  • All operators - and, or, not, ==, !=, >, <, >=, <=, in
  • Attribute access - obj.field, user.field, obj.author == user
  • null support - obj.deleted_at == null

Examples

@guard('is_admin or is_author')
@guard('obj.status == "draft"')
@guard('obj.author == user')
@guard('obj.status in ["draft", "pending"]')
@guard('user.is_staff and not obj.is_locked')

@guard('is_author')
class PostUpdateView(UpdateView):
    model = Post

Quality

  • 192 tests passing
  • 96% code coverage

Installation

pip install git+https://github.com/meinsoft/django-shield.git