add: ability to transfer community ownership
This commit is contained in:
parent
d42375441f
commit
0c814e95d7
5 changed files with 139 additions and 2 deletions
|
@ -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