Skip to content

Commit

Permalink
Rename visibility to access
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Nov 19, 2024
1 parent dd58043 commit b21f876
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 53 deletions.
14 changes: 7 additions & 7 deletions backend/btrixcloud/colls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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}]

Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Migration 0036 -- collection visibility
Migration 0036 -- collection access
"""

from btrixcloud.migrations import BaseMigration
Expand All @@ -18,15 +18,15 @@ 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"]

# Set non-public collections to private
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:
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -1072,7 +1072,7 @@ class Collection(BaseMongoModel):
# Sorted by count, descending
tags: Optional[List[str]] = []

visibility: CollVisibilityType = CollVisibilityType.PRIVATE
access: CollAccessType = CollAccessType.PRIVATE


# ============================================================================
Expand All @@ -1083,7 +1083,7 @@ class CollIn(BaseModel):
description: Optional[str] = None
crawlIds: Optional[List[str]] = []

visibility: CollVisibilityType = CollVisibilityType.PRIVATE
access: CollAccessType = CollAccessType.PRIVATE


# ============================================================================
Expand All @@ -1099,7 +1099,7 @@ class UpdateColl(BaseModel):

name: Optional[str] = None
description: Optional[str] = None
visibility: Optional[CollVisibilityType] = None
access: Optional[CollAccessType] = None


# ============================================================================
Expand Down
2 changes: 1 addition & 1 deletion backend/btrixcloud/orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions backend/test/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
},
)

Expand Down Expand Up @@ -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"]
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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";
Expand Down
26 changes: 13 additions & 13 deletions frontend/src/pages/org/collection-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -100,7 +100,7 @@ export class CollectionDetail extends BtrixElement {
<header class="items-center gap-2 pb-3 md:flex">
<div class="mb-2 flex w-full items-center gap-2 md:mb-0">
<div class="flex size-8 items-center justify-center">
${this.collection?.visibility === CollectionVisibility.Unlisted
${this.collection?.access === CollectionAccess.Unlisted
? html`
<sl-tooltip content=${msg("Shareable")}>
<sl-icon
Expand All @@ -122,7 +122,7 @@ export class CollectionDetail extends BtrixElement {
</div>
${when(
this.isCrawler ||
this.collection?.visibility !== CollectionVisibility.Private,
this.collection?.access !== CollectionAccess.Private,
() => html`
<sl-button
variant=${this.collection?.crawlCount ? "primary" : "default"}
Expand Down Expand Up @@ -241,7 +241,7 @@ export class CollectionDetail extends BtrixElement {
style="--width: 32rem;"
>
${
this.collection?.visibility === CollectionVisibility.Unlisted
this.collection?.access === CollectionAccess.Unlisted
? ""
: html`<p class="mb-3">
${msg(
Expand All @@ -254,8 +254,8 @@ export class CollectionDetail extends BtrixElement {
() => html`
<div class="mb-5">
<sl-switch
?checked=${this.collection?.visibility ===
CollectionVisibility.Unlisted}
?checked=${this.collection?.access ===
CollectionAccess.Unlisted}
@sl-change=${(e: CustomEvent) =>
void this.onTogglePublic((e.target as SlCheckbox).checked)}
>${msg("Collection is Shareable")}</sl-switch
Expand All @@ -264,7 +264,7 @@ export class CollectionDetail extends BtrixElement {
`,
)}
</div>
${when(this.collection?.visibility === CollectionVisibility.Unlisted, this.renderShareInfo)}
${when(this.collection?.access === CollectionAccess.Unlisted, this.renderShareInfo)}
<div slot="footer" class="flex justify-end">
<sl-button size="small" @click=${() => (this.showShareInfo = false)}
>${msg("Done")}</sl-button
Expand Down Expand Up @@ -416,7 +416,7 @@ export class CollectionDetail extends BtrixElement {
${msg("Select Archived Items")}
</sl-menu-item>
<sl-divider></sl-divider>
${this.collection?.visibility === CollectionVisibility.Private
${this.collection?.access === CollectionAccess.Private
? html`
<sl-menu-item
style="--sl-color-neutral-700: var(--success)"
Expand Down Expand Up @@ -748,19 +748,19 @@ export class CollectionDetail extends BtrixElement {
};

private async onTogglePublic(isPublic: boolean) {
const visibility = !isPublic
? CollectionVisibility.Private
: CollectionVisibility.Unlisted;
const access = !isPublic
? CollectionAccess.Private
: CollectionAccess.Unlisted;
const res = await this.api.fetch<{ updated: boolean }>(
`/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 };
}
}

Expand Down
14 changes: 7 additions & 7 deletions frontend/src/pages/org/collections-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"
>
<btrix-table-cell class="p-3">
${col.visibility === CollectionVisibility.Unlisted
${col.access === CollectionAccess.Unlisted
? html`
<sl-tooltip content=${msg("Shareable")}>
<sl-icon
Expand Down Expand Up @@ -576,7 +576,7 @@ export class CollectionsList extends BtrixElement {
${msg("Edit Metadata")}
</sl-menu-item>
<sl-divider></sl-divider>
${col.visibility === CollectionVisibility.Private
${col.access === CollectionAccess.Private
? html`
<sl-menu-item
style="--sl-color-neutral-700: var(--success)"
Expand Down Expand Up @@ -651,12 +651,12 @@ export class CollectionsList extends BtrixElement {
});

private async onTogglePublic(coll: Collection, isPublic: boolean) {
const visibility = !isPublic
? CollectionVisibility.Private
: CollectionVisibility.Unlisted;
const access = !isPublic
? CollectionAccess.Private
: CollectionAccess.Unlisted;
await this.api.fetch(`/orgs/${this.orgId}/collections/${coll.id}`, {
method: "PATCH",
body: JSON.stringify({ visibility }),
body: JSON.stringify({ access }),
});

void this.fetchCollections();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/types/collection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum CollectionVisibility {
export enum CollectionAccess {
Private = "private",
Public = "public",
Unlisted = "unlisted",
Expand All @@ -15,7 +15,7 @@ export type Collection = {
totalSize: number;
tags: string[];
resources: string[];
visibility: CollectionVisibility;
access: CollectionAccess;
};

export type CollectionSearchValues = {
Expand Down

0 comments on commit b21f876

Please sign in to comment.