fix: Cannot view past 25 archived collections (#13171)

This commit is contained in:
Tom Moor
2026-07-27 20:41:52 -04:00
committed by GitHub
parent d0900e7277
commit b0ed00fef4
3 changed files with 49 additions and 13 deletions
@@ -24,10 +24,7 @@ function ArchiveLink() {
const [disclosure, setDisclosure] = useState<boolean>(false);
const [expanded, setExpanded] = useState<boolean | undefined>();
const { request, data, loading, error } = useRequest(
collections.fetchArchived,
true
);
const { data, loading, error } = useRequest(collections.fetchArchived, true);
useEffect(() => {
if (!isUndefined(data) && !loading && isUndefined(error)) {
@@ -45,12 +42,6 @@ function ArchiveLink() {
}
}, [disclosure, expanded]);
useEffect(() => {
if (expanded) {
void request();
}
}, [expanded, request]);
const handleDisclosureClick = useCallback((ev) => {
ev.preventDefault();
ev.stopPropagation();
@@ -84,6 +75,7 @@ function ArchiveLink() {
<Relative>
<PaginatedList<Collection>
aria-label={t("Archived collections")}
fetch={collections.fetchArchived}
items={collections.archived}
loading={<PlaceholderCollections />}
renderError={(props) => <StyledError {...props} />}
@@ -56,6 +56,44 @@ describe("#collections.list", () => {
expect(body.data[0].archivedBy.id).toBe(collection.archivedById);
});
it("should include archived private collections for admin", async () => {
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const collection = await buildCollection({
teamId: team.id,
permission: null,
archivedAt: new Date(),
});
const res = await server.post("/api/collections.list", admin, {
body: {
statusFilter: [CollectionStatusFilter.Archived],
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].id).toEqual(collection.id);
expect(body.policies[0].abilities.restore).toBeTruthy();
});
it("should not include archived private collections for member", async () => {
const team = await buildTeam();
const user = await buildUser({ teamId: team.id });
await buildCollection({
teamId: team.id,
permission: null,
archivedAt: new Date(),
});
const res = await server.post("/api/collections.list", user, {
body: {
statusFilter: [CollectionStatusFilter.Archived],
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data).toHaveLength(0);
});
it("should exclude archived collections", async () => {
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
+9 -3
View File
@@ -722,11 +722,17 @@ router.post(
],
};
const includeArchived = !!statusFilter?.includes(
CollectionStatusFilter.Archived
);
if (!statusFilter) {
where[Op.and].push({ archivedAt: { [Op.eq]: null } });
}
if (!includeListOnly || !user.isAdmin) {
// Admins can restore any archived collection, including private ones they
// are not a member of, so they must be able to see them listed.
if (!user.isAdmin || !(includeListOnly || includeArchived)) {
where[Op.and].push({ id: collectionIds });
}
@@ -737,7 +743,7 @@ router.post(
}
const statusQuery = [];
if (statusFilter?.includes(CollectionStatusFilter.Archived)) {
if (includeArchived) {
statusQuery.push({
archivedAt: {
[Op.ne]: null,
@@ -755,7 +761,7 @@ router.post(
const [collections, total] = await Promise.all([
Collection.scope(
statusFilter?.includes(CollectionStatusFilter.Archived)
includeArchived
? [
{
method: ["withMembership", user.id],