cats_core 1.0.9 → 1.0.13
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/application_controller.rb +1 -1
- data/app/controllers/cats/core/menus_controller.rb +19 -0
- data/app/controllers/cats/core/roles_controller.rb +1 -1
- data/app/models/cats/core/notification.rb +1 -1
- data/app/models/cats/core/role_menu.rb +3 -0
- data/app/models/cats/core/store.rb +8 -2
- data/app/models/cats/core/user.rb +13 -1
- data/app/notifications/cats/core/simple_notification.rb +15 -4
- data/app/serializers/cats/core/role_menu_serializer.rb +11 -0
- data/app/services/cats/core/menu_service.rb +9 -0
- data/app/services/cats/core/notification_service.rb +3 -6
- data/config/routes.rb +3 -2
- data/db/migrate/20210715114910_create_cats_core_users.rb +1 -0
- data/db/migrate/20210717140855_create_cats_core_stores.rb +4 -3
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/stores.rb +2 -2
- data/spec/factories/cats/core/users.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c166b58630fc770c2447694d5d57f59edd26ab7bee0caf07f762fc16d21f4069
|
4
|
+
data.tar.gz: 7cc6aead85c41426225eb4d306e92cf85ac7024b4690324a62985b7c6b163756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a6c48372747e4c159c7fae9d51af746740fe7d556fc9b0cee36d9ba814ccd33aa25be298681729ad474b63c7c30881b79dcdb5da2a2da47d9962f6b3df325a2
|
7
|
+
data.tar.gz: 30805a86c89f24e1472a177c7cedf1c18a5ccbc18756bf316eca62138d63247a05ee42c18004b06a1ce898ac4343341045eff7f59921d16ea70a22ac2c33d4d9
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class MenusController < ApplicationController
|
4
|
+
before_action :set_service
|
5
|
+
|
6
|
+
def index
|
7
|
+
menu = @service.fetch_menu(current_user)
|
8
|
+
data = ActiveModelSerializers::SerializableResource.new(menu, each_serializer: RoleMenuSerializer)
|
9
|
+
render json: { success: true, data: data }
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_service
|
15
|
+
@service = MenuService.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -6,7 +6,7 @@ module Cats
|
|
6
6
|
belongs_to :recipient, polymorphic: true
|
7
7
|
|
8
8
|
def message
|
9
|
-
{ id: id, read: !read_at.nil
|
9
|
+
{ id: id, read: !read_at.nil?, created_at: created_at }.merge(to_notification.message)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.messages(notifications)
|
@@ -2,10 +2,10 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class Store < ApplicationRecord
|
4
4
|
belongs_to :warehouse, class_name: 'Cats::Core::Location'
|
5
|
+
belongs_to :store_keeper, class_name: 'Cats::Core::User'
|
5
6
|
has_many :stacks
|
6
|
-
has_many :receipt_plans, as: :receivable
|
7
7
|
|
8
|
-
validates :name, :
|
8
|
+
validates :name, :length, :width, :height, presence: true
|
9
9
|
validates :length, :width, :height, numericality: { greater_than: 0 }
|
10
10
|
validates :gangway_length, :gangway_width, :gangway_corner_dist, presence: true, if: :has_gangway?
|
11
11
|
validates :gangway_length,
|
@@ -20,6 +20,12 @@ module Cats
|
|
20
20
|
|
21
21
|
errors.add(:warehouse, 'must be a valid warehouse') unless warehouse.location_type == Location::WAREHOUSE
|
22
22
|
end
|
23
|
+
|
24
|
+
def store_keeper_name
|
25
|
+
"#{store_keeper.first_name} #{store_keeper.last_name}"
|
26
|
+
end
|
27
|
+
|
28
|
+
delegate(:phone_number, to: :store_keeper, prefix: true)
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -8,9 +8,11 @@ module Cats
|
|
8
8
|
has_and_belongs_to_many :roles, join_table: :cats_core_users_cats_core_roles
|
9
9
|
has_many :notifications, as: :recipient
|
10
10
|
|
11
|
+
validates :password, length: { minimum: 6 }, if: proc { |u| u.password.present? }, on: :update
|
11
12
|
validates :first_name, :last_name, :email, presence: true
|
12
|
-
validates :password, length: { minimum: 6 }
|
13
|
+
validates :password, presence: true, length: { minimum: 6 }, on: :create
|
13
14
|
validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
15
|
+
validate :validate_phone_number
|
14
16
|
|
15
17
|
def warehouses
|
16
18
|
return unless details.key?('warehouses')
|
@@ -23,6 +25,16 @@ module Cats
|
|
23
25
|
|
24
26
|
Cats::Core::Store.where(id: details['stores'])
|
25
27
|
end
|
28
|
+
|
29
|
+
def validate_phone_number
|
30
|
+
return unless phone_number.present?
|
31
|
+
|
32
|
+
return if phone_number.length == 10 && /0\d{9}/.match(phone_number)
|
33
|
+
|
34
|
+
return if phone_number.length == 12 && /251\d{9}/.match(phone_number)
|
35
|
+
|
36
|
+
errors.add(:phone_number, 'must be 10 or 12 digits and should match with local phone pattern')
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
@@ -1,9 +1,20 @@
|
|
1
1
|
# This is a simple notification class which delivers a
|
2
2
|
# message via database delivery method. It requires a
|
3
|
-
# +
|
3
|
+
# +body+ and +title+ parameter to instantiate, which represents the
|
4
4
|
# text message to deliver.
|
5
|
-
|
6
|
-
|
5
|
+
module Cats
|
6
|
+
module Core
|
7
|
+
class SimpleNotification < Noticed::Base
|
8
|
+
deliver_by :database
|
7
9
|
|
8
|
-
|
10
|
+
param :body
|
11
|
+
param :title
|
12
|
+
|
13
|
+
def message
|
14
|
+
title = params[:title]
|
15
|
+
body = params[:body]
|
16
|
+
{ title: title, body: body }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
9
20
|
end
|
@@ -16,22 +16,19 @@ module Cats
|
|
16
16
|
}
|
17
17
|
}.freeze
|
18
18
|
|
19
|
-
def initialize(code, params)
|
19
|
+
def initialize(rules, code, params)
|
20
|
+
@rules = rules
|
20
21
|
@code = code
|
21
22
|
@params = params
|
22
23
|
end
|
23
24
|
|
24
|
-
def notification_rules
|
25
|
-
NOTIFICATION_RULES
|
26
|
-
end
|
27
|
-
|
28
25
|
def create_notifier(rule)
|
29
26
|
clazz = rule[:notification].constantize
|
30
27
|
clazz.with(**@params)
|
31
28
|
end
|
32
29
|
|
33
30
|
def notify
|
34
|
-
rule =
|
31
|
+
rule = @rules[@code]
|
35
32
|
notifier = create_notifier(rule)
|
36
33
|
app_code = rule[:application]
|
37
34
|
roles = rule[:recipients]
|
data/config/routes.rb
CHANGED
@@ -2,14 +2,15 @@ Cats::Core::Engine.routes.draw do
|
|
2
2
|
post '/login', controller: :access, action: :login
|
3
3
|
get '/notifications/unread', controller: :notifications, action: :unread
|
4
4
|
get '/notifications/read', controller: :notifications, action: :read
|
5
|
-
|
5
|
+
|
6
|
+
resources :menus, only: [:index]
|
6
7
|
resources :notifications, only: [:index] do
|
7
8
|
member do
|
8
9
|
post 'mark_as_read', controller: :notifications, action: :mark_as_read
|
9
10
|
post 'mark_as_unread', controller: :notifications, action: :mark_as_unread
|
10
11
|
end
|
11
12
|
end
|
12
|
-
resources :roles do
|
13
|
+
resources :roles, param: :name do
|
13
14
|
member do
|
14
15
|
get 'users', controller: :roles, action: :users
|
15
16
|
end
|
@@ -7,6 +7,7 @@ class CreateCatsCoreUsers < ActiveRecord::Migration[6.1]
|
|
7
7
|
t.boolean :active, null: false, default: true
|
8
8
|
t.string :password_digest
|
9
9
|
t.jsonb :details
|
10
|
+
t.string :phone_number
|
10
11
|
t.references :application_module,
|
11
12
|
null: false,
|
12
13
|
index: { name: 'am_on_users_indx' },
|
@@ -2,8 +2,6 @@ class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
|
|
2
2
|
def change
|
3
3
|
create_table :cats_core_stores do |t|
|
4
4
|
t.string :name, null: false
|
5
|
-
t.string :store_keeper_name, null: false
|
6
|
-
t.string :store_keeper_phone
|
7
5
|
t.float :length, null: false
|
8
6
|
t.float :width, null: false
|
9
7
|
t.float :height, null: false
|
@@ -16,7 +14,10 @@ class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
|
|
16
14
|
null: false,
|
17
15
|
index: { name: 'warehouse_on_stores_indx' },
|
18
16
|
foreign_key: { to_table: :cats_core_locations }
|
19
|
-
|
17
|
+
t.references :store_keeper,
|
18
|
+
null: false,
|
19
|
+
index: { name: 'store_keeper_on_store_indx' },
|
20
|
+
foreign_key: { to_table: :cats_core_users }
|
20
21
|
t.timestamps
|
21
22
|
end
|
22
23
|
end
|
data/lib/cats/core/version.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :store, class: 'Cats::Core::Store' do
|
3
3
|
name { FFaker::Name.name }
|
4
|
-
store_keeper_name { FFaker::Name.name }
|
5
|
-
store_keeper_phone { FFaker::Name.name }
|
6
4
|
length { 50 }
|
7
5
|
width { 40 }
|
8
6
|
height { 10 }
|
@@ -12,5 +10,7 @@ FactoryBot.define do
|
|
12
10
|
gangway_width { 4 }
|
13
11
|
gangway_corner_dist { 18 }
|
14
12
|
warehouse
|
13
|
+
store_keeper factory: :user
|
14
|
+
store_keeper_id { create(:user).id }
|
15
15
|
end
|
16
16
|
end
|
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.0.
|
4
|
+
version: 1.0.13
|
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-08-
|
11
|
+
date: 2021-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- Rakefile
|
219
219
|
- app/controllers/cats/core/access_controller.rb
|
220
220
|
- app/controllers/cats/core/application_controller.rb
|
221
|
+
- app/controllers/cats/core/menus_controller.rb
|
221
222
|
- app/controllers/cats/core/notifications_controller.rb
|
222
223
|
- app/controllers/cats/core/roles_controller.rb
|
223
224
|
- app/controllers/cats/core/users_controller.rb
|
@@ -245,6 +246,8 @@ files:
|
|
245
246
|
- app/models/cats/core/way_bill.rb
|
246
247
|
- app/models/cats/core/way_bill_item.rb
|
247
248
|
- app/notifications/cats/core/simple_notification.rb
|
249
|
+
- app/serializers/cats/core/role_menu_serializer.rb
|
250
|
+
- app/services/cats/core/menu_service.rb
|
248
251
|
- app/services/cats/core/notification_service.rb
|
249
252
|
- app/services/cats/core/token_auth_service.rb
|
250
253
|
- config/routes.rb
|