def forbidden(**kw): raise ProcessingException(status=403, detail='forbidden')
def raise_error(**kw): raise ProcessingException(status=500)
def handle400(): return ProcessingException(description=STATUS_MESSAGE.BAD_REQUEST, code=STATUS_CODE.ER_400)
def handle405(): return ProcessingException(description=STATUS_MESSAGE['METHOD_NOT_ALLOWED'], code=STATUS_CODE['ER_405'])
def handle401(): return ProcessingException(description=STATUS_MESSAGE.NOT_AUTHORIZED, code=STATUS_CODE.ER_401)
def handle405(): return ProcessingException(description=STATUS_MESSAGE.METHOD_NOT_ALLOWED, code=STATUS_CODE.ER_405)
def auth_admin_func(instance_id=None, **kwargs): current_user = get_jwt_identity() if not current_user == "jim": raise ProcessingException(description='Only admins can access this view', code=401)
def preprocessors_check_adm_or_normal_user(instance_id=None, **kargs): if not (current_user.is_admin or current_user.username == instance_id): raise ProcessingException(description='Forbidden', code=403)
def is_auth_to_app_edit(*args, **kw): if not current_user.group.app_edit_all: raise ProcessingException(description='Not authenticated!', code=401)
def is_auth_to_user_drop(*args, **kw): if not current_user.group.user_drop: raise ProcessingException(description='Not authenticated!', code=401)
def auth_func(*args, **kw): if not login_fresh() and not current_user.is_authenticated: if not 'user' in session: raise ProcessingException(description='Not authenticated!', code=401)
def handle401(): return ProcessingException(description=STATUS_MESSAGE['NOT_AUTHORIZED'], code=STATUS_CODE['ER_401'])
def handle400(): return ProcessingException(description=STATUS_MESSAGE['BAD_REQUEST'], code=STATUS_CODE['ER_400'])
def auth(*args, **kargs): """ Required API request to be authenticated """ if not current_user.is_authenticated: raise ProcessingException(description='Not authenticated', code=401)
def auth_func(**kw): '''Ensures api users are authenticated.''' if not current_user.is_authenticated: raise ProcessingException(description='Not Authorized', code=401)
def preprocessor_check_adm(*args, **kargs): if not current_user.is_admin: raise ProcessingException(description='Forbidden', code=403)
def auth_func(**kw): if not current_user.is_authenticated: raise ProcessingException(description='Not Authorized', code=401)
def is_authorized(self, user, obj): if user.id != obj.user_id: raise ProcessingException(description='Not Authorized', code=401)
def auth_request(**kw): if not current_user.is_authenticated: user = load_user_from_request(request) if not user: raise ProcessingException(description='Not Authorized', status=401)
def handle404(): return ProcessingException(description=STATUS_MESSAGE.NOT_FOUND, code=STATUS_CODE.ER_404)
def check(description, amount, content): if (not description) or (not amount) or (not content): raise ProcessingException(description='Tositteista puuttuu tietoja.')
def handle500(): return ProcessingException( description=STATUS_MESSAGE.INTERNAL_SERVER_ERROR, code=STATUS_CODE.ER_500)
def authenticate(*args, **kwargs): if not current_user.is_authenticated: raise ProcessingException(description='Not authenticated', code=401)
def delete_preprocessor(self, instance_id=None, **kw): try: article = ArticleController(current_user.id).get(id=instance_id) except NotFound: raise ProcessingException(description='No such article.', code=404) self.is_authorized(current_user, article)
def handle404(): return ProcessingException(description=STATUS_MESSAGE['NOT_FOUND'], code=STATUS_CODE['ER_404'])