mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
remove duplicate dao invite fns and improve naming
This commit is contained in:
@@ -9,7 +9,7 @@ def save_invited_user(invited_user):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def get_invited_user(service_id, invited_user_id):
|
def get_invited_user_by_service_and_id(service_id, invited_user_id):
|
||||||
return InvitedUser.query.filter_by(service_id=service_id, id=invited_user_id).one()
|
return InvitedUser.query.filter_by(service_id=service_id, id=invited_user_id).one()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,7 @@ from sqlalchemy.sql.expression import func
|
|||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import VersionOptions, transactional, version_class
|
from app.dao.dao_utils import VersionOptions, transactional, version_class
|
||||||
from app.models import (
|
from app.models import Domain, Organisation, Service, User
|
||||||
Domain,
|
|
||||||
InvitedOrganisationUser,
|
|
||||||
Organisation,
|
|
||||||
Service,
|
|
||||||
User,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def dao_get_organisations():
|
def dao_get_organisations():
|
||||||
@@ -125,10 +119,6 @@ def dao_add_service_to_organisation(service, organisation_id):
|
|||||||
db.session.add(service)
|
db.session.add(service)
|
||||||
|
|
||||||
|
|
||||||
def dao_get_invited_organisation_user(user_id):
|
|
||||||
return InvitedOrganisationUser.query.filter_by(id=user_id).one()
|
|
||||||
|
|
||||||
|
|
||||||
def dao_get_users_for_organisation(organisation_id):
|
def dao_get_users_for_organisation(organisation_id):
|
||||||
return db.session.query(
|
return db.session.query(
|
||||||
User
|
User
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ from app.dao.invited_org_user_dao import (
|
|||||||
get_invited_org_user as dao_get_invited_org_user,
|
get_invited_org_user as dao_get_invited_org_user,
|
||||||
)
|
)
|
||||||
from app.dao.invited_org_user_dao import (
|
from app.dao.invited_org_user_dao import (
|
||||||
|
get_invited_org_user_by_id,
|
||||||
get_invited_org_users_for_organisation,
|
get_invited_org_users_for_organisation,
|
||||||
save_invited_org_user,
|
save_invited_org_user,
|
||||||
)
|
)
|
||||||
from app.dao.organisation_dao import dao_get_invited_organisation_user
|
|
||||||
from app.dao.templates_dao import dao_get_template_by_id
|
from app.dao.templates_dao import dao_get_template_by_id
|
||||||
from app.errors import InvalidRequest, register_errors
|
from app.errors import InvalidRequest, register_errors
|
||||||
from app.models import EMAIL_TYPE, KEY_TYPE_NORMAL, InvitedOrganisationUser
|
from app.models import EMAIL_TYPE, KEY_TYPE_NORMAL, InvitedOrganisationUser
|
||||||
@@ -117,7 +117,7 @@ def invited_org_user_url(invited_org_user_id, invite_link_host=None):
|
|||||||
|
|
||||||
@organisation_invite_blueprint.route('/invite/organisation/<uuid:invited_org_user_id>', methods=['GET'])
|
@organisation_invite_blueprint.route('/invite/organisation/<uuid:invited_org_user_id>', methods=['GET'])
|
||||||
def get_invited_org_user(invited_org_user_id):
|
def get_invited_org_user(invited_org_user_id):
|
||||||
invited_user = dao_get_invited_organisation_user(invited_org_user_id)
|
invited_user = get_invited_org_user_by_id(invited_org_user_id)
|
||||||
return jsonify(data=invited_user.serialize()), 200
|
return jsonify(data=invited_user.serialize()), 200
|
||||||
|
|
||||||
|
|
||||||
@@ -141,5 +141,5 @@ def validate_invitation_token(token):
|
|||||||
errors = {'invitation': 'Something’s wrong with this link. Make sure you’ve copied the whole thing.'}
|
errors = {'invitation': 'Something’s wrong with this link. Make sure you’ve copied the whole thing.'}
|
||||||
raise InvalidRequest(errors, status_code=400)
|
raise InvalidRequest(errors, status_code=400)
|
||||||
|
|
||||||
invited_user = dao_get_invited_organisation_user(invited_user_id)
|
invited_user = get_invited_org_user_by_id(invited_user_id)
|
||||||
return jsonify(data=invited_user.serialize()), 200
|
return jsonify(data=invited_user.serialize()), 200
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ from itsdangerous import BadData, SignatureExpired
|
|||||||
from notifications_utils.url_safe_token import check_token, generate_token
|
from notifications_utils.url_safe_token import check_token, generate_token
|
||||||
|
|
||||||
from app.config import QueueNames
|
from app.config import QueueNames
|
||||||
from app.dao.invited_user_dao import get_invited_user as dao_get_invited_user
|
|
||||||
from app.dao.invited_user_dao import (
|
from app.dao.invited_user_dao import (
|
||||||
get_invited_user_by_id,
|
get_invited_user_by_id,
|
||||||
|
get_invited_user_by_service_and_id,
|
||||||
get_invited_users_for_service,
|
get_invited_users_for_service,
|
||||||
save_invited_user,
|
save_invited_user,
|
||||||
)
|
)
|
||||||
@@ -69,13 +69,13 @@ def get_invited_users_by_service(service_id):
|
|||||||
|
|
||||||
@service_invite.route('/service/<service_id>/invite/<invited_user_id>', methods=['GET'])
|
@service_invite.route('/service/<service_id>/invite/<invited_user_id>', methods=['GET'])
|
||||||
def get_invited_user_by_service(service_id, invited_user_id):
|
def get_invited_user_by_service(service_id, invited_user_id):
|
||||||
invited_user = dao_get_invited_user(service_id, invited_user_id)
|
invited_user = get_invited_user_by_service_and_id(service_id, invited_user_id)
|
||||||
return jsonify(data=invited_user_schema.dump(invited_user).data), 200
|
return jsonify(data=invited_user_schema.dump(invited_user).data), 200
|
||||||
|
|
||||||
|
|
||||||
@service_invite.route('/service/<service_id>/invite/<invited_user_id>', methods=['POST'])
|
@service_invite.route('/service/<service_id>/invite/<invited_user_id>', methods=['POST'])
|
||||||
def update_invited_user(service_id, invited_user_id):
|
def update_invited_user(service_id, invited_user_id):
|
||||||
fetched = dao_get_invited_user(service_id=service_id, invited_user_id=invited_user_id)
|
fetched = get_invited_user_by_service_and_id(service_id=service_id, invited_user_id=invited_user_id)
|
||||||
|
|
||||||
current_data = dict(invited_user_schema.dump(fetched).data.items())
|
current_data = dict(invited_user_schema.dump(fetched).data.items())
|
||||||
current_data.update(request.get_json())
|
current_data.update(request.get_json())
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ from sqlalchemy.orm.exc import NoResultFound
|
|||||||
from app import db
|
from app import db
|
||||||
from app.dao.invited_user_dao import (
|
from app.dao.invited_user_dao import (
|
||||||
delete_invitations_created_more_than_two_days_ago,
|
delete_invitations_created_more_than_two_days_ago,
|
||||||
get_invited_user,
|
|
||||||
get_invited_user_by_id,
|
get_invited_user_by_id,
|
||||||
|
get_invited_user_by_service_and_id,
|
||||||
get_invited_users_for_service,
|
get_invited_users_for_service,
|
||||||
save_invited_user,
|
save_invited_user,
|
||||||
)
|
)
|
||||||
@@ -65,7 +65,7 @@ def test_create_invited_user_sets_default_folder_permissions_of_empty_list(
|
|||||||
|
|
||||||
|
|
||||||
def test_get_invited_user_by_service_and_id(notify_db, notify_db_session, sample_invited_user):
|
def test_get_invited_user_by_service_and_id(notify_db, notify_db_session, sample_invited_user):
|
||||||
from_db = get_invited_user(sample_invited_user.service.id, sample_invited_user.id)
|
from_db = get_invited_user_by_service_and_id(sample_invited_user.service.id, sample_invited_user.id)
|
||||||
assert from_db == sample_invited_user
|
assert from_db == sample_invited_user
|
||||||
|
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ def test_get_unknown_invited_user_returns_none(notify_db, notify_db_session, sam
|
|||||||
unknown_id = uuid.uuid4()
|
unknown_id = uuid.uuid4()
|
||||||
|
|
||||||
with pytest.raises(NoResultFound) as e:
|
with pytest.raises(NoResultFound) as e:
|
||||||
get_invited_user(sample_service.id, unknown_id)
|
get_invited_user_by_service_and_id(sample_service.id, unknown_id)
|
||||||
assert 'No row was found for one()' in str(e.value)
|
assert 'No row was found for one()' in str(e.value)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ from app import db
|
|||||||
from app.dao.organisation_dao import (
|
from app.dao.organisation_dao import (
|
||||||
dao_add_service_to_organisation,
|
dao_add_service_to_organisation,
|
||||||
dao_add_user_to_organisation,
|
dao_add_user_to_organisation,
|
||||||
dao_get_invited_organisation_user,
|
|
||||||
dao_get_organisation_by_email_address,
|
dao_get_organisation_by_email_address,
|
||||||
dao_get_organisation_by_id,
|
dao_get_organisation_by_id,
|
||||||
dao_get_organisation_by_service_id,
|
dao_get_organisation_by_service_id,
|
||||||
@@ -275,16 +274,6 @@ def test_get_organisation_by_service_id(sample_service, sample_organisation):
|
|||||||
assert organisation_2 == another_org
|
assert organisation_2 == another_org
|
||||||
|
|
||||||
|
|
||||||
def test_dao_get_invited_organisation_user(sample_invited_org_user):
|
|
||||||
invited_org_user = dao_get_invited_organisation_user(sample_invited_org_user.id)
|
|
||||||
assert invited_org_user == sample_invited_org_user
|
|
||||||
|
|
||||||
|
|
||||||
def test_dao_get_invited_organisation_user_returns_none(notify_db):
|
|
||||||
with pytest.raises(expected_exception=SQLAlchemyError):
|
|
||||||
dao_get_invited_organisation_user(uuid.uuid4())
|
|
||||||
|
|
||||||
|
|
||||||
def test_dao_get_users_for_organisation(sample_organisation):
|
def test_dao_get_users_for_organisation(sample_organisation):
|
||||||
first = create_user(email='first@invited.com')
|
first = create_user(email='first@invited.com')
|
||||||
second = create_user(email='another@invited.com')
|
second = create_user(email='another@invited.com')
|
||||||
|
|||||||
Reference in New Issue
Block a user