Commit 5ac149f0 authored by o@immerda.ch's avatar o@immerda.ch
Browse files

update interface to create/delete new-style aliases

parent 2517c5a4
function enableDelete() {
document.getElementById('enable_delete_form').style.display = 'none';
document.getElementById('delete_form').style.display = 'block';
}
function loadActions() {
if (document.getElementById('enable_delete_form'))
document.getElementById('enable_delete_form').addEventListener("click", enableDelete);
}
window.addEventListener("load", loadActions)
......@@ -13,8 +13,6 @@ function enableOverride() {
}
function loadActions() {
if (document.getElementById('only_mailbox'))
document.getElementById('only_mailbox').addEventListener("change", action)
if (document.getElementById('enable_delete_form'))
document.getElementById('enable_delete_form').addEventListener("click", enableDelete);
if (document.getElementById('enable_override_form'))
......
class AppPasswordsController < ApplicationController
include ApiBackend
before_action :requires_secured_mailstorage
def show
......
require 'zxcvbn'
class ApplicationController < ActionController::Base
include ApiBackend
protect_from_forgery with: :exception
# Happens when api token times out
......@@ -114,8 +116,7 @@ class ApplicationController < ActionController::Base
helper_method :any_resource_exists?
def list_of_canonical_resources
# TODO: move to api
['mailman', 'schleuder']
@@resource_types ||= api.resource_available
end
helper_method :list_of_canonical_resources
......@@ -124,10 +125,12 @@ class ApplicationController < ActionController::Base
name = uid.split(":", 2)[1]
localpart = name.split("@", 2)[0]
# TODO: move to api
{
available = {
mailman: "https://lists.immerda.ch/mailman/admin/%{localpart}",
schleuder: "https://schleuder.immerda.ch/lists/%{name}"
}[which.to_sym] % {name: name, localpart: localpart}
}
return unless available[which.to_sym]
available[which.to_sym] % {name: name, localpart: localpart}
end
helper_method :canonical_resources_edit_link
......
......@@ -304,21 +304,23 @@ module ApiBackend
'value' => value})
end
def list(filter = nil, domain = nil, mailbox = nil, deleted = nil)
def list(filter = nil, domain = nil, deleted = nil)
get(['users_admin', 'list'], {
'filter' => filter,
'domain' => domain,
'mailbox' => mailbox,
'deleted' => deleted,})
end
def list_forwards(filter = nil, domain = nil)
get(['users_admin', 'list_forwards'], {
'filter' => filter,
'domain' => domain})
end
def create_new_mailbox_admin(email, pw, forward, mail_crypt_enabled, recovery_email, keep_recovery_token, storagehost)
def create_new_mailbox_admin(email, pw, mail_crypt_enabled, recovery_email, keep_recovery_token, storagehost)
post(['users_admin', 'create_new_mailbox'], {
"email" => email,
"password" => pw,
"forward" => forward,
"storagehost" => storagehost,
"mail_crypt_enabled" => mail_crypt_enabled,
"recovery_email" => recovery_email,
......@@ -326,16 +328,24 @@ module ApiBackend
})
end
def create_new_forward_admin(email, forwards)
def create_new_forward_admin(email, target)
post(['users_admin', 'create_new_forward'], {
"email" => email,
"forwards" => forwards})
"target" => target})
end
def delete_forward_admin(uid)
post(['users_admin', 'delete_forward'], {"uid" => uid})
end
def acl_show()
get ['acl', 'show']
end
def resource_available
get(['resource', 'available'])['available']
end
def my_resources()
get ['resource', 'mine']
end
......
class DeleteAccountController < ApplicationController
include ApiBackend
def delete
if (p = params[:pass]).present?
begin
......
class DomainsController < AdminController
include ApiBackend
before_action :fetch_domain, :only => ['delete','edit','update']
def index
@domains = api.list_domains
......
class EmailForwardController < AdminController
def index
@filter = params[:filter].present? ? params[:filter] : nil
@domain = params[:domain].present? ? params[:domain] : nil
begin
res = api.list_forwards(@filter, @domain)
@entries = res['entries']
rescue ApiBackend::ApiError
flash[:danger] = :fail
end
end
def edit
@type, uid = params[:uid].split(':', 2)
uid = uid.split("@")
@uid = uid.join("@")
@from = "#{uid[0]}@#{uid[1]}"
@to = "#{uid[2]}@#{uid[3]}"
end
def update
if params[:delete]
api.delete_forward_admin(params[:uid])
flash[:success] = :success
else
flash[:danger] = :not_implemented
end
redirect_to email_forward_path
end
def create
full_email = "#{params[:alias]}@#{params[:domain]}"
api.create_new_forward_admin(full_email, params[:forward])
redirect_to email_forward_path and return
rescue ApiBackend::ApiError => e
flash[:danger] = e.api_msg || :failed
fetch_deps
render 'new'
end
def new
fetch_deps
end
private
def fetch_deps
@domains = api.list_domains
rescue ApiBackend::ApiError
flash[:danger] = :fail
redirect_to email_forward_path
end
end
class InvitesController < ApplicationController
include ApiBackend
def show
e = params['expire']
e = "#{e["by(1i)"]}-#{e["by(2i)"]}-#{e["by(3i)"]}"
......
class JabberController < ApplicationController
include ApiBackend
before_action :ensure_jabber_enabled?
before_action :fetch_public_domains, :only => ['index']
def index
......
class JabberDomainsController < AdminController
include ApiBackend
before_action :fetch_domain, :only => ['delete','edit','update']
before_action :fetch_jabberhosts, :only => ['new','create','delete','edit','update']
def index
......
class JabberIdsController < AdminController
include ApiBackend
def index
@filter = params[:filter].present? ? params[:filter] : nil
@domain = params[:domain].present? ? params[:domain] : nil
......
class MailCryptController < ApplicationController
include ApiBackend
def enable
@keep_recovery_token = params[:keep_recovery_token]
if !@keep_recovery_token
......
class PasswordController < ApplicationController
include ApiBackend
def update
if !password_policy?(params[:new])
redirect_to '/password' and return
......
class RecoveryEmailController < ApplicationController
include ApiBackend
def update
@email_recovery_token = params[:email_recovery_token].present?
@recovery_email = params[:recovery_email]
......
class ReservedIdentifiersController < ApplicationController
include ApiBackend
def resource_list
['schleuder', 'mailman']
end
......
class ResourcesAdminController < ApplicationController
include ApiBackend
def resource_list
['schleuder', 'mailman']
list_of_canonical_resources
end
helper_method :resource_list
......
class ResourcesController < ApplicationController
include ApiBackend
def show
if list_of_canonical_resources.include? params[:kind]
@resource_name = params[:kind]
......
require 'base64'
class SessionsController < ApplicationController
include ApiBackend
def destroy_local
reset_user_session
if SamlConfig.idp_sso_logout
......
class SignupController < ApplicationController
include ApiBackend
def new
if @token
# on by default
......
Supports Markdown
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