mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-17 04:58:50 -04:00
Merge branch 'master' into reset-password
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
from flask import current_app
|
||||
from app import db
|
||||
from app.models import Notification
|
||||
from app.models import Notification, Job
|
||||
from sqlalchemy import desc
|
||||
|
||||
|
||||
def dao_create_notification(notification):
|
||||
if notification.job_id:
|
||||
db.session.query(Job).filter_by(
|
||||
id=notification.job_id
|
||||
).update({Job.notifications_sent: Job.notifications_sent + 1})
|
||||
db.session.add(notification)
|
||||
db.session.commit()
|
||||
|
||||
@@ -19,12 +23,12 @@ def get_notification_for_job(service_id, job_id, notification_id):
|
||||
|
||||
|
||||
def get_notifications_for_job(service_id, job_id, page=1):
|
||||
query = Notification.query.filter_by(service_id=service_id, job_id=job_id)\
|
||||
.order_by(desc(Notification.created_at))\
|
||||
query = Notification.query.filter_by(service_id=service_id, job_id=job_id) \
|
||||
.order_by(desc(Notification.created_at)) \
|
||||
.paginate(
|
||||
page=page,
|
||||
per_page=current_app.config['PAGE_SIZE']
|
||||
)
|
||||
page=page,
|
||||
per_page=current_app.config['PAGE_SIZE']
|
||||
)
|
||||
return query
|
||||
|
||||
|
||||
|
||||
@@ -162,6 +162,7 @@ class Job(db.Model):
|
||||
onupdate=datetime.datetime.now)
|
||||
status = db.Column(db.Enum(*JOB_STATUS_TYPES, name='job_status_types'), nullable=False, default='pending')
|
||||
notification_count = db.Column(db.Integer, nullable=False)
|
||||
notifications_sent = db.Column(db.Integer, nullable=False, default=0)
|
||||
processing_started = db.Column(
|
||||
db.DateTime,
|
||||
index=False,
|
||||
|
||||
@@ -4,6 +4,7 @@ from flask import (
|
||||
request,
|
||||
current_app
|
||||
)
|
||||
import bleach
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app.dao.templates_dao import (
|
||||
@@ -34,6 +35,7 @@ def create_template(service_id):
|
||||
if errors:
|
||||
return jsonify(result="error", message=errors), 400
|
||||
new_template.service = fetched_service
|
||||
new_template.content = _strip_html(new_template.content)
|
||||
try:
|
||||
dao_create_template(new_template)
|
||||
except IntegrityError as ex:
|
||||
@@ -55,6 +57,7 @@ def update_template(service_id, template_id):
|
||||
|
||||
current_data = dict(template_schema.dump(fetched_template).data.items())
|
||||
current_data.update(request.get_json())
|
||||
current_data['content'] = _strip_html(current_data['content'])
|
||||
|
||||
update_dict, errors = template_schema.load(current_data)
|
||||
if errors:
|
||||
@@ -79,3 +82,7 @@ def get_template_by_id_and_service_id(service_id, template_id):
|
||||
return jsonify(data=data)
|
||||
else:
|
||||
return jsonify(result="error", message="Template not found"), 404
|
||||
|
||||
|
||||
def _strip_html(content):
|
||||
return bleach.clean(content, tags=[], strip=True)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime
|
||||
from flask import (jsonify, request, abort, Blueprint, current_app)
|
||||
from flask import (jsonify, request, abort, Blueprint)
|
||||
from app import encryption
|
||||
|
||||
from app.dao.users_dao import (
|
||||
@@ -77,6 +77,8 @@ def verify_user_password(user_id):
|
||||
result="error",
|
||||
message={'password': ['Required field missing data']}), 400
|
||||
if user_to_verify.check_password(txt_pwd):
|
||||
user_to_verify.logged_in_at = datetime.utcnow()
|
||||
save_model_user(user_to_verify)
|
||||
reset_failed_login_count(user_to_verify)
|
||||
return jsonify({}), 204
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user