cats_core 1.1.18 → 1.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/roles_controller.rb +19 -0
- data/app/controllers/cats/core/users_controller.rb +66 -2
- data/app/serializers/cats/core/role_serializer.rb +3 -0
- data/app/serializers/cats/core/user_serializer.rb +3 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20210715120018_create_cats_core_roles.rb +1 -1
- data/lib/cats/core/version.rb +1 -1
- metadata +4 -2
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
|
@@ -1,8 +1,23 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class RolesController < ApplicationController
|
4
|
+
include Common
|
5
|
+
|
4
6
|
before_action :set_role, only: [:users]
|
5
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
|
+
|
6
21
|
def users
|
7
22
|
data = ActiveModelSerializers::SerializableResource.new(@role.users)
|
8
23
|
render json: { success: true, data: data }
|
@@ -13,6 +28,10 @@ module Cats
|
|
13
28
|
def set_role
|
14
29
|
@role = Role.find_by(name: params[:name])
|
15
30
|
end
|
31
|
+
|
32
|
+
def model_params
|
33
|
+
params.require(:payload).permit(:name, :application_module_id)
|
34
|
+
end
|
16
35
|
end
|
17
36
|
end
|
18
37
|
end
|
@@ -1,7 +1,64 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class UsersController < ApplicationController
|
4
|
-
|
4
|
+
include Common
|
5
|
+
|
6
|
+
before_action :set_user, only: %i[update roles assign_role revoke_role stores warehouse hub]
|
7
|
+
|
8
|
+
def index
|
9
|
+
users = Cats::Core::User.joins(:application_module)
|
10
|
+
.where(cats_core_application_modules: { prefix: params[:prefix] })
|
11
|
+
render json: { success: true, data: serialize(users) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
prefix = model_params[:application_prefix]
|
16
|
+
application_module = Cats::Core::ApplicationModule.find_by(prefix: prefix)
|
17
|
+
|
18
|
+
obj = Cats::Core::User.new(model_params.except(:application_prefix))
|
19
|
+
obj.application_module = application_module
|
20
|
+
if obj.save
|
21
|
+
render json: { success: true, data: serialize(obj) }, status: :created
|
22
|
+
else
|
23
|
+
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
if model_params[:application_prefix]
|
29
|
+
prefix = model_params[:application_prefix]
|
30
|
+
application_module = Cats::Core::ApplicationModule.find_by(prefix: prefix)
|
31
|
+
@user.assign_attributes(model_params.except(:application_prefix))
|
32
|
+
@user.application_module = application_module
|
33
|
+
else
|
34
|
+
@user.assign_attributes(model_params)
|
35
|
+
end
|
36
|
+
|
37
|
+
if @user.save
|
38
|
+
render json: { success: true, data: serialize(@user) }
|
39
|
+
else
|
40
|
+
render json: { success: false, error: @user.errors.full_messages[0] }, status: :unprocessable_entity
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def roles
|
45
|
+
data = ActiveModelSerializers::SerializableResource.new(@user.roles)
|
46
|
+
render json: { success: true, data: data }
|
47
|
+
end
|
48
|
+
|
49
|
+
def assign_role
|
50
|
+
role = Cats::Core::Role.find(params[:role_id])
|
51
|
+
@user.roles << role
|
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)
|
60
|
+
render json: { success: true, data: data }
|
61
|
+
end
|
5
62
|
|
6
63
|
def stores
|
7
64
|
data = ActiveModelSerializers::SerializableResource.new(@user.stores)
|
@@ -21,7 +78,14 @@ module Cats
|
|
21
78
|
private
|
22
79
|
|
23
80
|
def set_user
|
24
|
-
@user = User.find(params[:id])
|
81
|
+
@user = Cats::Core::User.find(params[:id])
|
82
|
+
end
|
83
|
+
|
84
|
+
def model_params
|
85
|
+
params.require(:payload).permit(
|
86
|
+
:first_name, :last_name, :email, :phone_number, :active, :password, :password_confirmation, :details,
|
87
|
+
:application_prefix
|
88
|
+
)
|
25
89
|
end
|
26
90
|
end
|
27
91
|
end
|
data/config/routes.rb
CHANGED
@@ -5,6 +5,13 @@ Cats::Core::Engine.routes.draw do
|
|
5
5
|
get '/notifications/unread', controller: :notifications, action: :unread
|
6
6
|
get '/notifications/read', controller: :notifications, action: :read
|
7
7
|
|
8
|
+
resources :application_modules, param: :prefix do
|
9
|
+
member do
|
10
|
+
get 'roles', controller: :roles, action: :index
|
11
|
+
get 'users', controller: :users, action: :index
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
8
15
|
resources :menus, only: [:index]
|
9
16
|
resources :notifications, only: [:index] do
|
10
17
|
member do
|
@@ -12,6 +19,8 @@ Cats::Core::Engine.routes.draw do
|
|
12
19
|
post 'mark_as_unread', controller: :notifications, action: :mark_as_unread
|
13
20
|
end
|
14
21
|
end
|
22
|
+
|
23
|
+
get '/roles/:id/', controller: :roles, action: :show
|
15
24
|
resources :roles, param: :name do
|
16
25
|
member do
|
17
26
|
get 'users', controller: :roles, action: :users
|
@@ -19,9 +28,13 @@ Cats::Core::Engine.routes.draw do
|
|
19
28
|
end
|
20
29
|
resources :users do
|
21
30
|
member do
|
31
|
+
get 'roles'
|
32
|
+
get 'unassigned_roles', controller: :roles, action: :unassigned_roles
|
22
33
|
get 'stores', controller: :users, action: :stores
|
23
34
|
get 'warehouse', controller: :users, action: :warehouse
|
24
35
|
get 'hub', controller: :users, action: :hub
|
36
|
+
post 'assign_role'
|
37
|
+
post 'revoke_role'
|
25
38
|
end
|
26
39
|
end
|
27
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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cats_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -297,7 +297,9 @@ files:
|
|
297
297
|
- app/serializers/cats/core/receipt_serializer.rb
|
298
298
|
- app/serializers/cats/core/receipt_transaction_serializer.rb
|
299
299
|
- app/serializers/cats/core/role_menu_serializer.rb
|
300
|
+
- app/serializers/cats/core/role_serializer.rb
|
300
301
|
- app/serializers/cats/core/unit_of_measure_serializer.rb
|
302
|
+
- app/serializers/cats/core/user_serializer.rb
|
301
303
|
- app/services/cats/core/dispatch_service.rb
|
302
304
|
- app/services/cats/core/menu_service.rb
|
303
305
|
- app/services/cats/core/notification_service.rb
|