diff --git a/api/ElectionApi.py b/api/ElectionApi.py index 7cb99fcd..da88412a 100644 --- a/api/ElectionApi.py +++ b/api/ElectionApi.py @@ -23,7 +23,7 @@ def get_by_id(electionId): if result is None: raise NotFoundException( message="Election not found (electionId=%d)" % electionId, - const=MESSAGE_CODE_ELECTION_NOT_FOUND + code=MESSAGE_CODE_ELECTION_NOT_FOUND ) return Schema().dump(result).data diff --git a/app.py b/app.py index 027f0da2..54fdbe6f 100644 --- a/app.py +++ b/app.py @@ -18,7 +18,7 @@ cache = Cache(config={ "DEBUG": True, # some Flask specific configs "CACHE_TYPE": "simple", # Flask-Caching related configs - "CACHE_DEFAULT_TIMEOUT": 18144000000 # One month + "CACHE_DEFAULT_TIMEOUT": 18144000000 # One month }) @@ -44,7 +44,8 @@ def render_connexion_problem_exception(connexion_exception): return json.dumps({ "detail": connexion_exception.detail, "status": connexion_exception.status, - "title": connexion_exception.title + "title": connexion_exception.title, + "code": connexion_exception.args[4] }, indent=2), connexion_exception.status diff --git a/auth/__init__.py b/auth/__init__.py index 39981b2a..c56c8bec 100644 --- a/auth/__init__.py +++ b/auth/__init__.py @@ -135,6 +135,7 @@ def get_user_name() -> str: """ return connexion.context[USER_NAME] + def get_user_roles(): return connexion.context[USER_ROLES] @@ -229,17 +230,20 @@ def authorize(func, required_roles=None, *args, **kwargs): user_access_area_ids.extend([x.get(AREA_ID) for x in claims.get(claim)]) if role is DATA_EDITOR_ROLE: + counting_centre_ids = [] global_area_map = init_global_area_map() for electoral_district_id in user_access_area_ids: if electoral_district_id in global_area_map["electoral_district_counting_centre"]: - user_access_area_ids.extend( + counting_centre_ids.extend( global_area_map["electoral_district_counting_centre"][electoral_district_id] ) + elif role is POLLING_DIVISION_REPORT_VIEWER_ROLE or role is POLLING_DIVISION_REPORT_VERIFIER_ROLE: + counting_centre_ids = [] global_area_map = init_global_area_map() for electoral_district_id in user_access_area_ids: if electoral_district_id in global_area_map["electoral_district_polling_division"]: - user_access_area_ids.extend( + counting_centre_ids.extend( global_area_map["electoral_district_polling_division"][electoral_district_id] ) diff --git a/exception/__init__.py b/exception/__init__.py index 4b92945a..8b4feec0 100644 --- a/exception/__init__.py +++ b/exception/__init__.py @@ -2,24 +2,24 @@ def UnauthorizedException(message="", code=None): - raise ProblemException(401, "Unauthorized", message, "Unauthorized") + raise ProblemException(401, "Unauthorized", message, "Unauthorized", code) def ForbiddenException(message="", code=None): - raise ProblemException(403, "Forbidden", message, "Forbidden") + raise ProblemException(403, "Forbidden", message, "Forbidden", code) def NotFoundException(message="", code=None): - raise ProblemException(404, "Not Found", message, "NotFound") + raise ProblemException(404, "Not Found", message, "NotFound", code) def MethodNotAllowedException(message="", code=None): - raise ProblemException(405, "Method Not Allowed", message, "MethodNotAllowed") + raise ProblemException(405, "Method Not Allowed", message, "MethodNotAllowed", code) def InternalServerErrorException(message="", code=None): - raise ProblemException(500, "Internal Server Error", message, "InternalServerError") + raise ProblemException(500, "Internal Server Error", message, "InternalServerError", code) def NotImplementedException(message="", code=None): - raise ProblemException(501, "Not Implemented", message, "NotImplemented") + raise ProblemException(501, "Not Implemented", message, "NotImplemented", code) diff --git a/exception/messages.py b/exception/messages.py index 402cc1ce..705ef31e 100644 --- a/exception/messages.py +++ b/exception/messages.py @@ -21,3 +21,4 @@ MESSAGE_CODE_SUBMISSION_IRRELEVANT_VERSION_CANNOT_BE_MAPPED = 19 MESSAGE_CODE_SUBMISSION_NOT_FOUND = 21 # next: 23 +# Do not change the numbers and new always. These are linked to client applications. diff --git a/orm/entities/Area/Electorate/AdministrativeDistrict.py b/orm/entities/Area/Electorate/AdministrativeDistrict.py index 550986ad..f2a38f4e 100644 --- a/orm/entities/Area/Electorate/AdministrativeDistrict.py +++ b/orm/entities/Area/Electorate/AdministrativeDistrict.py @@ -1,9 +1,6 @@ -from app import db from orm.entities.Area import Electorate -from orm.entities.Area.Electorate import Province -from orm.enums import ElectorateTypeEnum, AreaTypeEnum -from exception import NotFoundException -from sqlalchemy.orm import relationship, synonym +from orm.enums import AreaTypeEnum +from sqlalchemy.orm import synonym from sqlalchemy.ext.associationproxy import association_proxy diff --git a/orm/entities/Area/Electorate/ElectoralDistrict.py b/orm/entities/Area/Electorate/ElectoralDistrict.py index 0a2fa853..96fdd52c 100644 --- a/orm/entities/Area/Electorate/ElectoralDistrict.py +++ b/orm/entities/Area/Electorate/ElectoralDistrict.py @@ -1,10 +1,6 @@ -from app import db from orm.entities.Area import Electorate -from orm.entities.Area.Electorate import Country -from orm.enums import ElectorateTypeEnum, AreaTypeEnum -from exception import NotFoundException +from orm.enums import AreaTypeEnum from sqlalchemy.orm import synonym -from sqlalchemy.ext.associationproxy import association_proxy class ElectoralDistrictModel(Electorate.Model): diff --git a/orm/entities/Area/Electorate/PollingDistrict.py b/orm/entities/Area/Electorate/PollingDistrict.py index b680093a..b867a1da 100644 --- a/orm/entities/Area/Electorate/PollingDistrict.py +++ b/orm/entities/Area/Electorate/PollingDistrict.py @@ -1,8 +1,5 @@ -from app import db from orm.entities.Area import Electorate -from orm.entities.Area.Electorate import PollingDivision from orm.enums import AreaTypeEnum -from exception import NotFoundException from sqlalchemy.orm import synonym from sqlalchemy.ext.associationproxy import association_proxy diff --git a/orm/entities/Area/Electorate/PollingDivision.py b/orm/entities/Area/Electorate/PollingDivision.py index e476cdb7..3f08278d 100644 --- a/orm/entities/Area/Electorate/PollingDivision.py +++ b/orm/entities/Area/Electorate/PollingDivision.py @@ -1,9 +1,6 @@ -from app import db from orm.entities import Electorate -from orm.entities.Area.Electorate import ElectoralDistrict -from orm.enums import ElectorateTypeEnum, AreaTypeEnum -from exception import NotFoundException -from sqlalchemy.orm import relationship, synonym +from orm.enums import AreaTypeEnum +from sqlalchemy.orm import synonym from sqlalchemy.ext.associationproxy import association_proxy diff --git a/orm/entities/Area/Electorate/Province.py b/orm/entities/Area/Electorate/Province.py index 3080c77a..78699d08 100644 --- a/orm/entities/Area/Electorate/Province.py +++ b/orm/entities/Area/Electorate/Province.py @@ -1,14 +1,9 @@ -from app import db from orm.entities import Electorate -from orm.entities.Area.Electorate import Country -from orm.enums import ElectorateTypeEnum, AreaTypeEnum -from exception import NotFoundException -from sqlalchemy.orm import relationship, synonym +from orm.enums import AreaTypeEnum +from sqlalchemy.orm import synonym class ProvinceModel(Electorate.Model): - # parentElectorateId = db.Column(db.Integer, db.ForeignKey("electorateId"), nullable=True) - country = synonym("parentElectorate") __mapper_args__ = { diff --git a/orm/entities/Election/election_helper.py b/orm/entities/Election/election_helper.py index 75d046b4..a49ed539 100644 --- a/orm/entities/Election/election_helper.py +++ b/orm/entities/Election/election_helper.py @@ -39,27 +39,27 @@ def get_root_token(electionId): AREA_CLAIM_PREFIX + DATA_EDITOR_ROLE: str([{ "areaId": electoral_district.areaId } for electoral_district in electoral_districts]), - AREA_CLAIM_PREFIX + POLLING_DIVISION_REPORT_VIEWER_ROLE: str([{ - "areaId": electoral_district.areaId - } for electoral_district in electoral_districts]), - AREA_CLAIM_PREFIX + POLLING_DIVISION_REPORT_VERIFIER_ROLE: str([{ - "areaId": electoral_district.areaId - } for electoral_district in electoral_districts]), - AREA_CLAIM_PREFIX + ELECTORAL_DISTRICT_REPORT_VIEWER_ROLE: str([{ - "areaId": electoral_district.areaId - } for electoral_district in electoral_districts]), - AREA_CLAIM_PREFIX + ELECTORAL_DISTRICT_REPORT_VERIFIER_ROLE: str([{ - "areaId": electoral_district.areaId - } for electoral_district in electoral_districts]), - AREA_CLAIM_PREFIX + NATIONAL_REPORT_VIEWER_ROLE: str([{ - "areaId": country.areaId - } for country in countries]), - AREA_CLAIM_PREFIX + NATIONAL_REPORT_VERIFIER_ROLE: str([{ - "areaId": country.areaId - } for country in countries]), - AREA_CLAIM_PREFIX + EC_LEADERSHIP_ROLE: str([{ - "areaId": country.areaId - } for country in countries]) + # AREA_CLAIM_PREFIX + POLLING_DIVISION_REPORT_VIEWER_ROLE: str([{ + # "areaId": electoral_district.areaId + # } for electoral_district in electoral_districts]), + # AREA_CLAIM_PREFIX + POLLING_DIVISION_REPORT_VERIFIER_ROLE: str([{ + # "areaId": electoral_district.areaId + # } for electoral_district in electoral_districts]), + # AREA_CLAIM_PREFIX + ELECTORAL_DISTRICT_REPORT_VIEWER_ROLE: str([{ + # "areaId": electoral_district.areaId + # } for electoral_district in electoral_districts]), + # AREA_CLAIM_PREFIX + ELECTORAL_DISTRICT_REPORT_VERIFIER_ROLE: str([{ + # "areaId": electoral_district.areaId + # } for electoral_district in electoral_districts]), + # AREA_CLAIM_PREFIX + NATIONAL_REPORT_VIEWER_ROLE: str([{ + # "areaId": country.areaId + # } for country in countries]), + # AREA_CLAIM_PREFIX + NATIONAL_REPORT_VERIFIER_ROLE: str([{ + # "areaId": country.areaId + # } for country in countries]), + # AREA_CLAIM_PREFIX + EC_LEADERSHIP_ROLE: str([{ + # "areaId": country.areaId + # } for country in countries]) } # Generate a token with claims for everything. diff --git a/orm/entities/TallySheetVersionRow/TallySheetVersionRow_PRE_21.py b/orm/entities/TallySheetVersionRow/TallySheetVersionRow_PRE_21.py index 156708cb..983f485a 100644 --- a/orm/entities/TallySheetVersionRow/TallySheetVersionRow_PRE_21.py +++ b/orm/entities/TallySheetVersionRow/TallySheetVersionRow_PRE_21.py @@ -2,9 +2,7 @@ from app import db -from orm.entities import Candidate -from orm.entities.Election import ElectionCandidate, InvalidVoteCategory -from exception import NotFoundException +from orm.entities.Election import InvalidVoteCategory from orm.entities.SubmissionVersion import TallySheetVersion