Sanitize Helpdesk mail settings for all projects
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
"""Reset RedmineUP Helpdesk mail settings on the LAN test Redmine instance.
|
||||
|
||||
This is intended to be run after importing a production database into the test
|
||||
instance. It finds projects with the Helpdesk module enabled and rewrites only
|
||||
the incoming/outgoing mail settings so test mail flows through Mailpit.
|
||||
instance. It rewrites every active project's incoming/outgoing Helpdesk mail
|
||||
settings so test mail flows through Mailpit and imported real credentials cannot
|
||||
be used accidentally.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -113,7 +114,7 @@ class RemoteRedmine:
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Reset Helpdesk mail settings for projects with the contacts_helpdesk module enabled."
|
||||
description="Reset Helpdesk mail settings for all active projects."
|
||||
)
|
||||
parser.add_argument("--ssh-host", default=os.getenv("REDMINE_SSH_HOST", DEFAULT_SSH_HOST))
|
||||
parser.add_argument("--ssh-key", type=Path, default=Path(os.getenv("REDMINE_SSH_KEY", str(DEFAULT_SSH_KEY))))
|
||||
@@ -141,12 +142,12 @@ def main() -> int:
|
||||
remote = RemoteRedmine(args.ssh_host, args.ssh_key, args.remote_redmine)
|
||||
|
||||
try:
|
||||
projects = find_helpdesk_projects(remote, args.project)
|
||||
projects = find_active_projects(remote, args.project)
|
||||
if not projects:
|
||||
print("No active projects with contacts_helpdesk enabled matched the requested filters.")
|
||||
print("No active projects matched the requested filters.")
|
||||
return 0
|
||||
|
||||
print(f"Matched {len(projects)} Helpdesk-enabled project(s):")
|
||||
print(f"Matched {len(projects)} active project(s):")
|
||||
for project in projects:
|
||||
print(f" - #{project['id']} {project['identifier']} ({project['name']})")
|
||||
|
||||
@@ -165,7 +166,7 @@ def main() -> int:
|
||||
return 1
|
||||
|
||||
|
||||
def find_helpdesk_projects(remote: RemoteRedmine, filters: list[str]) -> list[dict[str, Any]]:
|
||||
def find_active_projects(remote: RemoteRedmine, filters: list[str]) -> list[dict[str, Any]]:
|
||||
where = ["p.status = 1"]
|
||||
if filters:
|
||||
clauses = []
|
||||
@@ -183,9 +184,6 @@ SELECT HEX(CAST(JSON_OBJECT(
|
||||
'name', p.name
|
||||
) AS CHAR)) AS document
|
||||
FROM projects p
|
||||
JOIN enabled_modules em
|
||||
ON em.project_id = p.id
|
||||
AND em.name = 'contacts_helpdesk'
|
||||
WHERE {' AND '.join(where)}
|
||||
ORDER BY p.identifier;
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user