Closed jreyesr closed 3 years ago
For the frontend:
used_space
and maximum_space
fields in User are exposed by the UserSerializerthis.loggedInUser.used_space
and this.loggedInUser.maximum_space
to style a progress bar. Use https://bootstrap-vue.org/docs/components/progress#custom-progress-label to write a nice label. ~Probably use variant="secondary"
to contrast with the teal navbar.~this.loggedInUser.used_space >= this.loggedInUser.maximum_space
, disable the Create Flight and Create Project buttons. On the AddNewFlightPartial and AddNewProject components:
unable_reason
that returns "Póngase en contacto con AgroSmart para activar su cuenta." if this.targetUser.type
is not ACTIVE or ADMIN, "Su almacenamiento está lleno." if this.targetUser.used_space >= this.targetUser.maximum_space
, and "" otherwisecanCreateFlights
/canCreateProjects
computed properties to be return this.unable_reason == ""
No puede crear vuelos. {{ unable_reason }}
(same for Projects)fetch
/axios
calls, and display a nice error message.
When the app is paid, there will be a limit on available disk space per user (á la Gmail, only 45 GB instead of 15). Therefore, there must be a way to track disk usage per user, display it, and prevent the creation of Flights and Projects when a user is over capacity. Required changes would be:
used_space
andmaximum_space
fields in the User, Flight and UserProject model (probably aPositiveIntegerField
) tracking the number of KILObytes (don't track bytes, PositiveIntegerField is only guaranteed to hold a 32-bit integer, which would cap out at 4GB).User.maximum_space
should have a default value ofdefault=45*1024*1024
update_disk_space(self)
on the Flight and UserProject models, that should use something like https://stackoverflow.com/a/1392549 to compute the number of bytes used by the Flight/Project and update theself.used_space
field. Don't forget to callself.save()
!update_disk_space(self)
on the User model that loops over all UserProjects and Flights that belong toself
and updatesself.used_space
to the new value. Don't forget to callself.save()
!flight.update_disk_space()
andflight.user.update_disk_space()
on the webhook (after all postprocessing).proj.update_disk_space()
andproj.user.update_disk_space()
on the Project creation code path, just after https://github.com/IS-AgroSmart/AgroSmart-Web/blob/8d107206110f10c4276373a7aedd1198d0fcb647/core/serializers.py#L75flight.update_disk_space()
,project.update_disk_space()
andproj.user.update_disk_space()
after https://github.com/IS-AgroSmart/AgroSmart-Web/blob/8d107206110f10c4276373a7aedd1198d0fcb647/core/views.py#L485-L487 The call toflight.update_disk_space()
should be inside thefor
, the other two calls should go afterproject._create_index_datastore(clean_index)
project.update_disk_space()
andproject.user.update_disk_space()
somewhere (near the end) on theupload_geotiff
andupload_vectorfile
views: https://github.com/IS-AgroSmart/AgroSmart-Web/blob/8d107206110f10c4276373a7aedd1198d0fcb647/core/views.py#L406 https://github.com/IS-AgroSmart/AgroSmart-Web/blob/8d107206110f10c4276373a7aedd1198d0fcb647/core/views.py#L355user.update_disk_space()
whenever a Flight or Project is deleted, made demo or made normal again.post_delete
signals, near https://github.com/IS-AgroSmart/AgroSmart-Web/blob/8d107206110f10c4276373a7aedd1198d0fcb647/core/models.py#L466-L467make_demo
anddelete_demo
actions on theFlightViewSet
andUserProjectViewSet
classes onviews.py
.upload_images
view, reject uploads if user disk quota is exceeded: after L236, checkflight.user.used_space
againstflight.user.maximum_space
. If over quota, return HTTP status code 402 (Payment Required) https://github.com/IS-AgroSmart/AgroSmart-Web/blob/2849cf12cf783ff0837c91eebeb328c270021382/core/views.py#L232-L238create
method to block creation if user is over quota: get the effective user (can berequest.user
orUser.objects.get(pk=request.META["HTTP_TARGETUSER"])
), check the user'sused_space
andmaximum_space
; if it's over quota, return HTTP 402.create_raster_index
,upload_geotiff
andupload_vectorfile
views. If over quota, return HTTP 402.