mirror of
https://github.com/outline/outline.git
synced 2026-08-03 13:27:25 +03:00
fix: Cannot view past 25 archived collections (#13171)
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user