Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Leymonerie
slapos.core
Commits
55fc2d9f
Commit
55fc2d9f
authored
Feb 25, 2022
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_cloud: Add Person.notify() API
Used to create support requests to send users notifications.
parent
76618994
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
411 additions
and
0 deletions
+411
-0
master/bt5/slapos_cloud/TestTemplateItem/portal_components/test.erp5.testSlapOSCloudPersonSlapInterfaceWorkflow.py
...s/test.erp5.testSlapOSCloudPersonSlapInterfaceWorkflow.py
+205
-0
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/script_Person_notify.py
...ow/person_slap_interface_workflow/script_Person_notify.py
+60
-0
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/script_Person_notify.xml
...w/person_slap_interface_workflow/script_Person_notify.xml
+76
-0
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/state_draft.xml
...l_workflow/person_slap_interface_workflow/state_draft.xml
+1
-0
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/state_open_order_created.xml
...rson_slap_interface_workflow/state_open_order_created.xml
+1
-0
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/transition_notify.xml
...flow/person_slap_interface_workflow/transition_notify.xml
+68
-0
No files found.
master/bt5/slapos_cloud/TestTemplateItem/portal_components/test.erp5.testSlapOSCloudPersonSlapInterfaceWorkflow.py
View file @
55fc2d9f
...
@@ -1253,3 +1253,208 @@ class TestSlapOSCorePersonRequestToken(SlapOSTestCaseMixin):
...
@@ -1253,3 +1253,208 @@ class TestSlapOSCorePersonRequestToken(SlapOSTestCaseMixin):
self
.
assertEqual
(
self
.
assertEqual
(
token
.
getPortalType
(),
"One Time Restricted Access Token"
)
token
.
getPortalType
(),
"One Time Restricted Access Token"
)
self
.
assertEqual
(
token
.
getUrlMethod
(),
"POST"
)
self
.
assertEqual
(
token
.
getUrlMethod
(),
"POST"
)
class
TestSlapOSCorePersonNotify
(
SlapOSTestCaseMixin
):
def
afterSetUp
(
self
):
SlapOSTestCaseMixin
.
afterSetUp
(
self
)
self
.
person
=
self
.
makePerson
()
self
.
tic
()
def
beforeTearDown
(
self
):
pass
def
test_Person_notify_mandatory_argument
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
person
.
notify
)
self
.
assertRaises
(
TypeError
,
self
.
person
.
notify
,
support_request_title
=
"a"
)
self
.
assertRaises
(
TypeError
,
self
.
person
.
notify
,
support_request_title
=
"a"
,
support_request_description
=
"b"
)
def
test_Person_notify_unknown_aggregate
(
self
):
self
.
assertRaises
(
KeyError
,
self
.
person
.
notify
,
support_request_title
=
"a"
,
support_request_description
=
"b"
,
aggregate
=
"c"
)
def
test_Person_notify_computer_node
(
self
):
compute_node
,
_
=
self
.
_makeComputeNode
()
self
.
_test_Person_notify
(
compute_node
)
def
test_Person_notify_instance_tree
(
self
):
person
=
self
.
portal
.
person_module
.
template_member
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
instance_tree
=
self
.
portal
\
.
instance_tree_module
.
template_instance_tree
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
instance_tree
.
validate
()
new_id
=
self
.
generateNewId
()
instance_tree
.
edit
(
title
=
"Test hosting sub ticket %s"
%
new_id
,
reference
=
"TESTHST-%s"
%
new_id
,
destination_section_value
=
person
)
self
.
_test_Person_notify
(
instance_tree
)
def
test_Person_notify_software_installation
(
self
):
self
.
_makeComputeNode
()
software_installation
=
self
.
portal
\
.
software_installation_module
.
template_software_installation
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
software_installation
.
edit
(
url_string
=
self
.
generateNewSoftwareReleaseUrl
(),
aggregate
=
self
.
compute_node
.
getRelativeUrl
(),
reference
=
'TESTSOFTINSTS-%s'
%
self
.
generateNewId
(),
title
=
'Start requested for %s'
%
self
.
compute_node
.
getUid
()
)
software_installation
.
validate
()
software_installation
.
requestStart
()
self
.
_test_Person_notify
(
software_installation
)
def
_test_Person_notify
(
self
,
aggregate_value
):
# Step 1: Notify
self
.
person
.
notify
(
support_request_title
=
"A"
,
support_request_description
=
"B"
,
aggregate
=
aggregate_value
.
getRelativeUrl
()
)
# Step 2: Check return
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertNotEqual
(
None
,
support_request_relative_url
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
get
(
"support_request_in_progress"
,
None
)
self
.
assertEqual
(
support_request_in_progress
,
support_request_relative_url
)
support_request
=
self
.
portal
.
restrictedTraverse
(
support_request_in_progress
)
self
.
assertEqual
(
support_request
.
getSimulationState
(),
"validated"
)
self
.
assertEqual
(
support_request
.
getTitle
(),
"A"
)
self
.
assertEqual
(
support_request
.
getDescription
(),
"B"
)
self
.
assertNotEqual
(
support_request
.
getStartDate
(),
None
)
self
.
assertEqual
(
support_request
.
getDestinationDecision
(),
self
.
person
.
getRelativeUrl
())
self
.
assertEqual
(
support_request
.
getAggregateValue
(),
aggregate_value
)
self
.
assertEqual
(
support_request
.
getResource
(),
"service_module/slapos_crm_monitoring"
)
# Step 3: Reset REQUEST and check in progress before catalog
self
.
person
.
REQUEST
.
set
(
"support_request_relative_url"
,
None
)
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertEqual
(
None
,
support_request_relative_url
)
self
.
person
.
notify
(
support_request_title
=
"A"
,
support_request_description
=
"B"
,
aggregate
=
aggregate_value
.
getRelativeUrl
()
)
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertNotEqual
(
None
,
support_request_relative_url
)
self
.
assertEqual
(
support_request_in_progress
,
support_request_relative_url
)
self
.
tic
()
# Step 4: Reset parameters and check if the support request is got again.
self
.
person
.
REQUEST
.
set
(
"support_request_relative_url"
,
None
)
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertEqual
(
None
,
support_request_relative_url
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
set
(
"support_request_in_progress"
,
None
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
set
(
"support_request_in_progress"
,
None
)
self
.
assertEqual
(
support_request_in_progress
,
None
)
self
.
commit
()
self
.
person
.
notify
(
support_request_title
=
"A"
,
support_request_description
=
"B"
,
aggregate
=
aggregate_value
.
getRelativeUrl
()
)
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertNotEqual
(
None
,
support_request_relative_url
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
get
(
"support_request_in_progress"
,
None
)
self
.
assertEqual
(
support_request_in_progress
,
support_request_relative_url
)
# Check if it is the same Support Request as before
self
.
assertEqual
(
support_request
.
getRelativeUrl
(),
support_request_relative_url
)
# Step 5: Retry the same thing, but now on suspended state
support_request
.
suspend
()
self
.
tic
()
self
.
person
.
REQUEST
.
set
(
"support_request_relative_url"
,
None
)
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertEqual
(
None
,
support_request_relative_url
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
set
(
"support_request_in_progress"
,
None
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
set
(
"support_request_in_progress"
,
None
)
self
.
assertEqual
(
support_request_in_progress
,
None
)
self
.
commit
()
self
.
person
.
notify
(
support_request_title
=
"A"
,
support_request_description
=
"B"
,
aggregate
=
aggregate_value
.
getRelativeUrl
()
)
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertNotEqual
(
None
,
support_request_relative_url
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
get
(
"support_request_in_progress"
,
None
)
self
.
assertEqual
(
support_request_in_progress
,
support_request_relative_url
)
# Check if it is the same Support Request as before and still suspended
self
.
assertEqual
(
support_request
.
getRelativeUrl
(),
support_request_relative_url
)
self
.
assertEqual
(
support_request
.
getSimulationState
(),
"suspended"
)
# Step 6: If the support request is closed, create indeed a new one.
support_request
.
invalidate
()
self
.
tic
()
self
.
person
.
REQUEST
.
set
(
"support_request_relative_url"
,
None
)
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertEqual
(
None
,
support_request_relative_url
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
set
(
"support_request_in_progress"
,
None
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
set
(
"support_request_in_progress"
,
None
)
self
.
assertEqual
(
support_request_in_progress
,
None
)
self
.
commit
()
self
.
person
.
notify
(
support_request_title
=
"A"
,
support_request_description
=
"B"
,
aggregate
=
aggregate_value
.
getRelativeUrl
()
)
support_request_relative_url
=
self
.
person
.
REQUEST
.
get
(
"support_request_relative_url"
,
None
)
self
.
assertNotEqual
(
None
,
support_request_relative_url
)
support_request_in_progress
=
self
.
person
.
REQUEST
.
get
(
"support_request_in_progress"
,
None
)
self
.
assertEqual
(
support_request_in_progress
,
support_request_relative_url
)
# Check if it is the another Support Request
self
.
assertEqual
(
support_request
.
getSimulationState
(),
"invalidated"
)
self
.
assertNotEqual
(
support_request
.
getRelativeUrl
(),
support_request_relative_url
)
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/script_Person_notify.py
0 → 100644
View file @
55fc2d9f
person
=
state_change
[
'object'
]
portal
=
person
.
getPortalObject
()
# Get required arguments
kwargs
=
state_change
.
kwargs
# Required args
# Raise TypeError if all parameters are not provided
try
:
support_request_title
=
kwargs
[
'support_request_title'
]
description
=
kwargs
[
'support_request_description'
]
# Aggregate can be None, so it isn't included on the kwargs
aggregate
=
kwargs
[
"aggregate"
]
except
KeyError
:
raise
TypeError
,
"Person_requestSupportRequest takes exactly 3 arguments"
aggregate_value
=
portal
.
restrictedTraverse
(
aggregate
)
support_request_in_progress
=
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Support Request'
,
title
=
support_request_title
,
simulation_state
=
[
"validated"
,
"submitted"
,
"suspended"
],
default_aggregate_uid
=
aggregate_value
.
getUid
(),
)
if
support_request_in_progress
is
not
None
:
context
.
REQUEST
.
set
(
"support_request_relative_url"
,
support_request_in_progress
.
getRelativeUrl
())
context
.
REQUEST
.
set
(
"support_request_in_progress"
,
support_request_in_progress
.
getRelativeUrl
())
return
support_request_in_progress
=
context
.
REQUEST
.
get
(
"support_request_in_progress"
,
None
)
if
support_request_in_progress
is
not
None
:
support_request
=
portal
.
restrictedTraverse
(
support_request_in_progress
,
None
)
if
support_request
and
support_request
.
getTitle
()
==
support_request_title
and
\
support_request
.
getAggregateUid
()
==
aggregate_value
.
getUid
():
context
.
REQUEST
.
set
(
"support_request_relative_url"
,
support_request_in_progress
)
return
# Ensure resoure is Monitoring
resource
=
portal
.
service_module
.
\
slapos_crm_monitoring
.
getRelativeUrl
()
support_request
=
portal
.
restrictedTraverse
(
portal
.
portal_preferences
.
getPreferredSupportRequestTemplate
())
\
.
Base_createCloneDocument
(
batch_mode
=
1
)
support_request
.
edit
(
title
=
support_request_title
,
description
=
description
,
start_date
=
DateTime
(),
destination_decision
=
person
.
getRelativeUrl
(),
aggregate_value
=
aggregate_value
,
resource
=
resource
)
support_request
.
validate
()
context
.
REQUEST
.
set
(
"support_request_relative_url"
,
support_request
.
getRelativeUrl
())
context
.
REQUEST
.
set
(
"support_request_in_progress"
,
support_request
.
getRelativeUrl
())
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/script_Person_notify.xml
0 → 100644
View file @
55fc2d9f
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"Workflow Script"
module=
"erp5.portal_type"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
Script_magic
</string>
</key>
<value>
<int>
3
</int>
</value>
</item>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key>
<string>
_asgns
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
name_container
</string>
</key>
<value>
<string>
container
</string>
</value>
</item>
<item>
<key>
<string>
name_context
</string>
</key>
<value>
<string>
context
</string>
</value>
</item>
<item>
<key>
<string>
name_m_self
</string>
</key>
<value>
<string>
script
</string>
</value>
</item>
<item>
<key>
<string>
name_subpath
</string>
</key>
<value>
<string>
traverse_subpath
</string>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
state_change
</string>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
script_Person_notify
</string>
</value>
</item>
<item>
<key>
<string>
portal_type
</string>
</key>
<value>
<string>
Workflow Script
</string>
</value>
</item>
<item>
<key>
<string>
title
</string>
</key>
<value>
<string>
Person_notify
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/state_draft.xml
View file @
55fc2d9f
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
<key>
<string>
categories
</string>
</key>
<key>
<string>
categories
</string>
</key>
<value>
<value>
<tuple>
<tuple>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_notify
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_compute_node
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_compute_node
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_network
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_network
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_organisation
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_organisation
</string>
...
...
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/state_open_order_created.xml
View file @
55fc2d9f
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
<value>
<value>
<tuple>
<tuple>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_draft
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_draft
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_notify
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_compute_node
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_compute_node
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_network
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_network
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_organisation
</string>
<string>
destination/portal_workflow/person_slap_interface_workflow/transition_request_organisation
</string>
...
...
master/bt5/slapos_cloud/WorkflowTemplateItem/portal_workflow/person_slap_interface_workflow/transition_notify.xml
0 → 100644
View file @
55fc2d9f
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"Workflow Transition"
module=
"erp5.portal_type"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
action
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
action_name
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
categories
</string>
</key>
<value>
<tuple>
<string>
action_type/workflow
</string>
<string>
before_script/portal_workflow/person_slap_interface_workflow/script_Person_checkConsistency
</string>
<string>
after_script/portal_workflow/person_slap_interface_workflow/script_Person_notify
</string>
</tuple>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
guard_permission
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
icon
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
transition_notify
</string>
</value>
</item>
<item>
<key>
<string>
portal_type
</string>
</key>
<value>
<string>
Workflow Transition
</string>
</value>
</item>
<item>
<key>
<string>
title
</string>
</key>
<value>
<string>
Notify
</string>
</value>
</item>
<item>
<key>
<string>
trigger_type
</string>
</key>
<value>
<int>
2
</int>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment