Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Myers <[email protected]>
  • Loading branch information
Elizafox committed Mar 14, 2024
1 parent e98ce02 commit 61acccd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bancache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl BanCache {
}
}

pub(crate) fn invalidate(&mut self, network: IpNetwork) {
pub(crate) fn invalidate(&self, network: IpNetwork) {
self.cache
.invalidate_entries_if(move |k, _| network.contains(*k))
.expect("Could not invalidate cache");
Expand Down
6 changes: 5 additions & 1 deletion src/web/admin/cidr_ban.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ mod post {
}
};

// Invalidate so users who aren't banned will now be
state.bancache.invalidate(network.clone());

Mutation::create_cidr_ban(&state.db, network, submit_ban_form.reason, &user.0).await?;

messages.success(format!(
Expand All @@ -152,7 +155,7 @@ mod post {
session: Session,
auth_session: AuthSession,
messages: Messages,
State(mut state): State<AppState>,
State(state): State<AppState>,
Form(delete_form): Form<DeleteForm>,
) -> Result<Response, AppError> {
csrf_crate::verify(&session, &delete_form.authenticity_token, &state.protect).await?;
Expand All @@ -167,6 +170,7 @@ mod post {
let begin = vec_to_ipaddr(ban.range_begin)?;
let end = vec_to_ipaddr(ban.range_end)?;

// Invalidate the ban cache for all networks in this range
for network in find_networks(begin, end)? {
state.bancache.invalidate(network);
}
Expand Down

0 comments on commit 61acccd

Please sign in to comment.