add: purge/restore post api
This commit is contained in:
parent
81307752c2
commit
dd4f8b6d58
6 changed files with 102 additions and 4 deletions
|
@ -17,6 +17,8 @@ version = "1.0.0"
|
|||
"general:link.stats" = "Stats"
|
||||
"general:action.save" = "Save"
|
||||
"general:action.delete" = "Delete"
|
||||
"general:action.purge" = "Purge"
|
||||
"general:action.restore" = "Restore"
|
||||
"general:action.accept" = "Accept"
|
||||
"general:action.back" = "Back"
|
||||
"general:action.report" = "Report"
|
||||
|
|
|
@ -382,6 +382,7 @@ and show_community and community.id != config.town_square or question %}
|
|||
>
|
||||
</a>
|
||||
|
||||
{% if not post.is_deleted %}
|
||||
<button
|
||||
class="red"
|
||||
onclick="trigger('me::remove_post', ['{{ post.id }}'])"
|
||||
|
@ -389,7 +390,23 @@ and show_community and community.id != config.town_square or question %}
|
|||
{{ icon "trash" }}
|
||||
<span>{{ text "general:action.delete" }}</span>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% endif %} {% if is_helper and post.is_deleted %}
|
||||
<button
|
||||
class="red"
|
||||
onclick="trigger('me::purge_post', ['{{ post.id }}'])"
|
||||
>
|
||||
{{ icon "trash-2" }}
|
||||
<span>{{ text "general:action.purge" }}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="green"
|
||||
onclick="trigger('me::restore_post', ['{{ post.id }}'])"
|
||||
>
|
||||
{{ icon "undo" }}
|
||||
<span>{{ text "general:action.restore" }}</span>
|
||||
</button>
|
||||
{% endif %} {% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -62,6 +62,48 @@
|
|||
});
|
||||
});
|
||||
|
||||
self.define("purge_post", async (_, id) => {
|
||||
if (
|
||||
!(await trigger("atto::confirm", [
|
||||
"Are you sure you want to do this? This cannot be undone.",
|
||||
]))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/posts/${id}/purge`, {
|
||||
method: "DELETE",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
self.define("restore_post", async (_, id) => {
|
||||
if (
|
||||
!(await trigger("atto::confirm", [
|
||||
"Are you sure you want to do this?",
|
||||
]))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/posts/${id}/restore`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
self.define("react", async (_, element, asset, asset_type, is_like) => {
|
||||
await trigger("atto::debounce", ["reactions::toggle"]);
|
||||
fetch("/api/v1/reactions", {
|
||||
|
|
|
@ -183,7 +183,7 @@ pub async fn delete_request(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn real_delete_request(
|
||||
pub async fn purge_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
|
@ -208,6 +208,31 @@ pub async fn real_delete_request(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn restore_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if !user.permissions.check(FinePermission::MANAGE_POSTS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
match data.fake_delete_post(id, user, false).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Post restored".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_content_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
|
|
|
@ -94,8 +94,12 @@ pub fn routes() -> Router {
|
|||
.route("/posts", post(communities::posts::create_request))
|
||||
.route("/posts/{id}", delete(communities::posts::delete_request))
|
||||
.route(
|
||||
"/posts/{id}/real_delete",
|
||||
delete(communities::posts::real_delete_request),
|
||||
"/posts/{id}/purge",
|
||||
delete(communities::posts::purge_request),
|
||||
)
|
||||
.route(
|
||||
"/posts/{id}/restore",
|
||||
post(communities::posts::restore_request),
|
||||
)
|
||||
.route(
|
||||
"/posts/{id}/repost",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue