From 719ff951b447a6875cfabbd27f38cdd116a2a6e1 Mon Sep 17 00:00:00 2001 From: Peidong Liu Date: Tue, 9 May 2017 01:16:22 +0800 Subject: [PATCH 1/2] fix a bug that only root's info can be modified in /user/list --- conf/docklet.conf.template | 11 ----------- src/beansapplicationmgr.py | 20 ++++++++++---------- src/env.py | 4 ---- user/user.py | 5 ++++- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/conf/docklet.conf.template b/conf/docklet.conf.template index d797499..72c00ab 100644 --- a/conf/docklet.conf.template +++ b/conf/docklet.conf.template @@ -130,17 +130,6 @@ # default: authenticate local and PAM users # EXTERNAL_LOGIN=False -# EMAIL_FROM_ADDRESS : the e-mail address to send activating e-mail to user -# If this address is "", no email will be sent out. -# default: "" -# EMAIL_FROM_ADDRESS="" - -# ADMIN_EMAIL_ADDRESS : when an activating request is sent, an e-mail will -# be sent to this address to remind the admin. -# If this address i "", no email will be sent to admin. -# default: "" -# ADMIN_EMAIL_ADDRESS="" - # DATA_QUOTA : whether enable the quota of data volume or not # True or False, default: False # DATA_QUOTA=False diff --git a/src/beansapplicationmgr.py b/src/beansapplicationmgr.py index 2099d8a..b64df00 100755 --- a/src/beansapplicationmgr.py +++ b/src/beansapplicationmgr.py @@ -18,12 +18,12 @@ import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header +from settings import settings -email_from_address = env.getenv('EMAIL_FROM_ADDRESS') # send email to remind users of their beans def send_beans_email(to_address, username, beans): - global email_from_address + email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return #text = 'Dear '+ username + ':\n' + ' Your beans in docklet are less than' + beans + '.' @@ -53,7 +53,7 @@ def send_beans_email(to_address, username, beans): # a class that will deal with users' requests about beans application. class ApplicationMgr: - + def __init__(self): # create database try: @@ -71,13 +71,13 @@ class ApplicationMgr: applymsgs = ApplyMsg.query.filter_by(username=username).all() lasti = len(applymsgs) - 1 # the last index, the last application is also the latest application. if lasti >= 0 and applymsgs[lasti].status == "Processing": - return [False, "You already have a processing application, please be patient."] + return [False, "You already have a processing application, please be patient."] # store the application into the database applymsg = ApplyMsg(username,number,reason) db.session.add(applymsg) db.session.commit() return [True,""] - + # get all applications of a user def query(self,username): applymsgs = ApplyMsg.query.filter_by(username=username).all() @@ -85,7 +85,7 @@ class ApplicationMgr: for msg in applymsgs: ans.append(msg.ch2dict()) return ans - + # get all unread applications @administration_required def queryUnRead(self,*,cur_user): @@ -94,7 +94,7 @@ class ApplicationMgr: for msg in applymsgs: ans.append(msg.ch2dict()) return {"success":"true","applymsgs":ans} - + # agree an application @administration_required def agree(self,msgid,*,cur_user): @@ -108,7 +108,7 @@ class ApplicationMgr: user.beans += applymsg.number db.session.commit() return {"success":"true"} - + # reject an application @administration_required def reject(self,msgid,*,cur_user): @@ -127,9 +127,9 @@ class ApprovalRobot(threading.Thread): self.stop = False self.interval = 20 self.maxtime = maxtime # The max time that users may wait for from 'processing' to 'agreed' - + def stop(self): - self.stop = True + self.stop = True def run(self): while not self.stop: diff --git a/src/env.py b/src/env.py index a847f79..e01110c 100755 --- a/src/env.py +++ b/src/env.py @@ -50,10 +50,6 @@ def getenv(key): return os.environ.get("STORAGE", "file") elif key =="EXTERNAL_LOGIN": return os.environ.get("EXTERNAL_LOGIN", "False") - elif key =="EMAIL_FROM_ADDRESS": - return os.environ.get("EMAIL_FROM_ADDRESS", "") - elif key =="ADMIN_EMAIL_ADDRESS": - return os.environ.get("ADMIN_EMAIL_ADDRESS", "") elif key =="DATA_QUOTA": return os.environ.get("DATA_QUOTA", "False") elif key =="DATA_QUOTA_CMD": diff --git a/user/user.py b/user/user.py index f1a293c..6eb9152 100755 --- a/user/user.py +++ b/user/user.py @@ -219,7 +219,10 @@ def query_user(cur_user, user, form): global G_usermgr logger.info("handle request: user/query/") #result = G_usermgr.query(ID = form.get("ID"), cur_user = cur_user) - result = G_usermgr.query(username = user, cur_user = cur_user) + if (form.get("ID", None) != None): + result = G_usermgr.query(ID = form.get("ID"), cur_user = cur_user) + else: + result = G_usermgr.query(username = user, cur_user = cur_user) if (result.get('success', None) == None or result.get('success', None) == "false"): return json.dumps(result) else: From 19ee71d35e29c8a74f1f9a6cc9db6439f36532eb Mon Sep 17 00:00:00 2001 From: Peidong Liu Date: Tue, 9 May 2017 01:18:37 +0800 Subject: [PATCH 2/2] use settings.get('E_MAIL_FROM_ADDRESS') to get e-mail address --- src/notificationmgr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/notificationmgr.py b/src/notificationmgr.py index c94826f..426099d 100644 --- a/src/notificationmgr.py +++ b/src/notificationmgr.py @@ -9,6 +9,7 @@ from email.mime.multipart import MIMEMultipart from email.header import Header from datetime import datetime import env +from settings import settings class NotificationMgr: def __init__(self): @@ -36,7 +37,7 @@ class NotificationMgr: return [Notification.query.filter_by(id=notify_id).first() for notify_id in notify_ids] def mail_notification(self, notify_id): - email_from_address = env.getenv('EMAIL_FROM_ADDRESS') + email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return {'success' : 'true'} notify = Notification.query.filter_by(id=notify_id).first()