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
Guillaume Hervier
slapos.core
Commits
57a0f6b5
Commit
57a0f6b5
authored
May 12, 2014
by
Alain Takoudjou
Committed by
Rafael Monnerat
Nov 10, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Erp5-Alarm: Check and change wrong allocation scope on public and friend computer
parent
fc29856b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
355 additions
and
0 deletions
+355
-0
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Alarm_checkAndUpdateComputerAllocationScope.xml
...pos_cloud/Alarm_checkAndUpdateComputerAllocationScope.xml
+80
-0
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Computer_checkAndUpdateAllocationScope.xml
...s/slapos_cloud/Computer_checkAndUpdateAllocationScope.xml
+157
-0
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSComputerAllocationScope.py
...oud/TestTemplateItem/testSlapOSComputerAllocationScope.py
+118
-0
No files found.
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Alarm_checkAndUpdateComputerAllocationScope.xml
0 → 100644
View file @
57a0f6b5
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</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>
_body
</string>
</key>
<value>
<string>
portal = context.getPortalObject()\n
\n
category_public = portal.restrictedTraverse("portal_categories/allocation_scope/open/public", None)\n
category_friend = portal.restrictedTraverse("portal_categories/allocation_scope/open/friend", None)\n
\n
if category_public is not None:\n
portal.portal_catalog.searchAndActivate(\n
portal_type=\'Computer\',\n
default_allocation_scope_uid=[category_public.getUid(), category_friend.getUid()],\n
validation_state="validated",\n
method_id=\'Computer_checkAndUpdateAllocationScope\',\n
activate_kw={\'tag\': tag}\n
)\n
context.activate(after_tag=tag).getId()\n
</string>
</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_checkAndUpdateComputerAllocationScope
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/SkinTemplateItem/portal_skins/slapos_cloud/Computer_checkAndUpdateAllocationScope.xml
0 → 100644
View file @
57a0f6b5
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</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>
_body
</string>
</key>
<value>
<string
encoding=
"cdata"
>
<![CDATA[
from DateTime import DateTime\n
\n
computer = context\n
portal = context.getPortalObject()\n
allocation_scope = computer.getAllocationScope()\n
\n
if allocation_scope != \'open/public\' and \\\n
allocation_scope != \'open/friend\':\n
return\n
\n
is_service_provider = False\n
person = computer.getSourceAdministrationValue(portal_type="Person")\n
\n
for assignment in person.contentValues(portal_type="Assignment"):\n
assignment = assignment.getObject()\n
if assignment.getRole() == \'service_provider\':\n
is_service_provider = True\n
break\n
\n
if not is_service_provider:\n
#Turn this computer allocation scope to \'open/personal\'\n
edit_kw = {\n
\'allocation_scope\': \'open/personal\',\n
\'subject_list\': [\'\'],\n
\'destination_section_value\': person,\n
} \n
computer.edit(**edit_kw)\n
\n
# Create a ticket (or re-open it) for this issue!\n
ticket_title = \'Allocation scope has been changed for %s\' % computer.\\\n
getReference()\n
message = """Dear user,\n
\n
Your computer %s with ID %s was configured with allocation scope \'%s\', but you are\n
not allowed to turn computer to \'public\' or \'friend\' state because you are not a service provider.\n
The computer allocation scope has been changed to \'open/personal\'. Please contact us for more informations.\n
\n
Regards,\n
\n
SlapOS Team\n
""" % (computer.getTitle(), computer.getReference(),\n
allocation_scope)\n
ressource = portal.service_module.slapos_crm_information.getRelativeUrl()\n
\n
support_request_in_progress = portal.portal_catalog.getResultValue(\n
portal_type = \'Support Request\',\n
title = ticket_title,\n
simulation_state = ["validated","submitted","suspended"],\n
source_project_uid = computer.getUid()\n
)\n
if support_request_in_progress is None:\n
support_request = portal.support_request_module.\\\n
slapos_crm_support_request_template.\\\n
Base_createCloneDocument(batch_mode=1)\n
support_request.edit(\n
title = ticket_title,\n
resource = ressource,\n
description = ticket_title,\n
start_date = DateTime(),\n
destination_decision=computer.getSourceAdministration(),\n
source_project_value = computer.getRelativeUrl()\n
)\n
support_request.validate()\n
support_request.suspend()\n
else:\n
support_request = support_request_in_progress.getObject()\n
\n
# create Web message if needed for this ticket\n
event_list = context.portal_catalog(follow_up_uid=support_request.getUid(), \n
sort_on=[(\'delivery.start_date\', \'DESC\')],\n
)\n
if len(event_list) >
0 and \\\n
(event_list[0].getStartDate() - DateTime()
< 1
):\n
#
User
has
already
been
notified
this
day.\n
return\n
event =
portal.event_module.slapos_crm_web_message_template.\\\n
Base_createCloneDocument(
batch_mode=
1)\n
event.edit(\n
title=
\'We
have
changed
allocation
scope
for
%s\'
%
computer.getReference(),\n
text_content=
message,\n
start_date =
DateTime(),\n
resource =
ressource,\n
source=
person.getRelativeUrl(),\n
follow_up=
support_request.getRelativeUrl(),\n
)\n
event.stop()\n
event.deliver()\n
]]
></string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string></string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Computer_checkAndUpdateAllocationScope
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/TestTemplateItem/testSlapOSComputerAllocationScope.py
0 → 100644
View file @
57a0f6b5
# Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.
from
Products.SlapOS.tests.testSlapOSMixin
import
testSlapOSMixin
from
AccessControl
import
getSecurityManager
from
DateTime
import
DateTime
import
transaction
class
TestAllocationScope
(
testSlapOSMixin
):
def
afterSetUp
(
self
):
super
(
TestAllocationScope
,
self
).
afterSetUp
()
self
.
user_id
=
getSecurityManager
().
getUser
().
getId
()
def
beforeTearDown
(
self
):
transaction
.
abort
()
def
generateNewId
(
self
):
return
self
.
getPortalObject
().
portal_ids
.
generateNewId
(
id_group
=
(
'slapos_core_test'
))
def
test_GroupCompany
(
self
):
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
)
computer
.
updateLocalRolesOnSecurityGroups
()
self
.
assertSecurityGroup
(
computer
,
[
'G-COMPANY'
,
self
.
user_id
],
False
)
self
.
assertRoles
(
computer
,
'G-COMPANY'
,
[
'Assignor'
])
self
.
assertRoles
(
computer
,
self
.
user_id
,
[
'Owner'
])
def
test_ComputerAgent
(
self
):
reference
=
'TESTPERSON-%s'
%
self
.
generateNewId
()
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
,
reference
=
reference
)
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
source_administration
=
person
.
getRelativeUrl
())
computer
.
updateLocalRolesOnSecurityGroups
()
self
.
assertSecurityGroup
(
computer
,
[
self
.
user_id
,
'G-COMPANY'
,
reference
],
False
)
self
.
assertRoles
(
computer
,
reference
,
[
'Assignee'
])
self
.
assertRoles
(
computer
,
self
.
user_id
,
[
'Owner'
])
def
test_NotAllowedAllocationScope
(
self
):
reference
=
'TESTPERSON-%s'
%
self
.
generateNewId
()
computer_ref
=
'TESTCOMP-%s'
%
self
.
generateNewId
()
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
,
reference
=
reference
)
assignment
=
person
.
newContent
(
portal_type
=
'Assignment'
)
assignment
.
setRole
(
'role/member'
)
assignment
.
setStartDate
(
DateTime
())
assignment
.
open
()
assignment
.
updateLocalRolesOnSecurityGroups
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
source_administration
=
person
.
getRelativeUrl
(),
reference
=
computer_ref
)
# open/public
computer
.
edit
(
allocation_scope
=
'open/public'
)
computer
.
updateLocalRolesOnSecurityGroups
()
computer
.
Computer_checkAndUpdateAllocationScope
()
self
.
assertEquals
(
computer
.
getAllocationScope
(),
'open/personal'
)
# open/personal
computer
.
edit
(
allocation_scope
=
'open/personal'
,
source_administration
=
person
.
getRelativeUrl
()
)
computer
.
updateLocalRolesOnSecurityGroups
()
computer
.
Computer_checkAndUpdateAllocationScope
()
self
.
assertEquals
(
computer
.
getAllocationScope
(),
'open/personal'
)
# open/friend
friend_reference
=
'TESTPERSON-%s'
%
self
.
generateNewId
()
friend_person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
,
reference
=
friend_reference
)
computer
.
edit
(
allocation_scope
=
'open/friend'
,
destination_section
=
friend_person
.
getRelativeUrl
()
)
computer
.
updateLocalRolesOnSecurityGroups
()
computer
.
Computer_checkAndUpdateAllocationScope
()
self
.
assertEquals
(
computer
.
getAllocationScope
(),
'open/personal'
)
def
test_AllowedAllocationScope
(
self
):
# Test computer allocation scope with 'service_provider' user assignment
reference
=
'TESTPERSON-%s'
%
self
.
generateNewId
()
person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
,
reference
=
reference
)
assignment
=
person
.
newContent
(
portal_type
=
'Assignment'
)
assignment
.
setRole
(
'role/service_provider'
)
assignment
.
setStartDate
(
DateTime
())
assignment
.
open
()
assignment
.
updateLocalRolesOnSecurityGroups
()
computer
=
self
.
portal
.
computer_module
.
newContent
(
portal_type
=
'Computer'
,
source_administration
=
person
.
getRelativeUrl
())
# open/public
computer
.
edit
(
allocation_scope
=
'open/public'
)
computer
.
updateLocalRolesOnSecurityGroups
()
computer
.
Computer_checkAndUpdateAllocationScope
()
self
.
assertEquals
(
computer
.
getAllocationScope
(),
'open/public'
)
# open/personal
computer
.
edit
(
allocation_scope
=
'open/personal'
,
source_administration
=
person
.
getRelativeUrl
()
)
computer
.
updateLocalRolesOnSecurityGroups
()
computer
.
Computer_checkAndUpdateAllocationScope
()
self
.
assertEquals
(
computer
.
getAllocationScope
(),
'open/personal'
)
# open/friend
friend_reference
=
'TESTPERSON-%s'
%
self
.
generateNewId
()
friend_person
=
self
.
portal
.
person_module
.
newContent
(
portal_type
=
'Person'
,
reference
=
friend_reference
)
computer
.
edit
(
allocation_scope
=
'open/friend'
,
destination_section
=
friend_person
.
getRelativeUrl
()
)
computer
.
updateLocalRolesOnSecurityGroups
()
computer
.
Computer_checkAndUpdateAllocationScope
()
self
.
assertEquals
(
computer
.
getAllocationScope
(),
'open/friend'
)
\ No newline at end of file
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