def domain_delete(domain_name): utils.require_global_admin() domain = utils.get_domain_admin(domain_name) db.session.delete(domain) db.session.commit() flask.flash('Domain %s deleted' % domain) return flask.redirect(flask.url_for('.domain_list'))
def manager_delete(manager): user = utils.get_user(manager, admin=True) domain = utils.get_domain_admin(user.domain_name) if user in domain.managers: domain.managers.remove(user) db.session.commit() flask.flash('User %s can no longer manager %s' % (user, domain)) else: flask.flash('User %s is not manager' % user, 'error') return flask.redirect( flask.url_for('.manager_list', domain_name=domain.name))
def domain_edit(domain_name): utils.require_global_admin() domain = utils.get_domain_admin(domain_name) form = forms.DomainForm(obj=domain) wtforms_components.read_only(form.name) if form.validate_on_submit(): form.populate_obj(domain) db.session.commit() flask.flash('Domain %s saved' % domain) return flask.redirect(flask.url_for('.domain_list')) return flask.render_template('domain/edit.html', form=form, domain=domain)
def manager_create(domain_name): domain = utils.get_domain_admin(domain_name) form = forms.ManagerForm() if form.validate_on_submit(): user = utils.get_user(form.manager.data, admin=True) if user in domain.managers: flask.flash('User %s is already manager' % user, 'error') else: domain.managers.append(user) db.session.add(domain) db.session.commit() flask.flash('User %s can now manage %s' % (user, domain.name)) return flask.redirect( flask.url_for('.manager_list', domain_name=domain.name)) return flask.render_template('manager/create.html', domain=domain, form=form)
def alias_create(domain_name): domain = utils.get_domain_admin(domain_name) if domain.max_aliases and len(domain.aliases) >= domain.max_aliases: flask.flash('Too many aliases for domain %s' % domain, 'error') return flask.redirect( flask.url_for('.alias_list', domain_name=domain.name)) form = forms.AliasForm() if form.validate_on_submit(): if domain.has_email(form.localpart.data): flask.flash('Email is already used', 'error') else: alias = models.Alias(domain=domain) form.populate_obj(alias) db.session.add(alias) db.session.commit() flask.flash('Alias %s created' % alias) return flask.redirect( flask.url_for('.alias_list', domain_name=domain.name)) return flask.render_template('alias/create.html', domain=domain, form=form)
def user_create(domain_name): domain = utils.get_domain_admin(domain_name) if domain.max_users and len(domain.users) >= domain.max_users: flask.flash('Too many users for domain %s' % domain, 'error') return flask.redirect( flask.url_for('.user_list', domain_name=domain.name)) form = forms.UserForm() if form.validate_on_submit(): if domain.has_email(form.localpart.data): flask.flash('Email is already used', 'error') else: user = models.User(domain=domain) form.populate_obj(user) user.set_password(form.pw.data) db.session.add(user) db.session.commit() flask.flash('User %s created' % user) return flask.redirect( flask.url_for('.user_list', domain_name=domain.name)) return flask.render_template('user/create.html', domain=domain, form=form)
def manager_create(domain_name): domain = utils.get_domain_admin(domain_name) form = forms.ManagerForm() form.manager.choices = [ (user.email, user.email) for user in flask_login.current_user.get_managed_emails( include_aliases=False) ] if form.validate_on_submit(): user = utils.get_user(form.manager.data, admin=True) if user in domain.managers: flask.flash('User %s is already manager' % user, 'error') else: domain.managers.append(user) db.session.commit() flask.flash('User %s can now manage %s' % (user, domain.name)) return flask.redirect( flask.url_for('.manager_list', domain_name=domain.name)) return flask.render_template('manager/create.html', domain=domain, form=form)
def user_create(domain_name): domain = utils.get_domain_admin(domain_name) if domain.max_users and len(domain.users) >= domain.max_users: flask.flash('Too many users for domain %s' % domain, 'error') return flask.redirect( flask.url_for('.user_list', domain_name=domain.name)) form = forms.UserForm() if form.validate_on_submit(): if domain.has_address(form.localpart.data): flask.flash('Address %s is already used' % address, 'error') else: user = models.User(localpart=form.localpart.data, domain=domain) user.comment = form.comment.data user.quota_bytes = int(form.quota_bytes.data) user.enable_imap = form.enable_imap.data user.enable_pop = form.enable_pop.data user.set_password(form.pw.data) db.session.add(user) db.session.commit() flask.flash('User %s created' % user) return flask.redirect( flask.url_for('.user_list', domain_name=domain.name)) return flask.render_template('user/create.html', domain=domain, form=form)
def domain_genkeys(domain_name): domain = utils.get_domain_admin(domain_name) domain.generate_dkim_key() return flask.redirect( flask.url_for(".domain_details", domain_name=domain_name))
def domain_details(domain_name): domain = utils.get_domain_admin(domain_name) return flask.render_template('domain/details.html', domain=domain, config=flask_app.config)
def manager_list(domain_name): domain = utils.get_domain_admin(domain_name) return flask.render_template('manager/list.html', domain=domain)
def alias_list(domain_name): domain = utils.get_domain_admin(domain_name) return flask.render_template('alias/list.html', domain=domain)