Merge branch 'master' into request-creator-name

This commit is contained in:
richard-dds
2018-08-08 15:28:36 -04:00
committed by GitHub
12 changed files with 145 additions and 29 deletions

View File

@@ -14,3 +14,17 @@ class AlreadyExistsError(Exception):
@property
def message(self):
return "{} already exists".format(self.resource_name)
class UnauthorizedError(Exception):
def __init__(self, user, action):
self.user = user
self.action = action
@property
def message(self):
return "User {} not authorized to {}".format(self.user.id, self.action)
class UnauthenticatedError(Exception):
pass

View File

@@ -1,4 +1,4 @@
from sqlalchemy import exists, and_
from sqlalchemy import exists, and_, exc
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.orm.attributes import flag_modified
@@ -42,11 +42,14 @@ class Requests(object):
@classmethod
def exists(cls, request_id, creator_id):
return db.session.query(
exists().where(
and_(Request.id == request_id, Request.creator == creator_id)
)
).scalar()
try:
return db.session.query(
exists().where(
and_(Request.id == request_id, Request.creator == creator_id)
)
).scalar()
except exc.DataError:
return False
@classmethod
def get(cls, request_id):