Exemple #1
0
def get_workflow_starts_in_data(notification, workflow):
  """Get workflow data for which cycle has started."""
  if workflow.status != "Active":
    return {}
  if (not workflow.next_cycle_start_date or
          workflow.next_cycle_start_date < date.today()):
    return {}  # this can only be if the cycle has successfully started
  result = {}

  force = workflow.notify_on_change

  people_with_role = (
      workflow.get_persons_for_rolename("Admin") +
      workflow.get_persons_for_rolename("Workflow Member"))
  for wf_person in people_with_role:
    result[wf_person.email] = {
        "user": data_handlers.get_person_dict(wf_person),
        "force_notifications": {
            notification.id: force
        },
        "cycle_starts_in": {
            workflow.id: {
                "workflow_url": get_workflow_url(workflow),
                "start_date": workflow.next_cycle_start_date,
                "start_date_statement": utils.get_digest_date_statement(
                    workflow.next_cycle_start_date, "start", True),
                "custom_message": workflow.notify_custom_message,
                "title": workflow.title,
            }
        }
    }
  return result
Exemple #2
0
def get_workflow_starts_in_data(notification, workflow):
  if workflow.status != "Active":
    return {}
  if (not workflow.next_cycle_start_date or
          workflow.next_cycle_start_date < date.today()):
    return {}  # this can only be if the cycle has successfully started
  result = {}

  workflow_owners = get_workflow_owners_dict(workflow.context_id)
  force = workflow.notify_on_change

  for user_roles in workflow.context.user_roles:
    wf_person = user_roles.person
    result[wf_person.email] = {
        "user": data_handlers.get_person_dict(wf_person),
        "force_notifications": {
            notification.id: force
        },
        "cycle_starts_in": {
            workflow.id: {
                "workflow_owners": workflow_owners,
                "workflow_url": get_workflow_url(workflow),
                "start_date": workflow.next_cycle_start_date,
                "start_date_statement": utils.get_digest_date_statement(
                    workflow.next_cycle_start_date, "start", True),
                "custom_message": workflow.notify_custom_message,
                "title": workflow.title,
            }
        }
    }
  return result
Exemple #3
0
def get_cycle_task_declined_data(notification):
    cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
    if cycle_task:
        assignees = set().union(
            cycle_task.get_persons_for_rolename("Task Assignees"),
            cycle_task.get_persons_for_rolename("Task Secondary Assignees"))
    else:
        assignees = []
    if not assignees:
        logger.warning('%s for notification %s not found.',
                       notification.object_type, notification.id)
        return {}

    force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change
    result = {}
    for person in assignees:
        person_dict = {
            person.email: {
                "user": data_handlers.get_person_dict(person),
                "force_notifications": {
                    notification.id: force
                },
                "task_declined": {
                    cycle_task.id: get_cycle_task_dict(cycle_task)
                }
            }
        }
        result = merge_dicts(result, person_dict)
    return result
Exemple #4
0
def get_cycle_task_due(notification):
  cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}
  if not cycle_task.contact:
    logger.warning(
        'Contact for cycle task %s not found.',
        notification.object_id)
    return {}

  notif_name = notification.notification_type.name
  due = "due_today" if notif_name == "cycle_task_due_today" else "due_in"
  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change
  return {
      cycle_task.contact.email: {
          "user": data_handlers.get_person_dict(cycle_task.contact),
          "force_notifications": {
              notification.id: force
          },
          due: {
              cycle_task.id: get_cycle_task_dict(cycle_task)
          }
      }
  }
Exemple #5
0
def get_cycle_task_due(notification):
  cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}
  if not cycle_task.contact:
    logger.warning(
        'Contact for cycle task %s not found.',
        notification.object_id)
    return {}

  notif_name = notification.notification_type.name
  due = "due_today" if notif_name == "cycle_task_due_today" else "due_in"
  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change
  return {
      cycle_task.contact.email: {
          "user": data_handlers.get_person_dict(cycle_task.contact),
          "force_notifications": {
              notification.id: force
          },
          due: {
              cycle_task.id: get_cycle_task_dict(cycle_task)
          }
      }
  }
