add: ability to transfer community ownership
This commit is contained in:
parent
d42375441f
commit
0c814e95d7
5 changed files with 139 additions and 2 deletions
|
@ -68,6 +68,11 @@
|
|||
async function create_community_from_form(e) {
|
||||
e.preventDefault();
|
||||
await trigger("atto::debounce", ["communities::create"]);
|
||||
|
||||
if (e.target.title.value.includes(" ")) {
|
||||
return alert("Cannot contain spaces!");
|
||||
}
|
||||
|
||||
fetch("/api/v1/communities", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
|
@ -317,6 +317,33 @@
|
|||
});
|
||||
};
|
||||
|
||||
globalThis.transfer_ownership = async (uid) => {
|
||||
if (
|
||||
!(await trigger("atto::confirm", [
|
||||
"Are you sure you would like to do this?\n\nThis action is PERMANENT!",
|
||||
]))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/communities/{{ community.id }}/transfer_ownership`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user: uid,
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
globalThis.select_user_from_form = (e) => {
|
||||
e.preventDefault();
|
||||
fetch(
|
||||
|
@ -359,6 +386,7 @@
|
|||
${res.payload.role !== 33 ? `<button class="red quaternary" onclick="update_user_role('${e.target.uid.value}', 33)">Ban</button>` : `<button class="quaternary" onclick="update_user_role('${e.target.uid.value}', 5)">Unban</button>`}
|
||||
${res.payload.role !== 65 ? `<button class="red quaternary" onclick="update_user_role('${e.target.uid.value}', 65)">Send to review</button>` : `<button class="green quaternary" onclick="update_user_role('${e.target.uid.value}', 5)">Accept join request</button>`}
|
||||
<button class="red quaternary" onclick="kick_user('${e.target.uid.value}')">Kick</button>
|
||||
<button class="red quaternary" onclick="transfer_ownership('${e.target.uid.value}')">Transfer ownership</button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2" ui_ident="permissions" id="permissions">
|
||||
|
|
|
@ -12,12 +12,13 @@ use tetratto_core::model::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
State, get_user_from_token,
|
||||
get_user_from_token,
|
||||
routes::api::v1::{
|
||||
CreateCommunity, UpdateCommunityContext, UpdateCommunityJoinAccess,
|
||||
CreateCommunity, UpdateCommunityContext, UpdateCommunityJoinAccess, UpdateCommunityOwner,
|
||||
UpdateCommunityReadAccess, UpdateCommunityTitle, UpdateCommunityWriteAccess,
|
||||
UpdateMembershipRole,
|
||||
},
|
||||
State,
|
||||
};
|
||||
|
||||
pub async fn redirect_from_id(
|
||||
|
@ -201,6 +202,38 @@ pub async fn update_join_access_request(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn update_owner_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
Json(req): Json<UpdateCommunityOwner>,
|
||||
) -> 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()),
|
||||
};
|
||||
|
||||
match data
|
||||
.update_community_owner(
|
||||
id,
|
||||
user,
|
||||
match req.user.parse::<usize>() {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Community updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_membership(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
|
|
|
@ -64,6 +64,10 @@ pub fn routes() -> Router {
|
|||
"/communities/{id}/access/join",
|
||||
post(communities::communities::update_join_access_request),
|
||||
)
|
||||
.route(
|
||||
"/communities/{id}/transfer_ownership",
|
||||
post(communities::communities::update_owner_request),
|
||||
)
|
||||
.route(
|
||||
"/communities/{id}/upload/avatar",
|
||||
post(communities::images::upload_avatar_request),
|
||||
|
@ -342,6 +346,11 @@ pub struct UpdateMembershipRole {
|
|||
pub role: CommunityPermission,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateCommunityOwner {
|
||||
pub user: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateUserRole {
|
||||
pub role: FinePermission,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue