Skip to content

Commit

Permalink
Merge branch 'bcgov:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
avni-work authored Oct 17, 2024
2 parents a77ca4c + d818a6c commit 8f6be2e
Show file tree
Hide file tree
Showing 43 changed files with 1,292 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Specify a code owner for the strr-api directory
strr-api/ @kris-daxiom @thorwolpert
/strr-api @kris-daxiom @thorwolpert
1 change: 1 addition & 0 deletions queue_services/strr-pay/devops/gcp/clouddeploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ serialPipeline:
service-account: "sa-api@bcrbk9-test.iam.gserviceaccount.com"
- targetId: bcrbk9-sandbox
profiles: [sandbox]
strategy:
standard:
verify: false
deployParameters:
Expand Down
2 changes: 0 additions & 2 deletions strr-api/migrations/versions/20240801_0544_64243bf62473_.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('certificates', schema=None) as batch_op:
batch_op.drop_constraint('certificates_registration_number_key', type_='unique')
batch_op.drop_column('registration_number')
with op.batch_alter_table('registrations', schema=None) as batch_op:
batch_op.add_column(sa.Column('registration_number', sa.String(), nullable=True))
Expand All @@ -35,5 +34,4 @@ def downgrade():

with op.batch_alter_table('certificates', schema=None) as batch_op:
batch_op.add_column(sa.Column('registration_number', sa.VARCHAR(), autoincrement=False, nullable=False))
batch_op.create_unique_constraint('certificates_registration_number_key', ['registration_number'])
# ### end Alembic commands ###
6 changes: 0 additions & 6 deletions strr-api/migrations/versions/20240927_1313_c8d5441975d9_.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def upgrade():
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('documents', schema=None) as batch_op:
batch_op.drop_constraint('documents_eligibility_id_fkey', type_='foreignkey')
batch_op.drop_column('eligibility_id')

with op.batch_alter_table('registrations', schema=None) as batch_op:
Expand All @@ -76,7 +75,6 @@ def upgrade():
batch_op.drop_index('ix_registrations_submission_date')
batch_op.create_index(batch_op.f('ix_registrations_registration_type'), ['registration_type'], unique=False)
batch_op.create_index(batch_op.f('ix_registrations_sbc_account_id'), ['sbc_account_id'], unique=False)
batch_op.drop_constraint('registrations_rental_property_id_fkey', type_='foreignkey')
batch_op.drop_column('rental_property_id')
batch_op.drop_column('submission_date')

Expand All @@ -96,7 +94,6 @@ def upgrade():
type_=ownershiptype,
existing_nullable=False,
postgresql_using="ownership_type::ownershiptype")
batch_op.drop_constraint('rental_properties_property_manager_id_fkey', type_='foreignkey')
batch_op.create_foreign_key(None, 'registrations', ['registration_id'], ['id'])
batch_op.drop_column('property_manager_id')

