Exemplo n.º 1
0
        async def process(self, req: Request['InspectDone_POST.Arguments'],
                          user: User) -> None:
            # Fetch and check job and task.
            self.initTask(req)
            job = self.job
            task = self.task
            taskName = task.getName()
            taskRun = task.getLatestRun()
            if not taskRun.isWaitingForInspection():
                raise InvalidRequest(
                    'Given task is not waiting for inspection')

            # Check result and summary.
            result = req.args.result
            if result not in (ResultCode.OK, ResultCode.WARNING,
                              ResultCode.ERROR):
                raise InvalidRequest(f'Invalid inspection result "{result}"')
            summary = req.args.summary

            # Check store permissions.
            checkPrivilegeForOwned(user, 't/m', job)

            # Store mid-level data, if any.
            data = cast(Mapping[str, str], req.args.data)
            if data:
                self.resultStorage.putData(taskName, taskRun.getId(), data)

            # Store inspection result.
            job.inspectDone(taskName, result, summary)
Exemplo n.º 2
0
        async def process(self, req: Request['AbortTask_POST.Arguments'],
                          user: User) -> None:
            # pylint: disable=attribute-defined-outside-init
            jobId = req.args.jobId
            taskName = req.args.taskName
            action = req.args.action

            if action is Actions.CANCEL:
                page = cast(AbortTask_POST, self.page)
                raise Redirect(page.getParentURL(req.args))
            assert action is Actions.ABORT, action

            job = self.jobDB[jobId]
            checkPrivilegeForOwned(user, 't/d', job,
                                   ('abort tasks in this job', 'abort tasks'))
            message: XMLContent
            if taskName == '/all-waiting':
                aborted = job.abortAll(lambda task: task.isWaiting(),
                                       user.name)
                if aborted:
                    message = 'All waiting tasks have been aborted.'
                else:
                    message = 'There were no waiting tasks.'
            elif taskName == '/all':
                aborted = job.abortAll(user=user.name)
                if aborted:
                    message = 'All unfinished tasks have been aborted.'
                else:
                    message = 'There were no unfinished tasks.'
            else:
                result = job.abortTask(taskName, user.name)
                message = 'Task ', xhtml.b[taskName], ' ', result, '.'
            self.message = message
Exemplo n.º 3
0
        async def process(self, req: Request, user: User) -> None:
            page = cast(RecordDelete_GET, getattr(self, 'page'))
            action = req.args.action
            if action is not Actions.DELETE:
                assert action is Actions.CANCEL, action
                raise Redirect(page.getCancelURL(req.args))

            assert isinstance(self, RecordDeleteProcessor), self
            record = fetchRecordForDeletion(self, req.args.id)
            checkPrivilegeForOwned(
                user, self.db.privilegeObject + '/d', record,
                ('delete this ' + self.recordName, 'delete ' + self.denyText))
            self.db.remove(record)
Exemplo n.º 4
0
 async def process(self, req: Request['ScheduleIndex_POST.Arguments'],
                   user: User) -> None:
     actions = cast(Mapping[str, str], req.args.action)
     for scheduleId, action in actions.items():
         # Toggle suspend.
         scheduled = self.scheduleDB.get(scheduleId)
         # TODO: Report when action is not possible, instead of ignoring.
         if scheduled is not None:
             checkPrivilegeForOwned(user, 's/m', scheduled,
                                    ('suspend/resume this schedule',
                                     'suspend/resume schedules'))
             if not scheduled.isDone():
                 scheduled.setSuspend(action is Actions.SUSPEND)
     raise Redirect(
         pageURL('ScheduleIndex',
                 ScheduleIndex_GET.Arguments.subset(req.args)))
Exemplo n.º 5
0
 async def process(self,
                   req: Request['TriggerSchedule_POST.Arguments'],
                   user: User
                   ) -> None:
     scheduleId = req.args.scheduleId
     try:
         schedule = self.scheduleDB[scheduleId]
     except KeyError:
         raise InvalidRequest(
             f'Schedule "{scheduleId}" does not exist'
             )
     checkPrivilegeForOwned(
         user, 's/m', schedule,
         ( f'trigger schedule "{scheduleId}" that is not owned by you',
           'trigger schedules' )
         )
     try:
         schedule.setTrigger()
     except ValueError as ex:
         raise InvalidRequest( str(ex) )
Exemplo n.º 6
0
        async def process(self, req: Request['ConfigTags_POST.Arguments'],
                          user: User) -> None:
            args = req.args
            action = args.action
            if action is not Actions.APPLY:
                assert action is Actions.CANCEL, action
                raise Redirect(args.refererURL or parentPage)

            configDB = self.configDB
            self.notices = []
            self.findConfigs(configDB)
            if self.notices:
                return
            configs = self.configs

            checkPrivilegeForOwned(
                user, 'c/m', configs,
                ('change tags on configurations owned by other users',
                 'change configuration tags'))

            tagkeys = cast(Mapping[str, str], args.tagkeys)
            tagvalues = cast(Mapping[str, str], args.tagvalues)
            commontags = cast(Mapping[str, FrozenSet[str]], args.commontags)

            # Determine changes between the submitted tags and the stored
            # tags.
            additions: Dict[str, AbstractSet[str]] = {}
            removals: Dict[str, AbstractSet[str]] = {}
            for index, tagKey in tagkeys.items():
                storedValues = commontags.get(index, frozenset())
                values = textToValues(tagvalues[index])
                additions[tagKey] = values - storedValues
                removals[tagKey] = storedValues - values

            for config in configs:
                # TODO: Wrap update() call in context manager.
                for tagKey in tagkeys.values():
                    config.tags.updateTags(tagKey, additions[tagKey],
                                           removals[tagKey])
                configDB.update(config)