Add winery reviewer
This commit is contained in:
parent
8e63b969bf
commit
af7aef6d23
|
|
@ -423,15 +423,28 @@ class IsWineryReviewer(IsStandardUser):
|
|||
rules = [
|
||||
super().has_object_permission(request, view, obj)
|
||||
]
|
||||
if hasattr(obj, 'type_id'):
|
||||
est = EstablishmentSubType.objects.filter(establishment_type_id=obj.type_id)
|
||||
# AttributeError: 'Establishment' object has no attribute 'object_id'
|
||||
if hasattr(obj, 'type_id') or hasattr(obj, 'establishment_type_id'):
|
||||
type_id: int
|
||||
if hasattr(obj, 'type_id'):
|
||||
type_id = obj.type_id
|
||||
else:
|
||||
type_id = obj.establishment_type_id
|
||||
|
||||
est = EstablishmentSubType.objects.filter(establishment_type_id=type_id)
|
||||
role = Role.objects.filter(role=Role.WINERY_REVIEWER,
|
||||
establishment_subtype_id__in=[id for type.id in est],
|
||||
country_id=obj.country_id).first()
|
||||
|
||||
object_id: int
|
||||
if hasattr(obj, 'object_id'):
|
||||
object_id = obj.object_id
|
||||
else:
|
||||
object_id = obj.establishment_id
|
||||
|
||||
rules = [
|
||||
UserRole.objects.filter(user=request.user, role=role,
|
||||
establishment_id=obj.object_id
|
||||
establishment_id=object_id
|
||||
).exists(),
|
||||
super().has_object_permission(request, view, obj)
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user