Beispiel #1
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
Beispiel #2
0
  def test_merge_dicts(self):
    """Test merging more than two dictionaries."""
    dict1 = {
        "a": {
            "b": {
                "c": 1,
                "d": {
                    "e": 2
                }
            }
        }
    }
    dict2 = {
        "a": {
            "b": {
                "c": 1,
                "f": {
                    "e": 2
                }
            },
            "g": 3
        },
        "h": 4
    }
    dict3 = {
        "a": {
            "eeb": {
                "c": 1,
                "f": {
                    "e": 2
                }
            },
            "g": 3
        },
        "h": 4
    }

    result = {
        "a": {
            "b": {
                "c": 1,
                "d": {
                    "e": 2,
                },
                "f": {
                    "e": 2,
                },
            },
            "eeb": {
                "c": 1,
                "f": {
                    "e": 2
                }
            },
            "g": 3,
        },
        "h": 4,
    }
    expected_result = utils.merge_dicts(dict1, dict2, dict3)
    self.assertEqual(result, expected_result)
Beispiel #3
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
Beispiel #4
0
    def test_merge_dicts(self):
        """Test merging more than two dictionaries."""
        dict1 = {"a": {"b": {"c": 1, "d": {"e": 2}}}}
        dict2 = {"a": {"b": {"c": 1, "f": {"e": 2}}, "g": 3}, "h": 4}
        dict3 = {"a": {"eeb": {"c": 1, "f": {"e": 2}}, "g": 3}, "h": 4}

        result = {
            "a": {
                "b": {
                    "c": 1,
                    "d": {
                        "e": 2,
                    },
                    "f": {
                        "e": 2,
                    },
                },
                "eeb": {
                    "c": 1,
                    "f": {
                        "e": 2
                    }
                },
                "g": 3,
            },
            "h": 4,
        }
        expected_result = utils.merge_dicts(dict1, dict2, dict3)
        self.assertEqual(result, expected_result)
Beispiel #5
0
    def test_merge_dicts(self):
        dict1 = {"a": {"b": {"c": 1, "d": {"e": 2}}}}
        dict2 = {"a": {"b": {"c": 1, "f": {"e": 2}}, "g": 3}, "h": 4}
        dict3 = {"a": {"eeb": {"c": 1, "f": {"e": 2}}, "g": 3}, "h": 4}

        result = {
            "a": {
                "b": {
                    "c": 1,
                    "d": {
                        "e": 2,
                    },
                    "f": {
                        "e": 2,
                    },
                },
                "eeb": {
                    "c": 1,
                    "f": {
                        "e": 2
                    }
                },
                "g": 3,
            },
            "h": 4,
        }
        expected_result = utils.merge_dicts(dict1, dict2, dict3)
        self.assertEqual(result, expected_result)
Beispiel #6
0
  def test_merge_dicts(self):
    dict1 = {
        "a": {
            "b": {
                "c": 1,
                "d": {
                    "e": 2
                }
            }
        }
    }
    dict2 = {
        "a": {
            "b": {
                "c": 1,
                "f": {
                    "e": 2
                }
            },
            "g": 3
        },
        "h": 4
    }
    dict3 = {
        "a": {
            "eeb": {
                "c": 1,
                "f": {
                    "e": 2
                }
            },
            "g": 3
        },
        "h": 4
    }

    result = {
        "a": {
            "b": {
                "c": 1,
                "d": {
                    "e": 2,
                },
                "f": {
                    "e": 2,
                },
            },
            "eeb": {
                "c": 1,
                "f": {
                    "e": 2
                }
            },
            "g": 3,
        },
        "h": 4,
    }
    expected_result = utils.merge_dicts(dict1, dict2, dict3)
    self.assertEqual(result, expected_result)
Beispiel #7
0
def get_all_cycle_tasks_completed_data(notification, cycle):
  workflow_owners = get_workflow_owners_dict(cycle.context_id)
  force = cycle.workflow.notify_on_change
  result = {}
  for workflow_owner in workflow_owners.itervalues():
    wf_data = {
        workflow_owner['email']: {
            "user": workflow_owner,
            "force_notifications": {
                notification.id: force
            },
            "all_tasks_completed": {
                cycle.id: get_cycle_dict(cycle)
            }
        }
    }
    result = merge_dicts(result, wf_data)
  return result
Beispiel #8
0
def get_all_cycle_tasks_completed_data(notification, cycle):
  workflow_owners = get_workflow_owners_dict(cycle.context_id)
  force = cycle.workflow.notify_on_change
  result = {}
  for workflow_owner in workflow_owners.itervalues():
    wf_data = {
        workflow_owner['email']: {
            "user": workflow_owner,
            "force_notifications": {
                notification.id: force
            },
            "all_tasks_completed": {
                cycle.id: get_cycle_dict(cycle)
            }
        }
    }
    result = merge_dicts(result, wf_data)
  return result
Beispiel #9
0
def get_all_cycle_tasks_completed_data(notification, cycle):
    workflow_admins = get_workflow_admins_dict(cycle.workflow)
    force = cycle.workflow.notify_on_change
    result = {}

    for workflow_admin in workflow_admins.itervalues():
        wf_data = {
            workflow_admin['email']: {
                "user": workflow_admin,
                "today": date.today(),
                "force_notifications": {
                    notification.id: force
                },
                "all_tasks_completed": {
                    cycle.id: get_cycle_dict(cycle)
                }
            }
        }
        result = merge_dicts(result, wf_data)
    return result
Beispiel #10
0
def get_all_cycle_tasks_completed_data(notification, cycle):
  workflow_admins = get_workflow_admins_dict(cycle.workflow)
  force = cycle.workflow.notify_on_change
  result = {}

  for workflow_admin in workflow_admins.itervalues():
    wf_data = {
        workflow_admin['email']: {
            "user": workflow_admin,
            "today": date.today(),
            "force_notifications": {
                notification.id: force
            },
            "all_tasks_completed": {
                cycle.id: get_cycle_dict(cycle)
            }
        }
    }
    result = merge_dicts(result, wf_data)
  return result
Beispiel #11
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

    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)

    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
Beispiel #12
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)
Beispiel #13
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
Beispiel #14
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)
Beispiel #15
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
    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)
    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
Beispiel #16
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
Beispiel #17
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

  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)

  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
Beispiel #18
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
  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)
  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