Example #1
0
def changed_project_task(user, project, task, project_cohort_id=None):
    """If change made by an org admin, notify related account manager, or all
    the program owners. Otherwise, notify project liaison, or all the org
    admins.
    """
    t_dict = task.to_client_dict()
    program_config = Program.get_config(project.program_label)
    if project_cohort_id:
        link = '/dashboard/{pc}/tasks/{ckpt}/{task}'.format(
            pc=DatastoreModel.convert_uid(project_cohort_id),
            ckpt=DatastoreModel.convert_uid(task.checkpoint_id),
            task=task.uid
        )
    else:
        link = '/dashboard'
    params = {
        'task_id': task.uid,
        'context_id': project.uid,
        'subject': "Task updated",
        'body': u"{} updated \"{}\" in {}.".format(
            user.name, t_dict['name'], program_config['name']),
        'link': link,
        'autodismiss': True,
    }
    if user.non_admin:
        # Send to account managers (usu. set via program config ->
        # default_account_manager).
        parents = get_project_program_recipients(project)
    else:
        parents = get_project_organization_recipients(project)
    notes = [Notification.create(parent=p, **params) for p in parents]

    filtered_notes = Notification.filter_redundant(notes)
    ndb.put_multi(filtered_notes)
Example #2
0
def changed_organization_task(user, organization, task,
                              project_cohort_id=None):
    """Notify the other type of user, not one's own type: org or super."""
    t_dict = task.to_client_dict()
    if project_cohort_id:
        link = '/dashboard/{pc}/tasks/{ckpt}/{task}'.format(
            pc=DatastoreModel.convert_uid(project_cohort_id),
            ckpt=DatastoreModel.convert_uid(task.checkpoint_id),
            task=task.uid
        )
    else:
        link = '/dashboard'
    params = {
        'task_id': task.uid,
        'context_id': organization.uid,
        'subject': "Task updated",
        'body': u"{} updated \"{}\" in {}.".format(
            user.name, t_dict['name'], organization.name),
        'link': link,
        'autodismiss': True,
    }
    notes = []
    if user.super_admin:
        # Notify anyone who owns the organization.
        admins = User.get(
            user_type='user', owned_organizations=organization.uid)
        notes += [Notification.create(parent=a, **params) for a in admins]
    if user.non_admin:
        # Super admins are too busy to care.
        pass
        # # Old code for sending to supers.
        # supers = User.get(user_type='super_admin')
        # notes += [Notification.create(parent=s, **params) for s in supers]
    # else program admin? Program admins are largely not implemented, and likely
    # won't have rights to modify/approve organizations anyway.

    filtered_notes = Notification.filter_redundant(notes)
    ndb.put_multi(filtered_notes)