Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyOTRS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External 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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Som Connexió
OTRS
PyOTRS
Commits
61dd955b
Commit
61dd955b
authored
8 years ago
by
Robert Habermann
Browse files
Options
Downloads
Patches
Plain Diff
add GenericLink API
parent
94eb4ccf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyotrs/lib.py
+273
-1
273 additions, 1 deletion
pyotrs/lib.py
with
273 additions
and
1 deletion
pyotrs/lib.py
+
273
−
1
View file @
61dd955b
...
...
@@ -707,7 +707,8 @@ class Client(object):
self
.
webservicename
=
webservicename
# TODO 2016-30-10 (RH): check Name and Documentation
self
.
webservicename_link
=
"
GenericLinkConnectorREST
"
if
not
webservicename_link
:
self
.
webservicename_link
=
"
GenericLinkConnectorREST
"
if
not
session_timeout
:
self
.
session_timeout
=
28800
# 8 hours is OTRS default
...
...
@@ -1184,6 +1185,264 @@ class Client(object):
return
self
.
ticket_update
(
ticket_id
,
State
=
new_state
,
PendingTime
=
pt
)
"""
GenericInterface::Operation::Link::LinkAdd
* link_add
"""
def
link_add
(
self
,
src_object_id
,
dst_object_id
,
src_object_type
=
"
Ticket
"
,
dst_object_type
=
"
Ticket
"
,
link_type
=
"
Normal
"
,
state
=
"
Valid
"
):
"""
link_add
Args:
src_object_id (int): Integer value of source object ID
dst_object_id (int): Integer value of destination object ID
src_object_type (str): Object type of source; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
dst_object_type (str): Object type of destination; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
link_type (str): Type of the link:
"
Normal
"
or
"
ParentChild
"
(*default: Normal*)
state (str): State of the link (*default: Normal*)
Returns:
**True** or **False**: True if successful, otherwise **False**.
"""
if
not
self
.
session_id_store
.
value
:
raise
SessionNotCreated
(
"
Call session_create() or
"
"
session_restore_or_set_up_new() first
"
)
self
.
operation
=
"
LinkAdd
"
payload
=
{
"
SessionID
"
:
self
.
session_id_store
.
value
,
"
SourceObject
"
:
src_object_type
,
"
SourceKey
"
:
int
(
src_object_id
),
"
TargetObject
"
:
dst_object_type
,
"
TargetKey
"
:
int
(
dst_object_id
),
"
Type
"
:
link_type
,
"
State
"
:
state
}
return
self
.
_parse_and_validate_response
(
self
.
_send_request
(
payload
))
"""
GenericInterface::Operation::Link::LinkDelete
* link_delete
"""
def
link_delete
(
self
,
src_object_id
,
dst_object_id
,
src_object_type
=
"
Ticket
"
,
dst_object_type
=
"
Ticket
"
,
link_type
=
"
Normal
"
):
"""
link_delete
Args:
src_object_id (int): Integer value of source object ID
src_object_type (str): Object type of source; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
dst_object_id (int): Integer value of source object ID
dst_object_type (str): Object type of source; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
link_type (str): Type of the link:
"
Normal
"
or
"
ParentChild
"
(*default: Normal*)
Returns:
**True** or **False**: True if successful, otherwise **False**.
"""
if
not
self
.
session_id_store
.
value
:
raise
SessionNotCreated
(
"
Call session_create() or
"
"
session_restore_or_set_up_new() first
"
)
self
.
operation
=
"
LinkDelete
"
payload
=
{
"
SessionID
"
:
self
.
session_id_store
.
value
,
"
Object1
"
:
src_object_type
,
"
Key1
"
:
int
(
src_object_id
),
"
Object2
"
:
dst_object_type
,
"
Key2
"
:
int
(
dst_object_id
),
"
Type
"
:
link_type
}
return
self
.
_parse_and_validate_response
(
self
.
_send_request
(
payload
))
"""
GenericInterface::Operation::Link::LinkDeleteAll
* link_delete_all
"""
def
link_delete_all
(
self
,
object_id
,
object_type
=
"
Ticket
"
,):
"""
link_delete_all
Args:
object_id (int): Integer value of source object ID
object_type (str): Object type of source; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
Returns:
**True** or **False**: True if successful, otherwise **False**.
"""
if
not
self
.
session_id_store
.
value
:
raise
SessionNotCreated
(
"
Call session_create() or
"
"
session_restore_or_set_up_new() first
"
)
self
.
operation
=
"
LinkDeleteAll
"
payload
=
{
"
SessionID
"
:
self
.
session_id_store
.
value
,
"
Object
"
:
object_type
,
"
Key
"
:
int
(
object_id
)
}
return
self
.
_parse_and_validate_response
(
self
.
_send_request
(
payload
))
"""
GenericInterface::Operation::Link::LinkList
* link_list
"""
def
link_list
(
self
,
src_object_id
,
src_object_type
=
"
Ticket
"
,
dst_object_type
=
None
,
state
=
"
Valid
"
,
link_type
=
None
,
direction
=
None
):
"""
link_list
Args:
src_object_id (int): Object type of source; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
src_object_type (str): Object type of destination; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
dst_object_type (str): Object type of destination; e.g.
"
Ticket
"
,
"
FAQ
"
...
Optional restriction of the object where the links point to. (*default: Ticket*)
state (str): State of the link (*default: Valid*)
link_type (str): Type of the link:
"
Normal
"
or
"
ParentChild
"
(*default: Normal*)
direction (str): Optional restriction of the link direction (
'
Source
'
or
'
Target
'
).
Returns:
**Dict** or **None**: Dict if successful, if empty **None**.
"""
if
not
self
.
session_id_store
.
value
:
raise
SessionNotCreated
(
"
Call session_create() or
"
"
session_restore_or_set_up_new() first
"
)
self
.
operation
=
"
LinkList
"
payload
=
{
"
SessionID
"
:
self
.
session_id_store
.
value
,
"
Object
"
:
src_object_type
,
"
Key
"
:
int
(
src_object_id
),
"
State
"
:
state
}
if
dst_object_type
:
payload
.
update
({
"
Object2
"
:
dst_object_type
})
if
link_type
:
payload
.
update
({
"
Type
"
:
link_type
})
if
direction
:
payload
.
update
({
"
Direction
"
:
direction
})
return
self
.
_parse_and_validate_response
(
self
.
_send_request
(
payload
))
"""
GenericInterface::Operation::Link::PossibleLinkList
* link_possible_link_list
"""
def
link_possible_link_list
(
self
):
"""
link_possible_link_list
Returns:
**List** or **False**: List if successful, otherwise **False**.
"""
if
not
self
.
session_id_store
.
value
:
raise
SessionNotCreated
(
"
Call session_create() or
"
"
session_restore_or_set_up_new() first
"
)
self
.
operation
=
"
PossibleLinkList
"
payload
=
{
"
SessionID
"
:
self
.
session_id_store
.
value
,
}
if
self
.
_parse_and_validate_response
(
self
.
_send_request
(
payload
)):
return
self
.
result
else
:
return
False
"""
GenericInterface::Operation::Link::PossibleObjectsList
* link_possible_objects_list
"""
def
link_possible_objects_list
(
self
,
object_type
=
"
Ticket
"
):
"""
link_possible_objects_list
Args:
object_type (str): Object type; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
Returns:
**List** or **False**: List if successful, otherwise **False**.
"""
if
not
self
.
session_id_store
.
value
:
raise
SessionNotCreated
(
"
Call session_create() or
"
"
session_restore_or_set_up_new() first
"
)
self
.
operation
=
"
PossibleObjectsList
"
payload
=
{
"
SessionID
"
:
self
.
session_id_store
.
value
,
"
Object
"
:
object_type
,
}
if
self
.
_parse_and_validate_response
(
self
.
_send_request
(
payload
)):
return
self
.
result
else
:
return
False
"""
GenericInterface::Operation::Link::PossibleTypesList
* link_possible_types_list
"""
def
link_possible_types_list
(
self
,
src_object_type
=
"
Ticket
"
,
dst_object_type
=
"
Ticket
"
):
"""
link_possible_types_list
Args:
src_object_type (str): Object type of source; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
dst_object_type (str): Object type of destination; e.g.
"
Ticket
"
,
"
FAQ
"
...
(*default: Ticket*)
Returns:
**List** or **False**: List if successful, otherwise **False**.
"""
if
not
self
.
session_id_store
.
value
:
raise
SessionNotCreated
(
"
Call session_create() or
"
"
session_restore_or_set_up_new() first
"
)
self
.
operation
=
"
PossibleTypesList
"
payload
=
{
"
SessionID
"
:
self
.
session_id_store
.
value
,
"
Object1
"
:
src_object_type
,
"
Object2
"
:
dst_object_type
,
}
if
self
.
_parse_and_validate_response
(
self
.
_send_request
(
payload
)):
return
self
.
result
else
:
return
False
def
_build_url
(
self
,
ticket_id
=
None
):
"""
build url for request
...
...
@@ -1332,6 +1591,19 @@ class Client(object):
self
.
result
=
self
.
result_json
[
'
TicketID
'
]
return
True
# handle Link operations; Add, Delete, DeleteAll return: {"Success":1}
if
self
.
operation
in
[
"
LinkAdd
"
,
"
LinkDelete
"
,
"
LinkDeleteAll
"
]:
if
self
.
result_json
.
get
(
"
Success
"
,
None
)
==
1
:
# TODO 2016-10-30 (RH): enough?!
return
True
# LinkList result can be empty
if
self
.
operation
in
"
LinkList
"
:
_link_list
=
self
.
result_json
.
get
(
"
LinkList
"
,
None
)
if
_link_list
==
u
''
:
return
None
if
len
(
_link_list
):
return
_link_list
# now handle other operations
if
self
.
result_json
.
get
(
self
.
_result_type
,
None
):
self
.
_result_error
=
False
...
...
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