2018-10-18 15:57:43 +02:00
|
|
|
from mailu import models
|
2017-09-24 12:00:39 +02:00
|
|
|
from mailu.ui import ui, forms, access
|
2016-04-28 20:07:38 +02:00
|
|
|
|
|
|
|
import flask
|
2016-08-13 20:51:54 +02:00
|
|
|
import flask_login
|
2019-01-09 13:52:05 +02:00
|
|
|
import wtforms
|
2016-04-28 20:07:38 +02:00
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/fetch/list', methods=['GET', 'POST'], defaults={'user_email': None})
|
2019-01-04 19:01:46 +02:00
|
|
|
@ui.route('/fetch/list/<path:user_email>', methods=['GET'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.owner(models.User, 'user_email')
|
2016-05-01 20:04:40 +02:00
|
|
|
def fetch_list(user_email):
|
2016-08-29 19:24:39 +02:00
|
|
|
user_email = user_email or flask_login.current_user.email
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
2016-04-28 20:07:38 +02:00
|
|
|
return flask.render_template('fetch/list.html', user=user)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/fetch/create', methods=['GET', 'POST'], defaults={'user_email': None})
|
2019-01-04 19:01:46 +02:00
|
|
|
@ui.route('/fetch/create/<path:user_email>', methods=['GET', 'POST'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.owner(models.User, 'user_email')
|
2016-05-01 20:04:40 +02:00
|
|
|
def fetch_create(user_email):
|
2016-08-29 19:24:39 +02:00
|
|
|
user_email = user_email or flask_login.current_user.email
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
2016-04-28 20:07:38 +02:00
|
|
|
form = forms.FetchForm()
|
2019-01-25 16:08:41 +02:00
|
|
|
form.password.validators = [wtforms.validators.DataRequired()]
|
2016-04-28 20:07:38 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
fetch = models.Fetch(user=user)
|
2016-05-01 21:12:08 +02:00
|
|
|
form.populate_obj(fetch)
|
2022-11-13 18:15:50 +02:00
|
|
|
if form.folders.data:
|
|
|
|
fetch.folders = form.folders.data.replace(' ','').split(',')
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.add(fetch)
|
|
|
|
models.db.session.commit()
|
2016-04-28 20:07:38 +02:00
|
|
|
flask.flash('Fetch configuration created')
|
|
|
|
return flask.redirect(
|
2016-05-01 20:04:40 +02:00
|
|
|
flask.url_for('.fetch_list', user_email=user.email))
|
2016-04-28 20:07:38 +02:00
|
|
|
return flask.render_template('fetch/create.html', form=form)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/fetch/edit/<fetch_id>', methods=['GET', 'POST'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.owner(models.Fetch, 'fetch_id')
|
2016-04-28 20:07:38 +02:00
|
|
|
def fetch_edit(fetch_id):
|
2016-08-29 19:24:39 +02:00
|
|
|
fetch = models.Fetch.query.get(fetch_id) or flask.abort(404)
|
2016-04-28 20:07:38 +02:00
|
|
|
form = forms.FetchForm(obj=fetch)
|
|
|
|
if form.validate_on_submit():
|
2019-01-09 13:52:05 +02:00
|
|
|
if not form.password.data:
|
|
|
|
form.password.data = fetch.password
|
2016-05-01 21:12:08 +02:00
|
|
|
form.populate_obj(fetch)
|
2022-11-13 18:15:50 +02:00
|
|
|
if form.folders.data:
|
|
|
|
fetch.folders = form.folders.data.replace(' ','').split(',')
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.commit()
|
2016-04-28 20:07:38 +02:00
|
|
|
flask.flash('Fetch configuration updated')
|
|
|
|
return flask.redirect(
|
2016-05-01 20:04:40 +02:00
|
|
|
flask.url_for('.fetch_list', user_email=fetch.user.email))
|
2016-04-28 20:07:38 +02:00
|
|
|
return flask.render_template('fetch/edit.html',
|
|
|
|
form=form, fetch=fetch)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/fetch/delete/<fetch_id>', methods=['GET', 'POST'])
|
2016-08-29 19:35:09 +02:00
|
|
|
@access.confirmation_required("delete a fetched account")
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.owner(models.Fetch, 'fetch_id')
|
2016-04-28 20:07:38 +02:00
|
|
|
def fetch_delete(fetch_id):
|
2016-08-29 19:24:39 +02:00
|
|
|
fetch = models.Fetch.query.get(fetch_id) or flask.abort(404)
|
2016-11-22 12:38:05 +02:00
|
|
|
user = fetch.user
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.delete(fetch)
|
|
|
|
models.db.session.commit()
|
2016-04-28 20:07:38 +02:00
|
|
|
flask.flash('Fetch configuration delete')
|
|
|
|
return flask.redirect(
|
2016-11-22 12:38:05 +02:00
|
|
|
flask.url_for('.fetch_list', user_email=user.email))
|