def as_json(self, full_actions=False): """Gets the JSON representation of the WorkflowStatus Args: full_actions (bool, optional): Get the full Action objects as well? Defaults to False Returns: The JSON representation of the object """ ret = { "execution_id": str(self.execution_id), "workflow_id": str(self.workflow_id), "name": self.name, "status": self.status.name } if self.started_at: ret["started_at"] = utc_as_rfc_datetime(self.started_at) if self.status in [ WorkflowStatusEnum.completed, WorkflowStatusEnum.aborted ]: ret["completed_at"] = utc_as_rfc_datetime(self.completed_at) if full_actions: ret["action_statuses"] = [ action_status.as_json() for action_status in self._action_statuses ] elif self._action_statuses and self.status != WorkflowStatusEnum.completed: current_action = self._action_statuses[-1] ret['current_action'] = current_action.as_json(summary=True) return ret
def as_json(self, summary=False): """Gets the JSON representation of the object Args: summary (bool, optional): Only get a limited JSON? Defaults to False Returns: (dict): The JSON representation of the object """ ret = { "execution_id": str(self.execution_id), "action_id": str(self.action_id), "name": self.name, "app_name": self.app_name, "action_name": self.action_name } if summary: return ret ret.update({ "arguments": json.loads(self.arguments) if self.arguments else [], "status": self.status.name, "started_at": utc_as_rfc_datetime(self.started_at) }) if self.status in [ActionStatusEnum.success, ActionStatusEnum.failure]: ret["result"] = json.loads(self.result) ret["completed_at"] = utc_as_rfc_datetime(self.completed_at) return ret
def as_json(self, with_user_history=False): """Returns the dictionary representation of a User object. Args: with_user_history (bool, optional): Boolean to determine whether or not to include user history in the JSON representation of the User. Defaults to False. Returns: The dictionary representation of a User object. """ out = { "id": self.id, "username": self.username, "roles": [role.as_json() for role in self.roles], "active": self.active } if with_user_history: out.update({ "last_login_at": utc_as_rfc_datetime(self.last_login_at), "current_login_at": utc_as_rfc_datetime(self.current_login_at), "last_login_ip": self.last_login_ip, "current_login_ip": self.current_login_ip, "login_count": self.login_count }) return out
def as_json(self, with_read_by=True, user=None, summary=False): """Gets a JSON representation of the message Args: with_read_by (bool, optional): Should the JSON include who has read the message? Defaults to True. user (User, optional): If provided, information specific to the user is included. summary (bool, optional): If True, only give a brief summary of the messsage. Defaults to False. Returns: """ responded, responded_at, responded_by = self.is_responded() ret = {'id': self.id, 'subject': self.subject, 'created_at': utc_as_rfc_datetime(self.created_at), 'awaiting_response': self.requires_response and not responded} if user: ret['is_read'] = self.user_has_read(user) last_read_at = self.user_last_read_at(user) if last_read_at: ret['last_read_at'] = utc_as_rfc_datetime(last_read_at) if not summary: ret.update({'body': json.loads(self.body), 'workflow_execution_id': str(self.workflow_execution_id), 'requires_reauthorization': self.requires_reauth, 'requires_response': self.requires_response}) if responded: ret['responded_at'] = utc_as_rfc_datetime(responded_at) ret['responded_by'] = responded_by if with_read_by: ret['read_by'] = list(self.get_read_by()) return ret
def as_json(self, full_actions=False): """Gets the JSON representation of the WorkflowStatus Args: full_actions (bool, optional): Get the full Action objects as well? Defaults to False Returns: The JSON representation of the object """ ret = {"execution_id": str(self.execution_id), "workflow_id": str(self.workflow_id), "name": self.name, "status": self.status.name} if self.user: ret["user"] = self.user if self.started_at: ret["started_at"] = utc_as_rfc_datetime(self.started_at) if self.status in [WorkflowStatusEnum.completed, WorkflowStatusEnum.aborted]: ret["completed_at"] = utc_as_rfc_datetime(self.completed_at) if full_actions: ret["action_statuses"] = [action_status.as_json() for action_status in self._action_statuses] elif self._action_statuses and self.status != WorkflowStatusEnum.completed: current_action = self._action_statuses[-1] ret['current_action'] = current_action.as_json(summary=True) return ret
def as_json(self, with_read_by=True, user=None, summary=False): """Gets a JSON representation of the message Args: with_read_by (bool, optional): Should the JSON include who has read the message? Defaults to True. user (User, optional): If provided, information specific to the user is included. summary (bool, optional): If True, only give a brief summary of the messsage. Defaults to False. Returns: """ responded, responded_at, responded_by = self.is_responded() ret = {'id': self.id, 'subject': self.subject, 'created_at': utc_as_rfc_datetime(self.created_at), 'awaiting_response': self.requires_response and not responded} if user: ret['is_read'] = self.user_has_read(user) last_read_at = self.user_last_read_at(user) if last_read_at: ret['last_read_at'] = utc_as_rfc_datetime(last_read_at) if not summary: ret.update({'body': json.loads(self.body), 'workflow_execution_id': str(self.workflow_execution_id), 'requires_reauthorization': self.requires_reauth, 'requires_response': self.requires_response}) if responded: ret['responded_at'] = utc_as_rfc_datetime(responded_at) ret['responded_by'] = responded_by if with_read_by: ret['read_by'] = list(self.get_read_by()) return ret
def as_json(self, with_read_by=True, user=None, summary=False): responded, responded_at, responded_by = self.is_responded() ret = { 'id': self.id, 'subject': self.subject, 'created_at': utc_as_rfc_datetime(self.created_at), 'awaiting_response': self.requires_response and not responded } if user: ret['is_read'] = self.user_has_read(user) last_read_at = self.user_last_read_at(user) if last_read_at: ret['last_read_at'] = utc_as_rfc_datetime(last_read_at) if not summary: ret.update({ 'body': json.loads(self.body), 'workflow_execution_id': str(self.workflow_execution_id), 'requires_reauthorization': self.requires_reauth, 'requires_response': self.requires_response }) if responded: ret['responded_at'] = utc_as_rfc_datetime(responded_at) ret['responded_by'] = responded_by if with_read_by: ret['read_by'] = list(self.get_read_by()) return ret
def format_workflow_result_with_current_step(workflow_execution_id, status): workflow_status = current_app.running_context.execution_db.session.query(WorkflowStatus).filter_by( execution_id=workflow_execution_id).first() if workflow_status is not None: status_json = workflow_status.as_json() for field in (field for field in list(status_json.keys()) if field not in ('execution_id', 'workflow_id', 'name', 'status', 'current_action', 'user')): status_json.pop(field) status_json['timestamp'] = utc_as_rfc_datetime(datetime.utcnow()) status_json['status'] = status.name # in case this callback is called before it is properly set in the database return status_json return { 'execution_id': str(workflow_execution_id), 'timestamp': utc_as_rfc_datetime(datetime.utcnow()), 'status': status.name}
def format_workflow_result(sender, status): workflow_status = current_app.running_context.execution_db.session.query(WorkflowStatus).filter_by( execution_id=sender['execution_id']).first() if workflow_status is not None: return {'execution_id': str(sender['execution_id']), 'workflow_id': str(sender['id']), 'name': sender['name'], 'status': status.name, 'timestamp': utc_as_rfc_datetime(datetime.utcnow()), 'user': workflow_status.user} return {'execution_id': str(sender['execution_id']), 'workflow_id': str(sender['id']), 'name': sender['name'], 'status': status.name, 'timestamp': utc_as_rfc_datetime(datetime.utcnow())}
def as_json(self, with_cases=False): """Gets the JSON representation of an Event object. Args: with_cases (bool, optional): A boolean to determine whether or not the cases of the event object should be included in the output. Returns: The JSON representation of an Event object. """ output = {'id': self.id, 'timestamp': utc_as_rfc_datetime(self.timestamp), 'type': self.type, 'originator': str(self.originator), 'message': self.message if self.message is not None else '', 'note': self.note if self.note is not None else ''} if self.data is not None: try: output['data'] = json.loads(self.data) except (ValueError, TypeError): output['data'] = str(self.data) else: output['data'] = '' if with_cases: output['cases'] = [case.as_json(with_events=False) for case in self.cases] return output
def as_json(self): return { 'action': self.action.name, 'user_id': self.user_id, 'username': self.username, 'id': self.id, 'timestamp': utc_as_rfc_datetime(self.timestamp) }
def format_workflow_result(sender, status): return { 'execution_id': str(sender['execution_id']), 'workflow_id': str(sender['id']), 'name': sender['name'], 'status': status.name, 'timestamp': utc_as_rfc_datetime(datetime.utcnow()) }
def test_as_json_for_user(self): message, uid = self.get_default_message(commit=True) message_json = message.as_json(user=self.user) self.assertFalse(message_json['is_read']) message_json = message.as_json(user=self.user2) self.assertFalse(message_json['is_read']) message.record_user_action(self.user, MessageAction.read) message.record_user_action(self.user2, MessageAction.read) db.session.commit() user1_history = message.history[0] user2_history = message.history[1] message_json = message.as_json(user=self.user) self.assertTrue(message_json['is_read']) self.assertEqual(message_json['last_read_at'], utc_as_rfc_datetime(user1_history.timestamp)) message_json = message.as_json(user=self.user2) self.assertTrue(message_json['is_read']) self.assertEqual(message_json['last_read_at'], utc_as_rfc_datetime(user2_history.timestamp))
def test_as_json_with_responded(self): message, uid = self.get_default_message(commit=True, requires_response=True) message.record_user_action(self.user, MessageAction.respond) db.session.commit() message_json = message.as_json() message_history = message.history[0] self.assertFalse(message_json['awaiting_response']) self.assertEqual(message_json['responded_at'], utc_as_rfc_datetime(message_history.timestamp)) self.assertEqual(message_json['responded_by'], message_history.username)
def test_as_json_summary(self): message, uid = self.get_default_message(commit=True) message_json = message.as_json(summary=True) self.assertEqual(message_json['id'], message.id) self.assertEqual(message_json['subject'], 'subject here') self.assertFalse(message_json['awaiting_response']) self.assertEqual(message_json['created_at'], utc_as_rfc_datetime(message.created_at)) for field in ('read_by', 'responded_at', 'responded_by', 'body', 'workflow_execution_uid', 'requires_reauthorization', 'requires_response', 'is_read', 'last_read_at'): self.assertNotIn(field, message_json)
def test_as_json_for_user(self): message, uid = self.get_default_message(commit=True) message_json = message.as_json(user=self.user) self.assertFalse(message_json['is_read']) message_json = message.as_json(user=self.user2) self.assertFalse(message_json['is_read']) message.record_user_action(self.user, MessageAction.read) message.record_user_action(self.user2, MessageAction.read) db.session.commit() user1_history = message.history[0] user2_history = message.history[1] message_json = message.as_json(user=self.user) self.assertTrue(message_json['is_read']) self.assertEqual(message_json['last_read_at'], utc_as_rfc_datetime(user1_history.timestamp)) message_json = message.as_json(user=self.user2) self.assertTrue(message_json['is_read']) self.assertEqual(message_json['last_read_at'], utc_as_rfc_datetime(user2_history.timestamp))
def as_json(self): """gets a JSON representation of the message history entry Returns: dict: The JSON representation of the message history entry """ return {'action': self.action.name, 'user_id': self.user_id, 'username': self.username, 'id': self.id, 'timestamp': utc_as_rfc_datetime(self.timestamp)}
def as_json(self): """gets a JSON representation of the message history entry Returns: dict: The JSON representation of the message history entry """ return {'action': self.action.name, 'user_id': self.user_id, 'username': self.username, 'id': self.id, 'timestamp': utc_as_rfc_datetime(self.timestamp)}
def format_action_data(sender, kwargs, status): action_arguments = [convert_action_argument(argument) for argument in sender.get('arguments', [])] return {'action_name': sender['action_name'], 'app_name': sender['app_name'], 'action_id': sender['id'], 'name': sender['name'], 'execution_id': sender['execution_id'], 'timestamp': utc_as_rfc_datetime(datetime.utcnow()), 'status': status.name, 'arguments': action_arguments, 'workflow_execution_id': kwargs['data']['workflow']['execution_id']}
def test_as_json_summary(self): message, uid = self.get_default_message(commit=True) message_json = message.as_json(summary=True) self.assertEqual(message_json['id'], message.id) self.assertEqual(message_json['subject'], 'subject here') self.assertFalse(message_json['awaiting_response']) self.assertEqual(message_json['created_at'], utc_as_rfc_datetime(message.created_at)) for field in ('read_by', 'responded_at', 'responded_by', 'body', 'workflow_execution_uid', 'requires_reauthorization', 'requires_response', 'is_read', 'last_read_at'): self.assertNotIn(field, message_json)
def test_as_json_with_responded(self): message, uid = self.get_default_message(commit=True, requires_response=True) message.record_user_action(self.user, MessageAction.respond) db.session.commit() message_json = message.as_json() message_history = message.history[0] self.assertFalse(message_json['awaiting_response']) self.assertEqual(message_json['responded_at'], utc_as_rfc_datetime(message_history.timestamp)) self.assertEqual(message_json['responded_by'], message_history.username)
def as_json(self, summary=False): ret = { "execution_id": str(self.execution_id), "action_id": str(self.action_id), "name": self.name, "app_name": self.app_name, "action_name": self.action_name } if summary: return ret ret.update({ "arguments": json.loads(self.arguments) if self.arguments else [], "status": self.status.name, "started_at": utc_as_rfc_datetime(self.started_at) }) if self.status in [ActionStatusEnum.success, ActionStatusEnum.failure]: ret["result"] = json.loads(self.result) ret["completed_at"] = utc_as_rfc_datetime(self.completed_at) return ret
def as_json(self, with_user_history=False): """Returns the dictionary representation of a User object. Args: with_user_history (bool, optional): Boolean to determine whether or not to include user history in the JSON representation of the User. Defaults to False. Returns: (dict): The dictionary representation of a User object. """ out = {"id": self.id, "username": self.username, "roles": [role.as_json() for role in self.roles], "active": self.active} if with_user_history: out.update({ "last_login_at": utc_as_rfc_datetime(self.last_login_at), "current_login_at": utc_as_rfc_datetime(self.current_login_at), "last_login_ip": self.last_login_ip, "current_login_ip": self.current_login_ip, "login_count": self.login_count}) return out
def as_json(self, full_actions=False): ret = { "execution_id": str(self.execution_id), "workflow_id": str(self.workflow_id), "name": self.name, "status": self.status.name } if self.started_at: ret["started_at"] = utc_as_rfc_datetime(self.started_at) if self.status in [ WorkflowStatusEnum.completed, WorkflowStatusEnum.aborted ]: ret["completed_at"] = utc_as_rfc_datetime(self.completed_at) if full_actions: ret["action_statuses"] = [ action_status.as_json() for action_status in self._action_statuses ] elif self._action_statuses and self.status != WorkflowStatusEnum.completed: current_action = self._action_statuses[-1] ret['current_action'] = current_action.as_json(summary=True) return ret
def as_json(self, summary=False): """Gets the JSON representation of the object Args: summary (bool, optional): Only get a limited JSON? Defaults to False Returns: (dict): The JSON representation of the object """ ret = {"execution_id": str(self.execution_id), "action_id": str(self.action_id), "name": self.name, "app_name": self.app_name, "action_name": self.action_name} if summary: return ret ret.update( {"arguments": json.loads(self.arguments) if self.arguments else [], "status": self.status.name, "started_at": utc_as_rfc_datetime(self.started_at)}) if self.status in [ActionStatusEnum.success, ActionStatusEnum.failure]: ret["result"] = json.loads(self.result) ret["completed_at"] = utc_as_rfc_datetime(self.completed_at) return ret