Exemple #6
0
def get_workflow_starts_in_data(notification, workflow):
    if workflow.status != "Active":
        return {}
    if (not workflow.next_cycle_start_date
            or workflow.next_cycle_start_date < date.today()):
        return {}  # this can only be if the cycle has successfully started
    result = {}

    force = workflow.notify_on_change

    people_with_role = (workflow.get_persons_for_rolename("Admin") +
                        workflow.get_persons_for_rolename("Workflow Member"))
    for wf_person in people_with_role:
        result[wf_person.email] = {
            "user": data_handlers.get_person_dict(wf_person),
            "force_notifications": {
                notification.id: force
            },
            "cycle_starts_in": {
                workflow.id: {
                    "workflow_url":
                    get_workflow_url(workflow),
                    "start_date":
                    workflow.next_cycle_start_date,
                    "start_date_statement":
                    utils.get_digest_date_statement(
                        workflow.next_cycle_start_date, "start", True),
                    "custom_message":
                    workflow.notify_custom_message,
                    "title":
                    workflow.title,
                }
            }
        }
    return result
Exemple #7
0
def get_workflow_starts_in_data(notification, workflow):
  if workflow.status != "Active":
    return {}
  if (not workflow.next_cycle_start_date or
          workflow.next_cycle_start_date < date.today()):
    return {}  # this can only be if the cycle has successfully started
  result = {}

  workflow_owners = get_workflow_owners_dict(workflow.context_id)
  force = workflow.notify_on_change

  for user_roles in workflow.context.user_roles:
    wf_person = user_roles.person
    result[wf_person.email] = {
        "user": data_handlers.get_person_dict(wf_person),
        "force_notifications": {
            notification.id: force
        },
        "cycle_starts_in": {
            workflow.id: {
                "workflow_owners": workflow_owners,
                "workflow_url": get_workflow_url(workflow),
                "start_date": workflow.next_cycle_start_date,
                "start_date_statement": utils.get_digest_date_statement(
                    workflow.next_cycle_start_date, "start", True),
                "custom_message": workflow.notify_custom_message,
                "title": workflow.title,
            }
        }
    }
  return result
Exemple #8
0
def get_workflow_admins_dict(workflow):
    """Get dict representation of workflow admins."""
    wfa_people = workflow.get_persons_for_rolename("Admin")
    return {
        person.id: data_handlers.get_person_dict(person)
        for person in wfa_people
    }
Exemple #9
0
def get_cycle_task_declined_data(notification):
  """Get data of declined cycle tasks."""
  cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
  if cycle_task:
    assignees = set().union(
        cycle_task.get_persons_for_rolename("Task Assignees"),
        cycle_task.get_persons_for_rolename("Task Secondary Assignees"))
  else:
    assignees = []
  if not assignees:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}

  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change
  result = {}
  for person in assignees:
    person_dict = {
        person.email: {
            "user": data_handlers.get_person_dict(person),
            "force_notifications": {
                notification.id: force
            },
            "task_declined": {
                cycle_task.id: get_cycle_task_dict(cycle_task)
            }
        }
    }
    result = merge_dicts(result, person_dict)
  return result
Exemple #10
0
def get_cycle_task_overdue_data(
    notification, tasks_cache=None, del_rels_cache=None
):
  """Compile and return all relevant email data for task overdue notification.

  Args:
    notification: Notification instance for which to compile email data.
    tasks_cache (dict): prefetched CycleTaskGroupObjectTask instances
      accessible by their ID as a key
    del_rels_cache (dict): prefetched Revision instances representing the
      relationships to Tasks that were deleted grouped by task ID as a key
  Returns:
    Dictionary containing the compiled data under the key that equals the
    overdue task assignee's email address.
  """
  if tasks_cache is None:
    tasks_cache = {}

  cycle_task = tasks_cache.get(notification.object_id)
  if not cycle_task:
    cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)

  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}
  if not cycle_task.contact:
    logger.warning(
        'Contact for cycle task %s not found.',
        notification.object_id)
    return {}

  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change

  # the filter expression to be included in the cycle task's URL and
  # automatically applied when user visits it
  url_filter_exp = u"id=" + unicode(cycle_task.cycle_id)
  task_info = get_cycle_task_dict(cycle_task, del_rels_cache=del_rels_cache)

  task_info['task_group'] = cycle_task.cycle_task_group
  task_info['task_group_url'] = cycle_task_group_url(
      cycle_task, filter_exp=url_filter_exp)

  task_info['workflow'] = cycle_task.cycle.workflow
  task_info['workflow_cycle_url'] = cycle_task_workflow_cycle_url(
      cycle_task, filter_exp=url_filter_exp)

  return {
      cycle_task.contact.email: {
          "user": data_handlers.get_person_dict(cycle_task.contact),
          "force_notifications": {
              notification.id: force
          },
          "task_overdue": {
              cycle_task.id: task_info
          }
      }
  }
Exemple #11
0
def get_cycle_task_overdue_data(
    notification, tasks_cache=None, del_rels_cache=None
):
  """Compile and return all relevant email data for task overdue notification.

  Args:
    notification: Notification instance for which to compile email data.
    tasks_cache (dict): prefetched CycleTaskGroupObjectTask instances
      accessible by their ID as a key
    del_rels_cache (dict): prefetched Revision instances representing the
      relationships to Tasks that were deleted grouped by task ID as a key
  Returns:
    Dictionary containing the compiled data under the key that equals the
    overdue task assignee's email address.
  """
  if tasks_cache is None:
    tasks_cache = {}

  cycle_task = tasks_cache.get(notification.object_id)
  if not cycle_task:
    cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)

  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}
  if not cycle_task.contact:
    logger.warning(
        'Contact for cycle task %s not found.',
        notification.object_id)
    return {}

  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change

  # the filter expression to be included in the cycle task's URL and
  # automatically applied when user visits it
  url_filter_exp = u"id=" + unicode(cycle_task.cycle_id)
  task_info = get_cycle_task_dict(cycle_task, del_rels_cache=del_rels_cache)

  task_info['task_group'] = cycle_task.cycle_task_group
  task_info['task_group_url'] = cycle_task_group_url(
      cycle_task, filter_exp=url_filter_exp)

  task_info['workflow'] = cycle_task.cycle.workflow
  task_info['workflow_cycle_url'] = cycle_task_workflow_cycle_url(
      cycle_task, filter_exp=url_filter_exp)

  return {
      cycle_task.contact.email: {
          "user": data_handlers.get_person_dict(cycle_task.contact),
          "force_notifications": {
              notification.id: force
          },
          "task_overdue": {
              cycle_task.id: task_info
          }
      }
  }
Exemple #12
0
def get_workflow_owners_dict(context_id):
    owners = db.session.query(UserRole).join(Role).filter(
        and_(UserRole.context_id == context_id,
             Role.name == "WorkflowOwner")).all()
    return {
        user_role.person.id: data_handlers.get_person_dict(user_role.person)
        for user_role in owners
    }
Exemple #13
0
def get_cycle_task_due(notification, tasks_cache=None, del_rels_cache=None):
  """Build data needed for the "task due" email notifications.

  Args:
    notification (Notification): The notification to aggregate the data for.
    tasks_cache (dict): prefetched CycleTaskGroupObjectTask instances
      accessible by their ID as a key
    del_rels_cache (dict): prefetched Revision instances representing the
      relationships to Tasks that were deleted grouped by task ID as a key
  Returns:
    Data aggregated in a dictionary, grouped by task assignee's email address,
    which is used as a key.
  """
  if tasks_cache is None:
    tasks_cache = {}

  cycle_task = tasks_cache.get(notification.object_id)
  if not cycle_task:
    cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)

  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}
  if not cycle_task.contact:
    logger.warning(
        'Contact for cycle task %s not found.',
        notification.object_id)
    return {}

  notif_name = notification.notification_type.name
  due = "due_today" if notif_name == "cycle_task_due_today" else "due_in"
  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change

  url_filter_exp = u"id={}".format(cycle_task.cycle_id)
  task_info = get_cycle_task_dict(cycle_task, del_rels_cache=del_rels_cache)

  task_info["task_group"] = cycle_task.cycle_task_group
  task_info["task_group_url"] = cycle_task_group_url(
      cycle_task, filter_exp=url_filter_exp)

  task_info["workflow"] = cycle_task.cycle.workflow
  task_info["workflow_cycle_url"] = cycle_task_workflow_cycle_url(
      cycle_task, filter_exp=url_filter_exp)

  return {
      cycle_task.contact.email: {
          "user": data_handlers.get_person_dict(cycle_task.contact),
          "today": date.today(),
          "force_notifications": {
              notification.id: force
          },
          due: {
              cycle_task.id: task_info
          }
      }
  }
