Fix importing non owner comments
Temporarily chaning ownership of the ticket allows to post comment by any customer.
This commit is contained in:
parent
af7d142da1
commit
0f8696adbb
2 changed files with 11 additions and 8 deletions
|
@ -5,9 +5,6 @@ for everybody, you will probably have to customize it.
|
||||||
|
|
||||||
Known issues:
|
Known issues:
|
||||||
|
|
||||||
* Comments on issues from non creators are rejected by Zammad. This can be
|
|
||||||
workarounded by creating appropriate organizations in Zammad manually or
|
|
||||||
temporarily grainting Users group agent privilege.
|
|
||||||
* Disabled users from RT can not be accessed by API, thus will lack email
|
* Disabled users from RT can not be accessed by API, thus will lack email
|
||||||
address and will fail to be created. Enable all users prior to the migration.
|
address and will fail to be created. Enable all users prior to the migration.
|
||||||
* Timestamps are not preserved. The Zammad API doesn't seem to allow this.
|
* Timestamps are not preserved. The Zammad API doesn't seem to allow this.
|
||||||
|
|
16
rt2zammad.py
16
rt2zammad.py
|
@ -132,16 +132,16 @@ STATUSMAP = {"new": 1, "open": 2, "resolved": 4, "rejected": 4, "deleted": 4}
|
||||||
USERMAP = {}
|
USERMAP = {}
|
||||||
|
|
||||||
for user in target.user.all():
|
for user in target.user.all():
|
||||||
USERMAP[user["email"].lower()] = user["login"]
|
USERMAP[user["email"].lower()] = user
|
||||||
|
|
||||||
|
|
||||||
def get_user(userdata):
|
def get_user(userdata, attr="login"):
|
||||||
email = userdata["EmailAddress"]
|
email = userdata["EmailAddress"]
|
||||||
lemail = email.lower()
|
lemail = email.lower()
|
||||||
# Search existing users
|
# Search existing users
|
||||||
if lemail not in USERMAP:
|
if lemail not in USERMAP:
|
||||||
for user in target.user.search({"query": email}):
|
for user in target.user.search({"query": email}):
|
||||||
USERMAP[user["email"].lower()] = user["login"]
|
USERMAP[user["email"].lower()] = user
|
||||||
# Create new one
|
# Create new one
|
||||||
if lemail not in USERMAP:
|
if lemail not in USERMAP:
|
||||||
kwargs = {"email": email}
|
kwargs = {"email": email}
|
||||||
|
@ -157,9 +157,9 @@ def get_user(userdata):
|
||||||
kwargs["lastname"] = last
|
kwargs["lastname"] = last
|
||||||
kwargs["firstname"] = first
|
kwargs["firstname"] = first
|
||||||
user = target.user.create(kwargs)
|
user = target.user.create(kwargs)
|
||||||
USERMAP[user["email"].lower()] = user["login"]
|
USERMAP[user["email"].lower()] = user
|
||||||
|
|
||||||
return USERMAP[lemail]
|
return USERMAP[lemail][attr]
|
||||||
|
|
||||||
|
|
||||||
# Create tickets
|
# Create tickets
|
||||||
|
@ -204,6 +204,10 @@ for ticket in tickets:
|
||||||
"mime-type": data["ContentType"],
|
"mime-type": data["ContentType"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
creator_id = get_user(users[item["Creator"]], "id")
|
||||||
|
chown = creator_id != new["customer_id"]
|
||||||
|
if chown:
|
||||||
|
target.ticket.update(new["id"], {"customer_id": creator_id})
|
||||||
TicketArticle(get_zammad(on_behalf_of=get_user(users[item["Creator"]]))).create(
|
TicketArticle(get_zammad(on_behalf_of=get_user(users[item["Creator"]]))).create(
|
||||||
{
|
{
|
||||||
"ticket_id": new["id"],
|
"ticket_id": new["id"],
|
||||||
|
@ -212,3 +216,5 @@ for ticket in tickets:
|
||||||
"attachments": files,
|
"attachments": files,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if chown:
|
||||||
|
target.ticket.update(new["id"], {"customer_id": new["customer_id"]})
|
||||||
|
|
Loading…
Reference in a new issue