mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
more
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
from datetime import timedelta
|
||||
|
||||
from sqlalchemy import func, or_
|
||||
from sqlalchemy import func, or_, select
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import autocommit, version_class
|
||||
@@ -23,16 +23,26 @@ def save_model_api_key(api_key):
|
||||
@autocommit
|
||||
@version_class(ApiKey)
|
||||
def expire_api_key(service_id, api_key_id):
|
||||
api_key = ApiKey.query.filter_by(id=api_key_id, service_id=service_id).one()
|
||||
api_key = (
|
||||
db.session.execute(
|
||||
select(ApiKey).filter_by(id=api_key_id, service_id=service_id)
|
||||
)
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
api_key.expiry_date = utc_now()
|
||||
db.session.add(api_key)
|
||||
|
||||
|
||||
def get_model_api_keys(service_id, id=None):
|
||||
if id:
|
||||
return ApiKey.query.filter_by(
|
||||
id=id, service_id=service_id, expiry_date=None
|
||||
).one()
|
||||
return (
|
||||
db.session.execute(
|
||||
select(ApiKey).filter_by(id=id, service_id=service_id, expiry_date=None)
|
||||
)
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
seven_days_ago = utc_now() - timedelta(days=7)
|
||||
return ApiKey.query.filter(
|
||||
or_(
|
||||
@@ -47,7 +57,13 @@ def get_unsigned_secrets(service_id):
|
||||
"""
|
||||
This method can only be exposed to the Authentication of the api calls.
|
||||
"""
|
||||
api_keys = ApiKey.query.filter_by(service_id=service_id, expiry_date=None).all()
|
||||
api_keys = (
|
||||
db.session.execute(
|
||||
select(ApiKey).filter_by(service_id=service_id, expiry_date=None)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
keys = [x.secret for x in api_keys]
|
||||
return keys
|
||||
|
||||
@@ -56,5 +72,9 @@ def get_unsigned_secret(key_id):
|
||||
"""
|
||||
This method can only be exposed to the Authentication of the api calls.
|
||||
"""
|
||||
api_key = ApiKey.query.filter_by(id=key_id, expiry_date=None).one()
|
||||
api_key = (
|
||||
db.session.execute(select(ApiKey).filter_by(id=key_id, expiry_date=None))
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
return api_key.secret
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from app import db
|
||||
from app.models import InvitedOrganizationUser
|
||||
from app.utils import utc_now
|
||||
@@ -11,19 +13,35 @@ def save_invited_org_user(invited_org_user):
|
||||
|
||||
|
||||
def get_invited_org_user(organization_id, invited_org_user_id):
|
||||
return InvitedOrganizationUser.query.filter_by(
|
||||
organization_id=organization_id, id=invited_org_user_id
|
||||
).one()
|
||||
return (
|
||||
db.session.execute(
|
||||
select(InvitedOrganizationUser).filter_by(
|
||||
organization_id=organization_id, id=invited_org_user_id
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
|
||||
|
||||
def get_invited_org_user_by_id(invited_org_user_id):
|
||||
return InvitedOrganizationUser.query.filter_by(id=invited_org_user_id).one()
|
||||
return (
|
||||
db.session.execute(
|
||||
select(InvitedOrganizationUser).filter_by(id=invited_org_user_id)
|
||||
)
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
|
||||
|
||||
def get_invited_org_users_for_organization(organization_id):
|
||||
return InvitedOrganizationUser.query.filter_by(
|
||||
organization_id=organization_id
|
||||
).all()
|
||||
return (
|
||||
db.session.execute(
|
||||
select(InvitedOrganizationUser).filter_by(organization_id=organization_id)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
|
||||
def delete_org_invitations_created_more_than_two_days_ago():
|
||||
|
||||
@@ -3,7 +3,7 @@ from app.dao.dao_utils import autocommit, version_class
|
||||
from app.enums import CallbackType
|
||||
from app.models import ServiceCallbackApi
|
||||
from app.utils import utc_now
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
@autocommit
|
||||
@version_class(ServiceCallbackApi)
|
||||
@@ -29,23 +29,23 @@ def reset_service_callback_api(
|
||||
|
||||
|
||||
def get_service_callback_api(service_callback_api_id, service_id):
|
||||
return ServiceCallbackApi.query.filter_by(
|
||||
return db.session.execute(select(ServiceCallbackApi).filter_by(
|
||||
id=service_callback_api_id, service_id=service_id
|
||||
).first()
|
||||
)).scalars().first()
|
||||
|
||||
|
||||
def get_service_delivery_status_callback_api_for_service(service_id):
|
||||
return ServiceCallbackApi.query.filter_by(
|
||||
return db.session.execute(select(ServiceCallbackApi).filter_by(
|
||||
service_id=service_id,
|
||||
callback_type=CallbackType.DELIVERY_STATUS,
|
||||
).first()
|
||||
)).scalars().first()
|
||||
|
||||
|
||||
def get_service_complaint_callback_api_for_service(service_id):
|
||||
return ServiceCallbackApi.query.filter_by(
|
||||
return db.session.execute(select(ServiceCallbackApi).filter_by(
|
||||
service_id=service_id,
|
||||
callback_type=CallbackType.COMPLAINT,
|
||||
).first()
|
||||
)).scalars().first()
|
||||
|
||||
|
||||
@autocommit
|
||||
|
||||
Reference in New Issue
Block a user