Expand Down Expand Up @@ -148,7 +145,6 @@ def downgrade():
with op.batch_alter_table('rental_properties', schema=None) as batch_op:
batch_op.add_column(sa.Column('property_manager_id', sa.INTEGER(), autoincrement=False, nullable=False))
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key('rental_properties_property_manager_id_fkey', 'property_managers', ['property_manager_id'], ['id'])
batch_op.alter_column('ownership_type',
existing_type=ownershiptype,
type_=sa.VARCHAR(),
Expand All @@ -168,7 +164,6 @@ def downgrade():
with op.batch_alter_table('registrations', schema=None) as batch_op:
batch_op.add_column(sa.Column('submission_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False))
batch_op.add_column(sa.Column('rental_property_id', sa.INTEGER(), autoincrement=False, nullable=False))
batch_op.create_foreign_key('registrations_rental_property_id_fkey', 'rental_properties', ['rental_property_id'], ['id'])
batch_op.drop_index(batch_op.f('ix_registrations_sbc_account_id'))
batch_op.drop_index(batch_op.f('ix_registrations_registration_type'))
batch_op.create_index('ix_registrations_submission_date', ['submission_date'], unique=False)
Expand All @@ -191,7 +186,6 @@ def downgrade():

with op.batch_alter_table('documents', schema=None) as batch_op:
batch_op.add_column(sa.Column('eligibility_id', sa.INTEGER(), autoincrement=False, nullable=False))
batch_op.create_foreign_key('documents_eligibility_id_fkey', 'eligibilities', ['eligibility_id'], ['id'])

op.drop_table('property_listings')
op.drop_table('property_contacts')
Expand Down
602 changes: 602 additions & 0 deletions strr-api/migrations/versions/20241010_2151_a6abe20bd998_.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions strr-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions strr-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "strr-api"
version = "0.0.13"
version = "0.0.14"
description = ""
authors = ["thorwolpert <thor@wolpert.ca>"]
license = "BSD 3-Clause"
Expand All @@ -14,7 +14,6 @@ launchdarkly-server-sdk = "^9.0.1"
python-dotenv = "^1.0.0"
flask-sqlalchemy = "^3.1.1"
flask-migrate = "^4.0.4"
sql-versioning = { git = "https://github.com/bcgov/lear.git", subdirectory = "python/common/sql-versioning", branch = "feature-legal-name" }
sentry-sdk = "^1.24.0"
flask-babel = "^4.0.0"
flask-cors = "^4.0.0"
Expand All @@ -33,6 +32,7 @@ google-cloud-storage = "2.14.0"
geoalchemy2 = "^0.15.1"
weasyprint = "^62.3"
sqlalchemy-utils = "^0.41.2"
sql-versioning = { git = "https://github.com/bcgov/sbc-connect-common.git", subdirectory = "python/sql-versioning", branch = "main" }

[tool.poetry.group.test.dependencies]
freezegun = "^1.2.2"
Expand Down
9 changes: 7 additions & 2 deletions strr-api/src/strr_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@
# POSSIBILITY OF SUCH DAMAGE.
"""This exports all of the models and schemas used by the application."""
from .account_roles import AccountRoles
from .address import Address
from .application import Application
from .auto_approval_record import AutoApprovalRecord
from .certificate import Certificate
from .db import db # noqa: I001
from .dss import DSSOrganization
from .events import Events
from .ltsa import LTSARecord
from .platforms import Platform
from .rental import Address, Document, PropertyContact, PropertyListing, Registration, RentalProperty
from .platforms import Platform, PlatformBrand, PlatformRegistration, PlatformRepresentative
from .rental import Document, PropertyContact, PropertyListing, Registration, RentalProperty
from .user import Contact, User

__all__ = (
"db",
"AccountRoles",
"Address",
"Application",
"User",
"RentalProperty",
Expand All @@ -62,4 +64,7 @@
"LTSARecord",
"Certificate",
"Platform",
"PlatformBrand",
"PlatformRegistration",
"PlatformRepresentative",
)
38 changes: 38 additions & 0 deletions strr-api/src/strr_api/models/address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Registration model.
"""

from __future__ import annotations

from sql_versioning import Versioned
from sqlalchemy.orm import relationship

from strr_api.models.base_model import BaseModel

from .db import db


class Address(Versioned, BaseModel):
"""Address"""

__tablename__ = "addresses"

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
country = db.Column(db.String, nullable=False)
street_address = db.Column(db.String, nullable=False)
street_address_additional = db.Column(db.String, nullable=True)
city = db.Column(db.String, nullable=False)
province = db.Column(db.String, nullable=False)
postal_code = db.Column(db.String, nullable=False)

contact = relationship("Contact", back_populates="address", foreign_keys="Contact.address_id")
rental_properties_address = relationship(
"RentalProperty", back_populates="address", foreign_keys="RentalProperty.address_id"
)

def to_oneline_address(self):
"""Convert object to one line address."""
unit = ""
if self.street_address_additional:
unit = f"{self.street_address_additional} "
return f"{unit}{self.street_address}, {self.city}, {self.province}, {self.country}, {self.postal_code}"
2 changes: 2 additions & 0 deletions strr-api/src/strr_api/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,13 @@ def to_dict(application: Application) -> dict:
reviewer_display_name = f"{reviewer_display_name} {application.reviewer.lastname}"
application_dict["header"]["reviewer"]["displayName"] = reviewer_display_name

application_dict["header"]["isCertificateIssued"] = False
if application.registration_id:
application_dict["header"]["registrationId"] = application.registration_id
application_dict["header"]["registrationStartDate"] = application.registration.start_date.isoformat()
application_dict["header"]["registrationEndDate"] = application.registration.expiry_date.isoformat()
application_dict["header"]["registrationStatus"] = application.registration.status.value
application_dict["header"]["registrationNumber"] = application.registration.registration_number
application_dict["header"]["isCertificateIssued"] = bool(application.registration.certificates)

return application_dict
4 changes: 2 additions & 2 deletions strr-api/src/strr_api/models/auto_approval_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.sql import text

from strr_api.models.base_model import BaseModel
from strr_api.models.base_model import SimpleBaseModel

from .db import db


class AutoApprovalRecord(BaseModel):
class AutoApprovalRecord(SimpleBaseModel):
"""AutoApprovalRecord Record"""

__tablename__ = "auto_approval_records"
Expand Down
43 changes: 42 additions & 1 deletion strr-api/src/strr_api/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
"""Base Model."""
import datetime

from sqlalchemy import Column, DateTime, ForeignKey
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm import relationship

from strr_api.models.user import User

from .db import db


class BaseModel(db.Model):
class SimpleBaseModel(db.Model):
"""Base class that defines all the common methods."""

__abstract__ = True
Expand Down Expand Up @@ -80,3 +87,37 @@ def reset(self):
if self:
db.session.delete(self)
db.session.commit()


class BaseModel(SimpleBaseModel):
"""Base class that defines all the common columns."""

__abstract__ = True

@declared_attr
def created_by_id(cls): # pylint:disable=no-self-argument, # noqa: N805
"""Return foreign key for created by."""
return Column(ForeignKey("users.id"), default=cls._get_current_user)

@declared_attr
def modified_by_id(cls): # pylint:disable=no-self-argument, # noqa: N805
"""Return foreign key for modified by."""
return Column(ForeignKey("users.id"), onupdate=cls._get_current_user)

@declared_attr
def created_by(cls): # pylint:disable=no-self-argument, # noqa: N805
"""Return relationship for created by."""
return relationship("User", foreign_keys=[cls.created_by_id], post_update=True, uselist=False)

@declared_attr
def modified_by(cls): # pylint:disable=no-self-argument, # noqa: N805
"""Return relationship for modified by."""
return relationship("User", foreign_keys=[cls.modified_by_id], post_update=True, uselist=False)

created = Column(DateTime, default=datetime.datetime.now)
modified = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)

@staticmethod
def _get_current_user():
user = User.find_user_in_context()
return user.id if user else None
10 changes: 9 additions & 1 deletion strr-api/src/strr_api/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@
"""
from flask_sqlalchemy import SQLAlchemy
from sql_versioning import versioned_session
from sqlalchemy import MetaData

# by convention in the Flask community these are lower case,
# whereas pylint wants them upper case
db = SQLAlchemy()

metadata = MetaData(
naming_convention={
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
}
)

db = SQLAlchemy(metadata=metadata)
versioned_session(db.session)
4 changes: 2 additions & 2 deletions strr-api/src/strr_api/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from sqlalchemy.sql import text

from strr_api.common.enum import BaseEnum, auto
from strr_api.models.base_model import BaseModel
from strr_api.models.base_model import SimpleBaseModel

from .db import db


class Events(BaseModel):
class Events(SimpleBaseModel):
"""Events related to application, registration etc."""

class EventType(BaseEnum):
Expand Down
4 changes: 2 additions & 2 deletions strr-api/src/strr_api/models/ltsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.sql import text

from strr_api.models.base_model import BaseModel
from strr_api.models.base_model import SimpleBaseModel

from .db import db


class LTSARecord(BaseModel):
class LTSARecord(SimpleBaseModel):
"""LTSA Record"""

__tablename__ = "ltsa"
Expand Down
Loading

0 comments on commit 8f6be2e

Please sign in to comment.