Exemple #14
0
def get_cycle_task_due(notification, tasks_cache=None, del_rels_cache=None):
  """Build data needed for the "task due" email notifications.

  Args:
    notification (Notification): The notification to aggregate the data for.
    tasks_cache (dict): prefetched CycleTaskGroupObjectTask instances
      accessible by their ID as a key
    del_rels_cache (dict): prefetched Revision instances representing the
      relationships to Tasks that were deleted grouped by task ID as a key
  Returns:
    Data aggregated in a dictionary, grouped by task assignee's email address,
    which is used as a key.
  """
  if tasks_cache is None:
    tasks_cache = {}

  cycle_task = tasks_cache.get(notification.object_id)
  if not cycle_task:
    cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)

  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}
  if not cycle_task.contact:
    logger.warning(
        'Contact for cycle task %s not found.',
        notification.object_id)
    return {}

  notif_name = notification.notification_type.name
  due = "due_today" if notif_name == "cycle_task_due_today" else "due_in"
  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change

  url_filter_exp = u"id={}".format(cycle_task.cycle_id)
  task_info = get_cycle_task_dict(cycle_task, del_rels_cache=del_rels_cache)

  task_info["task_group"] = cycle_task.cycle_task_group
  task_info["task_group_url"] = cycle_task_group_url(
      cycle_task, filter_exp=url_filter_exp)

  task_info["workflow"] = cycle_task.cycle.workflow
  task_info["workflow_cycle_url"] = cycle_task_workflow_cycle_url(
      cycle_task, filter_exp=url_filter_exp)

  return {
      cycle_task.contact.email: {
          "user": data_handlers.get_person_dict(cycle_task.contact),
          "today": date.today(),
          "force_notifications": {
              notification.id: force
          },
          due: {
              cycle_task.id: task_info
          }
      }
  }
Exemple #15
0
def get_cycle_task_declined_data(notification):
  cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
  if not cycle_task:
    return {}

  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change
  return {
      cycle_task.contact.email: {
          "user": data_handlers.get_person_dict(cycle_task.contact),
          "force_notifications": {
              notification.id: force
          },
          "task_declined": {
              cycle_task.id: get_cycle_task_dict(cycle_task)
          }
      }
  }
Exemple #16
0
def get_cycle_created_data(notification, cycle):
  if not cycle.is_current:
    return {}

  manual = notification.notification_type.name == "manual_cycle_created"
  force = cycle.workflow.notify_on_change
  result = {}

  for person in cycle.workflow.people:
    result[person.email] = {
        "user": data_handlers.get_person_dict(person),
        "force_notifications": {
            notification.id: force
        },
        "cycle_started": {
            cycle.id: get_cycle_dict(cycle, manual)
        }
    }
  return result
Exemple #17
0
def get_cycle_task_declined_data(notification):
  cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
  if not cycle_task or not cycle_task.contact:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}

  force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change
  return {
      cycle_task.contact.email: {
          "user": data_handlers.get_person_dict(cycle_task.contact),
          "force_notifications": {
              notification.id: force
          },
          "task_declined": {
              cycle_task.id: get_cycle_task_dict(cycle_task)
          }
      }
  }
Exemple #18
0
def get_cycle_created_data(notification, cycle):
  if not cycle.is_current:
    return {}

  manual = notification.notification_type.name == "manual_cycle_created"
  force = cycle.workflow.notify_on_change
  result = {}

  for user_role in cycle.workflow.context.user_roles:
    person = user_role.person
    result[person.email] = {
        "user": data_handlers.get_person_dict(person),
        "force_notifications": {
            notification.id: force
        },
        "cycle_started": {
            cycle.id: get_cycle_dict(cycle, manual)
        }
    }
  return result
Exemple #19
0
def get_cycle_created_data(notification, cycle):
  if not cycle.is_current:
    return {}

  manual = notification.notification_type.name == "manual_cycle_created"
  force = cycle.workflow.notify_on_change
  result = {}

  people_with_role = (
      cycle.workflow.get_persons_for_rolename("Admin") +
      cycle.workflow.get_persons_for_rolename("Workflow Member"))
  for person in people_with_role:
    result[person.email] = {
        "user": data_handlers.get_person_dict(person),
        "force_notifications": {
            notification.id: force
        },
        "cycle_started": {
            cycle.id: get_cycle_dict(cycle, manual)
        }
    }
  return result
Exemple #20
0
def get_cycle_created_data(notification, cycle):
  """Get data of created cycle."""
  if not cycle.is_current:
    return {}

  manual = notification.notification_type.name == "manual_cycle_created"
  force = cycle.workflow.notify_on_change
  result = {}

  people_with_role = (
      cycle.workflow.get_persons_for_rolename("Admin") +
      cycle.workflow.get_persons_for_rolename("Workflow Member"))
  for person in people_with_role:
    result[person.email] = {
        "user": data_handlers.get_person_dict(person),
        "force_notifications": {
            notification.id: force
        },
        "cycle_started": {
            cycle.id: get_cycle_dict(cycle, manual)
        }
    }
  return result
Exemple #21
0
def get_workflow_admins_dict(workflow):
  wfa_people = workflow.get_persons_for_rolename("Admin")
  return {person.id: data_handlers.get_person_dict(person)
          for person in wfa_people}
Exemple #22
0
def get_workflow_admins_dict(workflow):
    wfa_people = workflow.get_persons_for_rolename("Admin")
    return {
        person.id: data_handlers.get_person_dict(person)
        for person in wfa_people
    }
Exemple #23
0
def get_cycle_created_task_data(notification):
    cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
    if not cycle_task:
        logger.warning('%s for notification %s not found.',
                       notification.object_type, notification.id)
        return {}

    cycle_task_group = cycle_task.cycle_task_group
    cycle = cycle_task_group.cycle

    force = cycle.workflow.notify_on_change

    task_assignees = set().union(
        cycle_task.get_persons_for_rolename("Task Assignees"),
        cycle_task.get_persons_for_rolename("Task Secondary Assignees"))
    task_group_assignee = data_handlers.get_person_dict(
        cycle_task_group.contact)
    workflow_admins = get_workflow_admins_dict(cycle.workflow)
    task = {cycle_task.id: get_cycle_task_dict(cycle_task)}

    result = {
        task_group_assignee['email']: {
            "user": task_group_assignee,
            "force_notifications": {
                notification.id: force
            },
            "cycle_data": {
                cycle.id: {
                    "my_task_groups": {
                        cycle_task_group.id: deepcopy(task)
                    }
                }
            }
        }
    }
    for task_assignee in task_assignees:
        assignee_data = {
            task_assignee.email: {
                "user": data_handlers.get_person_dict(task_assignee),
                "force_notifications": {
                    notification.id: force
                },
                "cycle_data": {
                    cycle.id: {
                        "my_tasks": deepcopy(task)
                    }
                }
            }
        }
        result = merge_dicts(result, assignee_data)
    for workflow_admin in workflow_admins.itervalues():
        wf_admin_data = {
            workflow_admin['email']: {
                "user": workflow_admin,
                "force_notifications": {
                    notification.id: force
                },
                "cycle_data": {
                    cycle.id: {
                        "cycle_tasks": deepcopy(task)
                    }
                }
            }
        }
        result = merge_dicts(result, wf_admin_data)
    return result
Exemple #24
0
def get_cycle_created_task_data(notification):
  cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}

  cycle_task_group = cycle_task.cycle_task_group
  cycle = cycle_task_group.cycle

  force = cycle.workflow.notify_on_change

  task_assignee = data_handlers.get_person_dict(cycle_task.contact)
  task_group_assignee = data_handlers.get_person_dict(cycle_task_group.contact)
  workflow_owners = get_workflow_owners_dict(cycle.context_id)
  task = {
      cycle_task.id: get_cycle_task_dict(cycle_task)
  }

  result = {}

  assignee_data = {
      task_assignee['email']: {
          "user": task_assignee,
          "force_notifications": {
              notification.id: force
          },
          "cycle_data": {
              cycle.id: {
                  "my_tasks": deepcopy(task)
              }
          }
      }
  }
  tg_assignee_data = {
      task_group_assignee['email']: {
          "user": task_group_assignee,
          "force_notifications": {
              notification.id: force
          },
          "cycle_data": {
              cycle.id: {
                  "my_task_groups": {
                      cycle_task_group.id: deepcopy(task)
                  }
              }
          }
      }
  }
  for workflow_owner in workflow_owners.itervalues():
    wf_owner_data = {
        workflow_owner['email']: {
            "user": workflow_owner,
            "force_notifications": {
                notification.id: force
            },
            "cycle_data": {
                cycle.id: {
                    "cycle_tasks": deepcopy(task)
                }
            }
        }
    }
    result = merge_dicts(result, wf_owner_data)
  return merge_dicts(result, assignee_data, tg_assignee_data)
Exemple #25
0
def get_workflow_admins_dict(workflow):
  """Get dict representation of workflow admins."""
  wfa_people = workflow.get_persons_for_rolename("Admin")
  return {person.id: data_handlers.get_person_dict(person)
          for person in wfa_people}
Exemple #26
0
def get_cycle_task_due(notification, tasks_cache=None, del_rels_cache=None):
    """Build data needed for the "task due" email notifications.

  Args:
    notification (Notification): The notification to aggregate the data for.
    tasks_cache (dict): prefetched CycleTaskGroupObjectTask instances
      accessible by their ID as a key
    del_rels_cache (dict): prefetched Revision instances representing the
      relationships to Tasks that were deleted grouped by task ID as a key
  Returns:
    Data aggregated in a dictionary, grouped by task
    assignee/secondary assignee's email address, which is used as a key.
  """
    if tasks_cache is None:
        tasks_cache = {}

    cycle_task = tasks_cache.get(notification.object_id)
    if not cycle_task:
        cycle_task = get_object(CycleTaskGroupObjectTask,
                                notification.object_id)

    if not cycle_task:
        logger.warning('%s for notification %s not found.',
                       notification.object_type, notification.id)
        return {}
    task_assignees = set().union(
        cycle_task.get_persons_for_rolename("Task Assignees"),
        cycle_task.get_persons_for_rolename("Task Secondary Assignees"))
    if not task_assignees:
        logger.warning('Contact for cycle task %s not found.',
                       notification.object_id)
        return {}

    notif_name = notification.notification_type.name
    due = "due_today" if notif_name == "cycle_task_due_today" else "due_in"
    force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change

    task_info = get_cycle_task_dict(cycle_task, del_rels_cache=del_rels_cache)

    task_info["task_group"] = cycle_task.cycle_task_group

    task_info["workflow"] = cycle_task.cycle.workflow
    task_info["workflow_url"] = get_workflow_url(cycle_task.cycle.workflow,
                                                 "info")

    result = {}
    for person in task_assignees:
        person_dict = {
            person.email: {
                "user": data_handlers.get_person_dict(person),
                "today": date.today(),
                "force_notifications": {
                    notification.id: force
                },
                due: {
                    cycle_task.id: task_info
                }
            }
        }
        result = merge_dicts(result, person_dict)
    return result
Exemple #27
0
def get_cycle_created_task_data(notification):
  """Get data of created cycle task."""
  cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}

  cycle_task_group = cycle_task.cycle_task_group
  cycle = cycle_task_group.cycle

  force = cycle.workflow.notify_on_change

  task_assignees = set().union(
      cycle_task.get_persons_for_rolename("Task Assignees"),
      cycle_task.get_persons_for_rolename("Task Secondary Assignees"))
  task_group_assignee = data_handlers.get_person_dict(cycle_task_group.contact)
  workflow_admins = get_workflow_admins_dict(cycle.workflow)
  task = {
      cycle_task.id: get_cycle_task_dict(cycle_task)
  }

  result = {
      task_group_assignee['email']: {
          "user": task_group_assignee,
          "force_notifications": {
              notification.id: force
          },
          "cycle_data": {
              cycle.id: {
                  "my_task_groups": {
                      cycle_task_group.id: deepcopy(task)
                  }
              }
          }
      }
  }
  for task_assignee in task_assignees:
    assignee_data = {
        task_assignee.email: {
            "user": data_handlers.get_person_dict(task_assignee),
            "force_notifications": {
                notification.id: force
            },
            "cycle_data": {
                cycle.id: {
                    "my_tasks": deepcopy(task)
                }
            }
        }
    }
    result = merge_dicts(result, assignee_data)
  for workflow_admin in workflow_admins.itervalues():
    wf_admin_data = {
        workflow_admin['email']: {
            "user": workflow_admin,
            "force_notifications": {
                notification.id: force
            },
            "cycle_data": {
                cycle.id: {
                    "cycle_tasks": deepcopy(task)
                }
            }
        }
    }
    result = merge_dicts(result, wf_admin_data)
  return result
