def create_model(self, data): """ create a new job from given data """ user = auth.get_current_user() job = self.model_cls(user_email=user.email(), user_id=user.user_id()) self._set_model_data(job, data) job.put() logging.debug(u'created Job {} for {}'.format(job.key, job.user_email)) self.response_json(job)
def create_model(self, data): """ create a new model from given data """ user = auth.get_current_user() job = self.model_cls(user_id=user.user_id()) self._set_model_data(job, data) job.put() logging.debug('created Model {}'.format(job.key)) self.response_json(job)
def get_model(self, id): try: id = int(id) except ValueError: raise HTTPBadRequest('invalid job id') user = auth.get_current_user() model = self.model_cls.get_by_id(id) if model is None: raise HTTPNotFound() if model.user_id != user.user_id(): raise HTTPForbidden() return model
def get(self, id=None): if id is not None: return self.response_json(self.get_model(id)) else: user = auth.get_current_user() # ignore ids > 100 try: ids = [int(id) for id in self.request.GET.getall('id')[0:100]] except ValueError: raise HTTPBadRequest() job_futures = [self.model_cls.get_by_id_async(id) for id in ids] jobs = [future.get_result() for future in job_futures] jobs = filter(None, jobs) if any(job.user_id != user.user_id() for job in jobs): raise HTTPForbidden() return self.response_json(jobs)
def post(self, id): job = models.RemindJob.get_by_id(int(id)) user = auth.get_current_user() if job is None: raise HTTPNotFound() if job.user_id != user.user_id(): raise HTTPForbidden() if job.state != 'scheduled': logging.warn('check_reply for non-scheduled job not possible') raise HTTPBadRequest() reply = validation.disabled_reply_schema(self.json) job.disabled_reply = models.DisabledReply( message_id=reply['messageId'], from_name=reply['fromName'], from_email=reply['fromEmail']) job.add_to_check_reply_queue() self.response_json(None)
def get(self): user = auth.get_current_user() account_future = models.Account.get_by_id_async(user.user_id()) send_jobs_future = models.SendJob.query_display( user.user_id()).fetch_async() remind_jobs_future = models.RemindJob.query_display( user.user_id()).fetch_async() snippets_future = models.Snippet.query_display( user.user_id()).fetch_async() account = account_future.get_result() if account is None: self.response_json({'auth': 'need_code'}) return self.response_json( {'sendJobs': send_jobs_future.get_result(), 'remindJobs': remind_jobs_future.get_result(), 'snippets': snippets_future.get_result()})
def get(self): user = auth.get_current_user() account_future = models.Account.get_by_id_async(user.user_id()) send_jobs_future = models.SendJob.query_display( user.user_id()).fetch_async() remind_jobs_future = models.RemindJob.query_display( user.user_id()).fetch_async() snippets_future = models.Snippet.query_display( user.user_id()).fetch_async() account = account_future.get_result() if account is None: self.response_json({'auth': 'need_code'}) return self.response_json({ 'sendJobs': send_jobs_future.get_result(), 'remindJobs': remind_jobs_future.get_result(), 'snippets': snippets_future.get_result() })