Exemplo n.º 1
0
 def post(self, request, **kwargs):
     decision = get_object_or_404(Decision, **kwargs)
     if not DecisionAccess(request.user, decision).can_collapse:
         raise exceptions.PermissionDenied(
             _("You don't have an access to collapse reports"))
     collapse_reports(decision)
     return Response({})
Exemplo n.º 2
0
 def get_context_data(self, **kwargs):
     try:
         decision1 = Decision.objects.select_related('job').get(
             id=self.kwargs['decision1_id'])
         decision2 = Decision.objects.select_related('job').get(
             id=self.kwargs['decision2_id'])
     except Job.DoesNotExist:
         raise BridgeException(code=405)
     if not DecisionAccess(self.request.user, decision1).can_view or \
             not DecisionAccess(self.request.user, decision2).can_view:
         raise BridgeException(code=401)
     return {
         'decision1': decision1,
         'decision2': decision2,
         'data': CompareFileSet(decision1, decision2).data
     }
Exemplo n.º 3
0
 def check_object_permissions(self, request, obj):
     super().check_object_permissions(request, obj)
     if not DecisionAccess(request.user, obj).can_clear_verifier_files:
         self.permission_denied(
             request,
             message=_(
                 "You can't clear verifier input files of this decision"))
Exemplo n.º 4
0
 def get_context_data(self, **kwargs):
     if not DecisionAccess(self.request.user, self.object).can_copy:
         raise BridgeException(
             _("You don't have an access to copy job version"))
     context = super(DecisionCopyFormPage, self).get_context_data(**kwargs)
     decision_files = json.dumps(JSTreeConverter().make_tree(
         list(
             FileSystem.objects.filter(decision=self.object).values_list(
                 'name', 'file__hash_sum'))),
                                 ensure_ascii=False)
     context.update({
         'job':
         self.object.job,
         'unique_name':
         get_unique_decision_name(self.object.job),
         'cancel_url':
         reverse('jobs:decision', args=[self.object.id]),
         'files_data':
         decision_files,
         'start_data':
         StartDecisionData(self.request.user,
                           self.object.job,
                           base_decision=self.object)
     })
     return context
Exemplo n.º 5
0
 def get_generator(self):
     decision = self.get_object()
     if not DecisionAccess(self.request.user,
                           decision).can_download_verifier_files:
         raise BridgeException(code=400)
     if 'filters' not in self.request.GET:
         raise BridgeException()
     return FilesForCompetitionArchive(
         decision, json.loads(self.request.GET['filters']))
Exemplo n.º 6
0
 def get_context_data(self, **kwargs):
     if not DecisionAccess(self.request.user, self.object).can_restart:
         raise BridgeException(
             _("You don't have an access to restart this decision"))
     context = super(DecisionRestartPage, self).get_context_data(**kwargs)
     context['start_data'] = StartDecisionData(self.request.user,
                                               self.object.job,
                                               base_decision=self.object)
     return context
Exemplo n.º 7
0
 def post(self, request, **kwargs):
     with transaction.atomic():
         decision = get_object_or_404(Decision.objects.select_for_update(),
                                      **kwargs)
         if not DecisionAccess(request.user, decision).can_stop:
             raise exceptions.PermissionDenied(
                 _("You don't have an access to stop this decision"))
         cancel_decision(decision)
     decision_status_changed(decision)
     # If there are a lot of tasks that are not still deleted it could be too long
     # as there is request to DB for each task here (pre_delete signal)
     decision.tasks.all().delete()
     return Response({})
Exemplo n.º 8
0
 def get_context_data(self, **kwargs):
     if not DecisionAccess(self.request.user, self.object).can_restart:
         raise BridgeException(
             _("You don't have an access to restart this decision"))
     context = super(DecisionRestartPage, self).get_context_data(**kwargs)
     other_decisions = Decision.objects.filter(job=self.object.job).order_by('id') \
         .exclude(status=DECISION_STATUS[0][0]).only('id', 'title', 'start_date')
     context.update({
         'start_data':
         StartDecisionData(self.request.user, base_decision=self.object),
         'other_decisions':
         other_decisions
     })
     return context
Exemplo n.º 9
0
 def get_generator(self):
     instance = self.get_object()
     decisions_ids = self.request.GET.getlist('decision')
     if decisions_ids:
         for decision in Decision.objects.filter(
                 job=instance, id__in=decisions_ids).select_related('job'):
             if not DecisionAccess(self.request.user,
                                   decision).can_download:
                 raise BridgeException(code=408,
                                       back=reverse('jobs:job',
                                                    args=[instance.id]))
         return JobArchiveGenerator(instance, decisions_ids)
     if not JobAccess(self.request.user, instance).can_download:
         raise BridgeException(code=400,
                               back=reverse('jobs:job', args=[instance.id]))
     return JobArchiveGenerator(instance)
Exemplo n.º 10
0
def get_jobs_to_download(user, job_ids, decision_ids):
    jobs_qs_filter = Q()
    if job_ids:
        jobs_qs_filter |= Q(id__in=job_ids)
    if decision_ids:
        jobs_qs_filter |= Q(decision__id__in=decision_ids)
    if not jobs_qs_filter:
        raise BridgeException(
            _("Please select jobs or/and decisions you want to download"),
            back=reverse('jobs:tree'))

    # Collect selected jobs
    jobs_to_download = {}
    for job in Job.objects.filter(jobs_qs_filter):
        jobs_to_download[job.id] = {'instance': job, 'decisions': []}

    if not jobs_to_download:
        raise BridgeException(_("Jobs were not found"),
                              back=reverse('jobs:tree'))

    # Collect selected decisions
    for decision in Decision.objects.filter(
            pk__in=decision_ids).select_related('job'):
        if decision.job_id not in jobs_to_download:
            # Unexpected behavior
            continue
        jobs_to_download[decision.job_id]['decisions'].append(decision.id)
        if not DecisionAccess(user, decision).can_download:
            raise BridgeException(
                _("You don't have an access to one of the selected decisions"),
                back=reverse('jobs:tree'))

    # Check access to jobs without any selected decision (all decisions will be downloaded)
    for job_id in jobs_to_download:
        if not jobs_to_download[job_id]['decisions']:
            if not JobAccess(
                    user, jobs_to_download[job_id]['instance']).can_download:
                raise BridgeException(
                    _("You don't have an access to one of the selected jobs"),
                    back=reverse('jobs:tree'))
    return jobs_to_download
Exemplo n.º 11
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        # Decision access
        context['access'] = DecisionAccess(self.request.user, self.object)
        if not context['access'].can_view:
            raise PermissionDenied(
                _("You don't have an access to this decision"))

        # Decision files
        context['files'] = json.dumps(JSTreeConverter().make_tree(
            list(
                FileSystem.objects.filter(decision=self.object).values_list(
                    'name', 'file__hash_sum'))),
                                      ensure_ascii=False)

        # Other job decisions
        context['other_decisions'] = Decision.objects.filter(job=self.object.job)\
            .exclude(id=self.object.id).exclude(status=DECISION_STATUS[0][0])\
            .select_related('configuration').order_by('-start_date')

        # Decision progress and core report link
        context['progress'] = ProgressSerializerRO(instance=self.object,
                                                   context={
                                                       'request': self.request
                                                   }).data
        context['core_link'] = get_core_link(self.object)

        # Decision coverages
        context['Coverage'] = DecisionCoverageStatistics(self.object)

        context['parents'] = self.object.job.preset.get_ancestors(
            include_self=True)

        # Verification results
        context['reportdata'] = ViewJobData(self.request.user,
                                            self.get_view(VIEW_TYPES[2]),
                                            self.object)

        return context
Exemplo n.º 12
0
 def has_object_permission(self, request, view, obj):
     if isinstance(obj, Job):
         return JobAccess(request.user, obj).can_delete
     elif isinstance(obj, Decision):
         return DecisionAccess(request.user, obj).can_delete
     return True
Exemplo n.º 13
0
 def perform_destroy(self, instance):
     if not DecisionAccess(self.request.user, instance).can_delete:
         self.permission_denied(self.request,
                                message=_("You can't remove this decision"))
     super().perform_destroy(instance)
Exemplo n.º 14
0
 def check_object_permissions(self, request, obj):
     super().check_object_permissions(request, obj)
     if not DecisionAccess(request.user, obj).can_restart:
         self.permission_denied(
             request, _("You don't have an access to restart the decision"))
Exemplo n.º 15
0
 def check_object_permissions(self, request, obj):
     super(RenameDecisionView, self).check_object_permissions(request, obj)
     if not DecisionAccess(request.user, obj).can_rename:
         self.permission_denied(
             request, _("You don't have an access to rename the decision"))