Add org types table

This commit is contained in:
Pea Tyczynska
2019-07-10 18:17:33 +01:00
parent 663ab6d96b
commit 9dfc550f46
9 changed files with 93 additions and 15 deletions

View File

@@ -101,9 +101,14 @@ def dao_add_service_to_organisation(service, organisation_id):
organisation.services.append(service)
service.organisation_type = organisation.organisation_type
service.crown = organisation.crown
db.session.add(service)
def dao_get_invited_organisation_user(user_id):
return InvitedOrganisationUser.query.filter_by(id=user_id).one()

View File

@@ -41,6 +41,7 @@ from app.models import (
EMAIL_TYPE,
INTERNATIONAL_SMS_TYPE,
KEY_TYPE_TEST,
NON_CROWN_ORGANISATION_TYPES,
SMS_TYPE,
LETTER_TYPE,
)
@@ -282,7 +283,10 @@ def dao_create_service(
service.id = service_id or uuid.uuid4() # must be set now so version history model can use same id
service.active = True
service.research_mode = False
service.crown = service.organisation_type == 'central'
if organisation:
service.crown = organisation.crown
elif service.organisation_type in (NON_CROWN_ORGANISATION_TYPES + ['nhs']):
service.crown = False
service.count_as_live = not user.platform_admin
for permission in service_permissions:

View File

@@ -61,8 +61,6 @@ DELIVERY_STATUS_CALLBACK_TYPE = 'delivery_status'
COMPLAINT_CALLBACK_TYPE = 'complaint'
SERVICE_CALLBACK_TYPES = [DELIVERY_STATUS_CALLBACK_TYPE, COMPLAINT_CALLBACK_TYPE]
ORGANISATION_TYPES = ['central', 'local', 'nhs']
def filter_null_value_fields(obj):
return dict(
@@ -326,6 +324,21 @@ class Domain(db.Model):
organisation_id = db.Column('organisation_id', UUID(as_uuid=True), db.ForeignKey('organisation.id'), nullable=False)
ORGANISATION_TYPES = [
"central", "local", "nhs_central",
"nhs_local", "emergency_services", "school_or_college", "other",
]
NON_CROWN_ORGANISATION_TYPES = ["local", "nhs_central", "nhs_local", "emergency_services", "school_or_college"]
class OrganisationTypes(db.Model):
__tablename__ = 'organisation_types'
name = db.Column(db.String(255), primary_key=True)
is_crown = db.Column(db.Boolean, nullable=True)
annual_free_sms_fragment_limit = db.Column(db.BigInteger, nullable=False)
class Organisation(db.Model):
__tablename__ = "organisation"
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=False)
@@ -444,7 +457,7 @@ class Service(db.Model, Versioned):
db.String(255),
nullable=True,
)
crown = db.Column(db.Boolean, index=False, nullable=False, default=True)
crown = db.Column(db.Boolean, index=False, nullable=True)
rate_limit = db.Column(db.Integer, index=False, nullable=False, default=3000)
contact_link = db.Column(db.String(255), nullable=True, unique=False)
volume_sms = db.Column(db.Integer(), nullable=True, unique=False)

View File

@@ -86,7 +86,8 @@ from app.errors import (
)
from app.letters.utils import letter_print_day
from app.models import (
KEY_TYPE_NORMAL, LETTER_TYPE, NOTIFICATION_CANCELLED, Permission, Service, EmailBranding, LetterBranding
KEY_TYPE_NORMAL, LETTER_TYPE, NON_CROWN_ORGANISATION_TYPES, NOTIFICATION_CANCELLED, Permission, Service,
EmailBranding, LetterBranding
)
from app.notifications.process_notifications import persist_notification, send_notification_to_queue
from app.schema_validation import validate
@@ -224,8 +225,8 @@ def update_service(service_id):
service = service_schema.load(current_data).data
org_type = req_json.get('organisation_type', None)
if org_type:
service.crown = org_type == 'central'
if org_type and service.organisation_type in (NON_CROWN_ORGANISATION_TYPES + ["nhs"]):
service.crown = False
if 'email_branding' in req_json:
email_branding_id = req_json['email_branding']