2016-12-28 14:46:42 +01:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
|
2022-04-14 23:43:26 +02:00
|
|
|
from zerver.actions.uploads import notify_attachment_update
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.attachments import access_attachment_by_id, remove_attachment, user_attachments
|
2016-12-28 14:46:42 +01:00
|
|
|
from zerver.lib.response import json_success
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.models import UserProfile
|
2016-12-28 14:46:42 +01:00
|
|
|
|
|
|
|
|
2017-11-27 09:28:57 +01:00
|
|
|
def list_by_user(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
2021-02-12 08:19:30 +01:00
|
|
|
return json_success(
|
2022-01-31 13:44:02 +01:00
|
|
|
request,
|
|
|
|
data={
|
2021-02-12 08:19:30 +01:00
|
|
|
"attachments": user_attachments(user_profile),
|
|
|
|
"upload_space_used": user_profile.realm.currently_used_upload_space_bytes(),
|
2022-01-31 13:44:02 +01:00
|
|
|
},
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
|
|
|
|
2016-12-28 14:46:42 +01:00
|
|
|
|
2023-10-22 21:45:03 +02:00
|
|
|
def remove(request: HttpRequest, user_profile: UserProfile, attachment_id: int) -> HttpResponse:
|
|
|
|
attachment = access_attachment_by_id(user_profile, attachment_id, needs_owner=True)
|
2016-12-28 14:46:42 +01:00
|
|
|
remove_attachment(user_profile, attachment)
|
2023-10-22 21:45:03 +02:00
|
|
|
notify_attachment_update(user_profile, "remove", {"id": attachment_id})
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request)
|