def delete(self, user_id): if user_id == self.owner: for participation in self._members: db.session.delete(participation) db.session.delete(self) db.session.commit() else: raise Unauthorized("User with id {} is not the owner of this course".format(user_id))
def login(): user_info = flask.request.json found_user = user.User.check_password( user_info["email"], user_info["password"].encode('utf-8')) if not found_user: raise Unauthorized('Invalid email or password', status_code=401) found_user.generate_session_token() db.session.commit() return found_user.serialize()
def update_course(self, user_id, data, id): course = self.get_course_by_id(id) if course.owner_id != user_id: raise Unauthorized("User with id {} is not owner of this course".format(user_id)) if "problems" in data: problems = data.get('problems') problems = [self.problem_service.get_problem_by_key(key) for key in problems] course._problems = problems course.update(data) return course
def post(self): user_id = get_jwt_identity() data = request.get_json() pr_id = data.get('id') action = data.get('action') if self.user_service.check_admin(user_id): if action == self.ACCEPT_ACTION: return self.problem_service.accept_publish_request(pr_id) elif action == self.DECLINE_ACTION: return self.problem_service.decline_publish_request(pr_id) else: raise BadRequest("'{}' action is not valid".format(action)) else: raise Unauthorized("User with id {} is not admin".format(user_id))
def order_status(id_, exchange=TEST_EXCHANGE, stock=TEST_STOCK): ''' :param id_: the order id :param exchange: a string with the exchange name (case sesitive). \ Defaults to :py:data:`TEST_EXCHANGE`. :param stock: a string with the stock name (case sensitive) which must be traded in the \ exchange. Defaults to :py:data:`TEST_STOCK`. :rtype: :py:class:`Order` :return: The deserialized json response as a schematics object Retrieves the order status for the specified order on the given exchange. ''' sc, json = _make_request('/venues/{}/stocks/{}/orders/{}'.format( exchange, stock, id_)) if sc == 401: raise Unauthorized(sc, json) return Order(json)
def decorated_function(*args, **kwargs): req_key = flask.request.headers.get('x-api-key') if not any(req_key == s for s in valid_api_keys): raise Unauthorized('Unauthorized', 401) return f(*args, **kwargs)