Пример #1
0
    def test_close_tasklist(self):
        """Should delete all associated task reminders."""
        user1 = User.create(email='*****@*****.**', user_type='user')
        user2 = User.create(email='*****@*****.**', user_type='user')
        org = Organization.create(name="Foo Org", liaison_id=user1.uid)
        user1.owned_organizations = [org.uid]
        user2.owned_organizations = [org.uid]
        user1.put()
        user2.put()
        org.put()

        response = self.testapp.post_json(
            '/api/projects',
            {
                'organization_id': org.uid,
                'program_label': 'demo-program',
                'liaison_id': user1.uid
            },
            headers=login_headers(user1.uid),
        )
        project_dict = json.loads(response.body)
        project = Project.get_by_id(project_dict['uid'])

        # Simulate time passing and the datastore reaching consistency.
        trs1 = TaskReminder.get(ancestor=user1)
        trs2 = TaskReminder.get(ancestor=user2)

        Tasklist(project).close()

        self.assertEqual(len(TaskReminder.get(ancestor=user1)), 0)
        self.assertEqual(len(TaskReminder.get(ancestor=user2)), 0)
Пример #2
0
    def post(self, project_id, slug):
        """A project has been identified as new. Send them a welcome."""
        project = Project.get_by_id(project_id)
        program = Program.get_config(project.program_label)
        org = Organization.get_by_id(project.organization_id)

        # The Org liaison is preferred, but is not guaranteed to be set (users
        # choose their org liaison explicitly as one of the org tasks). Default
        # to the Project liaison, which is set on creation in
        # add_program.controller.js@joinProgram
        org_liaison = User.get_by_id(org.liaison_id)
        project_liaison = User.get_by_id(project.liaison_id)
        liaison = org_liaison or project_liaison

        email = Email.create(
            to_address=liaison.email,
            mandrill_template=slug,
            mandrill_template_content={
                'program_name': program['name'],
                'organization_name': org.name,
                'liaison_name': liaison.name,
                'join_date': util.datelike_to_iso_string(project.created),
            },
        )
        email.put()
Пример #3
0
def changed_survey_task(user, survey, task, project_cohort_id=None):
    """Behave just the same as project tasks IF notifing org admins."""
    if user.user_type != 'super_admin':
        # The user who took action is an org admin. Suppress these
        # notifications b/c super admins are too busy.
        return
    else:
        # The user who took action is a staff memeber, _do_ notify org admins
        # that we changed something, following rules for project tasks.
        project = Project.get_by_id(survey.project_id)
        changed_project_task(user, project, task, project_cohort_id)
Пример #4
0
    def test_program_admin_create(self):
        program_admin = User.create(email="*****@*****.**",
                                    owned_programs=[self.program_label])
        program_admin.put()

        response = self.testapp.post_json(
            '/api/projects',
            {'organization_id': self.org_id,
             'program_label': self.program_label},
            headers=login_headers(program_admin.uid),
        )
        response_dict = json.loads(response.body)

        self.assertIsNotNone(Project.get_by_id(response_dict['uid']))
Пример #5
0
    def test_user_create(self):
        user = User.create(email="*****@*****.**",
                           owned_organizations=[self.org_id])
        user.put()

        response = self.testapp.post_json(
            '/api/projects',
            {'organization_id': self.org_id,
             'program_label': self.program_label},
            headers=login_headers(user.uid),
        )
        response_dict = json.loads(response.body)

        # Project should exist.
        self.assertIsNotNone(Project.get_by_id(response_dict['uid']))

        # User should own it.
        self.assertIn(response_dict['uid'], user.key.get().owned_projects)

        return (response_dict, user)