Skip to content

Commit 07164f7

Browse files
tw4lSuaYoo
andauthored
Remove deleted collection from crawling defaults (#3186)
Fixes #3176 Removes deleted collection from `Organization.crawlingDefaults.dedupeCollId` if the collection was set as the dedupe coll source ## Testing 1. Create a dedupe collection 2. Set it as the org crawling default dedupe source 3. Delete the collection 4. Verify that the collection is no longer set in org crawling defaults --------- Co-authored-by: sua yoo <sua@suayoo.com>
1 parent 5970f53 commit 07164f7

File tree

6 files changed

+90
-14
lines changed

6 files changed

+90
-14
lines changed

backend/btrixcloud/colls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ async def delete_collection(self, coll_id: UUID, org: Organization):
685685
)
686686

687687
await self.crawl_ops.remove_collection_from_all_crawls(coll_id, org)
688+
await self.orgs.remove_collection_from_crawling_defaults(coll_id, org)
688689

689690
if coll.thumbnail:
690691
await self.delete_thumbnail(coll, org)

backend/btrixcloud/orgs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,27 @@ async def inc_org_bytes_stored_field(
16201620
except Exception as err:
16211621
print(f"Error updating field {field} on org {oid}: {err}", flush=True)
16221622

1623+
async def remove_collection_from_crawling_defaults(
1624+
self, coll_id: UUID, org: Organization
1625+
):
1626+
"""Remove collection from crawling defaults
1627+
1628+
At this point, only dedupeCollId is supported in crawling defaults.
1629+
If we add auto-add collections to defaults, we'll need to clean that
1630+
up here as well.
1631+
"""
1632+
try:
1633+
await self.orgs.find_one_and_update(
1634+
{"_id": org.id, "crawlingDefaults.dedupeCollId": coll_id},
1635+
{"$set": {"crawlingDefaults.dedupeCollId": None}},
1636+
)
1637+
# pylint: disable=broad-exception-caught
1638+
except Exception as err:
1639+
print(
1640+
f"Error removing coll {coll_id} from org {org.id} defaults: {err}",
1641+
flush=True,
1642+
)
1643+
16231644

16241645
# ============================================================================
16251646
# pylint: disable=too-many-statements, too-many-arguments

backend/test/test_collections.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,11 @@ def test_delete_collection(crawler_auth_headers, default_org_id, crawler_crawl_i
18051805
)
18061806
assert _second_coll_id not in r.json()["collectionIds"]
18071807

1808-
# Make a new empty (no crawls) collection and delete it
1808+
1809+
def test_deleted_collection_removed_from_crawling_defaults(
1810+
admin_auth_headers, crawler_auth_headers, default_org_id
1811+
):
1812+
# Make a new empty (no crawls) collection
18091813
r = requests.post(
18101814
f"{API_PREFIX}/orgs/{default_org_id}/collections",
18111815
headers=crawler_auth_headers,
@@ -1819,9 +1823,30 @@ def test_delete_collection(crawler_auth_headers, default_org_id, crawler_crawl_i
18191823
assert data["added"]
18201824
coll_id = data["id"]
18211825

1826+
# Set collection as default dedupeCollId for org
1827+
r = requests.post(
1828+
f"{API_PREFIX}/orgs/{default_org_id}/defaults/crawling",
1829+
headers=admin_auth_headers,
1830+
json={"dedupeCollId": coll_id},
1831+
)
1832+
assert r.status_code == 200
1833+
assert r.json()["updated"]
1834+
1835+
r = requests.get(f"{API_PREFIX}/orgs/{default_org_id}", headers=admin_auth_headers)
1836+
data = r.json()
1837+
assert data["crawlingDefaults"]
1838+
assert data["crawlingDefaults"]["dedupeCollId"] == coll_id
1839+
1840+
# Delete collection
18221841
r = requests.delete(
18231842
f"{API_PREFIX}/orgs/{default_org_id}/collections/{coll_id}",
18241843
headers=crawler_auth_headers,
18251844
)
18261845
assert r.status_code == 200
18271846
assert r.json()["success"]
1847+
1848+
# Ensure collection was removed from crawling defaults
1849+
r = requests.get(f"{API_PREFIX}/orgs/{default_org_id}", headers=admin_auth_headers)
1850+
data = r.json()
1851+
assert data["crawlingDefaults"]
1852+
assert data["crawlingDefaults"]["dedupeCollId"] is None

frontend/src/pages/org/collection-detail/collection-detail.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { parsePage, type PageChangeEvent } from "@/components/ui/pagination";
2525
import { viewStateContext, type ViewStateContext } from "@/context/view-state";
2626
import { ClipboardController } from "@/controllers/clipboard";
2727
import { SearchParamsValue } from "@/controllers/searchParamsValue";
28+
import type { BtrixRequestOrgUpdate } from "@/events/btrix-request-org-update";
2829
import type { EditDialogTab } from "@/features/collections/collection-edit-dialog";
2930
import { collectionShareLink } from "@/features/collections/helpers/share-link";
3031
import { SelectCollectionAccess } from "@/features/collections/select-collection-access";
@@ -1273,6 +1274,18 @@ export class CollectionDetail extends BtrixElement {
12731274
icon: "check2-circle",
12741275
id: "collection-delete-status",
12751276
});
1277+
1278+
// Collection may be used in crawling default, request update
1279+
this.dispatchEvent(
1280+
new CustomEvent<BtrixRequestOrgUpdate["detail"]>(
1281+
"btrix-request-org-update",
1282+
{
1283+
detail: { org: {} },
1284+
bubbles: true,
1285+
composed: true,
1286+
},
1287+
),
1288+
);
12761289
} catch {
12771290
this.notify.toast({
12781291
message: msg("Sorry, couldn't delete Collection at this time."),

frontend/src/pages/org/collections-list.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { BtrixElement } from "@/classes/BtrixElement";
1919
import { parsePage, type PageChangeEvent } from "@/components/ui/pagination";
2020
import { WithSearchOrgContext } from "@/context/search-org/WithSearchOrgContext";
2121
import { ClipboardController } from "@/controllers/clipboard";
22+
import type { BtrixRequestOrgUpdate } from "@/events/btrix-request-org-update";
2223
import type { CollectionSavedEvent } from "@/features/collections/collection-create-dialog";
2324
import { SelectCollectionAccess } from "@/features/collections/select-collection-access";
2425
import { emptyMessage } from "@/layouts/emptyMessage";
@@ -846,6 +847,18 @@ export class CollectionsList extends WithSearchOrgContext(BtrixElement) {
846847
icon: "check2-circle",
847848
id: "collection-delete-status",
848849
});
850+
851+
// Collection may be used in crawling default, request update
852+
this.dispatchEvent(
853+
new CustomEvent<BtrixRequestOrgUpdate["detail"]>(
854+
"btrix-request-org-update",
855+
{
856+
detail: { org: {} },
857+
bubbles: true,
858+
composed: true,
859+
},
860+
),
861+
);
849862
} catch (err) {
850863
const message =
851864
getIndexErrorMessage(err) ||

frontend/src/pages/org/index.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,20 @@ export class Org extends BtrixElement {
246246
}
247247
}
248248

249+
private readonly onRequestUpdateOrg = (e: BtrixRequestOrgUpdate) => {
250+
e.stopPropagation();
251+
252+
// Optimistic update
253+
if (Object.keys(e.detail.org).length) {
254+
AppStateService.partialUpdateOrg({
255+
id: this.orgId,
256+
...e.detail.org,
257+
});
258+
}
259+
260+
void this.updateOrg();
261+
};
262+
249263
private async updateOrg(e?: CustomEvent) {
250264
if (e) {
251265
e.stopPropagation();
@@ -292,6 +306,8 @@ export class Org extends BtrixElement {
292306
// Sync URL to create dialog
293307
const dialogName = this.getDialogName();
294308
if (dialogName) this.openDialog(dialogName);
309+
310+
this.addEventListener("btrix-request-org-update", this.onRequestUpdateOrg);
295311
}
296312

297313
private getDialogName() {
@@ -685,19 +701,6 @@ export class Org extends BtrixElement {
685701
return html`<btrix-org-settings
686702
activePanel=${activePanel}
687703
?isAddingMember=${isAddingMember}
688-
@btrix-request-org-update=${(e: BtrixRequestOrgUpdate) => {
689-
e.stopPropagation();
690-
691-
// Optimistic update
692-
if (Object.keys(e.detail.org).length) {
693-
AppStateService.partialUpdateOrg({
694-
id: this.orgId,
695-
...e.detail.org,
696-
});
697-
}
698-
699-
void this.updateOrg();
700-
}}
701704
@org-user-role-change=${this.onUserRoleChange}
702705
@org-remove-member=${this.onOrgRemoveMember}
703706
></btrix-org-settings>`;

0 commit comments

Comments
 (0)