Пример #1
0
 def on_get_all(self, req: Request, resp: Response):
     token = req.get_param('token', required=True)
     user_data = get_user_data(token)
     if not is_site_admin(user_data, self.uowm):
         raise HTTPUnauthorized(
             f'Not authorized to make this request',
             f'You are not authorized to make this request')
     with self.uowm.start() as uow:
         templates = uow.config_message_template.get_all()
         resp.body = json.dumps([temp.to_dict() for temp in templates])
Пример #2
0
 def on_delete_potential(self, req: Request, resp: Response, id: int):
     token = req.get_param('token', required=True)
     user_data = get_user_data(token)
     if not is_site_admin(user_data, self.uowm):
         raise HTTPUnauthorized(f'Not authorized to make this request',
                                f'You are not authorized to make this request')
     with self.uowm.start() as uow:
         template = uow.meme_template_potential.get_by_id(id)
         if not template:
             raise HTTPNotFound(title=f'Unable to find template with ID {id}',
                                description=f'Unable to find template with ID {id}')
         uow.meme_template_potential.remove(template)
         uow.commit()
Пример #3
0
 def on_get(self, req: Request, resp: Response, id: int):
     token = req.get_param('token', required=True)
     user_data = get_user_data(token)
     if not is_site_admin(user_data, self.uowm):
         raise HTTPUnauthorized(
             f'Not authorized to make this request',
             f'You are not authorized to make this request')
     with self.uowm.start() as uow:
         template = uow.config_message_template.get_by_id(id)
         if not template:
             raise HTTPNotFound(
                 title=f'Message template {id} not found',
                 description=f'Unable to find message template with ID {id}'
             )
         resp.body = json.dumps(template.to_dict())
Пример #4
0
 def on_delete(self, req: Request, resp: Response, subreddit: Text):
     token = req.get_param('token', required=True)
     user_data = get_user_data(token)
     if not is_site_admin(user_data, self.uowm):
         raise HTTPUnauthorized(
             f'Not authorized to make this request',
             f'You are not authorized to make this request')
     with self.uowm.start() as uow:
         sub = uow.monitored_sub.get_by_sub(subreddit)
         if not sub:
             raise HTTPNotFound(
                 title=f'Subreddit {subreddit} Not Found',
                 description=f'Subreddit {subreddit} Not Found')
         uow.monitored_sub.remove(sub)
         uow.commit()
Пример #5
0
 def on_post(self, req: Request, resp: Response):
     token = req.get_param('token', required=True)
     user_data = get_user_data(token)
     raw = json.load(req.bounded_stream)
     if not is_site_admin(user_data, self.uowm):
         raise HTTPUnauthorized(
             f'Not authorized to make this request',
             f'You are not authorized to make this request')
     with self.uowm.start() as uow:
         new_template = ConfigMessageTemplate(
             template_name=raw['template_name'],
             template=raw['template'],
             template_slug=raw['template_slug'])
         uow.config_message_template.add(new_template)
         try:
             resp.body = json.dumps(new_template.to_dict())
             uow.commit()
         except IntegrityError as e:
             raise HTTPInternalServerError(
                 title='Failed to save message template',
                 description=str(e))