Skip to content

Commit

Permalink
Fix logic for suggested id for new site.
Browse files Browse the repository at this point in the history
This would take the default "Plone" plus the count of existing sites.
Usually this works fine, first suggesting Plone, then Plone1, Plone2, etc.
But if you have Plone and Plone2 as existing site ids, it would suggest Plone2, which gives an error because it is already taken.

The fix is: keep this logic, but if the id is already taken, keep increasing the id until it is free.

This fixes #97
  • Loading branch information
mauritsvanrees committed Dec 18, 2024
1 parent 4291603 commit b352285
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions news/97.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix logic for suggested id for new site.
It could suggest an id that was already taken.
@mauritsvanrees
16 changes: 12 additions & 4 deletions src/plone/distribution/services/sites/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,18 @@ def _populate_server_defaults(self, distribution: Distribution) -> dict:
request = self.request
# Sites with default id
all_sites = self.get_sites()
sites = [site for site in all_sites if site["id"].startswith(DEFAULT_ID)]
server_defaults["site_id"] = (
f"{DEFAULT_ID}{len(sites)}" if sites else DEFAULT_ID
)
site_ids = [
site["id"] for site in all_sites if site["id"].startswith(DEFAULT_ID)
]
if site_ids:
count = len(site_ids)
new_site_id = f"{DEFAULT_ID}{count}"
while new_site_id in site_ids:
count += 1
new_site_id = f"{DEFAULT_ID}{count}"
else:
new_site_id = DEFAULT_ID
server_defaults["site_id"] = new_site_id
jsonschema = distribution.schema
uischema = distribution.uischema
if should_provide_default_language_default(uischema, jsonschema):
Expand Down

0 comments on commit b352285

Please sign in to comment.