Ejemplo n.º 1
0
def can_create_any_task_for_teamvideo(context, team_video, user):
    workflows = context.get('team_workflows')

    if can_create_task_subtitle(team_video, user, workflows):
        result = True
    elif can_create_task_translate(team_video, user, workflows):
        result = True
    else:
        result = False

    context['user_can_create_any_task'] = result

    return ''
Ejemplo n.º 2
0
    def test_can_create_task_translate(self):
        team, user, outsider = self.team, self.user, self.outsider

        # When no subtitles exist yet, no translations can be created.
        self.assertEqual(can_create_task_translate(self.nonproject_video), [])

        # Add some sample subtitles.  Now we can create translation tasks
        # (but not to that language, since it's already done).
        _set_subtitles(self.nonproject_video, 'en', True, True)

        langs = can_create_task_translate(self.nonproject_video)

        self.assertEqual(len(langs), TOTAL_LANGS - 1)
        self.assertTrue('en' not in langs)

        # Languages with translations finished can't have new translation tasks.
        _set_subtitles(self.nonproject_video, 'en', True, True, ['fr', 'de'])

        langs = can_create_task_translate(self.nonproject_video)

        self.assertEqual(len(langs), TOTAL_LANGS - 3)
        self.assertTrue('en' not in langs)
        self.assertTrue('fr' not in langs)

        # Test role restrictions.
        _set_subtitles(self.nonproject_video, 'en', True, True, ['fr'])

        # Any team member.
        team.task_assign_policy = Team.TASK_ASSIGN_IDS['Any team member']
        team.save()

        for r in [ROLE_CONTRIBUTOR, ROLE_MANAGER, ROLE_ADMIN, ROLE_OWNER]:
            with self.role(r):
                langs = can_create_task_translate(self.nonproject_video, user)

                self.assertEqual(len(langs), TOTAL_LANGS - 2)
                self.assertTrue('en' not in langs)
                self.assertTrue('fr' not in langs)

        langs = can_create_task_translate(self.nonproject_video, outsider)
        self.assertEqual(langs, [])

        # Managers+
        team.task_assign_policy = Team.TASK_ASSIGN_IDS['Managers and admins']
        team.save()

        for r in [ROLE_MANAGER, ROLE_ADMIN, ROLE_OWNER]:
            with self.role(r):
                langs = can_create_task_translate(self.nonproject_video, user)

                self.assertEqual(len(langs), TOTAL_LANGS - 2)
                self.assertTrue('en' not in langs)
                self.assertTrue('fr' not in langs)

        for r in [ROLE_CONTRIBUTOR]:
            with self.role(r):
                langs = can_create_task_translate(self.nonproject_video, user)
                self.assertEqual(langs, [])

        for r in [ROLE_MANAGER, ROLE_ADMIN]:
            with self.role(r, self.test_project):
                langs = can_create_task_translate(self.nonproject_video, user)
                self.assertEqual(langs, [])

        langs = can_create_task_translate(self.nonproject_video, outsider)
        self.assertEqual(langs, [])

        # Admins+
        team.task_assign_policy = Team.TASK_ASSIGN_IDS['Admins only']
        team.save()

        for r in [ROLE_ADMIN, ROLE_OWNER]:
            with self.role(r):
                langs = can_create_task_translate(self.nonproject_video, user)

                self.assertEqual(len(langs), TOTAL_LANGS - 2)
                self.assertTrue('en' not in langs)
                self.assertTrue('fr' not in langs)

        for r in [ROLE_CONTRIBUTOR, ROLE_MANAGER]:
            with self.role(r):
                langs = can_create_task_translate(self.nonproject_video, user)
                self.assertEqual(langs, [])

        for r in [ROLE_ADMIN]:
            with self.role(r, self.test_project):
                langs = can_create_task_translate(self.nonproject_video, user)
                self.assertEqual(langs, [])

        langs = can_create_task_translate(self.nonproject_video, outsider)
        self.assertEqual(langs, [])