diff --git a/src/httprest.py b/src/httprest.py index 67cfe50..ec75138 100755 --- a/src/httprest.py +++ b/src/httprest.py @@ -599,6 +599,16 @@ def create_notification(cur_user, user, form): result = G_notificationmgr.create_notification(cur_user=cur_user, form=form) return json.dumps(result) + +@app.route("/notification/query_self/", methods=['POST']) +@login_required +def query_self_notifications(cur_user, user, form): + global G_notificationmgr + logger.info("handle request: notification/query_self/") + result = G_notificationmgr.query_self_notifications(cur_user=cur_user, form=form) + return json.dumps(result) + + @app.route("/system/parmList/", methods=['POST']) @login_required def parmList_system(cur_user, user, form): diff --git a/src/notificationmgr.py b/src/notificationmgr.py index b9b67c4..76525c4 100644 --- a/src/notificationmgr.py +++ b/src/notificationmgr.py @@ -2,7 +2,7 @@ import json from log import logger from model import db, Notification, NotificationGroups -from userManager import administration_required +from userManager import administration_required, token_required class NotificationMgr: @@ -53,3 +53,23 @@ class NotificationMgr: 'groups': [group.group_name for group in groups] }) return {'success': 'true', 'data': notify_infos} + + @token_required + def query_self_notifications(self, *args, **kwargs): + user = kwargs['cur_user'] + group_name = user.user_group + notifies = NotificationGroups.query.filter_by(group_name=group_name).all() + notifies.extend(NotificationGroups.query.filter_by(group_name='all').all()) + notify_ids = [notify.notification_id for notify in notifies] + notify_ids = sorted(list(set(notify_ids)), reversed=True) + notify_simple_infos = [] + for notify_id in notify_ids: + notify = Notification.query.filter_by(id=notify_id).first() + if notify.status != 'open': + continue + notify_simple_infos.append({ + 'id': notify.id, + 'title': notify.title, + 'create_date': notify.create_date + }) + return {'success': 'true', 'data': notify_simple_infos} diff --git a/web/templates/base_AdminLTE.html b/web/templates/base_AdminLTE.html index f4db7d1..f19e24d 100644 --- a/web/templates/base_AdminLTE.html +++ b/web/templates/base_AdminLTE.html @@ -55,7 +55,26 @@