feat(admin-users): 支持按创建时间排序

This commit is contained in:
Entropy.Xu
2026-05-25 12:21:58 +08:00
parent 505d9fd8bc
commit aaad113190
13 changed files with 401 additions and 20 deletions
@@ -7,8 +7,8 @@ use super::types::{
normalize_user_group_name, LdapAuthUserProvisioningOutcome, StoredUserAuthRecord,
StoredUserExportRow, StoredUserGroup, StoredUserGroupMember, StoredUserGroupMembership,
StoredUserOAuthLinkSummary, StoredUserPreferenceRecord, StoredUserSessionRecord,
StoredUserSummary, UpsertUserGroupRecord, UserExportListQuery, UserExportSummary,
UserReadRepository,
StoredUserSummary, UpsertUserGroupRecord, UserExportListQuery, UserExportSortBy,
UserExportSummary, UserReadRepository,
};
use crate::DataLayerError;
@@ -409,6 +409,34 @@ fn filter_memory_export_rows(
.contains(&search)
});
}
match query.sort_by {
UserExportSortBy::CreatedAt => {
let created_at_by_id = repository
.auth_by_id
.read()
.expect("user repository lock")
.iter()
.filter_map(|(user_id, user)| {
user.created_at
.map(|created_at| (user_id.clone(), created_at.timestamp_millis()))
})
.collect::<BTreeMap<_, _>>();
rows.sort_by(|left, right| {
let primary = created_at_by_id
.get(&left.id)
.cmp(&created_at_by_id.get(&right.id));
let ordered = if query.sort_order.is_desc() {
primary.reverse()
} else {
primary
};
ordered.then_with(|| left.id.cmp(&right.id))
});
}
UserExportSortBy::Id => {
rows.sort_by(|left, right| left.id.cmp(&right.id));
}
}
rows
}
@@ -2682,6 +2710,7 @@ mod tests {
is_active: Some(true),
search: None,
group_id: None,
..Default::default()
})
.await
.expect("paged export should succeed");