ecom_core 1.0.21 → 1.0.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/ecom/core/access_controller.rb +33 -0
- data/app/controllers/ecom/core/application_controller.rb +40 -1
- data/app/controllers/ecom/core/application_modules_controller.rb +33 -0
- data/app/controllers/ecom/core/menus_controller.rb +26 -0
- data/app/controllers/ecom/core/user_roles_controller.rb +40 -0
- data/app/controllers/ecom/core/users_controller.rb +43 -0
- data/app/models/ecom/core/application_module.rb +1 -1
- data/app/models/ecom/core/custom_payment_detail.rb +10 -0
- data/app/models/ecom/core/menu.rb +1 -0
- data/app/models/ecom/core/user.rb +3 -1
- data/app/serializers/ecom/core/application_module_serializer.rb +9 -0
- data/app/serializers/ecom/core/user_role_serializer.rb +9 -0
- data/app/serializers/ecom/core/user_serializer.rb +9 -0
- data/app/services/ecom/core/token_auth_service.rb +21 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20200307112519_create_ecom_core_custom_payment_details.rb +24 -0
- data/lib/ecom/core/version.rb +1 -1
- data/spec/factories/ecom/core/custom_payment_details.rb +18 -0
- metadata +34 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f45781b38a120c782949fe3133566f994e81fe5723ce77f4e535b61b7d2ef3ad
|
4
|
+
data.tar.gz: 66f86d09d7b065950b202b2c5ffce8943da5168d8f96cc80b1763a312afe2aa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc70b7327aa2af6160cdb074430fa6ddc744c80df67a264c40cb20a577f7d248733c07d32894b714a28f9dd1c6f49ffabbdb25beae6174da7f9e0c662bdf8686
|
7
|
+
data.tar.gz: 4cc556044dc408bfec968a8e9f04c44c9a373fb02ed0a6af49ad2206d84fabc985cbeb404fae691740dbf1d209e5e6680c14f5499fd3c1494a9327b65fcd64cf
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class AccessController < ApplicationController
|
4
|
+
skip_before_action :authenticate, only: [:login]
|
5
|
+
|
6
|
+
def login
|
7
|
+
user = User.find_by(email: auth_params[:email])
|
8
|
+
if user
|
9
|
+
if user.authenticate(auth_params[:password])
|
10
|
+
roles = user.user_roles.each_with_object([]) do |role, result|
|
11
|
+
result << role.name
|
12
|
+
end
|
13
|
+
|
14
|
+
payload = { id: user.id, email: user.email, name: user.full_name, roles: roles }
|
15
|
+
jwt = TokenAuthService.issue(payload)
|
16
|
+
render json: { token: jwt, user: payload, error: nil }
|
17
|
+
else
|
18
|
+
render json: { error: 'Invalid username or password' }, status: 400
|
19
|
+
end
|
20
|
+
else
|
21
|
+
render json: { error: 'User does not exist' }, status: 400
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def auth_params
|
28
|
+
params.require(:auth).permit(:email, :password)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,7 +1,46 @@
|
|
1
1
|
module Ecom
|
2
2
|
module Core
|
3
3
|
class ApplicationController < ActionController::API
|
4
|
-
|
4
|
+
before_action :authenticate
|
5
|
+
|
6
|
+
def logged_in?
|
7
|
+
!current_user.nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_user
|
11
|
+
return unless auth_present?
|
12
|
+
|
13
|
+
user = User.find(auth['id'])
|
14
|
+
@current_user ||= user if user
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def authenticate
|
20
|
+
render json: { error: 'Unauthorized' }, status: 401 unless logged_in?
|
21
|
+
end
|
22
|
+
|
23
|
+
def token
|
24
|
+
return nil if request.env['HTTP_AUTHORIZATION'].nil?
|
25
|
+
|
26
|
+
request.env['HTTP_AUTHORIZATION'].scan(/Bearer (.*)$/).flatten.last
|
27
|
+
end
|
28
|
+
|
29
|
+
def auth
|
30
|
+
TokenAuthService.decode(token)
|
31
|
+
end
|
32
|
+
|
33
|
+
def auth_present?
|
34
|
+
!token.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_error_message(entity)
|
38
|
+
value = entity.errors.details.first[1][0][:value]
|
39
|
+
field = entity.errors.keys[0]
|
40
|
+
message = entity.errors.values[0][0]
|
41
|
+
|
42
|
+
entity.errors.full_message(field, "'#{value}' #{message}")
|
43
|
+
end
|
5
44
|
end
|
6
45
|
end
|
7
46
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class ApplicationModulesController < ApplicationController
|
4
|
+
def index
|
5
|
+
render json: ApplicationModuleSerializer.new(ApplicationModule.all)
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
application_module = ApplicationModule.new(application_module_params)
|
10
|
+
if application_module.save
|
11
|
+
render json: ApplicationModuleSerializer.new(application_module), status: :created
|
12
|
+
else
|
13
|
+
render json: { success: false, errors: application_module.errors }, status: :unprocessable_entity
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def update
|
18
|
+
application_module = ApplicationModule.find(params[:id])
|
19
|
+
if application_module.update(application_module_params)
|
20
|
+
render json: ApplicationModuleSerializer.new(application_module)
|
21
|
+
else
|
22
|
+
render json: { success: false, errors: application_module.errors }, status: :unprocessable_entity
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def application_module_params
|
29
|
+
params.require(:application_module).permit(:code, :name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class MenusController < ApplicationController
|
4
|
+
def index
|
5
|
+
user = current_user
|
6
|
+
roles = user.user_roles
|
7
|
+
app_module = roles[0].application_module
|
8
|
+
menus = []
|
9
|
+
roles.each do |role|
|
10
|
+
menu_list = role.menus.where(parent: nil, application_module: app_module)
|
11
|
+
menu_list.each do |menu|
|
12
|
+
children = []
|
13
|
+
menu.children.order(:label).each do |child|
|
14
|
+
if role.menus.include? child
|
15
|
+
children << { label: child.label, icon: child.icon, route: child.route }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
menus << { label: menu.label, icon: menu.icon, children: children }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
render json: menus
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class UserRolesController < ApplicationController
|
4
|
+
before_action :set_user_role, only: [:update]
|
5
|
+
|
6
|
+
def index
|
7
|
+
render json: UserRoleSerializer.new(UserRole.all)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
user_role = UserRole.new(user_role_params)
|
12
|
+
|
13
|
+
if user_role.save
|
14
|
+
render json: UserRoleSerializer.new(user_role), status: :created
|
15
|
+
else
|
16
|
+
render json: { success: false, errors: user_role.errors }, status: :unprocessable_entity
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
if @user_role.update(user_role_params)
|
22
|
+
render json: UserRoleSerializer.new(@user_role)
|
23
|
+
else
|
24
|
+
render json: { success: false, errors: @user_role.errors }, status: :unprocessable_entity
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def set_user_role
|
32
|
+
@user_role = UserRole.find(params[:id])
|
33
|
+
end
|
34
|
+
|
35
|
+
def user_role_params
|
36
|
+
params.require(:user_role).permit(:name, :application_module_id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class UsersController < ApplicationController
|
4
|
+
before_action :set_user, only: [:update]
|
5
|
+
|
6
|
+
def index
|
7
|
+
render json: UserSerializer.new(User.all)
|
8
|
+
end
|
9
|
+
|
10
|
+
def active
|
11
|
+
render json: UserSerializer.new(User.active)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
user = User.new(user_params)
|
16
|
+
if user.save
|
17
|
+
render json: UserSerializer.new(user), status: :created
|
18
|
+
else
|
19
|
+
render json: { success: false, errors: user.errors }, status: :unprocessable_entity
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def update
|
24
|
+
if @user.update(user_params)
|
25
|
+
render json: UserSerializer.new(@user)
|
26
|
+
else
|
27
|
+
render json: { success: false, errors: @user.errors }, status: :unprocessable_entity
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def set_user
|
35
|
+
@user = User.find(params[:id])
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_params
|
39
|
+
params.require(:user).permit(:first_name, :last_name, :email, :password, :active)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Ecom
|
2
|
+
module Core
|
3
|
+
class CustomPaymentDetail < ApplicationRecord
|
4
|
+
belongs_to :payment, class_name: 'Ecom::Core::Payment'
|
5
|
+
|
6
|
+
validates :name, :hours, :ot_hours, :base_salary, :overtime, :gross_salary, :tax, :pension, :net_salary, :net_pay,
|
7
|
+
:advance, :wage, presence: true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -3,6 +3,7 @@ module Ecom
|
|
3
3
|
class Menu < ApplicationRecord
|
4
4
|
belongs_to :parent, class_name: 'Ecom::Core::Menu', optional: true
|
5
5
|
belongs_to :application_module
|
6
|
+
has_many :children, class_name: 'Ecom::Core::Menu', foreign_key: 'parent_id'
|
6
7
|
|
7
8
|
validates :label, :route, presence: true
|
8
9
|
end
|
@@ -8,7 +8,9 @@ module Ecom
|
|
8
8
|
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i.freeze
|
9
9
|
validates :first_name, :last_name, :active, presence: true
|
10
10
|
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
|
11
|
-
validates :password, length: { minimum: 6 }
|
11
|
+
validates :password, presence: true, length: { minimum: 6 }, confirmation: true, if: :password
|
12
|
+
|
13
|
+
scope :active, -> { where(active: true) }
|
12
14
|
|
13
15
|
def full_name
|
14
16
|
"#{first_name} #{last_name}"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'jwt'
|
2
|
+
|
3
|
+
module Ecom
|
4
|
+
module Core
|
5
|
+
class TokenAuthService
|
6
|
+
AUTH_SECRET = '31a70abfaa57e5e77a3fc9f27aeaaf59b9a9f5355b5e16c842ee172035a8ed40bf82c1c971ecc176e4f0b4c9e6141db07fd4a5af3f7db9265e719fbe340b105a'
|
7
|
+
|
8
|
+
def self.issue(payload)
|
9
|
+
JWT.encode(payload, auth_secret, 'HS256')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.decode(token)
|
13
|
+
JWT.decode(token, auth_secret, true, algorithm: 'HS256').first
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.auth_secret
|
17
|
+
AUTH_SECRET
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
Ecom::Core::Engine.routes.draw do
|
2
|
+
post '/login', controller: :access, action: :login
|
3
|
+
|
4
|
+
resources :application_modules, only: %i[index create update]
|
5
|
+
resources :user_roles, only: %i[index create update]
|
6
|
+
resources :menus, only: %i[index]
|
7
|
+
resources :users, only: %i[index create update]
|
8
|
+
get '/users/active', controller: :users, action: :active
|
9
|
+
|
10
|
+
|
2
11
|
resources :crew_types
|
3
12
|
resources :equipment_types
|
4
13
|
resources :material_types
|
14
|
+
resources :menus, only: %i[index]
|
5
15
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateEcomCoreCustomPaymentDetails < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :ecom_core_custom_payment_details do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.float :hours, null: false
|
6
|
+
t.float :ot_hours, null: false, default: 0
|
7
|
+
t.float :base_salary, null: false
|
8
|
+
t.float :overtime, null: false
|
9
|
+
t.float :gross_salary, null: false
|
10
|
+
t.float :tax, null: false, default: 0
|
11
|
+
t.float :pension, null: false, default: 0
|
12
|
+
t.float :net_salary, null: false
|
13
|
+
t.float :net_pay, null: false
|
14
|
+
t.float :advance, null: false
|
15
|
+
t.float :wage, null: false
|
16
|
+
t.string :qualification
|
17
|
+
t.references :payment, null: false, index: { name: 'cpd_on_payment_indx' }
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_foreign_key :ecom_core_custom_payment_details, :ecom_core_payments, column: :payment_id
|
23
|
+
end
|
24
|
+
end
|
data/lib/ecom/core/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :custom_payment_detail, class: 'Ecom::Core::CustomPaymentDetail' do
|
3
|
+
name { FFaker::Name.name }
|
4
|
+
hours { 1.5 }
|
5
|
+
ot_hours { 1.5 }
|
6
|
+
base_salary { 1.5 }
|
7
|
+
overtime { 1.5 }
|
8
|
+
gross_salary { 100 }
|
9
|
+
tax { 15 }
|
10
|
+
pension { 5 }
|
11
|
+
net_salary { 80 }
|
12
|
+
net_pay { 80 }
|
13
|
+
advance { 0 }
|
14
|
+
wage { 1.5 }
|
15
|
+
qualification { FFaker::Name.name }
|
16
|
+
association :payment
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecom_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.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: 2020-
|
11
|
+
date: 2020-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aasm
|
@@ -53,21 +53,21 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: fast_jsonapi
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: jwt
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 6.0.2
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 6.0.2
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: factory_bot_rails
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,16 +205,22 @@ files:
|
|
191
205
|
- Rakefile
|
192
206
|
- app/controllers/concerns/ecom/core/lookupable.rb
|
193
207
|
- app/controllers/concerns/ecom/core/resource_typeable.rb
|
208
|
+
- app/controllers/ecom/core/access_controller.rb
|
194
209
|
- app/controllers/ecom/core/application_controller.rb
|
210
|
+
- app/controllers/ecom/core/application_modules_controller.rb
|
195
211
|
- app/controllers/ecom/core/crew_types_controller.rb
|
196
212
|
- app/controllers/ecom/core/equipment_types_controller.rb
|
197
213
|
- app/controllers/ecom/core/material_types_controller.rb
|
214
|
+
- app/controllers/ecom/core/menus_controller.rb
|
215
|
+
- app/controllers/ecom/core/user_roles_controller.rb
|
216
|
+
- app/controllers/ecom/core/users_controller.rb
|
198
217
|
- app/models/ecom/core/application_module.rb
|
199
218
|
- app/models/ecom/core/application_record.rb
|
200
219
|
- app/models/ecom/core/crew.rb
|
201
220
|
- app/models/ecom/core/crew_time.rb
|
202
221
|
- app/models/ecom/core/crew_type.rb
|
203
222
|
- app/models/ecom/core/currency.rb
|
223
|
+
- app/models/ecom/core/custom_payment_detail.rb
|
204
224
|
- app/models/ecom/core/equipment_type.rb
|
205
225
|
- app/models/ecom/core/lookup.rb
|
206
226
|
- app/models/ecom/core/material_type.rb
|
@@ -223,8 +243,12 @@ files:
|
|
223
243
|
- app/models/ecom/core/work_component_template.rb
|
224
244
|
- app/models/ecom/core/work_product.rb
|
225
245
|
- app/models/ecom/core/work_product_template.rb
|
246
|
+
- app/serializers/ecom/core/application_module_serializer.rb
|
226
247
|
- app/serializers/ecom/core/lookup_serializer.rb
|
227
248
|
- app/serializers/ecom/core/resource_type_serializer.rb
|
249
|
+
- app/serializers/ecom/core/user_role_serializer.rb
|
250
|
+
- app/serializers/ecom/core/user_serializer.rb
|
251
|
+
- app/services/ecom/core/token_auth_service.rb
|
228
252
|
- config/database.ci.yml
|
229
253
|
- config/routes.rb
|
230
254
|
- db/migrate/20190101112620_create_ecom_core_lookups.rb
|
@@ -256,6 +280,7 @@ files:
|
|
256
280
|
- db/migrate/20200207040844_add_net_pay_column_to_payment_details.rb
|
257
281
|
- db/migrate/20200210095535_add_advance_column_to_payment_details.rb
|
258
282
|
- db/migrate/20200221123207_add_employee_id_to_crew.rb
|
283
|
+
- db/migrate/20200307112519_create_ecom_core_custom_payment_details.rb
|
259
284
|
- lib/ecom/core.rb
|
260
285
|
- lib/ecom/core/engine.rb
|
261
286
|
- lib/ecom/core/version.rb
|
@@ -266,6 +291,7 @@ files:
|
|
266
291
|
- spec/factories/ecom/core/crew_types.rb
|
267
292
|
- spec/factories/ecom/core/crews.rb
|
268
293
|
- spec/factories/ecom/core/currencies.rb
|
294
|
+
- spec/factories/ecom/core/custom_payment_details.rb
|
269
295
|
- spec/factories/ecom/core/equipment_types.rb
|
270
296
|
- spec/factories/ecom/core/lookups.rb
|
271
297
|
- spec/factories/ecom/core/material_types.rb
|