fix: association removal panic

This commit is contained in:
trisua 2025-06-12 21:06:04 -04:00
parent 0dede99682
commit 6fcbb1fe00
3 changed files with 6 additions and 5 deletions

View file

@ -36,7 +36,7 @@
} }
.justify-start { .justify-start {
justify-content: flex-start; justify-content: flex-start !important;
} }
.items-center { .items-center {

View file

@ -5,7 +5,7 @@
(text "{% endblock %} {% block body %} {{ macros::nav() }}") (text "{% endblock %} {% block body %} {{ macros::nav() }}")
(main (main
("class" "flex flex-col gap-2") ("class" "flex flex-col gap-2")
(text "{{ macros::timelines_nav(selected=\"following\", posts=\"/following\", questions=\"/following/questions\") }} }}") (text "{{ macros::timelines_nav(selected=\"following\", posts=\"/following\", questions=\"/following/questions\") }}")
(div (div
("class" "card w-full flex flex-col gap-2") ("class" "card w-full flex flex-col gap-2")
(text "{% for post in list %} {% if post[2].read_access == \"Everybody\" -%} {% if post[0].context.repost and post[0].context.repost.reposting -%} {{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }} {% else %} {{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], poll=post[5]) }} {%- endif %} {%- endif %} {% endfor %} {{ components::pagination(page=page, items=list|length) }}"))) (text "{% for post in list %} {% if post[2].read_access == \"Everybody\" -%} {% if post[0].context.repost and post[0].context.repost.reposting -%} {{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }} {% else %} {{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], poll=post[5]) }} {%- endif %} {%- endif %} {% endfor %} {{ components::pagination(page=page, items=list|length) }}")))

View file

@ -152,9 +152,11 @@ pub async fn append_associations_request(
// check existing associations to remove associations to deleted users // check existing associations to remove associations to deleted users
// the user should take care of cleaning their ui themselves // the user should take care of cleaning their ui themselves
let mut removed_count: usize = 0;
for (idx, id) in user.associated.clone().iter().enumerate() { for (idx, id) in user.associated.clone().iter().enumerate() {
if data.get_user_by_id(id.to_owned()).await.is_err() { if data.get_user_by_id(id.to_owned()).await.is_err() {
user.associated.remove(idx); user.associated.remove(idx - removed_count);
removed_count += 1; // we need offset each index by this amount to account for removals
} }
} }
@ -501,8 +503,7 @@ pub async fn subscription_handler(
None => return Err("Socket refused"), None => return Err("Socket refused"),
}; };
if user.id.to_string() != user_id { if user.id.to_string() != user_id && !user.permissions.check(FinePermission::MANAGE_USERS) {
// TODO: maybe allow moderators to connect anyway
return Err("Socket refused (auth)"); return Err("Socket refused (auth)");
} }