2016-12-28 14:46:42 +01:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
|
2018-05-04 22:57:36 +02:00
|
|
|
from zerver.lib.actions 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
|
|
|
|
2019-01-15 13:16:08 +01:00
|
|
|
def remove(request: HttpRequest, user_profile: UserProfile, attachment_id: str) -> HttpResponse:
|
2021-02-12 08:19:30 +01:00
|
|
|
attachment = access_attachment_by_id(user_profile, int(attachment_id), needs_owner=True)
|
2016-12-28 14:46:42 +01:00
|
|
|
remove_attachment(user_profile, attachment)
|
2019-01-15 13:16:08 +01:00
|
|
|
notify_attachment_update(user_profile, "remove", {"id": int(attachment_id)})
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request)
|