anoubis 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +38 -0
- data/app/controllers/anoubis/application_controller.rb +78 -0
- data/app/controllers/anoubis/core/application_controller.rb +343 -0
- data/app/controllers/anoubis/core/data/actions.rb +962 -0
- data/app/controllers/anoubis/core/data/callbacks.rb +68 -0
- data/app/controllers/anoubis/core/data/convert.rb +407 -0
- data/app/controllers/anoubis/core/data/defaults.rb +217 -0
- data/app/controllers/anoubis/core/data/get.rb +531 -0
- data/app/controllers/anoubis/core/data/load.rb +89 -0
- data/app/controllers/anoubis/core/data/set.rb +49 -0
- data/app/controllers/anoubis/core/data/setup.rb +104 -0
- data/app/controllers/anoubis/core/data_controller.rb +28 -0
- data/app/controllers/anoubis/core/index/actions.rb +53 -0
- data/app/controllers/anoubis/core/index/callbacks.rb +23 -0
- data/app/controllers/anoubis/core/index_controller.rb +36 -0
- data/app/controllers/anoubis/etc/base.rb +52 -0
- data/app/controllers/anoubis/etc/data.rb +89 -0
- data/app/controllers/anoubis/etc/field.rb +468 -0
- data/app/controllers/anoubis/etc/field_options.rb +83 -0
- data/app/controllers/anoubis/etc/field_order.rb +51 -0
- data/app/controllers/anoubis/etc/filter.rb +251 -0
- data/app/controllers/anoubis/etc/menu.rb +101 -0
- data/app/controllers/anoubis/etc/model.rb +67 -0
- data/app/controllers/anoubis/etc/tab_item.rb +91 -0
- data/app/controllers/anoubis/etc.rb +8 -0
- data/app/controllers/anoubis/export.rb +47 -0
- data/app/controllers/anoubis/output/autocomplete.rb +30 -0
- data/app/controllers/anoubis/output/basic.rb +86 -0
- data/app/controllers/anoubis/output/data.rb +101 -0
- data/app/controllers/anoubis/output/delete.rb +41 -0
- data/app/controllers/anoubis/output/edit.rb +55 -0
- data/app/controllers/anoubis/output/frame.rb +227 -0
- data/app/controllers/anoubis/output/login.rb +71 -0
- data/app/controllers/anoubis/output/menu.rb +220 -0
- data/app/controllers/anoubis/output/update.rb +43 -0
- data/app/controllers/anoubis/sso/client/application_controller.rb +139 -0
- data/app/controllers/anoubis/sso/client/data/actions.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/callbacks.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/convert.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/defaults.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/get.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/load.rb +26 -0
- data/app/controllers/anoubis/sso/client/data/set.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/setup.rb +5 -0
- data/app/controllers/anoubis/sso/client/data_controller.rb +21 -0
- data/app/controllers/anoubis/sso/client/index/actions.rb +79 -0
- data/app/controllers/anoubis/sso/client/index/callbacks.rb +13 -0
- data/app/controllers/anoubis/sso/client/index_controller.rb +18 -0
- data/app/controllers/anoubis/sso/server/application_controller.rb +49 -0
- data/app/controllers/anoubis/sso/server/login_controller.rb +342 -0
- data/app/controllers/anoubis/sso/server/user_controller.rb +142 -0
- data/app/controllers/anoubis/tenant/application_controller.rb +54 -0
- data/app/controllers/anoubis/tenant/data/actions.rb +11 -0
- data/app/controllers/anoubis/tenant/data/callbacks.rb +11 -0
- data/app/controllers/anoubis/tenant/data/convert.rb +11 -0
- data/app/controllers/anoubis/tenant/data/defaults.rb +11 -0
- data/app/controllers/anoubis/tenant/data/get.rb +11 -0
- data/app/controllers/anoubis/tenant/data/load.rb +52 -0
- data/app/controllers/anoubis/tenant/data/set.rb +11 -0
- data/app/controllers/anoubis/tenant/data/setup.rb +11 -0
- data/app/controllers/anoubis/tenant/data_controller.rb +28 -0
- data/app/controllers/anoubis/tenant/index/actions.rb +191 -0
- data/app/controllers/anoubis/tenant/index/callbacks.rb +11 -0
- data/app/controllers/anoubis/tenant/index_controller.rb +38 -0
- data/app/controllers/anoubis/tenants_controller.rb +7 -0
- data/app/controllers/anoubis/users_controller.rb +7 -0
- data/app/jobs/anoubis/application_job.rb +6 -0
- data/app/mailers/anoubis/application_mailer.rb +8 -0
- data/app/models/anoubis/application_record.rb +45 -0
- data/app/models/anoubis/core/application_record.rb +250 -0
- data/app/models/anoubis/core/locales.rb +27 -0
- data/app/models/anoubis/sso/client/application_record.rb +3 -0
- data/app/models/anoubis/sso/client/group.rb +19 -0
- data/app/models/anoubis/sso/client/group_menu.rb +109 -0
- data/app/models/anoubis/sso/client/menu.rb +145 -0
- data/app/models/anoubis/sso/client/user.rb +81 -0
- data/app/models/anoubis/sso/client/user_group.rb +32 -0
- data/app/models/anoubis/sso/server/system.rb +36 -0
- data/app/models/anoubis/sso/server/user.rb +79 -0
- data/app/models/anoubis/tenant/application_record.rb +41 -0
- data/app/models/anoubis/tenant/group.rb +95 -0
- data/app/models/anoubis/tenant/group_locale.rb +19 -0
- data/app/models/anoubis/tenant/group_menu.rb +84 -0
- data/app/models/anoubis/tenant/menu.rb +156 -0
- data/app/models/anoubis/tenant/menu_locale.rb +27 -0
- data/app/models/anoubis/tenant/system.rb +127 -0
- data/app/models/anoubis/tenant/system_locale.rb +19 -0
- data/app/models/anoubis/tenant/system_menu.rb +51 -0
- data/app/models/anoubis/tenant/tenant.rb +107 -0
- data/app/models/anoubis/tenant/tenant_system.rb +19 -0
- data/app/models/anoubis/tenant/user.rb +225 -0
- data/app/models/anoubis/tenant/user_group.rb +32 -0
- data/app/services/anoubis/core_service.rb +16 -0
- data/app/services/anoubis/session_service.rb +17 -0
- data/app/validators/presence_in_tenant_validator.rb +20 -0
- data/config/initializers/mime_type.rb +1 -0
- data/config/locales/en.yml +120 -0
- data/config/locales/ru.yml +245 -0
- data/config/routes.rb +74 -0
- data/db/migrate/20181018085843_create_tenants.rb +13 -0
- data/db/migrate/20181018111217_create_systems.rb +10 -0
- data/db/migrate/20181018111713_create_tenant_systems.rb +11 -0
- data/db/migrate/20181018111925_create_groups.rb +13 -0
- data/db/migrate/20181018112151_create_users.rb +25 -0
- data/db/migrate/20181018115737_add_title_to_users.rb +10 -0
- data/db/migrate/20181022060211_create_menus.rb +18 -0
- data/db/migrate/20181115055245_create_group_menus.rb +12 -0
- data/db/migrate/20181115060830_create_system_menus.rb +11 -0
- data/db/migrate/20181122062131_create_user_groups.rb +11 -0
- data/db/migrate/20181221060727_create_menu_locales.rb +14 -0
- data/db/migrate/20181225062303_create_system_locales.rb +11 -0
- data/db/migrate/20181225062339_create_group_locales.rb +11 -0
- data/db/seeds.rb +268 -0
- data/lib/anoubis/engine.rb +13 -0
- data/lib/anoubis/version.rb +5 -0
- data/lib/anoubis.rb +213 -0
- data/lib/tasks/anubis_tasks.rake +10 -0
- data/lib/tasks/sessions/clear_sessions.rake +10 -0
- data/spec/anubis_spec.rb +5 -0
- data/spec/controllers/anoubis/index_controller_spec.rb +77 -0
- data/spec/dummy/Rakefile +3 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/bin/update +28 -0
- data/spec/dummy/config/application.rb +14 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +54 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +85 -0
- data/spec/dummy/config/environments/test.rb +46 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cors.rb +16 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +34 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/schema.rb +167 -0
- data/spec/dummy/db/seeds.rb +1 -0
- data/spec/factories/anubis_group_locales.rb +7 -0
- data/spec/factories/anubis_group_menus.rb +7 -0
- data/spec/factories/anubis_groups.rb +6 -0
- data/spec/factories/anubis_menu_locales.rb +9 -0
- data/spec/factories/anubis_menus.rb +6 -0
- data/spec/factories/anubis_system_locales.rb +7 -0
- data/spec/factories/anubis_system_menus.rb +6 -0
- data/spec/factories/anubis_systems.rb +5 -0
- data/spec/factories/anubis_tenants.rb +7 -0
- data/spec/factories/anubis_users.rb +10 -0
- data/spec/integration/navigation_test.rb +7 -0
- data/spec/models/anoubis/group_locale_spec.rb +25 -0
- data/spec/models/anoubis/group_menu_spec.rb +50 -0
- data/spec/models/anoubis/group_spec.rb +52 -0
- data/spec/models/anoubis/menu_locale_spec.rb +31 -0
- data/spec/models/anoubis/menu_spec.rb +48 -0
- data/spec/models/anoubis/system_locale_spec.rb +20 -0
- data/spec/models/anoubis/system_menu_spec.rb +49 -0
- data/spec/models/anoubis/system_spec.rb +53 -0
- data/spec/models/anoubis/tenant_spec.rb +67 -0
- data/spec/models/anoubis/user_spec.rb +57 -0
- data/spec/rails_helper.rb +32 -0
- data/spec/requests/anoubis/users_request_spec.rb +5 -0
- data/spec/spec_helper.rb +13 -0
- metadata +408 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require_dependency "anubis/tenant/application_controller"
|
2
|
+
require_dependency "anubis/tenant/data/actions"
|
3
|
+
require_dependency "anubis/tenant/data/load"
|
4
|
+
require_dependency "anubis/tenant/data/get"
|
5
|
+
require_dependency "anubis/tenant/data/set"
|
6
|
+
require_dependency "anubis/tenant/data/setup"
|
7
|
+
require_dependency "anubis/tenant/data/defaults"
|
8
|
+
require_dependency "anubis/tenant/data/convert"
|
9
|
+
require_dependency "anubis/tenant/data/callbacks"
|
10
|
+
|
11
|
+
module Anubis
|
12
|
+
##
|
13
|
+
# Module presents all core functions for Anubis Library
|
14
|
+
module Tenant
|
15
|
+
##
|
16
|
+
# Controller consists all procedures and function for presents and modify models data.
|
17
|
+
class DataController < Anubis::Tenant::ApplicationController
|
18
|
+
include Anubis::Tenant::Data::Actions
|
19
|
+
include Anubis::Tenant::Data::Load
|
20
|
+
include Anubis::Tenant::Data::Get
|
21
|
+
include Anubis::Tenant::Data::Set
|
22
|
+
include Anubis::Tenant::Data::Setup
|
23
|
+
include Anubis::Tenant::Data::Defaults
|
24
|
+
include Anubis::Tenant::Data::Convert
|
25
|
+
include Anubis::Tenant::Data::Callbacks
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Tenant
|
3
|
+
module Index
|
4
|
+
##
|
5
|
+
# Module contains all basic actions for {IndexController}.
|
6
|
+
module Actions
|
7
|
+
include Anubis::Core::Index::Actions
|
8
|
+
|
9
|
+
##
|
10
|
+
# <i>Login</i> action of index controller. Procedure checks user credential. If credentials are correct than user enters
|
11
|
+
# into the system and procedure returns session token. If credentials are incorrect then procedure returns error.
|
12
|
+
#
|
13
|
+
# <b>API request:</b>
|
14
|
+
# POST /api/<version>/login
|
15
|
+
# <b>Request body:</b>
|
16
|
+
# {
|
17
|
+
# "login": "login",
|
18
|
+
# "password": "password",
|
19
|
+
# "locale": "Country code"
|
20
|
+
# }
|
21
|
+
# <b>Parameters:</b>
|
22
|
+
# - <b>login</b> (String) -- the login of the user
|
23
|
+
# - <b>password</b> (String) -- the password of the user
|
24
|
+
# - <b>locale</b> (String) -- the output language locale <i>(optional value)</i>
|
25
|
+
#
|
26
|
+
# <b>Request example:</b>
|
27
|
+
# curl --header "Content-Type: application/json" --request POST --data '{"login":"<login>","password":"<password>"}' http://<server>:<port>/api/<api-version>/login
|
28
|
+
#
|
29
|
+
# <b>Results:</b><br>
|
30
|
+
#
|
31
|
+
# Resulting data is placed in self.output({Anubis::OutputLogin}) class and returns in JSON format.
|
32
|
+
#
|
33
|
+
# <b>Examples:</b>
|
34
|
+
#
|
35
|
+
# <b>Success:</b> HTTP response code 200
|
36
|
+
# {
|
37
|
+
# "result": 0,
|
38
|
+
# "message": "Successful",
|
39
|
+
# "name": "Name",
|
40
|
+
# "surname": "Surname",
|
41
|
+
# "token": "Session token",
|
42
|
+
# "email": "e-mail"
|
43
|
+
# }
|
44
|
+
#
|
45
|
+
# <b>Error:</b> HTTP response code 422
|
46
|
+
# {
|
47
|
+
# "result": -1,
|
48
|
+
# "message": "Incorrect user login or password"
|
49
|
+
# }
|
50
|
+
def login
|
51
|
+
self.output = Anubis::Output::Login.new
|
52
|
+
if params.has_key?(:login) && params.has_key?(:password)
|
53
|
+
user = Anubis::Tenant::User.where(login: params[:login].downcase, status: 0).first
|
54
|
+
|
55
|
+
if !user
|
56
|
+
tenant = Anubis::Tenant::Tenant.where(state: Anubis::Tenant::Tenant.states[:default]).first
|
57
|
+
user = Anubis::Tenant::User.where(login: (params[:login]+'.'+tenant.ident).downcase, status: 0).first
|
58
|
+
end
|
59
|
+
|
60
|
+
if !user
|
61
|
+
tenant = Anubis::Tenant::Tenant.find(1)
|
62
|
+
user = Anubis::Tenant::User.where(login: (params[:login]+'.'+tenant.ident).downcase, status: 0).first
|
63
|
+
end
|
64
|
+
|
65
|
+
if user && user.authenticate(params[:password])
|
66
|
+
if !user.auth_key
|
67
|
+
self.redis_save_user(user)
|
68
|
+
self.output.token = new_session_id
|
69
|
+
self.output.name = user.name
|
70
|
+
self.output.surname = user.surname
|
71
|
+
self.output.email = user.email
|
72
|
+
self.output.locale = user.locale
|
73
|
+
self.redis.set(self.redis_prefix + 'session:' + self.output.token, { uuid: user.uuid, login: Time.now, time: Time.now, ttl: Time.now + user.timeout}.to_json)
|
74
|
+
else
|
75
|
+
self.output.result = -2
|
76
|
+
end
|
77
|
+
else
|
78
|
+
self.output.result = -2
|
79
|
+
end
|
80
|
+
else
|
81
|
+
self.output.result = -1
|
82
|
+
end
|
83
|
+
respond_to do |format|
|
84
|
+
if self.output.result == 0
|
85
|
+
format.json { render json: self.output.to_h }
|
86
|
+
else
|
87
|
+
format.json { render json: self.output.to_h, status: :unprocessable_entity }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# <i>Menu</i> action of index controller. Procedure outputs menu for current user in JSON format.
|
94
|
+
# Authorization bearer is required.
|
95
|
+
#
|
96
|
+
# <b>API request:</b>
|
97
|
+
# GET /api/<version>/menu
|
98
|
+
# <b>Request Header:</b>
|
99
|
+
# {
|
100
|
+
# "Authorization": "Bearer <Session token>"
|
101
|
+
# }
|
102
|
+
#
|
103
|
+
# <b>Parameters:</b>
|
104
|
+
# - <b>locale</b> (String) -- the output language locale <i>(optional value)</i>
|
105
|
+
#
|
106
|
+
# <b>Request example:</b>
|
107
|
+
# curl --header "Content-Type: application/json" -header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/menu?locale=en
|
108
|
+
#
|
109
|
+
# <b>Results:</b><br>
|
110
|
+
#
|
111
|
+
# Resulting data is placed in self.output({Anubis::Output::Menu}) variable and returns in JSON format.
|
112
|
+
#
|
113
|
+
# <b>Examples:</b>
|
114
|
+
#
|
115
|
+
# <b>Success:</b> HTTP response code 200
|
116
|
+
# {
|
117
|
+
# "result": 0,
|
118
|
+
# "message": "Successful",
|
119
|
+
# "menu": {
|
120
|
+
# [{
|
121
|
+
# "mode": "admin/anubis",
|
122
|
+
# "title": "Administration",
|
123
|
+
# "page_title": "System administration",
|
124
|
+
# "short_title": "",
|
125
|
+
# "position": 0,
|
126
|
+
# "tab": 0,
|
127
|
+
# "action": "menu",
|
128
|
+
# "access": "read",
|
129
|
+
# "state": "visible",
|
130
|
+
# "parent": ""
|
131
|
+
# }]
|
132
|
+
# }
|
133
|
+
# }
|
134
|
+
#
|
135
|
+
# <b>Error:</b> HTTP response code 422
|
136
|
+
# {
|
137
|
+
# "result": -1,
|
138
|
+
# "message": "Session expired"
|
139
|
+
# }
|
140
|
+
def menu
|
141
|
+
self.output = Anubis::Output::Menu.new
|
142
|
+
access = Anubis::Tenant::GroupMenu.accesses[:read].to_s+','+Anubis::Tenant::GroupMenu.accesses[:write].to_s
|
143
|
+
locale = Anubis::Tenant::MenuLocale.locales[self.locale.to_s.to_sym]
|
144
|
+
query = <<-SQL
|
145
|
+
SELECT `t`.* FROM
|
146
|
+
(
|
147
|
+
SELECT `t2`.`id`, `t2`.`mode`, `t2`.`action`, `t2`.`title`, `t2`.`page_title`, `t2`.`short_title`,
|
148
|
+
`t2`.`position`, `t2`.`tab`, `t2`.`menu_id`, `t2`.`state`, MAX(`t2`.`access`) AS `access`,
|
149
|
+
`t2`.`user_id`, `t2`.`parent_mode`
|
150
|
+
FROM (
|
151
|
+
SELECT `menus`.`id`, `menus`.`mode`, `menus`.`action`, `menu_locales`.`title`, `menu_locales`.`page_title`,
|
152
|
+
`menu_locales`.`short_title`, `menus`.`position`, `menus`.`tab`, `menus`.`menu_id`, `menus`.`state`,
|
153
|
+
`group_menus`.`access`, `user_groups`.`user_id`, `parent_menu`.`mode` AS `parent_mode`
|
154
|
+
FROM (`menus`, `group_menus`, `groups`, `user_groups`)
|
155
|
+
LEFT JOIN `menu_locales` ON `menu_locales`.`menu_id` = `menus`.`id` AND `menu_locales`.`locale` = #{locale}
|
156
|
+
LEFT JOIN `menus` AS `parent_menu` ON `menus`.`menu_id` = `parent_menu`.`id`
|
157
|
+
WHERE `menus`.`id` = `group_menus`.`menu_id` AND `menus`.`status` = 0 AND `group_menus`.`group_id` = `groups`.`id` AND
|
158
|
+
`groups`.`id` = `user_groups`.`group_id` AND `user_groups`.`user_id` = #{self.current_user.id}
|
159
|
+
) AS `t2`
|
160
|
+
GROUP BY `t2`.`id`, `t2`.`mode`, `t2`.`action`, `t2`.`title`, `t2`.`page_title`, `t2`.`short_title`,
|
161
|
+
`t2`.`position`, `t2`.`tab`, `t2`.`menu_id`, `t2`.`state`, `t2`.`user_id`, `t2`.`parent_mode`) AS `t`
|
162
|
+
WHERE `t`.access IN (#{access}
|
163
|
+
)
|
164
|
+
ORDER BY `t`.`menu_id`, `t`.`position`
|
165
|
+
SQL
|
166
|
+
Anubis::Tenant::GroupMenu.find_by_sql(query).each do |data|
|
167
|
+
self.output.addElement({
|
168
|
+
mode: data.mode,
|
169
|
+
title: data.title,
|
170
|
+
page_title: data.page_title,
|
171
|
+
short_title: data.short_title,
|
172
|
+
position: data.position,
|
173
|
+
tab: data.tab,
|
174
|
+
action: data.action,
|
175
|
+
access: data.access,
|
176
|
+
state: Anubis::Tenant::Menu.states.invert[data.state],
|
177
|
+
parent: data.parent_mode
|
178
|
+
})
|
179
|
+
#self.output[:data].push menu_id[data.id.to_s.to_sym]
|
180
|
+
end
|
181
|
+
|
182
|
+
self.before_menu_output
|
183
|
+
|
184
|
+
respond_to do |format|
|
185
|
+
format.json { render json: around_menu_output(self.output.to_h) }
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_dependency "anubis/tenant/application_controller"
|
2
|
+
require_dependency "anubis/tenant/index/actions"
|
3
|
+
require_dependency "anubis/tenant/index/callbacks"
|
4
|
+
|
5
|
+
module Anubis
|
6
|
+
##
|
7
|
+
# Module presents all tenant functions for Anubis Library
|
8
|
+
module Tenant
|
9
|
+
##
|
10
|
+
# Controller processes main system functions. Authenticates user, checks user access, outputs main menu and etc.
|
11
|
+
class IndexController < Anubis::Tenant::ApplicationController
|
12
|
+
include Anubis::Tenant::Index::Actions
|
13
|
+
include Anubis::Tenant::Index::Callbacks
|
14
|
+
|
15
|
+
##
|
16
|
+
# Check if authentication required
|
17
|
+
def authenticate?
|
18
|
+
if controller_name == 'index'
|
19
|
+
if action_name == 'login'
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return true
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Check if authentication required
|
28
|
+
def check_menu_access?
|
29
|
+
if controller_name == 'index'
|
30
|
+
if action_name == 'login' || action_name == 'menu' || action_name == 'logout'
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
## Main application model record class inherited from {https://api.rubyonrails.org/classes/ActiveRecord/Base.html ActiveRecord::Base}
|
2
|
+
class Anoubis::ApplicationRecord < ActiveRecord::Base
|
3
|
+
self.abstract_class = true
|
4
|
+
|
5
|
+
## Redis database variable
|
6
|
+
attr_accessor :redis
|
7
|
+
|
8
|
+
##
|
9
|
+
# Returns {https://github.com/redis/redis-rb Redis database} class
|
10
|
+
# @return [Class] {https://github.com/redis/redis-rb Redis} class reference
|
11
|
+
def redis
|
12
|
+
@redis ||= Redis.new
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Returns {https://github.com/redis/redis-rb Redis database} class
|
17
|
+
# @return [Class] {https://github.com/redis/redis-rb Redis} class reference
|
18
|
+
def self.redis
|
19
|
+
Redis.new
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Returns {https://github.com/redis/redis-rb Redis} prefix for storing cache data. Prefix can be set in Rails.configuration.anoubis_redis_prefix configuration parameter.
|
24
|
+
# @return [String] {https://github.com/redis/redis-rb Redis} prefix
|
25
|
+
def redis_prefix
|
26
|
+
begin
|
27
|
+
value = Rails.configuration.redis_prefix
|
28
|
+
rescue
|
29
|
+
return ''
|
30
|
+
end
|
31
|
+
return value + ':'
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Returns {https://github.com/redis/redis-rb Redis} prefix for storing cache data. Prefix can be set in Rails.configuration.anoubis_redis_prefix configuration parameter.
|
36
|
+
# @return [String] {https://github.com/redis/redis-rb Redis} prefix
|
37
|
+
def self.redis_prefix
|
38
|
+
begin
|
39
|
+
value = Rails.configuration.redis_prefix
|
40
|
+
rescue
|
41
|
+
return ''
|
42
|
+
end
|
43
|
+
return value + ':'
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,250 @@
|
|
1
|
+
##
|
2
|
+
# Default ApplicationRecord for Anubis::Core library.
|
3
|
+
class Anubis::Core::ApplicationRecord < ActiveRecord::Base
|
4
|
+
self.abstract_class = true
|
5
|
+
|
6
|
+
# @!attribute created_at
|
7
|
+
# @return [DateTime] the date and time when item had been created
|
8
|
+
|
9
|
+
# @!attribute updated_at
|
10
|
+
# @return [DateTime] the date and time when item had been updated
|
11
|
+
|
12
|
+
# @!attribute redis
|
13
|
+
# @return [Object] pointer to Redis database
|
14
|
+
class_attribute :redis
|
15
|
+
|
16
|
+
# @!attribute [rw] current_user
|
17
|
+
# @return [String] definition of current user for this record
|
18
|
+
attr_accessor :current_user
|
19
|
+
|
20
|
+
# @!attribute [rw] need_refresh
|
21
|
+
# @return [Boolean] defines when table representation data should be updated even after simple update
|
22
|
+
class_attribute :need_refresh, default: false
|
23
|
+
|
24
|
+
# @!attribute [r] sys_title
|
25
|
+
attr_reader :sys_title
|
26
|
+
|
27
|
+
# @!attribute [r] can_new
|
28
|
+
attr_reader :can_new
|
29
|
+
|
30
|
+
# @!attribute [r] can_edit
|
31
|
+
attr_reader :can_edit
|
32
|
+
|
33
|
+
# @!attribute [r] can_delete
|
34
|
+
attr_reader :can_delete
|
35
|
+
|
36
|
+
after_initialize :after_initialize_core_anubis_model
|
37
|
+
before_validation :before_validation_core_anubis_model
|
38
|
+
|
39
|
+
public
|
40
|
+
|
41
|
+
##
|
42
|
+
# Is called after initialization Anubis::Core ActiveRecord. Sets default parameters.
|
43
|
+
def after_initialize_core_anubis_model
|
44
|
+
self.need_refresh = false
|
45
|
+
self.redis = Redis.new
|
46
|
+
self.current_user = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Return defined locale according by I18n
|
51
|
+
def current_locale
|
52
|
+
I18n.locale.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Checks if this record may be destroyed.
|
57
|
+
def can_destroy?
|
58
|
+
result = true
|
59
|
+
self.class.reflect_on_all_associations.all? do |assoc|
|
60
|
+
result = self.send(assoc.name).nil? if assoc.macro == :has_one
|
61
|
+
result = self.send(assoc.name).empty? if (assoc.macro == :has_many) && result
|
62
|
+
end
|
63
|
+
result
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Returns the default ActiveRecord 'where' for defined model.
|
68
|
+
# @param object [ApplicationController] pointer to used Application controller
|
69
|
+
# @param pid [Integer] parent model id if present (default: 0). Variable doesn't necessary
|
70
|
+
# @return [Hash] ActiveRecord 'where' definition
|
71
|
+
def self.get_where(object, pid = 0)
|
72
|
+
{ }
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Returns model's system title. Default value is the row ID. For another result procedure should be overridden.
|
77
|
+
# @return [String] model's system title
|
78
|
+
def sys_title
|
79
|
+
self.id
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Returns the ability to create new data. By default all items may be deleted. For another result
|
84
|
+
# procedure should be overridden.
|
85
|
+
# @return [Boolean] true if new data may be created.
|
86
|
+
def can_new(args = {})
|
87
|
+
true
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Returns the ability to edit the data. By default all items may be edited. For another result
|
92
|
+
# procedure should be overridden.
|
93
|
+
# @return [Boolean] true if data may be edited
|
94
|
+
def can_edit(args = {})
|
95
|
+
true
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Returns the ability to delete a data. By default all items may be deleted. For another result
|
100
|
+
# procedure should be overridden.
|
101
|
+
# @return [Boolean] true if data may be deleted
|
102
|
+
def can_delete(args = {})
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Sets current locale and nullifies locale variable that presents model translation data.
|
108
|
+
# @param value [String] new locale value ('ru', 'en', etc)
|
109
|
+
def current_locale=(value)
|
110
|
+
@current_locale = value
|
111
|
+
@model_locale = nil
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
##
|
117
|
+
# Is called before validation model's data. Sets user id of user that modify model's data
|
118
|
+
# (if updated_user_id field presents in database)
|
119
|
+
def before_validation_core_anubis_model
|
120
|
+
begin
|
121
|
+
self.updated_user_id = self.current_user.id if self.current_user
|
122
|
+
rescue
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
protected
|
128
|
+
|
129
|
+
##
|
130
|
+
# Returns text that was converted for russian quotes.
|
131
|
+
# @param str [String] - source text
|
132
|
+
# @return [String] converted text
|
133
|
+
def convert_russian_quotes(str)
|
134
|
+
return str.gsub(/^"/, "«").gsub(/ "/, " «").gsub(/«"/, "««").gsub(/" /, "» ").gsub(/"$/, "»").gsub(/"»/, "»»")
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# @!group Block of UUID functions
|
139
|
+
|
140
|
+
##
|
141
|
+
# Decodes binary UUID data into the UUID string
|
142
|
+
# @param data [Binary] binary representation of UUID
|
143
|
+
# @return [String, nil] string representation of UUID or nil if can't be decoded
|
144
|
+
def bin_to_uuid(data)
|
145
|
+
begin
|
146
|
+
data = data.unpack('H*')[0]
|
147
|
+
return data[0..7]+'-'+data[8..11]+'-'+data[12..15]+'-'+data[16..19]+'-'+data[20..31]
|
148
|
+
rescue
|
149
|
+
return nil
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Encodes string UUID data into the binary UUID
|
155
|
+
# @param data [Binary] string representation of UUID
|
156
|
+
# @return [Binary, nil] binary representation of UUID or nil if can't be encoded
|
157
|
+
def uuid_to_bin(data)
|
158
|
+
begin
|
159
|
+
return [data.delete('-')].pack('H*')
|
160
|
+
rescue
|
161
|
+
return nil
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
public
|
166
|
+
|
167
|
+
##
|
168
|
+
# Generates new UUID data
|
169
|
+
# @return [String] string representation of UUID
|
170
|
+
def new_uuid
|
171
|
+
SecureRandom.uuid
|
172
|
+
end
|
173
|
+
|
174
|
+
# @!endgroup
|
175
|
+
|
176
|
+
##
|
177
|
+
# @!group Block of Redis functions
|
178
|
+
|
179
|
+
##
|
180
|
+
# Returns defined application prefix for redis cache for current record. Default value ''
|
181
|
+
def redis_prefix
|
182
|
+
begin
|
183
|
+
value = Rails.configuration.redis_prefix
|
184
|
+
rescue
|
185
|
+
return ''
|
186
|
+
end
|
187
|
+
return value + ':'
|
188
|
+
end
|
189
|
+
|
190
|
+
##
|
191
|
+
# Returns defined application prefix for redis cache for model. Default value ''
|
192
|
+
def self.redis_prefix
|
193
|
+
begin
|
194
|
+
value = Rails.configuration.redis_prefix
|
195
|
+
rescue
|
196
|
+
return ''
|
197
|
+
end
|
198
|
+
return value + ':'
|
199
|
+
end
|
200
|
+
|
201
|
+
##
|
202
|
+
# Returns reference to Redis database
|
203
|
+
def self.redis
|
204
|
+
Redis.new
|
205
|
+
end
|
206
|
+
|
207
|
+
# @!endgroup
|
208
|
+
|
209
|
+
def get_locale
|
210
|
+
if self.current_locale && self.current_locale != ''
|
211
|
+
return self.current_locale
|
212
|
+
end
|
213
|
+
|
214
|
+
self.default_locale
|
215
|
+
end
|
216
|
+
|
217
|
+
def default_locale
|
218
|
+
Rails.configuration.i18n.default_locale.to_s
|
219
|
+
end
|
220
|
+
|
221
|
+
def get_locale_field(field, used_locale = nil)
|
222
|
+
field = field.to_s.to_sym
|
223
|
+
used_locale = self.current_locale.to_s unless used_locale
|
224
|
+
|
225
|
+
return '' unless self[field]
|
226
|
+
return self[field][used_locale] if self[field].key? used_locale
|
227
|
+
return '' unless self[field].key? self.default_locale.to_s
|
228
|
+
|
229
|
+
self[field][self.default_locale.to_s]
|
230
|
+
end
|
231
|
+
|
232
|
+
def set_locale_field(field, value, used_locale = nil)
|
233
|
+
field = field.to_s.to_sym
|
234
|
+
used_locale = self.current_locale.to_s unless used_locale
|
235
|
+
|
236
|
+
self[field] = {} unless self[field]
|
237
|
+
self[field][self.default_locale.to_s] = value unless self[field].key? self.default_locale.to_s
|
238
|
+
self[field][used_locale] = value
|
239
|
+
end
|
240
|
+
|
241
|
+
def is_field_localized(field, used_locale = nil)
|
242
|
+
field = field.to_s.to_sym
|
243
|
+
used_locale = self.current_locale.to_s unless used_locale
|
244
|
+
|
245
|
+
return false unless self[field]
|
246
|
+
return true if self[field].key? used_locale
|
247
|
+
|
248
|
+
false
|
249
|
+
end
|
250
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
##
|
2
|
+
# Defines all available locales.
|
3
|
+
module Anoubis::Core::Locales
|
4
|
+
# List of all possible locales.
|
5
|
+
LIST = {
|
6
|
+
ru: { id: 1, name: 'Russian' },
|
7
|
+
en: { id: 2, name: 'English' },
|
8
|
+
kz: { id: 3, name: 'Kazakh' }
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
class << self
|
12
|
+
##
|
13
|
+
# Returns the title of chosen locale
|
14
|
+
# @param key [String] identificator of locale ('ru', 'en', etc.)
|
15
|
+
# @return [String] english title of locale
|
16
|
+
def name(key)
|
17
|
+
LIST[key.to_sym][:name]
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Converts list of locales into enum attribute
|
22
|
+
# @return [Symbol] return symbols array for all locales.
|
23
|
+
def enums
|
24
|
+
LIST.reduce({}) { |res, v| res.merge("#{v.first}": v.last[:id]) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Anoubis::Sso::Client::Group < Anoubis::Sso::Client::ApplicationRecord
|
2
|
+
self.table_name = 'groups'
|
3
|
+
|
4
|
+
VALID_IDENT_REGEX = /\A[a-z]*\z/i
|
5
|
+
|
6
|
+
# @!attribute ident
|
7
|
+
# @return [String] the group's identifier. Identifier consists of lowercase alphabetical symbols.
|
8
|
+
validates :ident, length: { minimum: 3, maximum: 50 }, uniqueness: { case_sensitive: false }, format: { with: VALID_IDENT_REGEX }
|
9
|
+
|
10
|
+
validates :title, presence: true, length: { maximum: 100 }
|
11
|
+
|
12
|
+
def title
|
13
|
+
get_locale_field 'title_locale'
|
14
|
+
end
|
15
|
+
|
16
|
+
def title=(value)
|
17
|
+
self.set_locale_field 'title_locale', value
|
18
|
+
end
|
19
|
+
end
|