-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add slug to collections and use it in public collection URLs (#…
…2301) Resolves #2298 ## Changes - Slugs added to collections, can be specified separately when creating or updating collections or else is based off of supplied collection name - Migration added to backfill slugs for existing collections - Redirect collection to newest slug if changed - Adds option to copy public profile link to "Public Collections" action menu - Show "Back to <Org>" link instead of breadcrumbs --------- Co-authored-by: sua yoo <[email protected]> Co-authored-by: Ilya Kreymer <[email protected]>
- Loading branch information
Showing
27 changed files
with
414 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
backend/btrixcloud/migrations/migration_0039_coll_slugs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Migration 0039 -- collection slugs | ||
""" | ||
|
||
from btrixcloud.migrations import BaseMigration | ||
from btrixcloud.utils import slug_from_name | ||
|
||
|
||
MIGRATION_VERSION = "0039" | ||
|
||
|
||
class Migration(BaseMigration): | ||
"""Migration class.""" | ||
|
||
# pylint: disable=unused-argument | ||
def __init__(self, mdb, **kwargs): | ||
super().__init__(mdb, migration_version=MIGRATION_VERSION) | ||
|
||
async def migrate_up(self): | ||
"""Perform migration up. | ||
Add slug to collections that don't have one yet, based on name | ||
""" | ||
colls_mdb = self.mdb["collections"] | ||
|
||
async for coll_raw in colls_mdb.find({"slug": None}): | ||
coll_id = coll_raw["_id"] | ||
try: | ||
await colls_mdb.find_one_and_update( | ||
{"_id": coll_id}, | ||
{"$set": {"slug": slug_from_name(coll_raw.get("name", ""))}}, | ||
) | ||
# pylint: disable=broad-exception-caught | ||
except Exception as err: | ||
print( | ||
f"Error saving slug for collection {coll_id}: {err}", | ||
flush=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.