From 773084f504c42c8e1b0d36042b5b2be235a22728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 2 Sep 2020 11:39:54 +0200 Subject: [PATCH] Allow to provide default for user attributes For some reason roles is missing in some cases. --- rt2zammad.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rt2zammad.py b/rt2zammad.py index 1d3858b..1dec30f 100755 --- a/rt2zammad.py +++ b/rt2zammad.py @@ -154,7 +154,7 @@ for user in target.user.all(): USERMAP[user["email"].lower()] = user -def get_user(userdata, attr="login"): +def get_user(userdata, attr="login", default=None): email = userdata["EmailAddress"] lemail = email.lower() if lemail in config["usermap"]: @@ -181,7 +181,10 @@ def get_user(userdata, attr="login"): user = target.user.create(kwargs) USERMAP[user["email"].lower()] = user - return USERMAP[lemail][attr] + if default is None: + return USERMAP[lemail][attr] + return USERMAP[lemail]get(attr, default) + # Create tickets @@ -243,7 +246,7 @@ for ticket in tickets: ) creator_id = get_user(users[item["Creator"]], "id") chown = creator_id != new["customer_id"] and "Agent" not in get_user( - users[item["Creator"]], "roles" + users[item["Creator"]], "roles", [] ) if chown: target.ticket.update(new["id"], {"customer_id": creator_id})