fix: stacks manage page when user deletes profile
add: allow moderators to view deleted posts
This commit is contained in:
parent
4c26879d00
commit
81307752c2
14 changed files with 211 additions and 29 deletions
|
@ -589,6 +589,33 @@ pub async fn post_request(
|
|||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
if post.is_deleted {
|
||||
// act like the post doesn't exist (if missing MANAGE_POSTS)
|
||||
if let Some(ref ua) = user {
|
||||
if !ua.permissions.check(FinePermission::MANAGE_POSTS) {
|
||||
return Err(Html(
|
||||
render_error(
|
||||
Error::GeneralNotFound("post".to_string()),
|
||||
&jar,
|
||||
&data,
|
||||
&user,
|
||||
)
|
||||
.await,
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(Html(
|
||||
render_error(
|
||||
Error::GeneralNotFound("post".to_string()),
|
||||
&jar,
|
||||
&data,
|
||||
&user,
|
||||
)
|
||||
.await,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let community = match data.0.get_community_by_id(post.community).await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
|
|
|
@ -120,15 +120,29 @@ pub async fn manage_request(
|
|||
));
|
||||
}
|
||||
|
||||
let mut new_users = stack.users.clone();
|
||||
let mut changed_stack_users: bool = false;
|
||||
|
||||
let mut users: Vec<User> = Vec::new();
|
||||
|
||||
for uid in &stack.users {
|
||||
users.push(match data.0.get_user_by_id(uid.to_owned()).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
Err(_) => {
|
||||
// user deleted profile, remove from list
|
||||
new_users.remove(stack.users.iter().position(|x| x == uid).unwrap());
|
||||
changed_stack_users = true;
|
||||
continue;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if changed_stack_users {
|
||||
if let Err(e) = data.0.update_stack_users(stack.id, &user, new_users).await {
|
||||
return Err(Html(render_error(e, &jar, &data, &None).await));
|
||||
}
|
||||
}
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue