Last active
February 7, 2019 12:13
-
-
Save osantana/c118ac436fad44dd1c7b11618a1ea1b9 to your computer and use it in GitHub Desktop.
Usage Spike
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- resource: listing | |
- permissions: | |
- profile1: | |
- READ | |
- profile2: | |
- UPDATE | |
- fields: | |
- code: | |
- profile1: | |
- SET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from drf import fields | |
from permissions import READ, UPDATE, SET | |
# READ == read the duh! | |
# UPDATE(list-of-values-or-none-for-all-values) == update value (duh!*2) | |
# SET(list-of-values-or-none) == 'write once'. From None -> value | |
# UNSET(...) == remove info. From value -> None. | |
class OrderSerializer(OlistSerializer): | |
class Meta: | |
permissions = { | |
'seller': [READ], | |
'store': [UPDATE], | |
'channel': [READ], | |
} | |
# ownership access/queryset will be handled at the Resource Level | |
# fields | |
code = allow( # assuming a deny-all default. We can invert this to allow-all and create a deny() decorator. | |
fields.CharField(...), | |
permissions={ | |
'store': [READ, SET], | |
# ... fallback to resources permission ... | |
# eg. 'channel': [READ], | |
}, | |
) | |
channel_code = allow( | |
fields.CharField(...), | |
permissions={ | |
'channel': [SET], | |
}, | |
) | |
status = allow( | |
fields.OptionField(...), | |
permissions={ | |
'channel': [ | |
UPDATE('created', 'approved', 'canceled'), | |
], | |
'seller': [ | |
UPDATE('invoiced'), # <-- this is a fake case just for ilustration | |
], | |
}, | |
) | |
class ListingSerializer(OlistSerializer): | |
class Meta: | |
permissions = load('config.yml', 'listing') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment