mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-28 19:59:47 -04:00
remove free_sms_fragment_limit from service
* remove from model * still required when calling POST /service - we just call through from dao_create_service to add a new annual billing entry. * removed from POST /service/<id> update_service - if you want to update/add a new one, use POST /service/<id>/free-sms-fragment-limit * made sure tests create services with default 250k limit.
This commit is contained in:
@@ -61,12 +61,12 @@ def dao_get_all_free_sms_fragment_limit(service_id):
|
||||
).order_by(AnnualBilling.financial_year_start).all()
|
||||
|
||||
|
||||
def dao_insert_annual_billing(service):
|
||||
def dao_insert_annual_billing_for_this_year(service, free_sms_fragment_limit):
|
||||
"""
|
||||
This method is called from create_service which is wrapped in a transaction.
|
||||
"""
|
||||
annual_billing = AnnualBilling(
|
||||
free_sms_fragment_limit=service.free_sms_fragment_limit,
|
||||
free_sms_fragment_limit=free_sms_fragment_limit,
|
||||
financial_year_start=get_current_financial_year_start_year(),
|
||||
service=service,
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ from app.models import (
|
||||
)
|
||||
from app.statsd_decorators import statsd
|
||||
from app.utils import get_london_month_from_utc_column, get_london_midnight_in_utc
|
||||
from app.dao.annual_billing_dao import dao_insert_annual_billing
|
||||
from app.dao.annual_billing_dao import dao_insert_annual_billing_for_this_year
|
||||
|
||||
DEFAULT_SERVICE_PERMISSIONS = [
|
||||
SMS_TYPE,
|
||||
@@ -155,7 +155,7 @@ def dao_fetch_service_by_id_and_user(service_id, user_id):
|
||||
|
||||
@transactional
|
||||
@version_class(Service)
|
||||
def dao_create_service(service, user, service_id=None, service_permissions=None):
|
||||
def dao_create_service(service, user, free_sms_fragment_limit, service_id=None, service_permissions=None):
|
||||
# the default property does not appear to work when there is a difference between the sqlalchemy schema and the
|
||||
# db schema (ie: during a migration), so we have to set sms_sender manually here. After the GOVUK sms_sender
|
||||
# migration is completed, this code should be able to be removed.
|
||||
@@ -163,9 +163,6 @@ def dao_create_service(service, user, service_id=None, service_permissions=None)
|
||||
if service_permissions is None:
|
||||
service_permissions = DEFAULT_SERVICE_PERMISSIONS
|
||||
|
||||
if service.free_sms_fragment_limit is None:
|
||||
service.free_sms_fragment_limit = current_app.config['FREE_SMS_TIER_FRAGMENT_COUNT']
|
||||
|
||||
from app.dao.permissions_dao import permission_dao
|
||||
service.users.append(user)
|
||||
permission_dao.add_default_service_permissions_for_user(user, service)
|
||||
@@ -180,7 +177,7 @@ def dao_create_service(service, user, service_id=None, service_permissions=None)
|
||||
|
||||
# do we just add the default - or will we get a value from FE?
|
||||
insert_service_sms_sender(service, current_app.config['FROM_NUMBER'])
|
||||
dao_insert_annual_billing(service)
|
||||
dao_insert_annual_billing_for_this_year(service, free_sms_fragment_limit)
|
||||
db.session.add(service)
|
||||
|
||||
|
||||
|
||||
@@ -228,7 +228,6 @@ class Service(db.Model, Versioned):
|
||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
|
||||
prefix_sms = db.Column(db.Boolean, nullable=True, default=True)
|
||||
organisation_id = db.Column(UUID(as_uuid=True), db.ForeignKey('organisation.id'), index=True, nullable=True)
|
||||
free_sms_fragment_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=True)
|
||||
organisation = db.relationship('Organisation')
|
||||
dvla_organisation_id = db.Column(
|
||||
db.String,
|
||||
|
||||
@@ -203,7 +203,6 @@ class ServiceSchema(BaseSchema):
|
||||
organisation_type = field_for(models.Service, 'organisation_type')
|
||||
branding = field_for(models.Service, 'branding')
|
||||
dvla_organisation = field_for(models.Service, 'dvla_organisation')
|
||||
free_sms_fragment_limit = field_for(models.Service, 'free_sms_fragment_limit')
|
||||
permissions = fields.Method("service_permissions")
|
||||
override_flag = False
|
||||
reply_to_email_address = fields.Method(method_name="get_reply_to_email_address")
|
||||
|
||||
@@ -87,7 +87,6 @@ from app.schemas import (
|
||||
detailed_service_schema
|
||||
)
|
||||
from app.utils import pagination_links
|
||||
from app.billing.rest import update_free_sms_fragment_limit_data
|
||||
|
||||
service_blueprint = Blueprint('service', __name__)
|
||||
|
||||
@@ -154,19 +153,24 @@ def get_service_by_id(service_id):
|
||||
@service_blueprint.route('', methods=['POST'])
|
||||
def create_service():
|
||||
data = request.get_json()
|
||||
if not data.get('user_id', None):
|
||||
errors = {'user_id': ['Missing data for required field.']}
|
||||
errors = {
|
||||
required_field: ['Missing data for required field.']
|
||||
for required_field in ['user_id', 'free_sms_fragment_limit']
|
||||
if not data.get(required_field, None)
|
||||
}
|
||||
if errors:
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
|
||||
# validate json with marshmallow
|
||||
service_schema.load(request.get_json())
|
||||
service_schema.load(data)
|
||||
|
||||
user = get_user_by_id(data.pop('user_id', None))
|
||||
free_sms_fragment_limit = data.pop('free_sms_fragment_limit')
|
||||
|
||||
# unpack valid json into service object
|
||||
valid_service = Service.from_json(data)
|
||||
|
||||
dao_create_service(valid_service, user)
|
||||
dao_create_service(valid_service, user, free_sms_fragment_limit)
|
||||
return jsonify(data=service_schema.dump(valid_service).data), 201
|
||||
|
||||
|
||||
@@ -185,10 +189,6 @@ def update_service(service_id):
|
||||
update_dict.crown = org_type == 'central'
|
||||
dao_update_service(update_dict)
|
||||
|
||||
# bridging code between frontend is deployed and data has not been migrated yet. Can only update current year
|
||||
if 'free_sms_fragment_limit' in req_json:
|
||||
update_free_sms_fragment_limit_data(fetched_service.id, req_json['free_sms_fragment_limit'])
|
||||
|
||||
if service_going_live:
|
||||
send_notification_to_service_users(
|
||||
service_id=service_id,
|
||||
|
||||
Reference in New Issue
Block a user