mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 08:35:15 -05:00
Add organisation_to_service association table
- moved Organisation so that Service model has access to it
This commit is contained in:
@@ -209,6 +209,44 @@ class ServicePermissionTypes(db.Model):
|
||||
name = db.Column(db.String(255), primary_key=True)
|
||||
|
||||
|
||||
organisation_to_service = db.Table(
|
||||
'organisation_to_service',
|
||||
db.Model.metadata,
|
||||
# service_id is a primary key as you can only have one organisation per service
|
||||
db.Column(
|
||||
'service_id',
|
||||
UUID(as_uuid=True),
|
||||
db.ForeignKey('services.id'),
|
||||
primary_key=True,
|
||||
unique=True,
|
||||
nullable=False),
|
||||
db.Column('organisation_id', UUID(as_uuid=True), db.ForeignKey('organisation.id'), nullable=False),
|
||||
)
|
||||
|
||||
|
||||
class Organisation(db.Model):
|
||||
__tablename__ = "organisation"
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=False)
|
||||
name = db.Column(db.String(255), nullable=False, unique=True, index=True)
|
||||
active = db.Column(db.Boolean, nullable=False, default=True)
|
||||
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||
|
||||
services = db.relationship(
|
||||
'Service',
|
||||
secondary='organisation_to_service',
|
||||
uselist=True)
|
||||
|
||||
def serialize(self):
|
||||
serialized = {
|
||||
"id": str(self.id),
|
||||
"name": self.name,
|
||||
"active": self.active,
|
||||
}
|
||||
|
||||
return serialized
|
||||
|
||||
|
||||
class Service(db.Model, Versioned):
|
||||
__tablename__ = 'services'
|
||||
|
||||
@@ -260,7 +298,11 @@ class Service(db.Model, Versioned):
|
||||
crown = db.Column(db.Boolean, index=False, nullable=False, default=True)
|
||||
rate_limit = db.Column(db.Integer, index=False, nullable=False, default=3000)
|
||||
|
||||
association_proxy('permissions', 'service_permission_types')
|
||||
organisation = db.relationship(
|
||||
'Organisation',
|
||||
secondary=organisation_to_service,
|
||||
uselist=False,
|
||||
single_parent=True)
|
||||
|
||||
email_branding = db.relationship(
|
||||
'EmailBranding',
|
||||
@@ -303,24 +345,6 @@ class Service(db.Model, Versioned):
|
||||
return permission in [p.permission for p in self.permissions]
|
||||
|
||||
|
||||
class Organisation(db.Model):
|
||||
__tablename__ = "organisation"
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=False)
|
||||
name = db.Column(db.String(255), nullable=False, unique=True, index=True)
|
||||
active = db.Column(db.Boolean, nullable=False, default=True)
|
||||
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||
|
||||
def serialize(self):
|
||||
serialized = {
|
||||
"id": str(self.id),
|
||||
"name": self.name,
|
||||
"active": self.active,
|
||||
}
|
||||
|
||||
return serialized
|
||||
|
||||
|
||||
class AnnualBilling(db.Model):
|
||||
__tablename__ = "annual_billing"
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=False)
|
||||
|
||||
Reference in New Issue
Block a user