mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-26 01:04:00 -04:00
110067722: Post add-service endpoint saves the service and maps it to the user.
This commit is contained in:
@@ -10,11 +10,14 @@ def insert_new_service(service_name, user):
|
||||
limit=1000,
|
||||
active=False,
|
||||
restricted=True)
|
||||
|
||||
add_service(service)
|
||||
service.users.append(user)
|
||||
db.session.commit()
|
||||
return service.id
|
||||
try:
|
||||
add_service(service)
|
||||
service.users.append(user)
|
||||
db.session.commit()
|
||||
return service.id
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise e
|
||||
|
||||
|
||||
def get_service_by_id(id):
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from flask import render_template, jsonify, redirect
|
||||
from flask import render_template, jsonify, redirect, session
|
||||
from flask_login import login_required
|
||||
|
||||
from app.main import main
|
||||
from app.main.dao import services_dao, users_dao
|
||||
from app.main.forms import AddServiceForm
|
||||
|
||||
|
||||
@@ -17,7 +18,8 @@ def process_add_service():
|
||||
form = AddServiceForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
|
||||
user = users_dao.get_user_by_id(session['user_id'])
|
||||
services_dao.insert_new_service(form.service_name.data, user)
|
||||
return redirect('/dashboard')
|
||||
else:
|
||||
return jsonify(form.errors), 400
|
||||
|
||||
@@ -91,8 +91,6 @@ class Service(db.Model):
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(255), nullable=False, unique=True)
|
||||
|
||||
token_id = db.Column(db.BigInteger, index=True, unique=True)
|
||||
created_at = db.Column(db.DateTime, index=False, unique=False, nullable=False)
|
||||
active = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
||||
limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
|
||||
|
||||
Reference in New Issue
Block a user