mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 18:07:33 -02:30
satisfy generic Role code
* User in channels session is a lazy user class. This does not conform to what the generic Role ancestry code expects. The Role ancestry code expects a User objects. This change converts the lazy object into a proper User object before calling the permission code path.
This commit is contained in:
committed by
Ryan Petrello
parent
5818dcc980
commit
088373963b
@@ -13,6 +13,7 @@ from django.http.cookie import parse_cookie
|
|||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from channels.generic.websocket import AsyncJsonWebsocketConsumer
|
from channels.generic.websocket import AsyncJsonWebsocketConsumer
|
||||||
from channels.layers import get_channel_layer
|
from channels.layers import get_channel_layer
|
||||||
@@ -142,7 +143,14 @@ class EventConsumer(AsyncJsonWebsocketConsumer):
|
|||||||
|
|
||||||
@database_sync_to_async
|
@database_sync_to_async
|
||||||
def user_can_see_object_id(self, user_access, oid):
|
def user_can_see_object_id(self, user_access, oid):
|
||||||
return user_access.get_queryset().filter(pk=oid).exists()
|
# At this point user is a channels.auth.UserLazyObject object
|
||||||
|
# This causes problems with our generic role permissions checking.
|
||||||
|
# Specifically, type(user) != User
|
||||||
|
# Therefore, get the "real" User objects from the database before
|
||||||
|
# calling the access permission methods
|
||||||
|
user_access.user = User.objects.get(id=user_access.user.id)
|
||||||
|
res = user_access.get_queryset().filter(pk=oid).exists()
|
||||||
|
return res
|
||||||
|
|
||||||
async def receive_json(self, data):
|
async def receive_json(self, data):
|
||||||
from awx.main.access import consumer_access
|
from awx.main.access import consumer_access
|
||||||
|
|||||||
Reference in New Issue
Block a user