Commit 640503c9 authored by buttle's avatar buttle

Fixed first admin bug on new site.

Some code cleaning
parent ab3182d5
......@@ -31,7 +31,7 @@ babel = Babel(app)
csrf = CSRFProtect()
csrf.init_app(app)
app.config['APP_VERSION'] = 27
app.config['APP_VERSION'] = 28
app.config['SCHEMA_VERSION'] = 12
app.config['RESERVED_SLUGS'] = ['static', 'admin', 'admins', 'user', 'users', 'form', 'forms', 'site', 'sites', 'update']
......
......@@ -211,7 +211,7 @@ class User(object):
def isAdmin(self):
return self.user['admin']['isAdmin']
def isRootUser(self):
if self.email in app.config['ROOT_USERS']:
return True
......@@ -464,13 +464,12 @@ class Form(object):
def getConditionalFieldPositions(self):
conditionalFieldPositions=[]
if self.fieldConditions:
for fieldName, condition in self.fieldConditions.items():
if condition['type'] == 'number':
for position, field in enumerate(self.fieldIndex):
if field['name'] == fieldName:
conditionalFieldPositions.append(position)
break
for fieldName, condition in self.fieldConditions.items():
if condition['type'] == 'number':
for position, field in enumerate(self.fieldIndex):
if field['name'] == fieldName:
conditionalFieldPositions.append(position)
break
return conditionalFieldPositions
def findAll(cls, *args, **kwargs):
......@@ -746,7 +745,12 @@ class Site(object):
@property
def totalUsers(self):
return User().findAll(hostname=self.hostname).count()
@property
def admins(self):
criteria={"admin.isAdmin": True, 'hostname': self.hostname}
return [User(_id=user['_id']) for user in mongo.db.users.find(criteria)]
@property
def totalForms(self):
return Form().findAll(hostname=self.hostname).count()
......
{% extends "base.html" %}
{% block content %}
{% set fieldIndex = form.getFieldIndexForDataDisplay() %}
{% set tallyColumns = form.getConditionalFieldPositions() %}
<script src="/static/dataTables/jquery.dataTables.min.js"></script>
<script src="/static/dataTables/dataTables.bootstrap.min.js"></script>
{% if tallyColumns %}
......
......@@ -643,9 +643,7 @@ def list_entries(_id):
flash(gettext("No form found"), 'warning')
return redirect(make_url_for('my_forms'))
return render_template('list-entries.html', form=queriedForm,
tallyColumns=queriedForm.getConditionalFieldPositions(),
fieldIndex=queriedForm.getFieldIndexForDataDisplay())
return render_template('list-entries.html', form=queriedForm)
@app.route('/forms/csv/<string:_id>', methods=['GET'])
......@@ -878,6 +876,10 @@ def new_user(token=None):
validatedEmail=True
if invite.data['admin'] == True:
adminSettings['isAdmin']=invite.data['admin']
# the first admin of a new Site needs to config. SMTP before we can send emails.
# when validatedEmail=False, a validation email fails to be sent because SMTP is not congifured.
if not g.site.admins:
validatedEmail=True
if request.form['email'] in app.config['ROOT_USERS']:
adminSettings["isAdmin"]=True
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment