Skip to content

Commit

Permalink
upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
taraepp committed Nov 25, 2024
2 parents 0bf6cfd + 8834a3c commit 70c7801
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 151 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ gitops/tenant-gitops-4c2ba9
.vscode/settings.json
services/document-manager/document-manager.iml
/services/filesystem-provider/ej2-amazon-s3-aspcore-file-provider/Folder.DotSettings.user
/services/core-api/core-api.iml
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.typeCheckingMode": "basic",
"yapf.args": [
"--style={column_limit:100, spaces_before_comment:'15,30,50', SPLIT_BEFORE_EXPRESSION_AFTER_OPENING_PAREN:TRUE}"
]
Expand Down
2 changes: 1 addition & 1 deletion services/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@syncfusion/ej2-react-filemanager": "27.1.55",
"@syncfusion/ej2-react-pdfviewer": "27.1.58",
"@syncfusion/ej2-splitbuttons": "27.1.56",
"flagsmith": "3.19.1",
"flagsmith": "7.0.2",
"p-limit": "3.1.0",
"query-string": "5.1.1",
"ts-loader": "9.5.1"
Expand Down
2 changes: 1 addition & 1 deletion services/core-api/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ UNTP_DIGITAL_CONFORMITY_CREDENTIAL_CONTEXT=https://test.uncefact.org/vocabulary/
UNTP_DIGITAL_CONFORMITY_CREDENTIAL_SCHEMA=https://test.uncefact.org/vocabulary/untp/dcc/untp-dcc-schema-0.5.0.json
UNTP_BC_MINES_ACT_PERMIT_CONTEXT=https://bcgov.github.io/digital-trust-toolkit/contexts/BCMinesActPermit/v1.jsonld
ORGBOOK_CREDENTIAL_BASE_URL=https://dev.orgbook.traceability.site/credentials
ORGBOOK_PUBLISHER_API_KEY=ORGBOOK_PUBLISHER_API_KEY
ORGBOOK_PUBLISHER_CLIENT_SECRET=ORGBOOK_PUBLISHER_CLIENT_SECRET
# Permit Search Service
PERMITS_ENDPOINT=http://haystack
PERMITS_CLIENT_ID=mds-core-api-internal-5194
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
from datetime import date, datetime
from typing import Union

from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import validates
from sqlalchemy.schema import FetchedValue

from app.extensions import db
from app.api.constants import *
from app.api.mines.permits.permit_amendment.models.permit_amendment_document import (
PermitAmendmentDocument, )
from app.api.mines.permits.permit_conditions.models.permit_conditions import (
PermitConditions, )
from app.api.utils.models_mixins import AuditMixin, Base, SoftDeleteMixin
from app.api.verifiable_credentials.aries_constants import IssueCredentialIssuerState
from app.extensions import db
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import validates
from sqlalchemy.schema import FetchedValue
from app.api.parties.party_appt.models.mine_party_appt import MinePartyAppointment

from . import permit_amendment_status_code, permit_amendment_type_code

Expand Down Expand Up @@ -44,11 +46,11 @@ class PermitAmendment(SoftDeleteMixin, AuditMixin, Base):
permit_amendment_status_description = association_proxy('permit_amendment_status',
'description')
permit_guid = association_proxy('permit', 'permit_guid')
permit_no = association_proxy('permit', 'permit_no')
permit_no: str = association_proxy('permit', 'permit_no') #type: ignore[reportAssignmentType]
permit_amendment_type = db.relationship('PermitAmendmentTypeCode')
permit_amendment_type_description = association_proxy('permit_amendment_type', 'description')
#liability_adjustment is the change of work assessed for the new amendment,
# This value is added to previous amendments to create the new total assessment for the permit
#liability_adjustment is the change of work assessed for the new amendment,
# This value is added to previous amendments to create the new total assessment for the permit
liability_adjustment = db.Column(db.Numeric(16, 2))
security_received_date = db.Column(db.DateTime)
security_not_required = db.Column(db.Boolean)
Expand All @@ -57,7 +59,9 @@ class PermitAmendment(SoftDeleteMixin, AuditMixin, Base):
UUID(as_uuid=True), db.ForeignKey('now_application_identity.now_application_guid'))
now_identity = db.relationship(
'NOWApplicationIdentity', lazy='select', foreign_keys=[now_application_guid])
mine = db.relationship('Mine', lazy='select', back_populates='_mine_permit_amendments')
mine: 'Mine' = db.relationship(
'Mine', lazy='select',
back_populates='_mine_permit_amendments') #type: ignore[reportAssignmentType]
conditions = db.relationship(
'PermitConditions',
lazy='select',
Expand Down Expand Up @@ -97,12 +101,12 @@ class PermitAmendment(SoftDeleteMixin, AuditMixin, Base):

# Note: This relationship is lazy loaded on purpose to avoid being loaded unless absolutely necessary
# a selectin or joined query here causes performance issues due to the nested structure of NoW and Major Projects.
permittee_appointments = db.relationship(
permittee_appointments: list[MinePartyAppointment] = db.relationship(
"MinePartyAppointment",
lazy="select",
secondary='permit',
secondaryjoin='and_(foreign(Permit.permit_id) == remote(MinePartyAppointment.permit_id))',
order_by='desc(MinePartyAppointment.start_date)')
order_by='desc(MinePartyAppointment.start_date)') #type: ignore[reportAssignmentType]

@hybrid_property
def issuing_inspector_name(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class ProjectSummary(SoftDeleteMixin, AuditMixin, Base):
def __get_address_type_code(cls, address_data):
if isinstance(address_data, list):
return address_data[0].get('address_type_code')
return address_data.get('address_type_code')
return address_data.get('address_type_code', None) if address_data else None

def __repr__(self):
return f'{self.__class__.__name__} {self.project_summary_id}'
Expand Down Expand Up @@ -297,7 +297,7 @@ def create_or_update_party(cls, party_data, job_title_code, existing_party):
address_type_code=addr.get('address_type_code'),
)
new_party.address.append(new_address)
else:
elif address_data is not None:
new_address = Address.create(
suite_no=address_data.get('suite_no'),
address_line_1=address_data.get('address_line_1'),
Expand Down
30 changes: 30 additions & 0 deletions services/core-api/app/api/services/orgbook_publisher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import requests

from flask import current_app
from app.config import Config

token_url = f"{Config.ORGBOOK_PUBLISHER_BASE_URL}/auth/token"
cred_publish_url = f"{Config.ORGBOOK_PUBLISHER_BASE_URL}/credentials/publish"


class OrgbookPublisherService():
### class to manage API calls to the Orgbook Publisher, it's a service that will sign and publish data to Orgbook. The data is currently UNTP Digital Conformity Credentials that prove business have mines act permits.
token: str

def __init__(self):
self.token = self.get_new_token()

def get_headers(self):
return {"Authorization": f"Bearer {self.token}"}

def get_new_token(self):
payload = {
"client_id": Config.CHIEF_PERMITTING_OFFICER_DID_WEB,
"client_secret": Config.ORGBOOK_PUBLISHER_CLIENT_SECRET
}
token_resp = requests.post(token_url, json=payload)
token_resp.raise_for_status()
return token_resp.json()["access_token"]

def publish_cred(self, payload: dict) -> requests.Response:
return requests.post(cred_publish_url, json=payload, headers=self.get_headers())
9 changes: 6 additions & 3 deletions services/core-api/app/api/utils/feature_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ def __str__(self):


flagsmith = Flagsmith(
environment_id=Config.FLAGSMITH_KEY,
api=Config.FLAGSMITH_URL,
environment_key=Config.FLAGSMITH_KEY,
api_url=Config.FLAGSMITH_URL,
)


def is_feature_enabled(feature):
try:
return flagsmith.has_feature(feature) and flagsmith.feature_enabled(feature)
feature = str(feature).strip()
flags = flagsmith.get_environment_flags()

return feature in flags.flags and flags.is_feature_enabled(feature)
except Exception as e:
current_app.logger.error(f'Failed to look up feature flag for: {feature}. ' + str(e))
return False
Loading

0 comments on commit 70c7801

Please sign in to comment.