Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
transporte
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Logistik
transporte
Commits
2b1cc21f
Unverified
Commit
2b1cc21f
authored
2 years ago
by
hanfi
Browse files
Options
Downloads
Patches
Plain Diff
fixed zammad integration
parent
c70e9d08
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
transporte/views.py
+8
-8
8 additions, 8 deletions
transporte/views.py
transporte/zammad_integration.py
+20
-33
20 additions, 33 deletions
transporte/zammad_integration.py
with
28 additions
and
41 deletions
transporte/views.py
+
8
−
8
View file @
2b1cc21f
...
...
@@ -190,12 +190,12 @@ def edit_transport(id=None):
#
# if ticket is new, update object with zammad ticket id
#
#
if transport.ticket_id is None:
#
transport.ticket_id = update_ticket(transport)
#
db.session.add(transport)
#
db.session.commit()
#
else:
#
update_ticket(transport)
if
transport
.
ticket_id
is
None
:
transport
.
ticket_id
=
update_ticket
(
transport
)
db
.
session
.
add
(
transport
)
db
.
session
.
commit
()
else
:
update_ticket
(
transport
)
for
file
in
request
.
files
.
getlist
(
"
file_upload
"
):
if
file
.
filename
:
...
...
@@ -322,8 +322,8 @@ def mark_transport(mark, id=None):
#
# close ticket
#
#
if transport.ticket_id:
#
close_ticket(transport, mark)
if
transport
.
ticket_id
:
close_ticket
(
transport
,
mark
)
db
.
session
.
add
(
transport
)
db
.
session
.
commit
()
...
...
This diff is collapsed.
Click to expand it.
transporte/zammad_integration.py
+
20
−
33
View file @
2b1cc21f
...
...
@@ -5,27 +5,28 @@ from flask import render_template
from
zammad_py
import
ZammadAPI
def
close_ticket
(
transport
,
reason
):
client
=
ZammadAPI
(
username
=
app
.
config
[
"
ZAMMAD_USER
"
],
password
=
app
.
config
[
"
ZAMMAD_PASS
"
],
host
=
app
.
config
[
"
ZAMMAD_HOST
"
],
is_secure
=
app
.
config
[
"
ZAMMAD_SECURE
"
],
def
get_client
():
return
ZammadAPI
(
url
=
app
.
config
[
"
ZAMMAD_URL
"
],
http_token
=
app
.
config
[
"
ZAMMAD_TOKEN
"
]
)
def
get_user
(
email
,
client
):
# very cheap userlookup.
# the email should be unique so we never should get more than 1 result
# if 0 results we need create the user
zammad_search_result
=
client
.
user
.
search
(
f
"
query=email:
{
email
}
"
)
if
len
(
zammad_search_result
)
==
0
:
return
client
.
user
.
create
({
"
firstname
"
:
email
,
"
email
"
:
email
})
return
zammad_search_result
[
0
]
def
close_ticket
(
transport
,
reason
):
client
=
get_client
()
messagebody
=
reason
#
# if new helpdesk user is closing a ticket,
# we need to create the user in the ticket system
#
zammad_search_result
=
client
.
user
.
search
({
"
query
"
:
transport
.
user
.
login
})
if
zammad_search_result
:
zammad_user
=
zammad_search_result
[
0
]
else
:
zammad_user
=
client
.
user
.
create
(
{
"
firstname
"
:
transport
.
user
.
login
,
"
email
"
:
transport
.
user
.
login
}
)
zammad_user
=
get_user
(
transport
.
user
.
login
,
client
)
ticketTemplate
=
{
"
id
"
:
transport
.
ticket_id
,
...
...
@@ -50,23 +51,9 @@ def close_ticket(transport, reason):
def
update_ticket
(
transport
):
client
=
ZammadAPI
(
username
=
app
.
config
[
"
ZAMMAD_USER
"
],
password
=
app
.
config
[
"
ZAMMAD_PASS
"
],
host
=
app
.
config
[
"
ZAMMAD_HOST
"
],
is_secure
=
app
.
config
[
"
ZAMMAD_SECURE
"
],
)
client
=
get_client
()
#
# Create user if not exists
#
zammad_search_result
=
client
.
user
.
search
({
"
query
"
:
transport
.
user
.
login
})
if
zammad_search_result
:
zammad_user
=
zammad_search_result
[
0
]
else
:
zammad_user
=
client
.
user
.
create
(
{
"
firstname
"
:
transport
.
user
.
login
,
"
email
"
:
transport
.
user
.
login
}
)
zammad_user
=
get_user
(
transport
.
user
.
login
,
client
)
messagebody
=
render_template
(
"
email_transport_update.html
"
,
transport
=
transport
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment