cats_core 1.1.20 → 1.1.24
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 +13 -0
- data/app/controllers/cats/core/users_controller.rb +47 -3
- data/app/models/cats/core/user.rb +10 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20210715120018_create_cats_core_roles.rb +1 -1
- data/lib/cats/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e1e8fc9828a237ea12abdb6c0cf964aa9e0801ea7c5cb95c638071363c728b6
|
4
|
+
data.tar.gz: 2bc4c46c50608f1c12e99f4dbb50562bde3d255922bfb09fa905e15e24ed277e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d66571c610864eda20aea1815fef61697bf83d8cba9063de6623914cdbfdd66d9160bc36575d8e4e688076c813f5982ad6623b8cbc0302340cc42fa35f0eaccc
|
7
|
+
data.tar.gz: 2e2205cfc0c14723a269dc4e7d9f4e0d09c67234ab8375a403c05c35ec05c37ec2027acff491b82df87b85c93aa0c5993f4352ea2988d9efc28f5cd28a3a242b
|
@@ -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[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)
|
@@ -11,6 +11,36 @@ module Cats
|
|
11
11
|
render json: { success: true, data: serialize(users) }
|
12
12
|
end
|
13
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
|
+
|
14
44
|
def roles
|
15
45
|
data = ActiveModelSerializers::SerializableResource.new(@user.roles)
|
16
46
|
render json: { success: true, data: data }
|
@@ -19,7 +49,21 @@ module Cats
|
|
19
49
|
def assign_role
|
20
50
|
role = Cats::Core::Role.find(params[:role_id])
|
21
51
|
@user.roles << role
|
22
|
-
|
52
|
+
if role.name == 'warehouse_manager'
|
53
|
+
@user.add_detail(:warehouse, params[:warehouse_id])
|
54
|
+
elsif role.name =='hub_manager'
|
55
|
+
@user.add_detail(:hub, params[:hub_id])
|
56
|
+
end
|
57
|
+
|
58
|
+
data = ActiveModelSerializers::SerializableResource.new(role)
|
59
|
+
render json: { success: true, data: data }
|
60
|
+
end
|
61
|
+
|
62
|
+
def revoke_role
|
63
|
+
role = Cats::Core::Role.find(params[:role_id])
|
64
|
+
@user.roles.delete(role)
|
65
|
+
@user.remove_detail(role.name) if ['warehouse_manager', 'hub_manager'].include?(role.name)
|
66
|
+
data = ActiveModelSerializers::SerializableResource.new(role)
|
23
67
|
render json: { success: true, data: data }
|
24
68
|
end
|
25
69
|
|
@@ -47,7 +91,7 @@ module Cats
|
|
47
91
|
def model_params
|
48
92
|
params.require(:payload).permit(
|
49
93
|
:first_name, :last_name, :email, :phone_number, :active, :password, :password_confirmation, :details,
|
50
|
-
:
|
94
|
+
:application_prefix
|
51
95
|
)
|
52
96
|
end
|
53
97
|
end
|
@@ -31,6 +31,16 @@ module Cats
|
|
31
31
|
Cats::Core::Location.find_by(id: details['hub'], location_type: Cats::Core::Location::HUB)
|
32
32
|
end
|
33
33
|
|
34
|
+
def add_detail(key, value)
|
35
|
+
details[key] = value
|
36
|
+
save!
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove_detail(key)
|
40
|
+
details.delete(key)
|
41
|
+
save!
|
42
|
+
end
|
43
|
+
|
34
44
|
def validate_phone_number
|
35
45
|
return unless phone_number.present?
|
36
46
|
|
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
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.24
|
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
|