-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating a family or collection now used the organisation of the user (…
…#32) * Create a family using the organisation of the user * Create collections with the org of the logged in user * fixed after review * fixed after review
- Loading branch information
1 parent
2fb8513
commit 8c38808
Showing
21 changed files
with
146 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from sqlalchemy.orm import Session | ||
from app.errors import ValidationError | ||
from app.repository import app_user_repo | ||
|
||
|
||
def get_organisation(db: Session, user_email: str) -> int: | ||
"""Gets a user's organisation""" | ||
org_id = app_user_repo.get_org_id(db, user_email) | ||
if org_id is None: | ||
raise ValidationError(f"Could not get the organisation for user {user_email}") | ||
return org_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from typing import cast | ||
from sqlalchemy.orm import Session | ||
from sqlalchemy import text | ||
from app.clients.db.models.app.users import Organisation | ||
from app.clients.db.models.app.users import AppUser, Organisation, OrganisationUser | ||
from app.clients.db.models.document.physical_document import ( | ||
LanguageSource, | ||
PhysicalDocument, | ||
|
@@ -221,6 +221,24 @@ def _setup_organisation(test_db: Session) -> int: | |
) | ||
) | ||
test_db.flush() | ||
|
||
# Also link to the test user | ||
test_db.add( | ||
AppUser( | ||
email="[email protected]", name="Test", hashed_password="", is_superuser=False | ||
) | ||
) | ||
test_db.flush() | ||
test_db.add( | ||
OrganisationUser( | ||
appuser_email="[email protected]", | ||
organisation_id=org.id, | ||
job_title="", | ||
is_active=True, | ||
is_admin=False, | ||
) | ||
) | ||
test_db.commit() | ||
return cast(int, org.id) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,13 @@ | |
HASH_PASSWORD = auth_service.get_password_hash(PLAIN_PASSWORD) | ||
VALID_USERNAME = "[email protected]" | ||
|
||
ORG_ID = 1234 | ||
|
||
|
||
def mock_app_user_repo(app_user_repo, monkeypatch: MonkeyPatch, mocker): | ||
app_user_repo.user_active = True | ||
|
||
app_user_repo.error = False | ||
|
||
def mock_get_app_user_authorisation( | ||
_, __ | ||
) -> list[Tuple[OrganisationUser, Organisation]]: | ||
|
@@ -28,15 +31,19 @@ def mock_get_user_by_email(_, __) -> MaybeAppUser: | |
is_superuser=True, | ||
) | ||
|
||
def mock_get_org_id(_, user_email: str) -> int: | ||
return ORG_ID | ||
|
||
def mock_is_active(_, email: str) -> bool: | ||
return app_user_repo.user_active | ||
|
||
app_user_repo.error = False | ||
monkeypatch.setattr(app_user_repo, "get_user_by_email", mock_get_user_by_email) | ||
monkeypatch.setattr(app_user_repo, "get_org_id", mock_get_org_id) | ||
monkeypatch.setattr(app_user_repo, "is_active", mock_is_active) | ||
monkeypatch.setattr( | ||
app_user_repo, "get_app_user_authorisation", mock_get_app_user_authorisation | ||
) | ||
mocker.spy(app_user_repo, "get_user_by_email") | ||
mocker.spy(app_user_repo, "get_org_id") | ||
mocker.spy(app_user_repo, "is_active") | ||
mocker.spy(app_user_repo, "get_app_user_authorisation") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pytest import MonkeyPatch | ||
|
||
ORG_ID = 1234 | ||
|
||
|
||
def mock_app_user_service(app_user_service, monkeypatch: MonkeyPatch, mocker): | ||
def mock_get_organisation(_, user_email: str) -> int: | ||
return ORG_ID | ||
|
||
monkeypatch.setattr(app_user_service, "get_organisation", mock_get_organisation) | ||
mocker.spy(app_user_service, "get_organisation") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.