2018-07-02 01:08:13 -04:00
|
|
|
from django.http import HttpResponse
|
2018-07-02 01:30:32 -04:00
|
|
|
from ronkyuu import webmention
|
2018-07-02 01:08:13 -04:00
|
|
|
|
2018-07-02 19:19:50 -04:00
|
|
|
from entries.from_url import from_url
|
2018-07-02 01:30:32 -04:00
|
|
|
from entries.jobs import ping_hub, send_mentions
|
2018-07-02 01:08:13 -04:00
|
|
|
|
2018-07-02 20:03:35 -04:00
|
|
|
from .. import error
|
2018-07-02 01:08:13 -04:00
|
|
|
|
2023-08-10 02:52:37 -04:00
|
|
|
|
2018-07-02 01:08:13 -04:00
|
|
|
def delete(request):
|
|
|
|
normalise = {
|
2023-08-10 02:52:37 -04:00
|
|
|
"application/json": lambda r: r.json.get("url"),
|
|
|
|
"application/x-www-form-urlencoded": lambda r: r.POST.get("url"),
|
2018-07-02 01:08:13 -04:00
|
|
|
}
|
2023-08-10 02:52:37 -04:00
|
|
|
if "delete" not in request.token:
|
|
|
|
raise error.bad_scope("delete")
|
2018-07-02 01:08:13 -04:00
|
|
|
if request.content_type not in normalise:
|
2018-07-02 20:03:35 -04:00
|
|
|
raise error.unsupported_type(request.content_type)
|
2018-07-02 01:08:13 -04:00
|
|
|
url = normalise[request.content_type](request)
|
2018-07-02 19:19:50 -04:00
|
|
|
entry = from_url(url)
|
2018-07-02 01:08:13 -04:00
|
|
|
|
|
|
|
if entry.author != request.token.user:
|
2023-08-10 02:52:37 -04:00
|
|
|
raise error.forbid("entry belongs to another user")
|
2018-07-02 01:08:13 -04:00
|
|
|
|
2018-07-02 01:30:32 -04:00
|
|
|
perma = entry.absolute_url
|
|
|
|
pings = entry.affected_urls
|
2023-08-10 02:52:37 -04:00
|
|
|
mentions = webmention.findMentions(perma)["refs"]
|
2018-07-02 01:30:32 -04:00
|
|
|
|
2018-07-02 01:08:13 -04:00
|
|
|
entry.delete()
|
2018-07-02 01:30:32 -04:00
|
|
|
|
|
|
|
ping_hub.delay(*pings)
|
|
|
|
send_mentions.delay(perma, mentions)
|
2018-07-02 01:08:13 -04:00
|
|
|
return HttpResponse(status=204)
|