Merge pull request #231 from PedroLiu/master

Fix a bug that only root's info can be modified in /user/list
This commit is contained in:
PedroLiu 2017-05-09 01:20:13 +08:00 committed by GitHub
commit 1e2a7528d6
5 changed files with 16 additions and 27 deletions

View File

@ -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

View File

@ -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:

View File

@ -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":

View File

@ -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()

View File

@ -218,7 +218,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: