Add fields to enable and/or disable pop and imap

master
Pierre Jaury 9 years ago
parent 49b33aba88
commit ec0304456b

@ -27,6 +27,8 @@ class UserForm(Form):
pw = fields.PasswordField('Password', [validators.DataRequired()])
pw2 = fields.PasswordField('Confirm password', [validators.EqualTo('pw')])
quota_bytes = fields_.DecimalSliderField('Quota', default=1000000000)
enable_imap = fields.BooleanField('Allow IMAP access', default=True)
enable_pop = fields.BooleanField('Allow POP3 access', default=True)
comment = fields.StringField('Comment')
submit = fields.SubmitField('Save')

@ -83,6 +83,10 @@ class User(Address):
quota_bytes = db.Column(db.Integer(), nullable=False, default=10**9)
global_admin = db.Column(db.Boolean(), nullable=False, default=False)
# Features
enable_imap = db.Column(db.Boolean(), nullable=False, default=True)
enable_pop = db.Column(db.Boolean(), nullable=False, default=True)
# Filters
forward = db.Column(db.String(160), nullable=True, default=None)
reply_subject = db.Column(db.String(255), nullable=True, default=None)

@ -10,34 +10,42 @@
{% endif %}
{% endmacro %}
{% macro form_field_errors(field) %}
{% if field.errors %}
{% for error in field.errors %}
<p class="help-block inline">{{ error }}</p>
{% endfor %}
{% endif %}
{% endmacro %}
{% macro form_fields(fields, prepend='', append='', label=True) %}
{% set width = (12 / fields|length)|int %}
<div class="form-group">
<div class="row">
{% for field in fields %}
<div class="col-lg-{{ width }} col-xs-12 {{ 'has-error' if field.errors else '' }}">
{{ field.label if label else '' }}
{% if field.errors %}
{% for error in field.errors %}
<p class="help-block inline">{{ error }}</p>
{% endfor %}
{% endif %}
{% if prepend or append %}<div class="input-group">{% endif %}
{{ prepend|safe }}
{{ field(class_="form-control", **kwargs) }}
{{ append|safe }}
{% if prepend or append %}</div>{% endif %}
{{ form_individual_field(field, prepend=prepend, append=append, label=label, **kwargs) }}
</div>
{% endfor %}
</div>
</div>
{% endmacro %}
{% macro form_individual_field(field, prepend='', append='', label=True) %}
{% if field.type == "BooleanField" %}
{{ field(**kwargs) }}<span>&nbsp;&nbsp;</span>
{{ field.label if label else '' }}
{% else %}
{{ field.label if label else '' }}{{ form_field_errors(field) }}
{% if prepend or append %}<div class="input-group">{% endif %}
{{ prepend|safe }}{{ field(class_="form-control", **kwargs) }}{{ append|safe }}
{% if prepend or append %}</div>{% endif %}
{% endif %}
{% endmacro %}
{% macro form_field(field) %}
{% if field.type == 'SubmitField' %}
{{ form_fields((field,), label=False, class="btn btn-default", **kwargs) }}
{% elif field.type == 'HiddenField' %}
{{ form_fields((field,), label=False, **kwargs) }}
{% else %}
{{ form_fields((field,), **kwargs) }}
{% endif %}

@ -16,6 +16,8 @@ New user
{{ macros.form_field(form.quota_bytes, step=1000000000, max=50000000000,
prepend='<span class="input-group-addon"><span id="quota">'+(form.quota_bytes.data//1000000000).__str__()+'</span> GiB</span>',
oninput='$("#quota").text(this.value/1000000000);') }}
{{ macros.form_field(form.enable_imap) }}
{{ macros.form_field(form.enable_pop) }}
{{ macros.form_field(form.comment) }}
{{ macros.form_field(form.submit) }}
</form>

@ -18,9 +18,7 @@ User list
<tr>
<th>Actions</th>
<th>Address</th>
<th>Name</th>
<th>Forward</th>
<th>Reply</th>
<th>Features</th>
<th>Quota</th>
<th>Comment</th>
<th>Created</th>
@ -38,11 +36,12 @@ User list
<a href="{{ url_for('.user_delete', user_email=user.get_id()) }}" title="Delete"><i class="fa fa-trash"></i></a>
</td>
<td>{{ user }}</td>
<td>{{ user.displayed_name }}</td>
<td>{% if user.forward %}<span class="label label-info">enabled</span>{% endif %}</td>
<td>{% if user.reply_subject %}<span class="label label-info">enabled</span>{% endif %}</td>
<td>
{% if user.enable_imap %}<span class="label label-info">imap</span>{% endif %}
{% if user.enable_pop %}<span class="label label-info">pop3</span>{% endif %}
</td>
<td>{{ user.quota_bytes | filesizeformat }}</td>
<td>{{ user.comment or '' }}</td>
<td>{{ user.comment or '-' }}</td>
<td>{{ user.created_at }}</td>
<td>{{ user.updated_at or '' }}</td>
</tr>

Loading…
Cancel
Save