cats_core 1.1.21 → 1.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7535241fdd71214b07a61f4bde93042bf22673e3cddf8819686da1a7ac2b277
|
4
|
+
data.tar.gz: 5b7b01689834652de56c72f5bf836cf2b8e1b476d432beb72f691c634b38ce8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12fb00d72b5c265e1ea938fed3ec613ead395a7f34cdc78e0bf814159167eafa04d4343f1a02b3b8ffbcd840fcbb8524dcdb0bae29804a832cb0345ae61304e4
|
7
|
+
data.tar.gz: 9460758729591b77bc7108fe3f891f23ac4fed319c3c78a47dd9bb11a9fc349059cadb17ae6b511e2aa36ffc241c2a077042b6e8bfead949f12156dc199bb9dc
|
@@ -5,6 +5,19 @@ module Cats
|
|
5
5
|
|
6
6
|
before_action :set_role, only: [:users]
|
7
7
|
|
8
|
+
def index
|
9
|
+
roles = Cats::Core::Role.joins(:application_module)
|
10
|
+
.where(cats_core_application_modules: { prefix: params[:prefix] })
|
11
|
+
render json: { success: true, data: serialize(roles) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def unassigned_roles
|
15
|
+
user = Cats::Core::User.find(params[:id])
|
16
|
+
roles = Cats::Core::Role.where(application_module_id: user.application_module_id)
|
17
|
+
unassigned = roles - user.roles
|
18
|
+
render json: { success: true, data: serialize(unassigned) }
|
19
|
+
end
|
20
|
+
|
8
21
|
def users
|
9
22
|
data = ActiveModelSerializers::SerializableResource.new(@role.users)
|
10
23
|
render json: { success: true, data: data }
|
@@ -3,7 +3,7 @@ module Cats
|
|
3
3
|
class UsersController < ApplicationController
|
4
4
|
include Common
|
5
5
|
|
6
|
-
before_action :set_user, only: %i[update roles assign_role stores warehouse hub]
|
6
|
+
before_action :set_user, only: %i[update roles assign_role revoke_role stores warehouse hub]
|
7
7
|
|
8
8
|
def index
|
9
9
|
users = Cats::Core::User.joins(:application_module)
|
@@ -49,7 +49,14 @@ module Cats
|
|
49
49
|
def assign_role
|
50
50
|
role = Cats::Core::Role.find(params[:role_id])
|
51
51
|
@user.roles << role
|
52
|
-
data = ActiveModelSerializers::SerializableResource.new(
|
52
|
+
data = ActiveModelSerializers::SerializableResource.new(role)
|
53
|
+
render json: { success: true, data: data }
|
54
|
+
end
|
55
|
+
|
56
|
+
def revoke_role
|
57
|
+
role = Cats::Core::Role.find(params[:role_id])
|
58
|
+
@user.roles.delete(role)
|
59
|
+
data = ActiveModelSerializers::SerializableResource.new(role)
|
53
60
|
render json: { success: true, data: data }
|
54
61
|
end
|
55
62
|
|
data/config/routes.rb
CHANGED
@@ -7,6 +7,7 @@ Cats::Core::Engine.routes.draw do
|
|
7
7
|
|
8
8
|
resources :application_modules, param: :prefix do
|
9
9
|
member do
|
10
|
+
get 'roles', controller: :roles, action: :index
|
10
11
|
get 'users', controller: :users, action: :index
|
11
12
|
end
|
12
13
|
end
|
@@ -28,10 +29,12 @@ Cats::Core::Engine.routes.draw do
|
|
28
29
|
resources :users do
|
29
30
|
member do
|
30
31
|
get 'roles'
|
32
|
+
get 'unassigned_roles', controller: :roles, action: :unassigned_roles
|
31
33
|
get 'stores', controller: :users, action: :stores
|
32
34
|
get 'warehouse', controller: :users, action: :warehouse
|
33
35
|
get 'hub', controller: :users, action: :hub
|
34
36
|
post 'assign_role'
|
37
|
+
post 'revoke_role'
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
@@ -23,6 +23,6 @@ class CreateCatsCoreRoles < ActiveRecord::Migration[6.1]
|
|
23
23
|
end
|
24
24
|
|
25
25
|
add_index(:cats_core_roles, [ :name, :resource_type, :resource_id ])
|
26
|
-
add_index(:cats_core_users_cats_core_roles, [ :user_id, :role_id ])
|
26
|
+
add_index(:cats_core_users_cats_core_roles, [ :user_id, :role_id ], unique: true)
|
27
27
|
end
|
28
28
|
end
|
data/lib/cats/core/version.rb
CHANGED