Exemple #28
0
def get_cycle_created_task_data(notification):
  cycle_task = get_object(CycleTaskGroupObjectTask, notification.object_id)
  if not cycle_task:
    logger.warning(
        '%s for notification %s not found.',
        notification.object_type, notification.id)
    return {}

  cycle_task_group = cycle_task.cycle_task_group
  cycle = cycle_task_group.cycle

  force = cycle.workflow.notify_on_change

  task_assignee = data_handlers.get_person_dict(cycle_task.contact)
  task_group_assignee = data_handlers.get_person_dict(cycle_task_group.contact)
  workflow_owners = get_workflow_owners_dict(cycle.context_id)
  task = {
      cycle_task.id: get_cycle_task_dict(cycle_task)
  }

  result = {}

  assignee_data = {
      task_assignee['email']: {
          "user": task_assignee,
          "force_notifications": {
              notification.id: force
          },
          "cycle_data": {
              cycle.id: {
                  "my_tasks": deepcopy(task)
              }
          }
      }
  }
  tg_assignee_data = {
      task_group_assignee['email']: {
          "user": task_group_assignee,
          "force_notifications": {
              notification.id: force
          },
          "cycle_data": {
              cycle.id: {
                  "my_task_groups": {
                      cycle_task_group.id: deepcopy(task)
                  }
              }
          }
      }
  }
  for workflow_owner in workflow_owners.itervalues():
    wf_owner_data = {
        workflow_owner['email']: {
            "user": workflow_owner,
            "force_notifications": {
                notification.id: force
            },
            "cycle_data": {
                cycle.id: {
                    "cycle_tasks": deepcopy(task)
                }
            }
        }
    }
    result = merge_dicts(result, wf_owner_data)
  return merge_dicts(result, assignee_data, tg_assignee_data)
Exemple #29
0
def get_workflow_owners_dict(context_id):
  owners = db.session.query(UserRole).join(Role).filter(
      and_(UserRole.context_id == context_id,
           Role.name == "WorkflowOwner")).all()
  return {user_role.person.id: data_handlers.get_person_dict(user_role.person)
          for user_role in owners}
Exemple #30
0
def get_cycle_task_overdue_data(notification,
                                tasks_cache=None,
                                del_rels_cache=None):
    """Compile and return all relevant email data for task overdue notification.

  Args:
    notification: Notification instance for which to compile email data.
    tasks_cache (dict): prefetched CycleTaskGroupObjectTask instances
      accessible by their ID as a key
    del_rels_cache (dict): prefetched Revision instances representing the
      relationships to Tasks that were deleted grouped by task ID as a key
  Returns:
    Dictionary containing the compiled data under the key that equals the
    overdue task assignee/secondary assignee's email address.
  """
    if tasks_cache is None:
        tasks_cache = {}

    cycle_task = tasks_cache.get(notification.object_id)
    if not cycle_task:
        cycle_task = get_object(CycleTaskGroupObjectTask,
                                notification.object_id)

    if not cycle_task:
        logger.warning('%s for notification %s not found.',
                       notification.object_type, notification.id)
        return {}
    assignees = set().union(
        cycle_task.get_persons_for_rolename("Task Assignees"),
        cycle_task.get_persons_for_rolename("Task Secondary Assignees"))
    if not assignees:
        logger.warning('Contact for cycle task %s not found.',
                       notification.object_id)
        return {}

    force = cycle_task.cycle_task_group.cycle.workflow.notify_on_change

    # the filter expression to be included in the cycle task's URL and
    # automatically applied when user visits it
    task_info = get_cycle_task_dict(cycle_task, del_rels_cache=del_rels_cache)

    task_info['task_group'] = cycle_task.cycle_task_group

    task_info['workflow'] = cycle_task.cycle.workflow
    task_info["workflow_url"] = get_workflow_url(cycle_task.cycle.workflow,
                                                 "info")
    result = {}
    for person in assignees:
        person_dict = {
            person.email: {
                "user": data_handlers.get_person_dict(person),
                "force_notifications": {
                    notification.id: force
                },
                "task_overdue": {
                    cycle_task.id: task_info
                }
            }
        }
        result = merge_dicts(result, person_dict)
    return result