Commit 1405be96 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: drop the idea of project owner

Project will be products sold on the store
parent 049e893d
......@@ -26,9 +26,9 @@ class TestSlapOSCoreProjectSlapInterfaceWorkflow(SlapOSTestCaseMixin):
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
portal = self.getPortalObject()
person_user = self.makePerson()
self.project = self.addProject()
person_user = self.makePerson(self.project)
self.tic()
# Login as new user
......@@ -37,9 +37,6 @@ class TestSlapOSCoreProjectSlapInterfaceWorkflow(SlapOSTestCaseMixin):
new_person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.assertEqual(person_user.getRelativeUrl(), new_person.getRelativeUrl())
self.project = portal.project_module.newContent(
portal_type="Project"
)
# Value set by the init
self.assertTrue(self.project.getReference().startswith("PROJ-"),
"Reference don't start with PROJ- : %s" % self.project.getReference())
......@@ -48,62 +45,16 @@ class TestSlapOSCoreProjectSlapInterfaceWorkflow(SlapOSTestCaseMixin):
def beforeTearDown(self):
transaction.abort()
def test_project_approveRegistration_no_reference(self):
self.project.setReference(None)
self.assertRaises(ValueError, self.project.approveRegistration)
def test_project_approveRegistration_already_validated(self):
# Login as admin since user cannot re-approve a validated project
self.login()
self.project.setReference(None)
self.project.validate()
# Don't raise if project is validated
self.assertEqual(self.project.approveRegistration(), None)
def test_project_approveRegistration(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.project.approveRegistration()
self.tic()
self.logout()
self.login(person.getUserId())
self.assertEqual(self.project.getValidationState(),
'validated')
self.assertNotEqual(self.project.getStartDate(),
None)
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationProjectValue() == self.project]
self.assertEqual(len(assignment_list), 1)
self.assertEqual(assignment_list[0].getValidationState(), 'open')
self.assertIn("Assigment for Project ", assignment_list[0].getTitle())
def test_project_leaveProject_no_user(self):
self.login()
self.assertRaises(Unauthorized, self.project.leaveProject)
def test_project_leaveProject_owner(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.project.edit(destination_decision=person.getRelativeUrl())
self.tic()
self.project.leaveProject()
self.assertEqual(self.project.getDestinationDecision(),
None)
def test_project_leaveProject_after_join(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
# Just make things fast, by using the API tested above
self.project.approveRegistration()
self.tic()
self.logout()
self.login(person.getUserId())
......@@ -173,8 +124,6 @@ class TestSlapOSCoreProjectSlapInterfaceWorkflow(SlapOSTestCaseMixin):
def test_project_acceptInvitation_already_member(self):
person = self.portal.portal_membership.getAuthenticatedMember().getUserValue()
self.project.approveRegistration()
self.tic()
self.login()
assignment_list = [i for i in person.objectValues(portal_type="Assignment")
if i.getDestinationProjectValue() == self.project]
......
......@@ -6,12 +6,6 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSCloudProjectSlapInterfaceWorkflow</string> </value>
......@@ -61,28 +55,13 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -95,7 +74,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -104,7 +83,7 @@
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
......
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:
project_title = kwargs['project_title']
except KeyError:
raise TypeError, "Person_requestProject takes exactly 1 argument"
tag = "%s_%s_ProjectInProgress" % (person.getUid(),
project_title)
if (portal.portal_activities.countMessageWithTag(tag) > 0):
# The software instance is already under creation but can not be fetched from catalog
# As it is not possible to fetch informations, it is better to raise an error
raise NotImplementedError(tag)
project_portal_type = "Project"
project_list = portal.portal_catalog.portal_catalog(
portal_type=project_portal_type, title=project_title, limit=2)
if len(project_list) == 2:
raise NotImplementedError
elif len(project_list) == 1:
context.REQUEST.set("project_relative_url", project_list[0].getRelativeUrl())
context.REQUEST.set("project_reference", project_list[0].getReference())
else:
module = portal.getDefaultModule(portal_type=project_portal_type)
project = module.newContent(
portal_type=project_portal_type,
title=project_title,
destination_decision_value=person,
activate_kw={'tag': tag}
)
context.REQUEST.set("project_relative_url", project.getRelativeUrl())
context.REQUEST.set("project_reference", project.getReference())
project.approveRegistration()
<?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>_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>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_requestProject</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_requestProject</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -19,7 +19,6 @@
<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_network</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_project</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_site</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_software_instance</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_support</string>
......
......@@ -20,7 +20,6 @@
<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_network</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_project</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_site</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_software_instance</string>
<string>destination/portal_workflow/person_slap_interface_workflow/transition_request_support</string>
......
<?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_requestProject</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_request_project</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>Request Project</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -35,6 +35,7 @@ if invitation_token.getSourceValue() == person:
for assignment in person.objectValues(portal_type="Assignment"):
if assignment.getDestinationProject() == project.getRelativeUrl() and \
assignment.getFunction() == 'customer' and \
assignment.getValidationState() == "open":
invitation_token.invalidate(comment="User already has assignment to the Person")
break
......@@ -43,6 +44,7 @@ if invitation_token.getValidationState() == "validated":
person.newContent(
title="Assigment for Project %s" % project.getTitle(),
portal_type="Assignment",
function='customer',
destination_project_value=project).open()
invitation_token.invalidate()
project = state_change["object"]
from DateTime import DateTime
portal = context.getPortalObject()
if project.getValidationState() != "draft":
return
if project.getReference() in [None, ""]:
raise ValueError("Reference is missing on the Project")
# Get the user id of the context owner.
local_role_list = project.get_local_roles()
for group, role_list in local_role_list:
if 'Owner' in role_list:
user_id = group
break
person = portal.portal_catalog.getResultValue(user_id=user_id)
if person is None:
# Value was created by super user, so there isn't a point on continue
return
for assignment in person.objectValues(portal_type="Assignment"):
if assignment.getDestinationProject() == project.getRelativeUrl():
if assignment.getValidationState() != "open":
assignment.open()
return
person.newContent(
title="Assigment for Project %s" % project.getTitle(),
portal_type="Assignment",
destination_project=project.getRelativeUrl()).open()
project.edit(start_date=DateTime())
project.validate()
<?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>_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>state_change</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_Project_approveRegistration</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>Project_approveRegistration</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -6,11 +6,8 @@ person = portal.portal_membership.getAuthenticatedMember().getUserValue()
if person is None:
raise Unauthorized
if project.getDestinationDecision() == person.getRelativeUrl():
project.setDestinationDecision(None)
for assignment in person.objectValues(portal_type="Assignment"):
# Close all user assignments (customer/admin/...) related to this project
if assignment.getDestinationProject() == project.getRelativeUrl() and \
assignment.getValidationState() != 'closed':
assignment.close()
break
......@@ -17,7 +17,6 @@
<value>
<tuple>
<string>destination/portal_workflow/project_slap_interface_workflow/transition_accept_invitation</string>
<string>destination/portal_workflow/project_slap_interface_workflow/transition_approve_registration</string>
<string>destination/portal_workflow/project_slap_interface_workflow/transition_leave_project</string>
</tuple>
</value>
......
<?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/project_slap_interface_workflow/script_Project_checkConsistency</string>
<string>after_script/portal_workflow/project_slap_interface_workflow/script_Project_approveRegistration</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_approve_registration</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>Approve Registration</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment