Skip to content
Closed
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
exclude: .pre-commit-config.yaml
- id: pt_structure
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.0
hooks:
- id: ruff
args: [ "--fix" ]
Expand Down
6 changes: 4 additions & 2 deletions src/onegov/org/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,10 @@
new_uri = request.host_url
else:
new_uri = request.domain
migration = LinkMigration(request, old_uri=old_uri, new_uri=new_uri)
total, grouped_count = migration.migrate_site_collection(
migration = LinkMigration(

Check warning on line 857 in src/onegov/org/cli.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/cli.py#L857

Added line #L857 was not covered by tests
request, old_uri=old_uri, new_uri=new_uri, use_domain=True
)
total, grouped_count = migration.migrate(

Check warning on line 860 in src/onegov/org/cli.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/cli.py#L860

Added line #L860 was not covered by tests
test=dry_run
)

Expand Down
91 changes: 84 additions & 7 deletions src/onegov/org/forms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@

from functools import cached_property
from lxml import etree
from openpyxl import load_workbook

from onegov.core.widgets import transform_structure
from onegov.core.widgets import XML_LINE_OFFSET
from onegov.form import Form
from onegov.form.fields import ChosenSelectField, URLPanelField
from onegov.form.fields import ChosenSelectField, URLPanelField, UploadField
from onegov.form.fields import ColorField
from onegov.form.fields import CssField
from onegov.form.fields import MarkupField
from onegov.form.fields import MultiCheckboxField
from onegov.form.fields import PreviewField
from onegov.form.fields import TagsField
from onegov.form.validators import WhitelistedMimeType, FileSizeLimit
from onegov.gever.encrypt import encrypt_symmetric
from onegov.gis import CoordinatesField
from onegov.org import _
Expand All @@ -37,7 +39,7 @@
from wtforms.fields import StringField
from wtforms.fields import TextAreaField
from wtforms.fields import URLField
from wtforms.validators import InputRequired
from wtforms.validators import InputRequired, DataRequired
from wtforms.validators import NumberRange
from wtforms.validators import Optional
from wtforms.validators import URL as UrlRequired
Expand Down Expand Up @@ -1233,34 +1235,109 @@


class LinkMigrationForm(Form):
migration_type = RadioField(
label=_('Migration Type'),
choices=[
('domain', _('Domain Migration')),
(
'text',
_(
'Bulk URL Migration. (Find and Replace any text, '
'a more general version.)'
),
),
],
default='domain',
validators=[InputRequired()],
)

old_domain = StringField(
label=_('Old domain'),
description='govikon.onegovcloud.ch',
validators=[InputRequired()]
depends_on=('migration_type', 'domain'),
validators=[InputRequired()],
)

url_mappings = UploadField(
label=_('URL Mappings Excel File'),
description=_(
'Excel file with column A containing URLs to find and column '
'B containing replacement URLs. This is useful in cases when we '
'need to replace the entire URL (for example, '
'https://domain.com/old-url to https://www.new-domain.com/new-url)'
),
validators=[
DataRequired(),
WhitelistedMimeType(
{
'application/vnd.ms-excel', # standard
(
'application/'
'vnd.openxmlformats-officedocument.spreadsheetml.sheet'
),
}
),
FileSizeLimit(10 * 1024 * 1024)
],
depends_on=('migration_type', 'text'),
render_kw={'force_simple': True}
)

test = BooleanField(
label=_('Test migration'),
description=_('Compares links to the current domain'),
default=True
description=_(
'Shows what would be changed without making actual changes'
),
default=True,
)

def ensure_correct_domain(self) -> bool | None:
if self.old_domain.data:
if self.migration_type.data == 'domain' and self.old_domain.data:
errors = []
if self.old_domain.data.startswith('http'):
errors.append(
_('Use a domain name without http(s)')
)
if '.' not in self.old_domain.data:
errors.append(_('Domain must contain a dot'))

if errors:
self.old_domain.errors = errors
return False
return None

def validate_url_mappings(self, file: UploadField) -> None:
if self.migration_type.data != 'text':
return

Check warning on line 1310 in src/onegov/org/forms/settings.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/forms/settings.py#L1310

Added line #L1310 was not covered by tests
if not file.file:
return

Check warning on line 1312 in src/onegov/org/forms/settings.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/forms/settings.py#L1312

Added line #L1312 was not covered by tests
try:
# Load the workbook from the file contents
workbook = load_workbook(filename=file.file, read_only=True)
# Get the active sheet (first sheet)
sheet = workbook.active
if sheet is None:
return

Check warning on line 1319 in src/onegov/org/forms/settings.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/forms/settings.py#L1319

Added line #L1319 was not covered by tests

# Check if sheet has any rows
if sheet.max_row < 1:
raise ValidationError(

Check warning on line 1323 in src/onegov/org/forms/settings.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/forms/settings.py#L1323

Added line #L1323 was not covered by tests
_('Excel file must contain at least one row of data')
)

# Check number of columns
if sheet.max_column != 2:
raise ValidationError(

Check warning on line 1329 in src/onegov/org/forms/settings.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/forms/settings.py#L1329

Added line #L1329 was not covered by tests
_(
'Excel file must contain exactly two columns: '
'URLs to find and replacement URLs'
)
)

# Reset file pointer for actual processing
file.file.seek(0)
except Exception as err:
raise ValidationError(_('Exception while reading xlsx')) from err

Check warning on line 1339 in src/onegov/org/forms/settings.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/forms/settings.py#L1338-L1339

Added lines #L1338 - L1339 were not covered by tests


class LinkHealthCheckForm(Form):

Expand Down
88 changes: 70 additions & 18 deletions src/onegov/org/locale/de_CH/LC_MESSAGES/onegov.org.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE 1.0\n"
"POT-Creation-Date: 2025-01-08 16:47+0100\n"
"POT-Creation-Date: 2025-01-09 15:47+0100\n"
"PO-Revision-Date: 2022-03-15 10:21+0100\n"
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
"Language-Team: German\n"
Expand Down Expand Up @@ -1020,6 +1020,9 @@ msgstr "Grosse Bilder"
msgid "Grid layout"
msgstr "Raster"

msgid "Show images on homepage"
msgstr "Bilder auf der Startseite zeigen"

msgid "By filename"
msgstr "Nach Dateiname"

Expand All @@ -1029,9 +1032,6 @@ msgstr "Nach Beschreibung"
msgid "By last change"
msgstr "Nach Zeitpunkt der letzten Änderung"

msgid "Show images on homepage"
msgstr "Bilder auf der Startseite zeigen"

msgid "Used in the overview and the e-mail subject"
msgstr "Wird in der Übersicht und als E-Mail Subjekt verwendet"

Expand Down Expand Up @@ -1694,10 +1694,10 @@ msgid "JavaScript for web statistics support"
msgstr "JavaScript für Web-Statistik"

msgid "Analytics URL"
msgstr ""
msgstr "Analytics URL"

msgid "URL pointing to the analytics page"
msgstr ""
msgstr "Link zur Analytics Seite"

msgid "Cantonal holidays"
msgstr "Kantonale Feiertage"
Expand Down Expand Up @@ -1924,21 +1924,56 @@ msgstr ""
"Ungültiges Format. Nur Themen und Unterthemen sind erlaubt - es werden keine "
"tiefer verschachtelte Strukturen unterstützt."

msgid "Migration Type"
msgstr "Migrations-Typ"

msgid "Domain Migration"
msgstr "Domain-Migration"

msgid ""
"Bulk URL Migration. (Find and Replace any text, a more general version.)"
msgstr "Suchen und Ersetzen von beliebigem Text, eine allgemeinere Version"

msgid "Old domain"
msgstr "Alte Domain"

msgid "URL Mappings Excel File"
msgstr "Excel-Datei mit Ersetzungstabelle"

msgid ""
"Excel file with column A containing URLs to find and column B containing "
"replacement URLs. This is useful in cases when we need to replace the entire "
"URL (for example, https://domain.com/old-url to https://www.new-domain.com/"
"new-url)"
msgstr "Eine Excel-Datei mit Spalte A, die die zu ersetzenden URLs enthält und "
"Spalte B, die die Ersatz-URLs enthält. Dies ist nützlich, wenn wir die "
"gesamte URL ersetzen müssen (zum Beispiel https://domain.com/old-url zu "
"https://www.new-domain.com/new-url)"

msgid "Test migration"
msgstr "Migration testen"

msgid "Compares links to the current domain"
msgstr "Vergleicht Links mit der aktuellen Domain"
msgid "Shows what would be changed without making actual changes"
msgstr "Zeigt, was geändert würde, ohne tatsächliche Änderungen vorzunehmen"

msgid "Use a domain name without http(s)"
msgstr "Benutze eine Domain ohne http(s)"

msgid "Domain must contain a dot"
msgstr "Die Domain muss einen Punkt enthalten"

msgid "Excel file must contain at least one row of data"
msgstr "Excel-Datei muss mindestens eine Datenzeile enthalten"

msgid ""
"Excel file must contain exactly two columns: URLs to find and replacement "
"URLs"
msgstr "Die Excel-Datei muss genau zwei Spalten enthalten: URLs zum Finden und "
"Ersetzungs-URLs"

msgid "Invalid Excel file format"
msgstr "Ungültiges Excel-Dateiformat"

msgid "Choose which links to check"
msgstr "Wählen Sie, welche Urls Überprüft werden sollen"

Expand Down Expand Up @@ -2312,7 +2347,8 @@ msgstr "Möchten Sie diesen Befragungszeitraum wirklich löschen?"

msgid ""
"Submissions associated with this submission window will be deleted as well."
msgstr ""
msgstr "Eingaben die mit diesem Befragungszeitraum verknüpft sind, werden "
"ebenfalls gelöscht."

msgid "Delete submission window"
msgstr "Befragungszeitraum löschen"
Expand Down Expand Up @@ -2958,8 +2994,8 @@ msgstr "Die Absage von ${title} kann nicht rückgängig gemacht werden."
msgid "Reject reservation"
msgstr "Reservation absagen"

#.
#. Used in sentence: "${event} published."
#.
msgid "Event"
msgstr "Veranstaltung"

Expand Down Expand Up @@ -4862,7 +4898,7 @@ msgstr ""
msgid ""
"Rule updated. ${deleted} allocations removed, ${created} new allocations "
"created."
msgstr ""
msgstr "Regel aktualisiert. ${deleted} Einteilungen entfernt, ${created} neue Einteilungen erstellt."

msgid "Rule not found"
msgstr "Regel nicht gefunden"
Expand Down Expand Up @@ -5867,6 +5903,12 @@ msgstr "Migration Links"
msgid "Migrate"
msgstr "Migrieren"

msgid ""
"Migrates links using the mappings provided in the Excel file. Please verify "
"the changes in test mode before applying them."
msgstr "Migriert Links mit den im Excel-File bereitgestellten Zuordnungen. "
"Bitte überprüfen Sie die Änderungen im Testmodus, bevor Sie sie anwenden."

#, python-format
msgid "Migrated ${number} links"
msgstr "${number} Links migriert"
Expand All @@ -5875,11 +5917,18 @@ msgstr "${number} Links migriert"
msgid "Total of ${number} links found."
msgstr "Total ${number} Links gefunden"

#, python-format
msgid "${group}: ${number} changes"
msgstr "${group}: ${number} Änderungen"

#, python-format
msgid ""
"Migrates links from the given domain to the current domain \"${domain}\"."
"Migrates links from the given domain to the current domain \"${domain}\". "
"The form must be used *after* the DNS changeover to \"${domain}\"."
msgstr ""
"Migriert Links von der angegebenen Domain zur aktuellen Domain \"${domain}\"."
"Migriert Links von der angegebenen Domain zur aktuellen Domain "
"\"${domain}\". Das Formular muss *nach* der DNS-Umstellung auf "
"\"${domain}\" verwendet werden."

msgid "OneGov API"
msgstr "OneGov API"
Expand Down Expand Up @@ -5936,16 +5985,16 @@ msgstr ""
"Einträge."

msgid "Delete Submissions"
msgstr ""
msgstr "Einträge löschen"

msgid "Do you really want to delete all submissions?"
msgstr ""
msgstr "Möchten Sie wirklich alle Einträge löschen?"

msgid "All submissions associated with this survey will be deleted."
msgstr ""
msgstr "Alle mit dieser Umfrage verbundenen Einträge werden gelöscht."

msgid "Delete submissions"
msgstr ""
msgstr "Einträge löschen"

msgid "Exports the submissions of the survey."
msgstr "Exportiert die Umfrageeinträge."
Expand All @@ -5972,7 +6021,7 @@ msgid "Edit Submission Window"
msgstr "Befragungszeitraum bearbeiten"

msgid "The submission window and all associated submissions were deleted"
msgstr ""
msgstr "Der Befragungszeitraum und alle zugehörigen Einträge wurden gelöscht"

msgid "Added a new text module"
msgstr "Textbaustein hinzugefügt"
Expand Down Expand Up @@ -6195,6 +6244,9 @@ msgstr "Ein Konto wurde für Sie erstellt"
msgid "The user was created successfully"
msgstr "Der Benutzer wurde erfolgreich erstellt"

#~ msgid "Compares links to the current domain"
#~ msgstr "Vergleicht Links mit der aktuellen Domain"

#~ msgid "Photo album. Will be shown at the end of content."
#~ msgstr "Fotoalbum. Wird am Ende des Inhalts angezeigt."

Expand Down
Loading
Loading