Esempio n. 1
0
 def get(self, id):
     '''This method receives an ID from an user and returns the user'''
     if Commons.isValidId(id) and auth.isAuthorized(id):
         user = User.objects(id=id)
         return Commons.notFound('user') if Commons.checkIfNotExists(
             user) else make_response(jsonify({'data': user}), 201)
     return auth.unauthorized()
Esempio n. 2
0
 def get(self, id):
     if Commons.isValidId(id):
         pages = Page.objects(categoryId=id)
         if Commons.checkIfNotExists(pages):
             return Commons.notFound('page')
         if auth.isAuthorized(pages[0].userId):
             return make_response(jsonify({'data': pages}), 201)
     return auth.unauthorized()
Esempio n. 3
0
 def delete(self, id):
     '''This method receives an ID from an user and deletes the user'''
     if Commons.isValidId(id) and auth.isAuthorized(id):
         user = User.objects(id=id)
         if Commons.checkIfNotExists(user):
             return Commons.notFound('user')
         user.delete()
         return make_response(jsonify({'data': 'User was deleted'}), 201)
     return auth.unauthorized()
Esempio n. 4
0
 def get(self, id):
     '''This method receives an ID from an category and returns the category'''
     if Commons.isValidId(id):
         category = Category.objects(id=id)
         if Commons.checkIfNotExists(category):
             return Commons.notFound('category')
         if auth.isAuthorized(category[0].userId):
             return make_response(jsonify({'data': category}), 201)
     return auth.unauthorized()
Esempio n. 5
0
 def get(self, id):
     '''This method receives an ID from an page and returns the page'''
     if Commons.isValidId(id):
         page = Page.objects(id=id)
         if Commons.checkIfNotExists(page):
             return Commons.notFound('page')
         if auth.isAuthorized(page[0].userId):
             Page.objects(id=id).update(views=page[0].views + 1)
             return make_response(jsonify({'data': page}), 201)
     return auth.unauthorized()
Esempio n. 6
0
 def delete(self, id):
     '''This method receives an ID from an page and deletes the page'''
     if Commons.isValidId(id):
         page = Page.objects(id=id)
         if Commons.checkIfNotExists(page):
             return Commons.notFound('page')
         if auth.isAuthorized(page[0].userId):
             page.delete()
             return make_response(jsonify({'data': 'Page was deleted'}),
                                  201)
     return auth.unauthorized()
Esempio n. 7
0
 def put(self, id):
     '''This method receives an ID from an user and updates the user'''
     params = self.reqparse.parse_args()
     if Commons.isValidId(id) and auth.isAuthorized(id):
         if Commons.checkIfNotExists(User.objects(id=id)):
             return Commons.notFound('user')
         data = commons.filterQueryParams(params)
         if data.has_key('password'):
             data['password'] = auth.hash_password(data['password'])
         User.objects(id=id).update_one(upsert=False,
                                        write_concern=None,
                                        **data)
         return make_response(jsonify({'data': 'User info updated'}), 201)
     return auth.unauthorized()
Esempio n. 8
0
 def put(self, id):
     '''This method receives an ID from an category and updates the category'''
     if Commons.isValidId(id):
         category = Category.objects(id=id)
         if Commons.checkIfNotExists(category):
             return Commons.notFound('category')
         if auth.isAuthorized(category[0].userId):
             params = Commons.filterQueryParams(self.reqparse.parse_args())
             Category.objects(id=id).update_one(upsert=False,
                                                write_concern=None,
                                                **params)
             return make_response(jsonify({'data': 'Category updated'}),
                                  201)
     return auth.unauthorized()
Esempio n. 9
0
 def put(self, id):
     '''This method receives an ID from an page and updates the page'''
     params = self.reqparse.parse_args()
     if Commons.isValidId(id):
         page = Page.objects(id=id)
         if Commons.checkIfNotExists(page):
             return Commons.notFound('page')
         if auth.isAuthorized(page[0].userId):
             data = Commons.filterQueryParams(params)
             Page.objects(id=id).update_one(upsert=False,
                                            write_concern=None,
                                            **data)
             return make_response(jsonify({'data': 'Page updated'}), 201)
     return auth.unauthorized()
Esempio n. 10
0
 def post(self):
     '''This method creates a new page related to an user'''
     params = self.reqparse.parse_args()
     if Commons.isValidId(params['categoryId']):
         Page(title=params['title'],
              url=params['url'],
              categoryId=params['categoryId'],
              userId=auth.user['id']).save()
         return make_response(jsonify({'data': 'Page created'}), 201)
     return make_response(jsonify({'error': 'Invalid categoryId'}), 500)
Esempio n. 11
0
 def get(self):
     users = User.objects.all() if auth.isAdmin() else User.objects(
         id=auth.user['id'])
     return Commons.notFound('user') if Commons.checkIfNotExists(
         users) else make_response(jsonify({'data': users}), 201)
Esempio n. 12
0
 def get(self):
     '''This method returns all categories from an user'''
     categories = Category.objects.all() if auth.isAdmin(
     ) else Category.objects(userId=auth.user['id'])
     return Commons.notFound('category') if Commons.checkIfNotExists(
         categories) else make_response(jsonify({'data': categories}), 201)
Esempio n. 13
0
 def get(self):
     '''This method returns all pages from an user'''
     pages = Page.objects.all() if auth.isAdmin() else Page.objects(
         userId=auth.user['id'])
     return Commons.notFound('page') if Commons.checkIfNotExists(
         pages) else make_response(jsonify({'data': pages}), 201)