def creat_idea(self): behavior = None try: behavior = self.behaviors_instances['Create_an_idea'] values = {'title': self.params('title'), 'text': self.params('text')} idea = Idea() idea.set_data(values) appstruct = {'_object_data': idea, 'keywords': self.params('keywords')} behavior.execute(self.context, self.request, appstruct) oid = get_oid(idea) localizer = self.request.localizer user = get_current() time = to_localized_time(datetime.datetime.today()) new_title = localizer.translate(_('Idea by'))+' '+\ getattr(user, 'title', user.name)+' '+\ localizer.translate(_('the'))+' '+\ time+' (UTC)' data = {'title': idea.title, 'oid': str(oid), 'body': renderers.render(self.idea_template, {'idea':idea}, self.request), 'new_title': new_title } result = data return result except Exception: return {}
def test_support_no_support_novaideo_config(self): # SetUp the 'no_support' Nova-Ideo configuration self.no_support_novaideo_config() context = self.request.root idea = Idea(title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction(context, self.request, process_id='ideamanagement', node_id='creatandpublish') # Execute the action actions[0].execute(context, self.request, {'_object_data': idea}) idea_result = context.ideas[0] # Members can't support the published idea alice = add_user({ 'first_name': 'Alice', 'last_name': 'Alice' }, self.request) self.request.user = alice alice_oid = get_oid(alice) actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement') expected_actions = [ 'seeworkinggroups', 'duplicate', 'comment', 'present', 'associate', 'see' ] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 6) self.assertTrue(all(a in expected_actions for a in actions_ids))
def test_create_idea_default_conf(self): # SetUp the default Nova-Ideo configuration self.default_novaideo_config() context = self.request.root idea = Idea( title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction( context, self.request, process_id='ideamanagement', node_id='creat') self.assertEqual(len(actions), 1) create_action = actions[0] self.assertEqual(create_action.node_id, 'creat') self.assertEqual(create_action.process_id, 'ideamanagement') # Execute the action create_action.execute( context, self.request, {'_object_data': idea}) ideas = context.ideas self.assertEqual(len(ideas), 1) idea_result = ideas[0] self.assertIs(idea_result, idea) self.assertIs(idea_result.author, self.request.user) self.assertIn('to work', idea_result.state) # Test the merge of keywords self.assertEqual(len(context.keywords), 0) # Test if we have a single action actions = getAllBusinessAction( context, self.request, process_id='ideamanagement', node_id='creat') self.assertEqual(len(actions), 1) # Owner actions actions = getAllBusinessAction( idea_result, self.request, process_id='ideamanagement') expected_actions = [ 'duplicate', 'edit', 'publish', 'abandon', 'associate', 'see'] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 6) self.assertTrue(all(a in expected_actions for a in actions_ids)) # Other member actions alice = add_user({ 'first_name': 'Alice', 'last_name': 'Alice' }, self.request) self.request.user = alice actions = getAllBusinessAction( idea_result, self.request, process_id='ideamanagement') actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 0)
def create_idea(request, title, text, keywords): """Create an Idea.""" container = request.root idea = Idea(title=title, text=text, keywords=keywords) actions = getAllBusinessAction(container, request, process_id='ideamanagement', node_id='creatandpublish') create_action = actions[0] create_action.execute(container, request, {'_object_data': idea})
def test_duplicate(self): # SetUp the default Nova-Ideo configuration self.default_novaideo_config() context = self.request.root idea = Idea(title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction(context, self.request, process_id='ideamanagement', node_id='creatandpublish') actions[0].execute(context, self.request, {'_object_data': idea}) idea_result = context.ideas[0] # duplicate actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement', node_id='duplicate') actions[0].execute( idea_result, self.request, { 'title': 'Duplicated idea', 'text': 'Idea text', 'keywords': ['dup 1'], 'attached_files': [] }) self.assertTrue(len(context.ideas), 2) new_idea = context.ideas[1] self.assertIn('to work', new_idea.state) self.assertEqual('Duplicated idea', new_idea.title) self.assertEqual('Idea text', new_idea.text) keywords = ['dup 1'] self.assertTrue(all(a in keywords for a in new_idea.keywords)) self.assertIs(idea_result, new_idea.originalentity) self.assertIn(new_idea, idea_result.duplicates) # new idea actions: can't publish ==> the same text actions = getAllBusinessAction(new_idea, self.request, process_id='ideamanagement') expected_actions = ['duplicate', 'edit', 'abandon', 'associate', 'see'] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 5) self.assertTrue(all(a in expected_actions for a in actions_ids)) # edit the text of the new idea new_idea.text = 'Duplicated text' # new idea actions: can publish actions = getAllBusinessAction(new_idea, self.request, process_id='ideamanagement') expected_actions = [ 'duplicate', 'edit', 'abandon', 'associate', 'see', 'publish' ] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 6) self.assertTrue(all(a in expected_actions for a in actions_ids))
def creat_idea(self): behavior = None try: tree = self.params('tree') tree = json.loads(tree) if tree else DEFAULT_TREE behavior = self.behaviors_instances['Create_an_idea'] values = { 'title': self.params('title'), 'text': self.params('text'), 'tree': tree } challenge = self.params('challenge') if challenge: try: challenge = get_obj(int(challenge)) values['challenge'] = challenge except: pass idea = Idea() idea.set_data(values) appstruct = {'_object_data': idea} behavior.execute(self.context, self.request, appstruct) oid = get_oid(idea) new_title = '' #self._get_new_title(user) data = { 'title': idea.title, 'oid': str(oid), 'body': renderers.render(self.idea_template, {'idea': idea}, self.request), 'new_title': new_title } result = data return result except Exception as error: log.warning(error) return {}
def test_create_and_publish_idea_moderation_conf(self): # SetUp the 'moderation' Nova-Ideo configuration self.moderation_novaideo_config() context = self.request.root idea = Idea( title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction( context, self.request, process_id='ideamanagement', node_id='creatandpublish') self.assertEqual(len(actions), 1) create_action = actions[0] self.assertEqual(create_action.node_id, 'creatandpublish') self.assertEqual(create_action.process_id, 'ideamanagement') # Execute the action create_action.execute( context, self.request, {'_object_data': idea}) ideas = context.ideas self.assertEqual(len(ideas), 1) idea_result = ideas[0] self.assertIs(idea_result, idea) self.assertIs(idea_result.author, self.request.user) self.assertIn('submitted', idea_result.state) # Test the merge of keywords self.assertEqual(len(context.keywords), 0) # Admin (Owner) actions actions = getAllBusinessAction( idea_result, self.request, process_id='ideamanagement') # User == sd Admin (No tokens, he can't support) expected_actions = [ 'duplicate', 'associate', 'see', 'publish_moderation', 'archive'] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 5) self.assertTrue(all(a in expected_actions for a in actions_ids)) # Other member actions alice = add_user({ 'first_name': 'Alice', 'last_name': 'Alice' }, self.request) self.request.user = alice actions = getAllBusinessAction( idea_result, self.request, process_id='ideamanagement') actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 0)
def creat_idea(self): behavior = None try: behavior = self.behaviors_instances['Create_an_idea'] values = {'title': self.params('title'), 'text': self.params('text')} keywords = self.params('keywords') if not isinstance(keywords, (list, tuple)): keywords = [keywords] values['keywords'] = keywords challenge = self.params('challenge') if challenge: try: challenge = get_obj(int(challenge)) values['challenge'] = challenge except: pass idea = Idea() idea.set_data(values) appstruct = {'_object_data': idea} behavior.execute(self.context, self.request, appstruct) oid = get_oid(idea) new_title = ''#self._get_new_title(user) data = {'title': idea.title, 'oid': str(oid), 'body': renderers.render(self.idea_template, {'idea': idea}, self.request), 'new_title': new_title } result = data return result except Exception as error: log.warning(error) return {}
def create_idea(self): context = self.request.root idea = Idea(title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction(context, self.request, process_id='ideamanagement', node_id='creat') create_action = actions[0] # Excute the action create_action.execute(context, self.request, {'_object_data': idea}) ideas = context.ideas return ideas[0]
def test_comment(self): # SetUp the default Nova-Ideo configuration self.default_novaideo_config() alice = add_user({ 'first_name': 'Alice', 'last_name': 'Alice' }, self.request) bob = add_user({ 'first_name': 'Bob', 'last_name': 'Bob', 'email': '*****@*****.**' }, self.request) self.request.user = alice context = self.request.root idea = Idea( title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction( context, self.request, process_id='ideamanagement', node_id='creatandpublish') actions[0].execute( context, self.request, {'_object_data': idea}) idea_result = context.ideas[0] self.assertTrue(idea_result.channel is not None) self.assertEqual(idea_result.channel.len_comments, 0) # comment self.request.user = bob comment = Comment( comment='The comment', intention='Remark' ) actions = getAllBusinessAction( idea_result, self.request, process_id='ideamanagement', node_id='comment') actions[0].execute( idea_result, self.request, { '_object_data': comment, }) self.assertEqual(idea_result.channel.len_comments, 1) self.assertIn(comment, idea_result.channel.comments) self.assertIn('published', comment.state) self.assertIs(bob, comment.author) self.assertEqual(len(bob.following_channels), 1) self.assertIn(idea_result.channel, bob.following_channels)
def test_present(self): # SetUp the default Nova-Ideo configuration self.default_novaideo_config() alice = add_user({ 'first_name': 'Alice', 'last_name': 'Alice' }, self.request) bob = add_user({ 'first_name': 'Bob', 'last_name': 'Bob', 'email': '*****@*****.**' }, self.request) self.request.user = alice context = self.request.root idea = Idea( title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction( context, self.request, process_id='ideamanagement', node_id='creatandpublish') actions[0].execute( context, self.request, {'_object_data': idea}) idea_result = context.ideas[0] # present actions = getAllBusinessAction( idea_result, self.request, process_id='ideamanagement', node_id='present') actions[0].execute( idea_result, self.request, { 'members': [bob], 'subject': 'Subject', 'message': 'Message', 'send_to_me': False, }) self.assertEqual(idea_result.len_contacted, 1) self.assertIn(bob, idea_result.persons_contacted)
def test_examine_examination_config(self): self.examination_novaideo_config() alice = add_user({ 'first_name': 'Alice', 'last_name': 'Alice' }, self.request) # Bob is an Examiner bob = add_user( { 'first_name': 'Bob', 'last_name': 'Bob', 'email': '*****@*****.**' }, self.request, ('Examiner', )) self.request.user = alice context = self.request.root idea = Idea(title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction(context, self.request, process_id='ideamanagement', node_id='creatandpublish') actions[0].execute(context, self.request, {'_object_data': idea}) idea_result = context.ideas[0] # Alice support the idea actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement', node_id='support') support_action = actions[0] support_action.execute(idea_result, self.request, {}) self.assertEqual(idea_result.len_support, 1) self.assertEqual(len(alice.evaluated_objs()), 1) # Alice can't examine actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement') actions_ids = [a.node_id for a in actions] self.assertFalse('makeitsopinion' in actions_ids) # Bob can examine self.request.user = bob actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement') actions_ids = [a.node_id for a in actions] self.assertTrue('makeitsopinion' in actions_ids) # makeitsopinion actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement', node_id='makeitsopinion') actions[0].execute(idea_result, self.request, { '_csrf_token_': 'none', 'opinion': 'to_study', 'explanation': 'test' }) self.assertIn('examined', idea_result.state) self.assertIn('published', idea_result.state) self.assertIn('to_study', idea_result.state) # Tokens are not removed from the idea self.assertEqual(idea_result.len_support, 1) # Tokens are removed from the user object self.assertEqual(len(alice.evaluated_objs()), 0) # actions: can't support self.request.user = alice actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement') expected_actions = [ 'duplicate', 'comment', 'present', 'associate', 'see' ] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 5) self.assertTrue(all(a in expected_actions for a in actions_ids))
def test_support_withdraw_oppose_idea(self): # SetUp the default Nova-Ideo configuration self.default_novaideo_config() context = self.request.root idea = Idea(title="Idea title", text="Idea text", keywords=["keyword 1", "keyword 2"]) # Find the 'creat' action of the idea management process actions = getAllBusinessAction(context, self.request, process_id='ideamanagement', node_id='creatandpublish') # Execute the action actions[0].execute(context, self.request, {'_object_data': idea}) idea_result = context.ideas[0] # Other member actions alice = add_user({ 'first_name': 'Alice', 'last_name': 'Alice' }, self.request) self.request.user = alice alice_oid = get_oid(alice) actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement', node_id='support') support_action = actions[0] support_action.execute(idea_result, self.request, {}) self.assertEqual(idea_result.len_support, 1) self.assertIs(idea_result.evaluation(alice), 'support') self.assertEqual(idea_result.len_opposition, 0) self.assertEqual(len(alice.evaluated_objs()), 1) self.assertEqual(len(idea_result._support_history), 1) # _support_history = [(user_oid, date, type[1, 0, -1])] self.assertIs(idea_result._support_history[0][0], alice_oid) # 1 == support self.assertEqual(idea_result._support_history[0][2], 1) # Alice can't support. Alice can withdraw the token actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement') expected_actions = [ 'seeworkinggroups', 'duplicate', 'comment', 'present', 'associate', 'see', 'withdraw_token', 'oppose' ] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 8) self.assertTrue(all(a in expected_actions for a in actions_ids)) # Withdraw actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement', node_id='withdraw_token') withdraw_token_action = actions[0] withdraw_token_action.execute(idea_result, self.request, {}) self.assertEqual(idea_result.len_support, 0) self.assertEqual(idea_result.len_opposition, 0) self.assertEqual(len(alice.evaluated_objs()), 0) self.assertEqual(len(idea_result._support_history), 2) self.assertIs(idea_result._support_history[1][0], alice_oid) # -1 == withdraw self.assertEqual(idea_result._support_history[1][2], -1) # Alice can support and can oppose actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement') expected_actions = [ 'seeworkinggroups', 'duplicate', 'comment', 'present', 'associate', 'see', 'support', 'oppose' ] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 8) self.assertTrue(all(a in expected_actions for a in actions_ids)) # oppose actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement', node_id='oppose') oppose_action = actions[0] oppose_action.execute(idea_result, self.request, {}) self.assertEqual(idea_result.len_support, 0) self.assertEqual(idea_result.len_opposition, 1) self.assertEqual(len(alice.evaluated_objs()), 1) self.assertEqual(len(idea_result._support_history), 3) self.assertIs(idea_result._support_history[2][0], alice_oid) # 0 == oppose self.assertEqual(idea_result._support_history[2][2], 0) # Alice can't support and cant oppose. Alice can withdraw the token actions = getAllBusinessAction(idea_result, self.request, process_id='ideamanagement') expected_actions = [ 'seeworkinggroups', 'duplicate', 'comment', 'present', 'associate', 'see', 'withdraw_token', 'support' ] actions_ids = [a.node_id for a in actions] self.assertEqual(len(actions_ids), 8) self.assertTrue(all(a in expected_actions for a in actions_ids))
def start(self, context, request, appstruct, **kw): novaideo_catalog = find_catalog('novaideo') dace_catalog = find_catalog('dace') identifier_index = novaideo_catalog['identifier'] object_provides_index = dace_catalog['object_provides'] query = object_provides_index.any([Iidea.__identifier__]) &\ identifier_index.any([YAMMER_CONNECTOR_ID+'_'+i for i in appstruct['messages']]) ideas = list(query.execute().all()) current_ideas = [i.source_data[YAMMER_CONNECTOR_ID]['id'] for i in ideas] messages = [m for m in appstruct['messages'] if m not in current_ideas] if not messages: return {} root = getSite() yammer_connectors = list(root.get_connectors(YAMMER_CONNECTOR_ID)) yammer_connector = yammer_connectors[0] if yammer_connectors else None access_token = yammer_connector.get_access_tokens(get_current()).get('access_token', None) \ if yammer_connector else None def replies_to_comment(replies, source, comment_action): for reply in replies.values(): comment_data = reply['data'] comment = Comment( intention=_('Remark'), comment=comment_data.pop('text'), files=comment_data.pop('attached_files') ) if comment_action: comment_action.execute( source, request, { '_object_data': comment, 'user': comment_data.pop('author'), 'alert': False, }) sub_replies = reply['replies'] if sub_replies: comment_actions = getAllBusinessAction( comment, request, process_id='commentmanagement', node_id='respond', process_discriminator='Application') if comment_actions: replies_to_comment( sub_replies, comment, comment_actions[0]) if yammer_connector and access_token: for m_id in messages: idea_data, replies = get_message_data( request, int(m_id), access_token, True, True) if idea_data: author = idea_data.pop('author') idea = Idea(**idea_data) root.addtoproperty('ideas', idea) if root.support_ideas: idea.state = PersistentList( ['submitted_support', 'published']) else: idea.state = PersistentList( ['published', 'submitted_support']) idea.init_published_at() grant_roles(user=author, roles=(('Owner', idea), )) idea.setproperty('author', author) idea.subscribe_to_channel(author) idea.format(request) idea.set_source_data({ 'app_name': YAMMER_CONNECTOR_ID, 'id': m_id }) idea.reindex() # add comments comment_actions = getAllBusinessAction( idea, request, process_id='ideamanagement', node_id='comment', process_discriminator='Application') if comment_actions: replies_to_comment(replies, idea, comment_actions[0]) return {}