Commit 26a70b6b authored by Romain Courteaud's avatar Romain Courteaud

slapos_upgrader: create Assignment for user without instances

Ensure people can see projects they used to see before migration
parent b6ca5f1e
...@@ -7,12 +7,18 @@ portal = context.getPortalObject() ...@@ -7,12 +7,18 @@ portal = context.getPortalObject()
person = context person = context
isTransitionPossible = portal.portal_workflow.isTransitionPossible isTransitionPossible = portal.portal_workflow.isTransitionPossible
assignment_project__state_dict = {}
# Close all existing assignments # Close all existing assignments
for assignment in person.contentValues(portal_type="Assignment"): for assignment in person.contentValues(portal_type="Assignment"):
if isTransitionPossible(assignment, 'close'): if isTransitionPossible(assignment, 'close'):
assignment.close(comment="Invalidated during migration") assignment.close(comment="Invalidated during migration")
assignment.reindexObject(activate_kw=activate_kw) assignment.reindexObject(activate_kw=activate_kw)
if assignment.hasDestinationProject():
# Create at least a customer assignment if user used to view this project
assignment_project__state_dict[assignment.getDestinationProject()] = False
# For every virtual master handled by this user, create an assignment # For every virtual master handled by this user, create an assignment
for project in portal.portal_catalog(portal_type="Project", destination__uid=person.getUid()): for project in portal.portal_catalog(portal_type="Project", destination__uid=person.getUid()):
assignment = person.newContent( assignment = person.newContent(
...@@ -31,6 +37,12 @@ for instance_tree in portal.portal_catalog(portal_type="Instance Tree", ...@@ -31,6 +37,12 @@ for instance_tree in portal.portal_catalog(portal_type="Instance Tree",
group_by=['follow_up_uid']): group_by=['follow_up_uid']):
project = instance_tree.getFollowUpValue() project = instance_tree.getFollowUpValue()
if project is not None: if project is not None:
assignment_project__state_dict[project.getRelativeUrl()] = False
for destination_project, is_already_created in assignment_project__state_dict.items():
project = portal.restrictedTraverse(destination_project)
if not is_already_created and (project.getValidationState() == 'validated'):
assignment = person.newContent( assignment = person.newContent(
portal_type="Assignment", portal_type="Assignment",
title="Client for %s" % project.getReference(), title="Client for %s" % project.getReference(),
......
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