Beispiel #1
0
    def clean(self):
        task = self.cleaned_data['task']
        assignee = self.cleaned_data.get('assignee', -1)

        if assignee != -1:
            # There are a bunch of edge cases here that we need to check.
            unassigning_from_self = (
                not assignee
            ) and task.assignee and task.assignee.id == self.user.id
            assigning_to_self = assignee and self.user.id == assignee.id
            can_assign_to_other_people = can_assign_task(task, self.user)

            # Users can always unassign a task from themselves.
            if not unassigning_from_self:
                # They can also assign a task TO themselves, assuming they can
                # perform it (which is checked further down).
                if not assigning_to_self:
                    # Otherwise they must have assign permissions in the team.
                    if not can_assign_to_other_people:
                        raise forms.ValidationError(
                            _(u'You do not have permission to assign this task.'
                              ))

            if assignee is None:
                return self.cleaned_data
            else:
                if not can_perform_task(assignee, task):
                    raise forms.ValidationError(
                        _(u'This user cannot perform that task.'))

        return self.cleaned_data
Beispiel #2
0
    def clean_task(self):
        task = self.cleaned_data['task']

        if not can_perform_task(self.user, task):
            raise forms.ValidationError(_(u'You cannot perform that task.'))

        if task.team_video.video_id != self.video.id:
            raise forms.ValidationError(_(u'Mismatched video and task!'))

        return task
Beispiel #3
0
def _get_related_task(request):
    """
    Checks if request has t=[task-id], and if so checks if the current
    user can perform it, in case all goes well, return the task to be
    performed.
    """
    task_pk = request.GET.get('t', None)
    if task_pk:
        from teams.permissions import can_perform_task
        try:
            task = Task.objects.get(pk=task_pk)
            if can_perform_task(request.user, task):
                return task
        except Task.DoesNotExist:
            return
Beispiel #4
0
    def _verify_no_blocking_subtitle_translate_tasks(self, team_video,
                                                     language_code):
        tasks = list(
            team_video.task_set.incomplete_subtitle_or_translate().filter(
                language__in=[language_code, '']))[:1]

        if tasks:
            task = tasks[0]

            # If this language is already assigned to someone else, fail.
            if (task.assignee and task.assignee != self.user):
                raise forms.ValidationError(
                    _(u"Sorry, we can't upload your subtitles because another "
                      u"user is already assigned to this language."))

            # If this language is unassigned, and the user can't assign herself
            # to it, fail.
            if (not task.assignee and not can_perform_task(self.user, task)):
                raise forms.ValidationError(
                    _(u"Sorry, we can't upload your subtitles because you do not "
                      u"have permission to claim this language."))
Beispiel #5
0
    def assign_task_for_editor(self):
        """Try to assign any unassigned tasks to our user.

        If we can't assign the task, return False.
        """
        if self.team_video is None:
            return True
        task_set = self.team_video.task_set.incomplete().filter(
            language=self.language_code)
        tasks = list(task_set[:1])
        if tasks:
            task = tasks[0]
            if task.assignee is None and can_perform_task(self.user, task):
                task.assignee = self.user
                task.set_expiration()
                task.save()

            if task.assignee != self.user:
                msg = fmt(_("Another user is currently performing "
                            "the %(task_type)s task for these subtitles"),
                          task_type=task.get_type_display())
                messages.error(self.request, msg)
                return False
        return True