def put(self, id): """PUT :param id: User's id to find. :return: Persisted user's base informations as JSON or error. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if get_jwt_identity() != id and ( not services_user.check_if_user_is_admin( get_jwt_identity())): abort(401) if not request.json: abort(400) user = services_user.select_user(id) [ user.__setattr__(key, value) for key, value in self.reqparse.parse_args().items() if value is not None ] return { 'user': marshal(services_user.update_user(user), services_user.user_fields) } raise MethodVersionNotFound()
def delete(self, id): """DELETE :param id: User's id to find. :return: True if elimination was successful or False if elimination was not possible. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if get_jwt_identity() != id and ( not services_user.check_if_user_is_admin( get_jwt_identity())): abort(401) return {'result': services_user.delete_user(id)} raise MethodVersionNotFound()
def get(self): """GET :return: All users. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if not services_user.check_if_user_is_admin(get_jwt_identity()): abort(401) return { 'users': [ marshal(user, services_user.user_fields) for user in services_user.select_users() ] } raise MethodVersionNotFound()
def get(self, id): """GET :param id: User's id to find. :return: User found as JSON. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if get_jwt_identity() != id and ( not services_user.check_if_user_is_admin( get_jwt_identity())): abort(401) return { 'user': marshal(services_user.select_user(id), services_user.user_fields) } raise MethodVersionNotFound()
def get(self, user_id, _id): """GET :param user_id: User's id to find. :param _id: Notification's id to find. :return: Notification found as JSON. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if get_jwt_identity() != user_id and ( not services_user.check_if_user_is_admin( get_jwt_identity())): abort(401) return { 'notification': marshal( services_notification.select_notification(_id, user_id), services_notification.notification_fields) } raise MethodVersionNotFound()
def get(self, user_id): """GET :param user_id: User's id to find. :return: All notifications. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if get_jwt_identity() != user_id and ( not services_user.check_if_user_is_admin( get_jwt_identity())): abort(401) return { 'notifications': [ marshal(notification, services_notification.notification_fields) for notification in services_notification.select_notifications(user_id) ] } raise MethodVersionNotFound()
def post(self): """POST :return: Persisted user's JSON or error. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if not services_user.check_if_user_is_admin(get_jwt_identity()): abort(401) if not request.json: abort(400) user = { key: value for key, value in self.reqparse.parse_args().items() if value is not None } return { 'user': marshal(services_user.insert_user(user['username']), services_user.user_fields) }, 201 raise MethodVersionNotFound()
def post(self, user_id): """POST :param user_id: User's id to find. :return: Persisted notification's base informations as JSON or error. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if get_jwt_identity() != user_id and ( not services_user.check_if_user_is_admin( get_jwt_identity())): abort(401) if not request.json: abort(400) return { 'notification': marshal( services_notification.insert_notification( request.json, user_id), services_notification.notification_fields) }, 201 raise MethodVersionNotFound()
def put(self, user_id, _id): """PUT :param user_id: User's id to find. :param _id: Notification's id to find. :return: Persisted notification's base informations as JSON or error. """ if request.headers.get('Accept-Version', '1.0') == '1.0': if get_jwt_identity() != user_id and ( not services_user.check_if_user_is_admin( get_jwt_identity())): abort(401) if not request.json: abort(400) result = services_notification.update_notification( _id, request.json, user_id) if not result: return {'result': False} return { 'notification': marshal(result, services_notification.notification_fields) } raise MethodVersionNotFound()