tethysplatform / tethys

The Tethys Platform main Django website project repository.
http://tethysplatform.org/
BSD 2-Clause "Simplified" License
92 stars 50 forks source link

Tethys Async Websocket Consumer with Permission Checks #1012

Closed ckrew closed 6 months ago

ckrew commented 7 months ago

This PR is to resolve issue https://github.com/tethysplatform/tethys/issues/1009.

The newly created TethysAsyncWebsocketConsumer class will replace the AsyncWebsocketConsumer class. The new TethysAsyncWebsocketConsumer class has the following capabilities:

The websocket tutorial docs have been updated as well to show the new capabilities.

coveralls commented 7 months ago

Coverage Status

coverage: 100.0%. remained the same when pulling e20223f31cc87b3b8ea3d6bef6a8142db2582007 on ckrew:websocket_permissions into 9f5b60c787c1c3f2bca29df83d3da64b1377f532 on tethysplatform:main.

ckrew commented 7 months ago

I updated this PR after reviewing some feedback. The main thing was keeping user experience consistent with regards to decorators. Users can now use the new capabilities just like a controller by supplying arguments in the decorator. An example is below:

image

The methods for connecting and disconnecting have now been separated according to user authorization. So there is now a "authorized_connect", "unauthorized_connect", "authorized_disconnect", and "unauthorized_disconnect" so that developers can handle whatever use case they experience.

For the backend, the solution was using a mixin and dynamically adding new methods from the mixin to the decorated class. This works for both async and sync websockets as well.

sdc50 commented 7 months ago

@swainn It looks like the Docker build is failing because the secrets.DOCKER_UPLOAD_URL is not being substituted in correctly. I'm not sure why that would be the case. On successful jobs it looks like this: ***:dev, but in this one its just :dev.

sdc50 commented 6 months ago

I think we decided that the docker build won't work because this is being merged from a fork. Once other checks pass then I approve merging.