def postUpdate(self): # publish if it isn't already: pw = getToolByName(self.context, 'portal_workflow') reviewState = pw.getInfoFor(self.context, 'review_state') if reviewState == 'draft': utilities.rename(self.context) pw.doActionFor(self.context, 'publish-for-site-members') # process invited externs: if getattr(self.context, 'invitedExterns', None): invitedExterns = self.context.invitedExterns.split(',') emailAddresses = set() for email in invitedExterns: email = email.strip() if covalent.validators.email(email): emailAddresses.add(email) urltool = getToolByName(self.context, 'portal_url') portal = urltool.getPortalObject() member_folder = portal['people'] for email in emailAddresses: member = get_member_by_email(email, member_folder) if member: # the member already exists self.context.inviteMember(member.id) continue # make member-objects (without invitation-mail) # become the owner of member_folder temporarily original_sm = getSecurityManager() member_folder_owner = member_folder.getOwner().getId() become_portal_user(portal, member_folder_owner) # add member uid = utilities.find_possible_id(email, member_folder) member = covalent.utilities.add_member_object( member_folder, uid, uid, email, sendInvitation=False) member.role = 'extern' member.activation_code = ''.join(random.sample( string.ascii_lowercase + string.digits, 8)) # become the normal user again setSecurityManager(original_sm) # put the new uid on the workspaces invited-list self.context.inviteMember(uid) # avoid the usual invitation mail self.alreadyInvited.add(uid) # send special invitation mail self.messenger.sendInvitationForExtern(uid) super(Edit, self).postUpdate()
def test_cnrd_workspace_creation(self): login(self.portal, testing.SITE_ADMIN) add_view = self.wss.restrictedTraverse("++add++ixds.Workspace") add_view.update() self.assertIn('workspace-draft', self.wss) workspace = self.wss['workspace-draft'] workspace.title = "Test Workspace" utilities.rename(workspace) helpers.do_action_for(workspace, 'publish-for-site-members') self.assertIn('test-workspace', self.wss)
def publish_post(post): """ Publish the post if it is not already published. Files and links uploaded to a post are moved to its workspace, related to the post they were added to and published.""" pw = getToolByName(post, 'portal_workflow') reviewState = pw.getInfoFor(post, 'review_state') ws = post.aq_parent if reviewState == 'private': post = utilities.rename(post) pw.doActionFor(post, 'publish') for itemId, item in post.items(): if not IRichMetaData.providedBy(item): continue # before moving we check if an object with this id already exists in # the workspace: if itemId in ws: newId = utilities.find_possible_id(itemId, ws) post.manage_renameObjects([itemId], [newId]) itemId = newId # move: clip = post.manage_cutObjects([itemId]) ws.manage_pasteObjects(clip) item = ws[itemId] # relate: intids = getUtility(IIntIds) relation = RelationValue(intids.getId(item)) post.aq_base.relatedFiles = getattr(post.aq_base, 'relatedFiles', []) if not relation.to_id in (x.to_id for x in post.aq_base.relatedFiles): post.aq_base.relatedFiles.append(relation)
def test_project_creation(self): login(self.portal, testing.SITE_ADMIN) workspaces = self.portal.restrictedTraverse("workspaces") add_view = workspaces.restrictedTraverse("++add++cnrd.Project") add_view.update() self.assertIn('project-draft', workspaces) project = workspaces['project-draft'] project.title = "Test Project" utilities.rename(project) ws_helpers.do_action_for(project, 'publish-for-site-members') self.assertIn('test-project', workspaces)