Commit 3dff1ef3 by John Doe

integrated permission removal path

parent bccc8aec
...@@ -8,7 +8,7 @@ class PermissionsController < ApplicationController ...@@ -8,7 +8,7 @@ class PermissionsController < ApplicationController
# GET /permissions.json # GET /permissions.json
def index def index
# return permissions for nilm specified by nilm_id # return permissions for nilm specified by nilm_id
@permissions = @nilm.permissions @permissions = @nilm.permissions.includes(:user, :user_group)
end end
# POST /permissions # POST /permissions
......
...@@ -25,6 +25,16 @@ class Permission < ApplicationRecord ...@@ -25,6 +25,16 @@ class Permission < ApplicationRecord
end end
end end
def target_type
if self.user_id?
return 'user'
elsif self.user_group_id?
return 'group'
else
return 'unknown'
end
end
def self.json_keys def self.json_keys
[:id, :nilm_id, :role] [:id, :nilm_id, :role]
end end
......
json.extract! permission, *Permission.json_keys
json.name permission.target_name
json.data do json.data do
json.extract! @permission, *Permission.json_keys json.extract! @permission, *Permission.json_keys
json.name @permission.target_name json.target_name @permission.target_name
json.target_type @permission.target_type
end end
json.partial! "helpers/messages", service: @service json.partial! "helpers/messages", service: @service
json.array!(@permissions) do |permission| json.array!(@permissions) do |permission|
json.extract! permission, *Permission.json_keys json.extract! permission, *Permission.json_keys
json.name permission.target_name json.target_name permission.target_name
json.target_type permission.target_type
json.removable permission.user_id!=current_user.id
end end
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 sign in to comment