Commit acbf642b authored by Tobias Kallauke's avatar Tobias Kallauke
Browse files

Permission assignment

parent d4ee3cae
......@@ -113,6 +113,15 @@ class Group
}
end
def add_permissions(group, pairs)
res = RestClient.post("#{ENV['API_URL']}groups/#{group}/permissions", { permissions: pairs }.to_json)
end
def remove_permissions(group, ids)
res = RestClient.delete("#{ENV['API_URL']}groups/#{group}/permissions", { permissions: ids }.to_json)
end
end
end
......
......@@ -12,7 +12,17 @@ class ConsumerController < ApplicationController
end
def add
def add; end
def update
# List of {user_id, permission_id} pairs to create
to_add = params['add']
Group.add_permissions(params[:gid], to_add) if !to_add.nil? && to_add.length
# List of permission-ids to delete
to_remove = params['remove']
Group.remove_permissions(params[:gid], to_remove) if !to_remove.nil? && to_remove.length
end
end
import * as $ from "jquery";
const add: {user: number, permission: number}[] = []
const add: {user_id: number, permission: number}[] = []
const remove: number[] = []
jQuery(() => {
......@@ -22,9 +22,9 @@ jQuery(() => {
}
} else {
if (checked)
add.push({ user: data['uid'], permission: data['pid'] })
add.push({ user_id: data['uid'], permission: data['pid'] })
else {
const pair = { user: data['uid'], permission: data['pid'] }
const pair = { user_id: data['uid'], permission: data['pid'] }
const index = add.indexOf(pair)
if (index < 0) {
console.error(`Permission-User pair ${pair} not in add array`)
......@@ -35,10 +35,18 @@ jQuery(() => {
}
})
jQuery("button").on("click", function () {
jQuery("button#permission-save").on("click", function () {
console.log(`Permission ids to delete: ${remove}`)
const temp = add.map(e => `user: ${e.user}, permission: ${e.permission}`)
const temp = add.map(e => `user: ${e.user_id}, permission: ${e.permission}`)
console.log(`Permission pairs to create: ${temp.join('\n')}`)
jQuery.post("", JSON.stringify({ add, remove })).then(function () {
location.reload()
})
})
jQuery("#group-nav a").each(function () {
if ( (this as HTMLAnchorElement).href === location.href ) this.classList.add("active")
})
});
......@@ -12,7 +12,9 @@ jQuery(() => {
updates.push({ uid: el.data("uid"), role: el.val() });
});
jQuery.post(location.href + "/roles", { updates: JSON.stringify(updates) });
jQuery.post(location.href + "/roles", { updates: JSON.stringify(updates) }).then(function () {
location.reload()
})
});
jQuery("#group-nav a").each(function () {
......
......@@ -26,4 +26,4 @@
<% end %>
</tbody>
</table>
<button class="btn btn-primary">Test</button>
<button class="mr-3 btn btn-primary" id="permission-save">Änderungen speichern</button>
......@@ -2,17 +2,18 @@ Rails.application.routes.draw do
get '/createuser', to: 'index#create_user'
post '/createuser', to: 'index#create_user'
get 'group/', to: 'group#list'
get 'group/:id', to: 'group#get', constraints: { id: /[0-9]+/ }
post 'group/:id/roles', to: 'group#update_roles', constraints: { id: /[0-9]+/ }
get 'group/:gid/consumer/:id', to: 'consumer#get', constraints: { gid: /[0-9]+/, id: /[0-9]+/ }
post 'group/:gid/consumer/:id', to: 'consumer#update', constraints: { gid: /[0-9]+/, id: /[0-9]+/ }
get 'group/:gid/consumer/add', to: 'consumer#add', constraints: { gid: /[0-9]+/ }
get '/', to: 'index#index'
get '/redoc', to: 'redoc#index'
get '/redoc/spec', to: 'redoc#spec'
get '/', to: 'index#index'
get '/redoc', to: 'redoc#index'
get '/redoc/spec', to: 'redoc#spec'
get '/swagger', to: 'swagger#index'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
{
// Liste aller Rechte die der Dienst hat
"permissions": [
{
"id": 1,
"name": "string",
"description": "string"
}
// ...
],
"users": [
{
"id": 1,
"login": "string",
// Jedes zugeordente Recht hat eine eigene Id
// Die wird gebraucht um das Recht für einen Benutzer wieder zu löschen
// FÜr jedes Recht (wie oben) ist in dieser Liste ein Eintrag
// Wenn null = Der Nutzer hat das Recht nicht
// Sonst ist die Nummer die Id des Rechts
// Wichtig: Reihenfolge muss hier genau wie in der permission Liste oben sein!
// (Nach Permission-Id sortiert)
"permissions": [
null,
11,
36
]
}
// ...
]
}
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