cats_core 1.0.8 → 1.0.12
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 +4 -4
- data/app/controllers/cats/core/access_controller.rb +37 -0
- 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/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/config/routes.rb +4 -2
- data/lib/cats/core/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad0f19c4e9e9d38a4038b2f94ca78ea18fb730dccb1c04bacf403a8fe5b29de5
|
4
|
+
data.tar.gz: 452ec1bb9126955274e5adae51d60a903e88674da97610b1b9945c43995d1ab6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40dcc3d2d091d837d24da04a8889bca46b8afa22662c27fa518fb3ef9b98c2b20aad829f3f5126e444566e6229ca67d954dfa0ac7f76e93c4f03ef80c40fded4
|
7
|
+
data.tar.gz: ad35c7773f8b1ea0bf10193d70e0857096da4768029c4b1de675b1a9c005e0d6fba86f8201739fafde97122a137a2122bd4aa12b506b965a053a2606f963d418
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class AccessController < ApplicationController
|
4
|
+
skip_before_action :authenticate, only: [:login]
|
5
|
+
|
6
|
+
def login
|
7
|
+
user = Cats::Core::User.find_by(email: auth_params[:email])
|
8
|
+
if user
|
9
|
+
if user.authenticate(auth_params[:password])
|
10
|
+
roles = user.roles.map(&:name)
|
11
|
+
|
12
|
+
unless roles.count.positive?
|
13
|
+
render json: { error: 'User has no roles.' }, status: :unprocessable_entity
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
payload = {
|
18
|
+
id: user.id, email: user.email, first_name: user.first_name, last_name: user.last_name, roles: roles
|
19
|
+
}
|
20
|
+
jwt = Cats::Core::TokenAuthService.issue(payload)
|
21
|
+
render json: { token: jwt, user: payload }
|
22
|
+
else
|
23
|
+
rener json: { error: 'Invalid username or password.' }, status: 400
|
24
|
+
end
|
25
|
+
else
|
26
|
+
render json: { error: 'User does not exist.' }, status: 400
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def auth_params
|
33
|
+
params.require(:auth).permit(:email, :password)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -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)
|
@@ -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
|
data/config/routes.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
Cats::Core::Engine.routes.draw do
|
2
|
+
post '/login', controller: :access, action: :login
|
2
3
|
get '/notifications/unread', controller: :notifications, action: :unread
|
3
4
|
get '/notifications/read', controller: :notifications, action: :read
|
4
|
-
|
5
|
+
|
6
|
+
resources :menus, only: [:index]
|
5
7
|
resources :notifications, only: [:index] do
|
6
8
|
member do
|
7
9
|
post 'mark_as_read', controller: :notifications, action: :mark_as_read
|
8
10
|
post 'mark_as_unread', controller: :notifications, action: :mark_as_unread
|
9
11
|
end
|
10
12
|
end
|
11
|
-
resources :roles do
|
13
|
+
resources :roles, param: :name do
|
12
14
|
member do
|
13
15
|
get 'users', controller: :roles, action: :users
|
14
16
|
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.0.
|
4
|
+
version: 1.0.12
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -216,7 +216,9 @@ files:
|
|
216
216
|
- MIT-LICENSE
|
217
217
|
- README.md
|
218
218
|
- Rakefile
|
219
|
+
- app/controllers/cats/core/access_controller.rb
|
219
220
|
- app/controllers/cats/core/application_controller.rb
|
221
|
+
- app/controllers/cats/core/menus_controller.rb
|
220
222
|
- app/controllers/cats/core/notifications_controller.rb
|
221
223
|
- app/controllers/cats/core/roles_controller.rb
|
222
224
|
- app/controllers/cats/core/users_controller.rb
|
@@ -244,6 +246,8 @@ files:
|
|
244
246
|
- app/models/cats/core/way_bill.rb
|
245
247
|
- app/models/cats/core/way_bill_item.rb
|
246
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
|
247
251
|
- app/services/cats/core/notification_service.rb
|
248
252
|
- app/services/cats/core/token_auth_service.rb
|
249
253
|
- config/routes.rb
|