diff --git a/backend/btrixcloud/colls.py b/backend/btrixcloud/colls.py index c729890414..23640404bd 100644 --- a/backend/btrixcloud/colls.py +++ b/backend/btrixcloud/colls.py @@ -89,7 +89,7 @@ async def add_collection(self, oid: UUID, coll_in: CollIn): name=coll_in.name, description=coll_in.description, modified=modified, - visibility=coll_in.visibility, + access=coll_in.access, ) try: await self.collections.insert_one(coll.to_dict()) @@ -189,7 +189,7 @@ async def get_collection( """Get collection by id""" query: dict[str, object] = {"_id": coll_id} if public_only: - query["visibility"] = {"$in": ["public", "unlisted"]} + query["access"] = {"$in": ["public", "unlisted"]} result = await self.collections.find_one(query) if not result: @@ -210,7 +210,7 @@ async def list_collections( sort_direction: int = 1, name: Optional[str] = None, name_prefix: Optional[str] = None, - visibility: Optional[str] = None, + access: Optional[str] = None, ): """List all collections for org""" # pylint: disable=too-many-locals, duplicate-code @@ -227,8 +227,8 @@ async def list_collections( regex_pattern = f"^{name_prefix}" match_query["name"] = {"$regex": regex_pattern, "$options": "i"} - if visibility: - match_query["visibility"] = visibility + if access: + match_query["access"] = access aggregate = [{"$match": match_query}] @@ -431,7 +431,7 @@ async def list_collection_all( sortDirection: int = 1, name: Optional[str] = None, namePrefix: Optional[str] = None, - visibility: Optional[str] = None, + access: Optional[str] = None, ): collections, total = await colls.list_collections( org.id, @@ -441,7 +441,7 @@ async def list_collection_all( sort_direction=sortDirection, name=name, name_prefix=namePrefix, - visibility=visibility, + access=access, ) return paginated_format(collections, total, page, pageSize) diff --git a/backend/btrixcloud/migrations/migration_0036_coll_visibility.py b/backend/btrixcloud/migrations/migration_0036_coll_visibility.py index e66041b30c..1b1b9d7417 100644 --- a/backend/btrixcloud/migrations/migration_0036_coll_visibility.py +++ b/backend/btrixcloud/migrations/migration_0036_coll_visibility.py @@ -1,5 +1,5 @@ """ -Migration 0036 -- collection visibility +Migration 0036 -- collection access """ from btrixcloud.migrations import BaseMigration @@ -18,7 +18,7 @@ def __init__(self, mdb, **kwargs): async def migrate_up(self): """Perform migration up. - Move from Collection.isPublic cool to Collection.visibility enum + Move from Collection.isPublic cool to Collection.access enum """ colls_mdb = self.mdb["collections"] @@ -26,7 +26,7 @@ async def migrate_up(self): try: await colls_mdb.update_many( {"isPublic": False}, - [{"$set": {"visibility": "private"}, "$unset": {"isPublic": 1}}], + [{"$set": {"access": "private"}, "$unset": {"isPublic": 1}}], ) # pylint: disable=broad-exception-caught except Exception as err: @@ -39,7 +39,7 @@ async def migrate_up(self): try: await colls_mdb.update_many( {"isPublic": True}, - [{"$set": {"visibility": "unlisted"}, "$unset": {"isPublic": 1}}], + [{"$set": {"access": "unlisted"}, "$unset": {"isPublic": 1}}], ) # pylint: disable=broad-exception-caught except Exception as err: diff --git a/backend/btrixcloud/models.py b/backend/btrixcloud/models.py index cb41f50854..841b7edfbc 100644 --- a/backend/btrixcloud/models.py +++ b/backend/btrixcloud/models.py @@ -1048,8 +1048,8 @@ class UpdateUpload(UpdateCrawl): # ============================================================================ -class CollVisibilityType(str, Enum): - """Collection visibility types""" +class CollAccessType(str, Enum): + """Collection access types""" PRIVATE = "private" UNLISTED = "unlisted" @@ -1072,7 +1072,7 @@ class Collection(BaseMongoModel): # Sorted by count, descending tags: Optional[List[str]] = [] - visibility: CollVisibilityType = CollVisibilityType.PRIVATE + access: CollAccessType = CollAccessType.PRIVATE # ============================================================================ @@ -1083,7 +1083,7 @@ class CollIn(BaseModel): description: Optional[str] = None crawlIds: Optional[List[str]] = [] - visibility: CollVisibilityType = CollVisibilityType.PRIVATE + access: CollAccessType = CollAccessType.PRIVATE # ============================================================================ @@ -1099,7 +1099,7 @@ class UpdateColl(BaseModel): name: Optional[str] = None description: Optional[str] = None - visibility: Optional[CollVisibilityType] = None + access: Optional[CollAccessType] = None # ============================================================================ diff --git a/backend/btrixcloud/orgs.py b/backend/btrixcloud/orgs.py index ac16ea563e..6775a1cd7b 100644 --- a/backend/btrixcloud/orgs.py +++ b/backend/btrixcloud/orgs.py @@ -930,7 +930,7 @@ async def get_org_metrics(self, org: Organization) -> dict[str, int]: ) collections_count = await self.colls_db.count_documents({"oid": org.id}) public_collections_count = await self.colls_db.count_documents( - {"oid": org.id, "visibility": {"$in": ["public", "unlisted"]}} + {"oid": org.id, "access": {"$in": ["public", "unlisted"]}} ) return { diff --git a/backend/test/test_collections.py b/backend/test/test_collections.py index 47e77dbc53..3400426bed 100644 --- a/backend/test/test_collections.py +++ b/backend/test/test_collections.py @@ -58,7 +58,7 @@ def test_create_public_collection( json={ "crawlIds": [crawler_crawl_id], "name": PUBLIC_COLLECTION_NAME, - "visibility": "public", + "access": "public", }, ) assert r.status_code == 200 @@ -73,7 +73,7 @@ def test_create_public_collection( f"{API_PREFIX}/orgs/{default_org_id}/collections/{_public_coll_id}", headers=crawler_auth_headers, ) - assert r.json()["visibility"] == "public" + assert r.json()["access"] == "public" def test_create_collection_taken_name( @@ -316,7 +316,7 @@ def test_collection_public(crawler_auth_headers, default_org_id): f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}", headers=crawler_auth_headers, json={ - "visibility": "public", + "access": "public", }, ) assert r.status_code == 200 @@ -335,7 +335,7 @@ def test_collection_public(crawler_auth_headers, default_org_id): f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}", headers=crawler_auth_headers, json={ - "visibility": "unlisted", + "access": "unlisted", }, ) assert r.status_code == 200 @@ -354,7 +354,7 @@ def test_collection_public(crawler_auth_headers, default_org_id): f"{API_PREFIX}/orgs/{default_org_id}/collections/{_coll_id}", headers=crawler_auth_headers, json={ - "visibility": "private", + "access": "private", }, ) @@ -448,7 +448,7 @@ def test_list_collections( assert first_coll["totalSize"] > 0 assert first_coll["modified"] assert first_coll["tags"] == ["wr-test-2", "wr-test-1"] - assert first_coll["visibility"] == "private" + assert first_coll["access"] == "private" second_coll = [coll for coll in items if coll["name"] == SECOND_COLLECTION_NAME][0] assert second_coll["id"] @@ -460,7 +460,7 @@ def test_list_collections( assert second_coll["totalSize"] > 0 assert second_coll["modified"] assert second_coll["tags"] == ["wr-test-2"] - assert second_coll["visibility"] == "private" + assert second_coll["access"] == "private" def test_remove_upload_from_collection(crawler_auth_headers, default_org_id): @@ -546,10 +546,10 @@ def test_filter_sort_collections( assert coll["oid"] == default_org_id assert coll.get("description") is None - # Test filtering by visibility + # Test filtering by access name_prefix = name_prefix.upper() r = requests.get( - f"{API_PREFIX}/orgs/{default_org_id}/collections?visibility=public", + f"{API_PREFIX}/orgs/{default_org_id}/collections?access=public", headers=crawler_auth_headers, ) assert r.status_code == 200 @@ -564,7 +564,7 @@ def test_filter_sort_collections( assert coll["name"] == PUBLIC_COLLECTION_NAME assert coll["oid"] == default_org_id assert coll.get("description") is None - assert coll["visibility"] == "public" + assert coll["access"] == "public" # Test sorting by name, ascending (default) r = requests.get( diff --git a/frontend/src/features/collections/collection-metadata-dialog.ts b/frontend/src/features/collections/collection-metadata-dialog.ts index f83e8eaff2..a5642ae6d4 100644 --- a/frontend/src/features/collections/collection-metadata-dialog.ts +++ b/frontend/src/features/collections/collection-metadata-dialog.ts @@ -14,7 +14,7 @@ import { when } from "lit/directives/when.js"; import { BtrixElement } from "@/classes/BtrixElement"; import type { Dialog } from "@/components/ui/dialog"; import type { MarkdownEditor } from "@/components/ui/markdown-editor"; -import { CollectionVisibility, type Collection } from "@/types/collection"; +import { CollectionAccess, type Collection } from "@/types/collection"; import { isApiError } from "@/utils/api"; import { maxLengthValidator } from "@/utils/form"; @@ -180,9 +180,9 @@ export class CollectionMetadataDialog extends BtrixElement { const body = JSON.stringify({ name, description, - visibility: !isPublic - ? CollectionVisibility.Private - : CollectionVisibility.Unlisted, + access: !isPublic + ? CollectionAccess.Private + : CollectionAccess.Unlisted, }); let path = `/orgs/${this.orgId}/collections`; let method = "POST"; diff --git a/frontend/src/pages/org/collection-detail.ts b/frontend/src/pages/org/collection-detail.ts index 817e2e2e05..a6259664d1 100644 --- a/frontend/src/pages/org/collection-detail.ts +++ b/frontend/src/pages/org/collection-detail.ts @@ -16,7 +16,7 @@ import type { APIPaginationQuery, APISortQuery, } from "@/types/api"; -import { CollectionVisibility, type Collection } from "@/types/collection"; +import { CollectionAccess, type Collection } from "@/types/collection"; import type { ArchivedItem, Crawl, Upload } from "@/types/crawler"; import type { CrawlState } from "@/types/crawlState"; import { formatNumber, getLocale } from "@/utils/localization"; @@ -100,7 +100,7 @@ export class CollectionDetail extends BtrixElement {
- ${this.collection?.visibility === CollectionVisibility.Unlisted + ${this.collection?.access === CollectionAccess.Unlisted ? html` ${when( this.isCrawler || - this.collection?.visibility !== CollectionVisibility.Private, + this.collection?.access !== CollectionAccess.Private, () => html` ${ - this.collection?.visibility === CollectionVisibility.Unlisted + this.collection?.access === CollectionAccess.Unlisted ? "" : html`

${msg( @@ -254,8 +254,8 @@ export class CollectionDetail extends BtrixElement { () => html`

void this.onTogglePublic((e.target as SlCheckbox).checked)} >${msg("Collection is Shareable")} - ${when(this.collection?.visibility === CollectionVisibility.Unlisted, this.renderShareInfo)} + ${when(this.collection?.access === CollectionAccess.Unlisted, this.renderShareInfo)}
(this.showShareInfo = false)} >${msg("Done")} - ${this.collection?.visibility === CollectionVisibility.Private + ${this.collection?.access === CollectionAccess.Private ? html` ( `/orgs/${this.orgId}/collections/${this.collectionId}`, { method: "PATCH", - body: JSON.stringify({ visibility }), + body: JSON.stringify({ access }), }, ); if (res.updated && this.collection) { - this.collection = { ...this.collection, visibility }; + this.collection = { ...this.collection, access }; } } diff --git a/frontend/src/pages/org/collections-list.ts b/frontend/src/pages/org/collections-list.ts index f111ac48b5..351cff0d1f 100644 --- a/frontend/src/pages/org/collections-list.ts +++ b/frontend/src/pages/org/collections-list.ts @@ -16,7 +16,7 @@ import type { CollectionSavedEvent } from "@/features/collections/collection-met import { pageHeader } from "@/layouts/pageHeader"; import type { APIPaginatedList, APIPaginationQuery } from "@/types/api"; import { - CollectionVisibility, + CollectionAccess, type Collection, type CollectionSearchValues, } from "@/types/collection"; @@ -504,7 +504,7 @@ export class CollectionsList extends BtrixElement { class="cursor-pointer select-none rounded border shadow transition-all focus-within:bg-neutral-50 hover:bg-neutral-50 hover:shadow-none" > - ${col.visibility === CollectionVisibility.Unlisted + ${col.access === CollectionAccess.Unlisted ? html` - ${col.visibility === CollectionVisibility.Private + ${col.access === CollectionAccess.Private ? html`