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
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Rafael Monnerat
slapos.core
Commits
cb88c2da
Commit
cb88c2da
authored
Jan 08, 2025
by
Romain Courteaud
🐸
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_cloud: ensure persons have the default assignment defined in the preference
parent
10a22b1f
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
378 additions
and
0 deletions
+378
-0
master/bt5/slapos_cloud/PathTemplateItem/portal_alarms/slapos_cloud_create_missing_subscription_assignment.xml
...s/slapos_cloud_create_missing_subscription_assignment.xml
+72
-0
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Alarm_createMissingSubscriptionAssignment.py
...slapos_cloud/Alarm_createMissingSubscriptionAssignment.py
+27
-0
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Alarm_createMissingSubscriptionAssignment.xml
...lapos_cloud/Alarm_createMissingSubscriptionAssignment.xml
+62
-0
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Assignment_createPersonMissingSubscriptionAssignment.py
...d/Assignment_createPersonMissingSubscriptionAssignment.py
+26
-0
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Assignment_createPersonMissingSubscriptionAssignment.xml
.../Assignment_createPersonMissingSubscriptionAssignment.xml
+62
-0
master/bt5/slapos_cloud/TestTemplateItem/portal_components/test.erp5.testSlapOSCloudAlarm.py
...eItem/portal_components/test.erp5.testSlapOSCloudAlarm.py
+128
-0
master/bt5/slapos_cloud/bt/template_path_list
master/bt5/slapos_cloud/bt/template_path_list
+1
-0
No files found.
master/bt5/slapos_cloud/PathTemplateItem/portal_alarms/slapos_cloud_create_missing_subscription_assignment.xml
0 → 100644
View file @
cb88c2da
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"Alarm"
module=
"erp5.portal_type"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
active_sense_method_id
</string>
</key>
<value>
<string>
Alarm_createMissingSubscriptionAssignment
</string>
</value>
</item>
<item>
<key>
<string>
automatic_solve
</string>
</key>
<value>
<int>
0
</int>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
enabled
</string>
</key>
<value>
<int>
1
</int>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
slapos_cloud_create_missing_subscription_assignment
</string>
</value>
</item>
<item>
<key>
<string>
periodicity_day_frequency
</string>
</key>
<value>
<int>
1
</int>
</value>
</item>
<item>
<key>
<string>
periodicity_hour
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
periodicity_minute
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
periodicity_month
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
periodicity_month_day
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
periodicity_week
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
title
</string>
</key>
<value>
<string>
Create Missing Subscription Assignment
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Alarm_createMissingSubscriptionAssignment.py
0 → 100644
View file @
cb88c2da
portal
=
context
.
getPortalObject
()
assignment_category_list
=
portal
.
portal_preferences
.
getPreferredSubscriptionAssignmentCategoryList
()
is_default_project_defined
=
False
for
assignment_category
in
assignment_category_list
:
if
assignment_category
.
startswith
(
'destination_project/project_module/'
):
is_default_project_defined
=
True
if
not
is_default_project_defined
:
return
portal
.
portal_catalog
.
searchAndActivate
(
portal_type
=
'Assignment'
,
# Do not create assignment if the Person does not have at least one
validation_state
=
'open'
,
# Prevent checking the same person multiple times
group_by
=
[
'parent_uid'
],
method_id
=
'Assignment_createPersonMissingSubscriptionAssignment'
,
# This alarm bruteforce checking all documents,
# without changing them directly.
# Increase priority to not block other activities
method_args
=
[
assignment_category_list
],
method_kw
=
{
"activate_kw"
:
{
'tag'
:
tag
,
'priority'
:
2
}},
activate_kw
=
{
'tag'
:
tag
,
'priority'
:
2
}
)
context
.
activate
(
after_tag
=
tag
).
getId
()
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Alarm_createMissingSubscriptionAssignment.xml
0 → 100644
View file @
cb88c2da
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"_reconstructor"
module=
"copy_reg"
/>
</klass>
<tuple>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
<global
name=
"object"
module=
"__builtin__"
/>
<none/>
</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>
tag, fixit, params
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Alarm_createMissingSubscriptionAssignment
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Assignment_createPersonMissingSubscriptionAssignment.py
0 → 100644
View file @
cb88c2da
from
zExceptions
import
Unauthorized
if
REQUEST
is
not
None
:
raise
Unauthorized
assignment_category_set
=
set
(
assignment_category_list
)
person
=
context
.
getParentValue
()
# check if user has an assignment matching the default preference
has_default_assignment
=
False
has_open_assignment
=
False
for
assignment
in
person
.
contentValues
(
portal_type
=
'Assignment'
):
if
assignment
.
getValidationState
()
!=
'open'
:
continue
has_open_assignment
=
True
has_default_assignment
=
has_default_assignment
or
(
assignment_category_set
<=
set
(
assignment
.
getCategoryList
()))
if
has_open_assignment
and
(
not
has_default_assignment
):
new_assignment
=
person
.
newContent
(
portal_type
=
"Assignment"
,
title
=
"Preferred Subscription Assignment"
)
new_assignment
.
setCategoryList
(
assignment_category_list
)
new_assignment
.
open
(
comment
=
"Created during the system preference subscription definition"
)
new_assignment
.
reindexObject
(
activate_kw
=
activate_kw
)
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Assignment_createPersonMissingSubscriptionAssignment.xml
0 → 100644
View file @
cb88c2da
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"_reconstructor"
module=
"copy_reg"
/>
</klass>
<tuple>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
<global
name=
"object"
module=
"__builtin__"
/>
<none/>
</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>
assignment_category_list, activate_kw=None, REQUEST=None
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Assignment_createPersonMissingSubscriptionAssignment
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/TestTemplateItem/portal_components/test.erp5.testSlapOSCloudAlarm.py
View file @
cb88c2da
...
@@ -7,6 +7,134 @@ from erp5.component.module.DateUtils import addToDate
...
@@ -7,6 +7,134 @@ from erp5.component.module.DateUtils import addToDate
class
TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm
(
SlapOSTestCaseMixin
):
class
TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm
(
SlapOSTestCaseMixin
):
#################################################################
# slapos_cloud_create_missing_subscription_assignment
#################################################################
def
test_Assignment_createPersonMissingSubscriptionAssignment_alarm_notOpenAssignment
(
self
):
# some preparation
project
=
self
.
portal
.
project_module
.
newContent
()
preference
=
self
.
portal
.
portal_preferences
.
slapos_default_system_preference
preference
.
edit
(
preferred_subscription_assignment_category_list
=
[
'destination_project/%s'
%
project
.
getRelativeUrl
()
]
)
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
)
assignment
=
person
.
newContent
(
portal_type
=
'Assignment'
)
self
.
tic
()
self
.
_test_alarm_not_visited
(
self
.
portal
.
portal_alarms
.
slapos_cloud_create_missing_subscription_assignment
,
assignment
,
'Assignment_createPersonMissingSubscriptionAssignment'
)
def
test_Assignment_createPersonMissingSubscriptionAssignment_alarm_oneAssignment
(
self
):
# some preparation
project
=
self
.
portal
.
project_module
.
newContent
()
preference
=
self
.
portal
.
portal_preferences
.
slapos_default_system_preference
preference
.
edit
(
preferred_subscription_assignment_category_list
=
[
'destination_project/%s'
%
project
.
getRelativeUrl
()
]
)
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
)
assignment
=
person
.
newContent
(
portal_type
=
'Assignment'
)
assignment
.
open
()
self
.
tic
()
self
.
_test_alarm
(
self
.
portal
.
portal_alarms
.
slapos_cloud_create_missing_subscription_assignment
,
assignment
,
'Assignment_createPersonMissingSubscriptionAssignment'
)
"""
def test_Assignment_createPersonMissingSubscriptionAssignment_alarm_twoAssignment(self):
person = self.portal.person_module.newContent(
portal_type='Person'
)
assignment1 = person.newContent(
portal_type='Assignment'
)
assignment1.open()
assignment2 = person.newContent(
portal_type='Assignment'
)
assignment2.open()
self.tic()
self._test_alarm(
self.portal.portal_alarms.slapos_cloud_create_missing_subscription_assignment,
assignment1,
'Assignment_createPersonMissingSubscriptionAssignment'
)
"""
#################################################################
# Assignment_createPersonMissingSubscriptionAssignment
#################################################################
def
test_Assignment_createPersonMissingSubscriptionAssignment_script_noSubscriptionAssignment
(
self
):
subscription_category_list
=
[
'activity/research'
,
'role/member'
]
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
)
assignment
=
person
.
newContent
(
portal_type
=
'Assignment'
)
assignment
.
open
()
assignment
.
Assignment_createPersonMissingSubscriptionAssignment
(
subscription_category_list
)
self
.
assertEquals
(
2
,
len
(
person
.
contentValues
(
portal_type
=
'Assignment'
)))
subscription_assignment
=
[
x
for
x
in
person
.
contentValues
(
portal_type
=
'Assignment'
)
if
x
.
getId
()
!=
assignment
.
getId
()][
0
]
self
.
assertEquals
(
'open'
,
subscription_assignment
.
getValidationState
())
self
.
assertSameSet
(
subscription_category_list
,
subscription_assignment
.
getCategoryList
())
def
test_Assignment_createPersonMissingSubscriptionAssignment_script_withOpenSubscriptionAssignment
(
self
):
subscription_category_list
=
[
'activity/research'
,
'role/member'
]
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
)
assignment
=
person
.
newContent
(
portal_type
=
'Assignment'
)
assignment
.
setCategoryList
(
subscription_category_list
)
assignment
.
open
()
assignment
.
Assignment_createPersonMissingSubscriptionAssignment
(
subscription_category_list
)
self
.
assertEquals
(
1
,
len
(
person
.
contentValues
(
portal_type
=
'Assignment'
)))
def
test_Assignment_createPersonMissingSubscriptionAssignment_script_withDraftSubscriptionAssignment
(
self
):
subscription_category_list
=
[
'activity/research'
,
'role/member'
]
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
)
assignment1
=
person
.
newContent
(
portal_type
=
'Assignment'
)
assignment1
.
setCategoryList
(
subscription_category_list
)
assignment2
=
person
.
newContent
(
portal_type
=
'Assignment'
)
assignment2
.
open
()
assignment2
.
Assignment_createPersonMissingSubscriptionAssignment
(
subscription_category_list
)
self
.
assertEquals
(
3
,
len
(
person
.
contentValues
(
portal_type
=
'Assignment'
)))
subscription_assignment
=
[
x
for
x
in
person
.
contentValues
(
portal_type
=
'Assignment'
)
if
(
x
.
getId
()
!=
assignment1
.
getId
())
and
(
x
.
getId
()
!=
assignment2
.
getId
())][
0
]
self
.
assertEquals
(
'open'
,
subscription_assignment
.
getValidationState
())
self
.
assertSameSet
(
subscription_category_list
,
subscription_assignment
.
getCategoryList
())
#################################################################
#################################################################
# slapos_assert_instance_tree_successor
# slapos_assert_instance_tree_successor
#################################################################
#################################################################
...
...
master/bt5/slapos_cloud/bt/template_path_list
View file @
cb88c2da
...
@@ -3,6 +3,7 @@ acl_users/slapos_machine
...
@@ -3,6 +3,7 @@ acl_users/slapos_machine
acl_users/slapos_shadow
acl_users/slapos_shadow
portal_alarms/slapos_allocate_instance
portal_alarms/slapos_allocate_instance
portal_alarms/slapos_assert_instance_tree_successor
portal_alarms/slapos_assert_instance_tree_successor
portal_alarms/slapos_cloud_create_missing_subscription_assignment
portal_alarms/slapos_cloud_garbage_collect_one_time_virtual_master_access_token
portal_alarms/slapos_cloud_garbage_collect_one_time_virtual_master_access_token
portal_alarms/slapos_cloud_invalidate_closed_compute_node
portal_alarms/slapos_cloud_invalidate_closed_compute_node
portal_alarms/slapos_cloud_invalidate_destroyed_instance
portal_alarms/slapos_cloud_invalidate_destroyed_instance
...
...
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