添加新接口
This commit is contained in:
parent
c467568b98
commit
3717a9f46f
|
@ -9,6 +9,8 @@ from flask import Flask, request
|
|||
# must first init loadenv
|
||||
import tools, env
|
||||
# default CONFIG=/opt/docklet/local/docklet-running.conf
|
||||
from notificationmgr import NotificationMgr
|
||||
|
||||
config = env.getenv("CONFIG")
|
||||
tools.loadenv(config)
|
||||
|
||||
|
@ -499,6 +501,7 @@ def groupadd_user(cur_user, user, form):
|
|||
result = G_usermgr.groupadd(form = form, cur_user = cur_user)
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/user/chdefault/", methods=['POST'])
|
||||
@login_required
|
||||
def chdefault(cur_user, user, form):
|
||||
|
@ -534,6 +537,7 @@ def data_user(cur_user, user, form):
|
|||
result = G_usermgr.userList(cur_user = cur_user)
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/user/groupNameList/", methods=['POST'])
|
||||
@login_required
|
||||
def groupNameList_user(cur_user, user, form):
|
||||
|
@ -551,6 +555,7 @@ def groupList_user(cur_user, user, form):
|
|||
result = G_usermgr.groupList(cur_user = cur_user)
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/user/groupQuery/", methods=['POST'])
|
||||
@login_required
|
||||
def groupQuery_user(cur_user, user, form):
|
||||
|
@ -559,6 +564,7 @@ def groupQuery_user(cur_user, user, form):
|
|||
result = G_usermgr.groupQuery(name = form.get("name"), cur_user = cur_user)
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/user/selfQuery/", methods=['POST'])
|
||||
@login_required
|
||||
def selfQuery_user(cur_user, user, form):
|
||||
|
@ -567,6 +573,7 @@ def selfQuery_user(cur_user, user, form):
|
|||
result = G_usermgr.selfQuery(cur_user = cur_user)
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/user/selfModify/", methods=['POST'])
|
||||
@login_required
|
||||
def selfModify_user(cur_user, user, form):
|
||||
|
@ -575,6 +582,15 @@ def selfModify_user(cur_user, user, form):
|
|||
result = G_usermgr.selfModify(cur_user = cur_user, newValue = form)
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/notification/create/", methods=['POST'])
|
||||
@login_required
|
||||
def create_notification(cur_user, user, form):
|
||||
global G_notificationmgr
|
||||
logger.info("handle request: notification/create/")
|
||||
result = G_notificationmgr.create_notification(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):
|
||||
|
@ -681,10 +697,10 @@ if __name__ == '__main__':
|
|||
runcmd = sys.argv[0]
|
||||
app.runpath = runcmd.rsplit('/', 1)[0]
|
||||
|
||||
|
||||
global G_nodemgr
|
||||
global G_vclustermgr
|
||||
global G_usermgr
|
||||
global G_notificationmgr
|
||||
global etcdclient
|
||||
global G_networkmgr
|
||||
global G_clustername
|
||||
|
@ -765,6 +781,8 @@ if __name__ == '__main__':
|
|||
etcdclient.deldir("_lock")
|
||||
|
||||
G_usermgr = userManager.userManager('root')
|
||||
G_notificationmgr = NotificationMgr()
|
||||
|
||||
clusternet = env.getenv("CLUSTER_NET")
|
||||
logger.info("using CLUSTER_NET %s" % clusternet)
|
||||
|
||||
|
|
16
src/model.py
16
src/model.py
|
@ -145,10 +145,22 @@ class Notification(db.Model):
|
|||
content = db.Column(db.String(8000))
|
||||
create_date = db.Column(db.String(10))
|
||||
|
||||
def __init__(self, title):
|
||||
def __init__(self, title, content=''):
|
||||
self.title = title
|
||||
self.content = ''
|
||||
self.content = content
|
||||
self.create_date = datetime.utcnow()
|
||||
|
||||
def __repr__(self):
|
||||
return '<Notification %r>' % self.title
|
||||
|
||||
|
||||
class NotificationGroups(db.Model):
|
||||
notification_id = db.Column(db.Integer)
|
||||
group_name = db.Column(db.String(100))
|
||||
|
||||
def __init__(self, notification_id, group_name):
|
||||
self.notification_id = notification_id
|
||||
self.group_name = group_name
|
||||
|
||||
def __repr__(self):
|
||||
return '<Notification: %r, Group: %r>' % (self.notification_id, self.group_name)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
from model import db, Notification, NotificationGroups
|
||||
from userManager import administration_required
|
||||
|
||||
|
||||
class NotificationMgr:
|
||||
def __init__(self):
|
||||
try:
|
||||
Notification.query.all()
|
||||
except:
|
||||
db.create_all()
|
||||
|
||||
@administration_required
|
||||
def create_notification(self, *args, **kwargs):
|
||||
'''
|
||||
Usage: createNotification(cur_user = 'Your current user', form = 'Post form')
|
||||
Post form: {title: 'Your title', content: 'Your content', groups: ['groupA', 'groupB']}
|
||||
'''
|
||||
form = kwargs['form']
|
||||
notify = Notification(form['title'], form['content'])
|
||||
db.session.add(notify)
|
||||
db.session.commit()
|
||||
for group_name in form['groups']:
|
||||
notify_groups = NotificationGroups(notify.id, group_name)
|
||||
db.session.add(notify_groups)
|
||||
db.session.commit()
|
||||
return {"success": 'true'}
|
||||
|
|
@ -150,10 +150,6 @@ class userManager:
|
|||
path = env.getenv('DOCKLET_LIB')
|
||||
subprocess.call([path+"/userinit.sh", username])
|
||||
db.session.commit()
|
||||
try:
|
||||
Notification.query.all()
|
||||
except:
|
||||
db.create_all()
|
||||
if not os.path.exists(fspath+"/global/sys/quota"):
|
||||
groupfile = open(fspath+"/global/sys/quota",'w')
|
||||
groups = []
|
||||
|
|
|
@ -348,6 +348,12 @@ def userinfo():
|
|||
def userquery():
|
||||
return userqueryView.as_view()
|
||||
|
||||
|
||||
@app.route("/notification/create/", methods=['POST'])
|
||||
@administration_required
|
||||
def create_notification():
|
||||
return CreateNotificationView.as_view()
|
||||
|
||||
@app.route("/system/modify/", methods=['POST'])
|
||||
@administration_required
|
||||
def systemmodify():
|
||||
|
|
|
@ -87,3 +87,10 @@ class historydelView(normalView):
|
|||
def post(self):
|
||||
dockletRequest.post('/system/historydel/', request.form)
|
||||
return redirect('/admin/')
|
||||
|
||||
|
||||
class CreateNotificationView(normalView):
|
||||
@classmethod
|
||||
def post(cls):
|
||||
dockletRequest.post('/notification/create/', request.form)
|
||||
return redirect('admin')
|
||||
|
|
Loading…
Reference in New Issue