Commit 0ec426b9 authored by o's avatar o

allow users to create mailman and schleuder lists

parent 2f76a90f
Pipeline #4746 passed with stages
in 17 minutes and 7 seconds
......@@ -344,10 +344,19 @@ module ApiBackend
get ['resource', 'schema'], {resource_type: what}
end
def resource_user_schema(what)
get ['resource', 'user_schema'], {resource_type: what}
end
def resource_list(what, deleted=false)
get ['resource', 'list'], {resource_type: what, deleted: deleted}
end
def resource_self_create(what, data)
post(['resource', 'self_create'],
{resource_type: what, data: data})
end
def resource_create(what, owner, data)
post(['resource', 'create'],
{resource_type: what, owner: owner, data: data})
......
......@@ -10,4 +10,45 @@ class ResourcesController < ApplicationController
redirect_to root_path
end
end
def resource_names
['mailman', 'schleuder']
end
def create
flash[:warning] = nil
@resource_names = resource_names
@resource_name = params[:resource_name]
@resource_name = nil unless @resource_names.include?(@resource_name)
if @resource_name
@resource_schema = api.resource_user_schema(@resource_name)['schema']
end
if @resource_name == 'schleuder'
begin
WkdSrvClient.get(current_user)
rescue
@disabled = true
flash[:warning] = 'missing_gpg_key'
end
end
end
def do_create
@resource_name = params[:resource_name]
if resource_names.include? @resource_name
data = {}
params.each do |name, v|
if name =~ /data_(.*)/
data[$1] = v
end
end
@res = api.resource_self_create(@resource_name, data)
flash[:success] = :success
end
redirect_to resources_path
rescue ApiError => e
flash[:danger] = e.api_msg
redirect_to new_resource_path
end
end
......@@ -20,7 +20,8 @@
invites: ({} if allow_invites?),
delete_account: {},
services: ({divider: true} if any_resources_enabled?),
resources: ({} if feature_toggle?('resource')),
resources: ({label: :my_resources} if feature_toggle?('resource')),
new_resource: ({} if feature_toggle?('resource')),
jabber: ({label: :manage_jabber} if resource_enabled?('jabber')),
} %>
<% end %>
......
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<% @resource_names.each do |pane| %>
<a class="nav-item nav-link <%= if pane == @resource_name then "active" else "" end %>"
href="?resource_name=<%= pane %>"
role="tab">
<%= pane %>
</a>
<% end %>
</div>
</nav>
<p>
<% if @resource_name && !@disabled %>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
<% @resource_schema.each do |n,v| %>
<div class="form-group">
<%= label_tag n %>
<%= case v
when 'text'
text_field_tag('data_'+n, "", class: 'form-control')
when Array
select_tag('data_'+n, options_for_select(v), class: 'form-control')
end %>
</div>
<% end %>
<%= submit_tag t(:create), name: 'create', class: "btn btn-primary" %>
<% end %>
<% end %>
</p>
......@@ -195,6 +195,9 @@ de:
invite_token:
one: "Einladungscode"
other: "Einladungscodes"
my_resources: "Liste meiner Zusatzdienste"
new_resource: "Dienst erstellen"
missing_gpg_key: "Hierfür wird ein gpg key benötigt. Bitte lade einen unter dem Punkt OpenPGP Schlüssel hoch."
activerecord:
......
......@@ -196,6 +196,9 @@ en:
invite_token:
one: "Invite Code"
other: "Invite Codes"
my_resources: "List my extra services"
new_resource: "Create service"
missing_gpg_key: "GPG Key needed. Please upload one in the OpenPGP Keys settings."
activerecord:
......
......@@ -65,7 +65,9 @@ Rails.application.routes.draw do
get '/msg', to: 'application#msg'
get '/resources', to: 'resources#show'
get '/resources', to: 'resources#show'
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