def Post(self): # Pull out the Job ID and reason in the request. args = self.request.params.mixed() job_id = args.get('job_id') reason = args.get('reason') if not job_id or not reason: raise api_request_handler.BadRequestError() job = job_module.JobFromId(job_id) if not job: raise api_request_handler.NotFoundError() # Enforce first that only the users that started the job and administrators # can cancel jobs. email = utils.GetEmail() if not utils.IsAdministrator() and email != job.user: raise api_request_handler.ForbiddenError() # Truncate the reason down to 255 caracters including ellipses. try: job.Cancel(email, reason[:252] + '...' if len(reason) > 255 else reason) return {'job_id': job.job_id, 'state': 'Cancelled'} except errors.CancelError as e: self.response.set_status(400) return {'job_id': job.job_id, 'message': e.message}
def testIsNotAdministrator(self): self.assertFalse(utils.IsAdministrator())
def testIsAdministrator(self): self.assertTrue(utils.IsAdministrator())
def _CheckUser(self): self._CheckIsLoggedIn() if not utils.IsAdministrator(): raise api_request_handler.ForbiddenError()