Commit ff98f4ad authored by o's avatar o

display existing resources

for people with existing resources show them in the webinterface
and also place some convenient edit buttons.
parent c288638a
Pipeline #4823 failed with stages
in 10 minutes and 2 seconds
......@@ -99,10 +99,39 @@ class ApplicationController < ActionController::Base
helper_method :resource_enabled?
def any_resources_enabled?
['jabber'].any?{|r| resource_enabled?(r) }
!session[:possible_resources].empty?
end
helper_method :any_resources_enabled?
def resource_exists?(resource)
(session[:existing_resources]||{})[resource].present?
end
helper_method :resource_exists?
def any_resources_exist?
!session[:existing_resources].empty?
end
helper_method :any_resources_exist?
def list_of_canonical_resources
# TODO: move to api
['mailman', 'schleuder']
end
helper_method :list_of_canonical_resources
def canonical_resources_edit_link(which, uid)
return unless which
name = uid.split(":", 2)[1]
localpart = name.split("@", 2)[0]
# TODO: move to api
{
mailman: "https://lists.immerda.ch/mailman/listinfo/:localpart",
schleuder: "https://schleuder.immerda.ch"
}[which.to_sym].gsub(":name", name).gsub(":localpart", localpart)
end
helper_method :canonical_resources_edit_link
def admin?
@is_admin ||= Admin::Enabled && session[:is_admin]
end
......@@ -138,6 +167,12 @@ class ApplicationController < ActionController::Base
session[:requires_2fa] = res['requires_2fa']
session[:possible_resources] = res['possible_resources']
begin
rs = api.my_resources['data'].map{|uid| [uid.split(":")[0], true]}.to_h
session[:existing_resources] = rs
rescue
end
return res
end
......
......@@ -2,22 +2,24 @@ class ResourcesController < ApplicationController
include ApiBackend
def show
if list_of_canonical_resources.include? params[:kind]
@resource_name = params[:kind]
end
begin
res = api.my_resources
@resources = res['data']
res = api.my_resources['data']
if @resource_name
res = res.select{|uid| uid =~ /^#{@resource_name}:/} || []
end
@resources = res
rescue ApiBackend::ApiError
flash[:danger] = :failed
redirect_to root_path
end
end
def resource_names
['mailman', 'schleuder']
end
def create
flash[:warning] = nil
@resource_names = resource_names
@resource_names = list_of_canonical_resources
@resource_name = params[:resource_name]
@resource_name = nil unless @resource_names.include?(@resource_name)
if @resource_name
......@@ -35,7 +37,7 @@ class ResourcesController < ApplicationController
def do_create
@resource_name = params[:resource_name]
if resource_names.include? @resource_name
if list_of_canonical_resources.include? @resource_name
data = {}
params.each do |name, v|
if name =~ /data_(.*)/
......@@ -44,6 +46,7 @@ class ResourcesController < ApplicationController
end
@res = api.resource_self_create(@resource_name, data)
update_account_properties
flash[:success] = :resource_created
end
redirect_to resources_path
......
......@@ -19,11 +19,19 @@
pgpkeys: {},
invites: ({} if allow_invites?),
delete_account: {},
services: ({divider: true} if any_resources_enabled?),
resources: ({label: :my_resources} if feature_toggle?('resource')),
services: ({divider: true} if any_resources_enabled? || any_resource_exists?),
new_resource: ({} if feature_toggle?('resource')),
}.merge(
list_of_canonical_resources.map do |name|
if resource_exists?(name)
["/resources/#{name}", {label: name}]
else
nil
end
end.compact.to_h
).merge({
jabber: ({label: :manage_jabber} if resource_enabled?('jabber')),
} %>
}) %>
<% end %>
<% @navbar_instance ||= 1; @navbar_instance = @navbar_instance + 1 %>
......
......@@ -15,6 +15,10 @@
<p>
<% if @resource_name && !@disabled %>
<div class="alert" role="alert">
<%= t("#{@resource_name}_description") %>
</div>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
......
<h3> <%= t(:my_resources) %></h3>
<% if @resource_name %>
<h3>
<%= t(:my) + ' ' + t(@resource_name) %>
</h3>
<div class="alert" role="alert">
<%= t("#{@resource_name}_description") %>
<br />
<%= t("#{@resource_name}_edit_description") %>
</div>
<% else %>
<h3>
<%= @local_part = @name.split("@", 2)[0] %>
</h3>
<% end %>
<p>
<% @resources.each do |res| %>
......@@ -7,7 +20,12 @@
<%= form_tag do %>
<%= hidden_field_tag 'uid', res %>
<%= res %>
<%= res.split(":", 2)[1] %>
<% if link = canonical_resources_edit_link(@resource_name, res) %>
<a href="<%= link %>" class="btn btn-primary"><%= t(:edit) %></a>
<% end %>
<button type="button" class="btn btn-warning" onclick="
style.display='none';
document.getElementById('delete_<%= resource_ui_id %>').style.display='inline';
......
......@@ -199,6 +199,13 @@ de:
new_resource: "Dienst erstellen"
missing_gpg_key: "Hierfür wird ein OpenPGP Schlüssel benötigt. Bitte lade einen unter dem Punkt OpenPGP Schlüssel hoch."
resource_created: "Dienst erfolgreich bestellt. Du wirst via E-Mail Benachrichtigt, dies kann bis zu 24h dauern."
my: "Meine"
mailman: "Emaillisten"
mailman_description: "Klassische Emaillisten zur Gruppenkommunikation oder als Newsletter."
mailman_edit_description: "Das Passwort zum bearbeiten der Liste wird beim erstellen per Email verschickt."
schleuder: "Verschlüsselte Emaillisten"
schleuder_description: "Verschlüsselte (Schleuder) Emaillisten zur Gruppenkommunikation oder Kommunikation mit externen Personen."
schleuder_edit_description: "Zum bearbeiten muss ein zusätzlicher \"Schleuder Account\" erstellt werden."
activerecord:
errors:
......
......@@ -200,6 +200,13 @@ en:
new_resource: "Create service"
missing_gpg_key: "OpenGPG Key needed. Please upload one in the OpenPGP Keys settings."
resource_created: "Service successfully scheduled for creation. You will be notified by mail. Please allow for up to 24h until it becomes available."
my: "My"
mailman: "Mailing Lists"
mailman_description: "Classic mailing lists for group communication or as newsletter."
mailman_edit_description: "The passwords for editing lists are sent upon creation to the admin."
schleuder: "Encrypted Lists"
schleuder_description: "Encrypted mailing lists based on schleuder, for group communication or communicating externally."
schleuder_edit_description: "For editing a dedicated \"schleuder account\" must be created."
activerecord:
errors:
......
......@@ -65,10 +65,10 @@ Rails.application.routes.draw do
get '/msg', to: 'application#msg'
get '/resources', to: 'resources#show'
post '/resources', to: 'resources#update'
get '/new_resource', to: 'resources#create'
post '/new_resource', to: 'resources#do_create'
get '/resources/:kind', to: 'resources#show'
post '/resources', to: 'resources#update'
get '/new_resource', to: 'resources#create'
post '/new_resource', to: 'resources#do_create'
else
root to: 'admin#index'
......
Markdown is supported
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