Commit 208f7696 authored by o's avatar o

resource editor view for admins

parent 9504e3e3
Pipeline #4065 passed with stages
in 18 minutes and 16 seconds
......@@ -335,6 +335,31 @@ module ApiBackend
def acl_show()
get ['acl', 'show']
end
def resources()
get ['resource']
end
def resources_admin(what)
get ['resource', what]
end
def resource_create(what, owner, data)
post(['resource', 'create'],
{resource_type: what, owner: owner, data: data})
end
def resource_delete(uid)
post(['resource', 'delete'], {uid: uid})
end
def resource_add_owner(uid, user)
post(['resource', 'add_owner'], {uid: uid, owner: user})
end
def resource_remove_owner(uid, user)
post(['resource', 'remove_owner'], {uid: uid, owner: user})
end
end
def api
......
class ResourcesAdminController < ApplicationController
include ApiBackend
def resource_list
['schleuder', 'mailman']
end
def resource_default
case @resource_name
when 'mailman'
'{"listenname": "", "listendomain": "", "mailman_host": ""}'
when 'schleuder'
'{"name": "", "domain": "", "schleuder_host": ""}'
end
end
helper_method :resource_list, :resource_default
def show
@resource_name = params['resource_name']
if resource_list.include? @resource_name
begin
@resources = api.resources_admin(@resource_name)['data']
rescue ApiBackend::ApiError
flash[:danger] = :failed
redirect_to root_path
end
end
end
def update
@params = params
uid = params[:uid]
case params[:commit]
when 'delete'
@res = api.resource_delete(uid)
when 'create'
@resource_name = params[:resource_name]
if resource_list.include? @resource_name
@res = api.resource_create(
@resource_name,
params[:owner],
JSON.parse(params[:data]))
end
when 'save'
if params['add_owner'].present?
api.resource_add_owner(uid, params['add_owner'])
end
params.each do |name, v|
if v == "1" && name =~ /remove_(.*)/
api.resource_remove_owner(uid, $1)
end
end
else
flash[:danger] = :failed
end
end
end
class ResourcesController < ApplicationController
include ApiBackend
def show
begin
res = api.resources
@resources = res['data']
rescue ApiBackend::ApiError
flash[:danger] = :failed
redirect_to root_path
end
end
end
......@@ -3,6 +3,7 @@
invites: {},
users: {label: :manage_users},
domains: {label: :manage_domains},
resources_admin: {},
jabber_ids: {label: :manage_jabber_ids},
jabber_domains: {label: :manage_jabber_domains},
} %>
......@@ -18,6 +19,7 @@
invites: ({} if allow_invites?),
delete_account: {},
services: ({divider: true} if any_resources_enabled?),
resources: ({} if feature_toggle?('resource')),
jabber: ({label: :manage_jabber} if resource_enabled?('jabber')),
} %>
<% end %>
......
<pre>
<%= @resources.to_yaml %>
</pre>
<%= form_tag "", method: :get do %>
<%= select_tag(:resource_name, options_for_select(resource_list, @resource_name)) %>
<%= submit_tag 'select' %>
<% end %>
<hr />
<% if @resources %>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
<%=label_tag 'data' %>
<%=text_field_tag 'data', resource_default, size: 400 %>
<%=label_tag 'owner' %>
<%=text_field_tag 'owner'%>
<%= submit_tag 'create' %>
<% end %>
<hr />
<% @resources.each do |res| %>
<%= form_tag do %>
<%= hidden_field_tag 'uid', res['uid'] %>
<div class="tooltipsummary"><%= res['resource']['name'] %>
<span class="tooltiptext"><%= res['resource'].to_json %></span>
</div>
<%= submit_tag 'delete' %>
</br />
Remove <br />
<% res['owners'].each do |o| %>
<%= check_box_tag "remove_#{o}" %> &nbsp; <%= o %> <br />
<% end %>
<%=label_tag 'add_owner' %>
<%=text_field_tag 'add_owner'%>
<br />
<%= submit_tag 'save' %>
<% end %>
<hr />
<% end %>
<% end %>
params:
<pre>
<%= @params.to_yaml %>
</pre>
res:
<pre>
<%= @res.to_yaml %>
</pre>
......@@ -65,6 +65,7 @@ Rails.application.routes.draw do
get '/msg', to: 'application#msg'
get '/resources', to: 'resources#show'
else
root to: 'admin#index'
......@@ -101,6 +102,9 @@ Rails.application.routes.draw do
get '/jabber_ids/:jid', to: 'jabber_ids#show'
post '/jabber_ids/:jid/delete', to: 'jabber_ids#delete'
end
get '/resources_admin', to: 'resources_admin#show'
post '/resources_admin', to: 'resources_admin#update'
end
get '/invites', to: 'invites#generate'
......
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