-
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.
Feature/pdct 1055 frontend create family enable the user to select th…
…e corpus (#129) * Enable the user to select the corpus on create * Add docstrings and add function to validate corpus exists in DB. * Update existing family tests and helpers to include corpus_import_id field * Added test to check family create fails when org mismatch between user and corpus * Raise auth error instead of validation error when org mismatch & fix service family layer * Add new tests for validating corpus on family create * Generalise error text and check error text in test * Add default value for family service update context * Bump package to 2.5.1 * Bump to 2.5.0
- Loading branch information
1 parent
f2ceb5f
commit a33f00e
Showing
19 changed files
with
319 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
from db_client.models.organisation.corpus import Corpus | ||
from sqlalchemy.orm import Session | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def get_corpus_org_id(db: Session, corpus_id: str) -> Optional[int]: | ||
"""Get the organisation ID a corpus belongs to. | ||
TODO: Will need to review as part of PDCT-1011. | ||
:param Session db: The DB session to connect to. | ||
:param str corpus_id: The corpus import ID we want to get the org | ||
for. | ||
:return Optional[int]: Return the organisation ID the given corpus | ||
belongs to or None. | ||
""" | ||
return db.query(Corpus.organisation_id).filter_by(import_id=corpus_id).scalar() | ||
|
||
|
||
def validate(db: Session, corpus_id: str) -> bool: | ||
"""Validate whether a corpus with the given ID exists in the DB. | ||
:param Session db: The DB session to connect to. | ||
:param str corpus_id: The corpus import ID we want to validate. | ||
:return bool: Return whether or not the corpus exists in the DB. | ||
""" | ||
corpora = [corpus[0] for corpus in db.query(Corpus.import_id).distinct().all()] | ||
return bool(corpus_id in corpora) |
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,47 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
from app.errors import RepositoryError, ValidationError | ||
from app.repository import corpus_repo | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def get_corpus_org_id(db: Session, corpus_import_id: str) -> Optional[int]: | ||
"""Get the organisation ID(s) a corpus belongs to. | ||
TODO: Will need to review as part of PDCT-1011. | ||
:param Session db: The DB session to connect to. | ||
:param str corpus_id: The corpus import ID we want to get the org | ||
for. | ||
:return Optional[int]: Return the organisation ID the given corpus | ||
belongs to or None. | ||
""" | ||
org_id = corpus_repo.get_corpus_org_id(db, corpus_import_id) | ||
return org_id | ||
|
||
|
||
def validate(db: Session, corpus_import_id: str) -> bool: | ||
"""Validate whether a corpus with the given ID exists in the DB. | ||
:param Session db: The DB session to connect to. | ||
:param str corpus_id: The corpus import ID we want to validate. | ||
:raises ValidationError: When the corpus ID is not found in the DB. | ||
:raises RepositoryError: When an error occurs. | ||
:return bool: Return whether or not the corpus exists in the DB. | ||
""" | ||
try: | ||
is_valid = corpus_repo.validate(db, corpus_import_id) | ||
if is_valid: | ||
return is_valid | ||
|
||
except Exception as e: | ||
_LOGGER.error(e) | ||
raise RepositoryError(e) | ||
|
||
msg = f"Corpus '{corpus_import_id}' not found" | ||
_LOGGER.error(msg) | ||
raise ValidationError(msg) |
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,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "admin_backend" | ||
version = "2.4.1" | ||
version = "2.5.0" | ||
description = "" | ||
authors = ["CPR-dev-team <[email protected]>"] | ||
packages = [{ include = "app" }, { include = "tests" }] | ||
|
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
Oops, something went wrong.