From b07158c2566d15d909c7c34f86a3159a4ecc4d02 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sun, 20 Mar 2016 11:00:01 +0100 Subject: [PATCH] Add the auto-reply feature in the admin panel --- admin/freeposte/forms.py | 6 ++++++ admin/freeposte/models.py | 6 +++++- admin/freeposte/templates/sidebar.html | 4 ++-- admin/freeposte/templates/user/reply.html | 9 +++++++++ admin/freeposte/templates/user/vacation.html | 1 - admin/freeposte/views/users.py | 21 +++++++++++++++----- 6 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 admin/freeposte/templates/user/reply.html delete mode 100644 admin/freeposte/templates/user/vacation.html diff --git a/admin/freeposte/forms.py b/admin/freeposte/forms.py index 3edd0b55..787cba1d 100644 --- a/admin/freeposte/forms.py +++ b/admin/freeposte/forms.py @@ -42,6 +42,12 @@ class UserForwardForm(Form): submit = fields.SubmitField('Update') +class UserReplyForm(Form): + reply_subject = fields.StringField('Reply subject') + reply_body = fields.StringField('Reply body', widget=widgets.TextArea()) + submit = fields.SubmitField('Update') + + class AliasCreateForm(Form): localpart = fields.StringField('Alias', [validators.DataRequired()]) destination = fields.StringField('Destination', widget=widgets.TextArea()) diff --git a/admin/freeposte/models.py b/admin/freeposte/models.py index 025f3c7d..6b5e9601 100644 --- a/admin/freeposte/models.py +++ b/admin/freeposte/models.py @@ -60,9 +60,13 @@ class User(Address): domain = db.relationship(Domain, backref='users') password = db.Column(db.String(255), nullable=False) quota_bytes = db.Column(db.Integer(), nullable=False, default=10**9) - forward = db.Column(db.String(160), nullable=True, default=None) global_admin = db.Column(db.Boolean(), nullable=False, default=False) + # Filters + forward = db.Column(db.String(160), nullable=True, default=None) + reply_topic = db.Column(db.String(255), nullable=True, default=None) + reply_body = db.Column(db.Text(), nullable=True, default=None) + is_authenticated = True is_active = True is_anonymous = False diff --git a/admin/freeposte/templates/sidebar.html b/admin/freeposte/templates/sidebar.html index d2581504..b0369576 100644 --- a/admin/freeposte/templates/sidebar.html +++ b/admin/freeposte/templates/sidebar.html @@ -19,8 +19,8 @@
  • - - Vacation + + Auto-reply
  • diff --git a/admin/freeposte/templates/user/reply.html b/admin/freeposte/templates/user/reply.html new file mode 100644 index 00000000..50864129 --- /dev/null +++ b/admin/freeposte/templates/user/reply.html @@ -0,0 +1,9 @@ +{% extends "form.html" %} + +{% block title %} +Automatic reply +{% endblock %} + +{% block subtitle %} +{{ user }} +{% endblock %} diff --git a/admin/freeposte/templates/user/vacation.html b/admin/freeposte/templates/user/vacation.html deleted file mode 100644 index a500fb36..00000000 --- a/admin/freeposte/templates/user/vacation.html +++ /dev/null @@ -1 +0,0 @@ -{% extends "working.html" %} diff --git a/admin/freeposte/views/users.py b/admin/freeposte/views/users.py index f06b0097..1effc2b9 100644 --- a/admin/freeposte/views/users.py +++ b/admin/freeposte/views/users.py @@ -103,14 +103,25 @@ def user_forward(user_email): if user_email: return flask.redirect( flask.url_for('user_list', domain_name=user.domain.name)) - return flask.render_template('user/forward.html', form=form, user=userĂ©) + return flask.render_template('user/forward.html', form=form, user=user) -@app.route('/user/vacation', methods=['GET', 'POST'], defaults={'user_email': None}) -@app.route('/user/vacation', methods=['GET', 'POST']) +@app.route('/user/reply', methods=['GET', 'POST'], defaults={'user_email': None}) +@app.route('/user/reply/', methods=['GET', 'POST']) @flask_login.login_required -def user_vacation(user_email): - return flask.render_template('user/vacation.html') +def user_reply(user_email): + user = utils.get_user(user_email) + form = forms.UserReplyForm() + if form.validate_on_submit(): + user.reply_subject = form.reply_subject.data + user.reply_body = form.reply_body.data + db.session.add(user) + db.session.commit() + flask.flash('Auto-reply message updated for %s' % user) + if user_email: + return flask.redirect( + flask.url_for('user_list', domain_name=user.domain.name)) + return flask.render_template('user/reply.html', form=form, user=user) @app.route('/user/fetchmail', methods=['GET', 'POST'], defaults={'user_email': None})