anoubis 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +38 -0
  5. data/app/controllers/anoubis/application_controller.rb +78 -0
  6. data/app/controllers/anoubis/core/application_controller.rb +343 -0
  7. data/app/controllers/anoubis/core/data/actions.rb +962 -0
  8. data/app/controllers/anoubis/core/data/callbacks.rb +68 -0
  9. data/app/controllers/anoubis/core/data/convert.rb +407 -0
  10. data/app/controllers/anoubis/core/data/defaults.rb +217 -0
  11. data/app/controllers/anoubis/core/data/get.rb +531 -0
  12. data/app/controllers/anoubis/core/data/load.rb +89 -0
  13. data/app/controllers/anoubis/core/data/set.rb +49 -0
  14. data/app/controllers/anoubis/core/data/setup.rb +104 -0
  15. data/app/controllers/anoubis/core/data_controller.rb +28 -0
  16. data/app/controllers/anoubis/core/index/actions.rb +53 -0
  17. data/app/controllers/anoubis/core/index/callbacks.rb +23 -0
  18. data/app/controllers/anoubis/core/index_controller.rb +36 -0
  19. data/app/controllers/anoubis/etc/base.rb +52 -0
  20. data/app/controllers/anoubis/etc/data.rb +89 -0
  21. data/app/controllers/anoubis/etc/field.rb +468 -0
  22. data/app/controllers/anoubis/etc/field_options.rb +83 -0
  23. data/app/controllers/anoubis/etc/field_order.rb +51 -0
  24. data/app/controllers/anoubis/etc/filter.rb +251 -0
  25. data/app/controllers/anoubis/etc/menu.rb +101 -0
  26. data/app/controllers/anoubis/etc/model.rb +67 -0
  27. data/app/controllers/anoubis/etc/tab_item.rb +91 -0
  28. data/app/controllers/anoubis/etc.rb +8 -0
  29. data/app/controllers/anoubis/export.rb +47 -0
  30. data/app/controllers/anoubis/output/autocomplete.rb +30 -0
  31. data/app/controllers/anoubis/output/basic.rb +86 -0
  32. data/app/controllers/anoubis/output/data.rb +101 -0
  33. data/app/controllers/anoubis/output/delete.rb +41 -0
  34. data/app/controllers/anoubis/output/edit.rb +55 -0
  35. data/app/controllers/anoubis/output/frame.rb +227 -0
  36. data/app/controllers/anoubis/output/login.rb +71 -0
  37. data/app/controllers/anoubis/output/menu.rb +220 -0
  38. data/app/controllers/anoubis/output/update.rb +43 -0
  39. data/app/controllers/anoubis/sso/client/application_controller.rb +139 -0
  40. data/app/controllers/anoubis/sso/client/data/actions.rb +5 -0
  41. data/app/controllers/anoubis/sso/client/data/callbacks.rb +5 -0
  42. data/app/controllers/anoubis/sso/client/data/convert.rb +5 -0
  43. data/app/controllers/anoubis/sso/client/data/defaults.rb +5 -0
  44. data/app/controllers/anoubis/sso/client/data/get.rb +5 -0
  45. data/app/controllers/anoubis/sso/client/data/load.rb +26 -0
  46. data/app/controllers/anoubis/sso/client/data/set.rb +5 -0
  47. data/app/controllers/anoubis/sso/client/data/setup.rb +5 -0
  48. data/app/controllers/anoubis/sso/client/data_controller.rb +21 -0
  49. data/app/controllers/anoubis/sso/client/index/actions.rb +79 -0
  50. data/app/controllers/anoubis/sso/client/index/callbacks.rb +13 -0
  51. data/app/controllers/anoubis/sso/client/index_controller.rb +18 -0
  52. data/app/controllers/anoubis/sso/server/application_controller.rb +49 -0
  53. data/app/controllers/anoubis/sso/server/login_controller.rb +342 -0
  54. data/app/controllers/anoubis/sso/server/user_controller.rb +142 -0
  55. data/app/controllers/anoubis/tenant/application_controller.rb +54 -0
  56. data/app/controllers/anoubis/tenant/data/actions.rb +11 -0
  57. data/app/controllers/anoubis/tenant/data/callbacks.rb +11 -0
  58. data/app/controllers/anoubis/tenant/data/convert.rb +11 -0
  59. data/app/controllers/anoubis/tenant/data/defaults.rb +11 -0
  60. data/app/controllers/anoubis/tenant/data/get.rb +11 -0
  61. data/app/controllers/anoubis/tenant/data/load.rb +52 -0
  62. data/app/controllers/anoubis/tenant/data/set.rb +11 -0
  63. data/app/controllers/anoubis/tenant/data/setup.rb +11 -0
  64. data/app/controllers/anoubis/tenant/data_controller.rb +28 -0
  65. data/app/controllers/anoubis/tenant/index/actions.rb +191 -0
  66. data/app/controllers/anoubis/tenant/index/callbacks.rb +11 -0
  67. data/app/controllers/anoubis/tenant/index_controller.rb +38 -0
  68. data/app/controllers/anoubis/tenants_controller.rb +7 -0
  69. data/app/controllers/anoubis/users_controller.rb +7 -0
  70. data/app/jobs/anoubis/application_job.rb +6 -0
  71. data/app/mailers/anoubis/application_mailer.rb +8 -0
  72. data/app/models/anoubis/application_record.rb +45 -0
  73. data/app/models/anoubis/core/application_record.rb +250 -0
  74. data/app/models/anoubis/core/locales.rb +27 -0
  75. data/app/models/anoubis/sso/client/application_record.rb +3 -0
  76. data/app/models/anoubis/sso/client/group.rb +19 -0
  77. data/app/models/anoubis/sso/client/group_menu.rb +109 -0
  78. data/app/models/anoubis/sso/client/menu.rb +145 -0
  79. data/app/models/anoubis/sso/client/user.rb +81 -0
  80. data/app/models/anoubis/sso/client/user_group.rb +32 -0
  81. data/app/models/anoubis/sso/server/system.rb +36 -0
  82. data/app/models/anoubis/sso/server/user.rb +79 -0
  83. data/app/models/anoubis/tenant/application_record.rb +41 -0
  84. data/app/models/anoubis/tenant/group.rb +95 -0
  85. data/app/models/anoubis/tenant/group_locale.rb +19 -0
  86. data/app/models/anoubis/tenant/group_menu.rb +84 -0
  87. data/app/models/anoubis/tenant/menu.rb +156 -0
  88. data/app/models/anoubis/tenant/menu_locale.rb +27 -0
  89. data/app/models/anoubis/tenant/system.rb +127 -0
  90. data/app/models/anoubis/tenant/system_locale.rb +19 -0
  91. data/app/models/anoubis/tenant/system_menu.rb +51 -0
  92. data/app/models/anoubis/tenant/tenant.rb +107 -0
  93. data/app/models/anoubis/tenant/tenant_system.rb +19 -0
  94. data/app/models/anoubis/tenant/user.rb +225 -0
  95. data/app/models/anoubis/tenant/user_group.rb +32 -0
  96. data/app/services/anoubis/core_service.rb +16 -0
  97. data/app/services/anoubis/session_service.rb +17 -0
  98. data/app/validators/presence_in_tenant_validator.rb +20 -0
  99. data/config/initializers/mime_type.rb +1 -0
  100. data/config/locales/en.yml +120 -0
  101. data/config/locales/ru.yml +245 -0
  102. data/config/routes.rb +74 -0
  103. data/db/migrate/20181018085843_create_tenants.rb +13 -0
  104. data/db/migrate/20181018111217_create_systems.rb +10 -0
  105. data/db/migrate/20181018111713_create_tenant_systems.rb +11 -0
  106. data/db/migrate/20181018111925_create_groups.rb +13 -0
  107. data/db/migrate/20181018112151_create_users.rb +25 -0
  108. data/db/migrate/20181018115737_add_title_to_users.rb +10 -0
  109. data/db/migrate/20181022060211_create_menus.rb +18 -0
  110. data/db/migrate/20181115055245_create_group_menus.rb +12 -0
  111. data/db/migrate/20181115060830_create_system_menus.rb +11 -0
  112. data/db/migrate/20181122062131_create_user_groups.rb +11 -0
  113. data/db/migrate/20181221060727_create_menu_locales.rb +14 -0
  114. data/db/migrate/20181225062303_create_system_locales.rb +11 -0
  115. data/db/migrate/20181225062339_create_group_locales.rb +11 -0
  116. data/db/seeds.rb +268 -0
  117. data/lib/anoubis/engine.rb +13 -0
  118. data/lib/anoubis/version.rb +5 -0
  119. data/lib/anoubis.rb +213 -0
  120. data/lib/tasks/anubis_tasks.rake +10 -0
  121. data/lib/tasks/sessions/clear_sessions.rake +10 -0
  122. data/spec/anubis_spec.rb +5 -0
  123. data/spec/controllers/anoubis/index_controller_spec.rb +77 -0
  124. data/spec/dummy/Rakefile +3 -0
  125. data/spec/dummy/app/assets/config/manifest.js +2 -0
  126. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  127. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  128. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  129. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  130. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  131. data/spec/dummy/app/jobs/application_job.rb +2 -0
  132. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  133. data/spec/dummy/app/models/application_record.rb +3 -0
  134. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  135. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  136. data/spec/dummy/bin/bundle +3 -0
  137. data/spec/dummy/bin/rails +4 -0
  138. data/spec/dummy/bin/rake +4 -0
  139. data/spec/dummy/bin/setup +33 -0
  140. data/spec/dummy/bin/update +28 -0
  141. data/spec/dummy/config/application.rb +14 -0
  142. data/spec/dummy/config/boot.rb +5 -0
  143. data/spec/dummy/config/cable.yml +10 -0
  144. data/spec/dummy/config/database.yml +54 -0
  145. data/spec/dummy/config/environment.rb +5 -0
  146. data/spec/dummy/config/environments/development.rb +54 -0
  147. data/spec/dummy/config/environments/production.rb +85 -0
  148. data/spec/dummy/config/environments/test.rb +46 -0
  149. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  150. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  151. data/spec/dummy/config/initializers/cors.rb +16 -0
  152. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  153. data/spec/dummy/config/initializers/inflections.rb +16 -0
  154. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  155. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  156. data/spec/dummy/config/locales/en.yml +33 -0
  157. data/spec/dummy/config/puma.rb +34 -0
  158. data/spec/dummy/config/routes.rb +3 -0
  159. data/spec/dummy/config/spring.rb +6 -0
  160. data/spec/dummy/config/storage.yml +34 -0
  161. data/spec/dummy/config.ru +5 -0
  162. data/spec/dummy/db/schema.rb +167 -0
  163. data/spec/dummy/db/seeds.rb +1 -0
  164. data/spec/factories/anubis_group_locales.rb +7 -0
  165. data/spec/factories/anubis_group_menus.rb +7 -0
  166. data/spec/factories/anubis_groups.rb +6 -0
  167. data/spec/factories/anubis_menu_locales.rb +9 -0
  168. data/spec/factories/anubis_menus.rb +6 -0
  169. data/spec/factories/anubis_system_locales.rb +7 -0
  170. data/spec/factories/anubis_system_menus.rb +6 -0
  171. data/spec/factories/anubis_systems.rb +5 -0
  172. data/spec/factories/anubis_tenants.rb +7 -0
  173. data/spec/factories/anubis_users.rb +10 -0
  174. data/spec/integration/navigation_test.rb +7 -0
  175. data/spec/models/anoubis/group_locale_spec.rb +25 -0
  176. data/spec/models/anoubis/group_menu_spec.rb +50 -0
  177. data/spec/models/anoubis/group_spec.rb +52 -0
  178. data/spec/models/anoubis/menu_locale_spec.rb +31 -0
  179. data/spec/models/anoubis/menu_spec.rb +48 -0
  180. data/spec/models/anoubis/system_locale_spec.rb +20 -0
  181. data/spec/models/anoubis/system_menu_spec.rb +49 -0
  182. data/spec/models/anoubis/system_spec.rb +53 -0
  183. data/spec/models/anoubis/tenant_spec.rb +67 -0
  184. data/spec/models/anoubis/user_spec.rb +57 -0
  185. data/spec/rails_helper.rb +32 -0
  186. data/spec/requests/anoubis/users_request_spec.rb +5 -0
  187. data/spec/spec_helper.rb +13 -0
  188. metadata +408 -0
data/config/routes.rb ADDED
@@ -0,0 +1,74 @@
1
+ Anoubis::Engine.routes.draw do
2
+ Rails.application.routes.draw do
3
+ begin
4
+ lib_type = Rails.configuration.anubis_type
5
+ rescue
6
+ lib_type = 'tenant'
7
+ end
8
+
9
+
10
+ if lib_type == 'tenant'
11
+ match 'api/:version/*path', { controller: 'anubis/tenant/index', action: 'options', constraints: { method: 'OPTIONS' }, via: [:options] }
12
+
13
+ post 'api/:version/login', to: 'anubis/tenant/index#login', :defaults => { :format => 'json' }
14
+ post 'api/:version/validate', to: 'anubis/tenant/index#validate', :defaults => { :format => 'json' }
15
+ post 'api/:version/recover', to: 'anubis/tenant/index#recover', :defaults => { :format => 'json' }
16
+ post 'api/:version/logout', to: 'anubis/tenant/index#logout', :defaults => { :format => 'json' }
17
+ get 'api/:version/menu', to: 'anubis/tenant/index#menu', :defaults => { :format => 'json' }
18
+
19
+ scope path: 'api', :defaults => { :format => 'json' } do
20
+ scope path: ':version' do
21
+ namespace :anubis do
22
+ get 'users', to: 'structure#index', as: 'structure_list'
23
+ get 'users/frame', to: 'structure#frame', as: 'structure_frame'
24
+
25
+ resources :tenants do
26
+ collection do
27
+ get :frame
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ if lib_type == 'sso-server'
36
+ scope path: 'api', defaults: { format: 'json' } do
37
+ scope path: ':version' do
38
+ match '*path', { controller: 'anubis/sso/server/login', action: 'options', constraints: { method: 'OPTIONS' }, via: [:options] }
39
+
40
+ get 'login', to: 'anubis/sso/server/login#index'
41
+ post 'login', to: 'anubis/sso/server/login#create'
42
+ get 'login/:session', to: 'anubis/sso/server/login#show'
43
+ put 'login/:session', to: 'anubis/sso/server/login#update'
44
+ delete 'login/:session', to: 'anubis/sso/server/login#destroy'
45
+
46
+ get 'user/current', to: 'anubis/sso/server/user#show_current'
47
+ get 'user/:uuid', to: 'anubis/sso/server/user#show'
48
+ put 'user/current', to: 'anubis/sso/server/user#update_current'
49
+ put 'user/:uuid', to: 'anubis/sso/server/user#update'
50
+ end
51
+ end
52
+ end
53
+
54
+ if lib_type == 'sso-client'
55
+ scope path: 'api', defaults: { format: 'json' } do
56
+ scope path: ':version' do
57
+ match '*path', { controller: 'anubis/sso/server/login', action: 'options', constraints: { method: 'OPTIONS' }, via: [:options] }
58
+
59
+ get 'menu', to: 'anubis/sso/client/index#menu'
60
+ post 'logout', to: 'anubis/sso/client/index#logout'
61
+ #get 'login', to: 'anubis/sso/server/login#index'
62
+ #post 'login', to: 'anubis/sso/server/login#create'
63
+ #put 'login/:session', to: 'anubis/sso/server/login#update'
64
+ #delete 'login/:session', to: 'anubis/sso/server/login#destroy'
65
+
66
+ #get 'user/current', to: 'anubis/sso/server/user#show_current'
67
+ #get 'user/:uuid', to: 'anubis/sso/server/user#show'
68
+ #put 'user/current', to: 'anubis/sso/server/user#update_current'
69
+ #put 'user/:uuid', to: 'anubis/sso/server/user#update'
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,13 @@
1
+ class CreateTenants < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :tenants do |t|
4
+ t.string :title, limit: 100
5
+ t.string :ident, limit: 10
6
+ t.integer :state, default: 0
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :tenants, [:title], unique: true
11
+ add_index :tenants, [:ident], unique: true
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSystems < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :systems do |t|
4
+ t.string :ident, limit: 15
5
+
6
+ t.timestamps
7
+ end
8
+ add_index :systems, [:ident], unique: true
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class CreateTenantSystems < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :tenant_systems do |t|
4
+ t.references :tenant, foreign_key: true
5
+ t.references :system, foreign_key: true
6
+
7
+ t.timestamps
8
+ end
9
+ add_index :tenant_systems, [:tenant_id, :system_id], unique: true
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class CreateGroups < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :groups do |t|
4
+ t.string :ident, limit: 50
5
+ t.references :system, foreign_key: true, index: true
6
+ t.string :full_ident, limit: 70
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :groups, [:ident, :system_id], unique: true
11
+ add_index :groups, [:full_ident], unique: true
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ class CreateUsers < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :login, limit: 65, null: false
5
+ t.string :email, limit: 50, null: false
6
+ t.string :name, limit: 100, null: false
7
+ t.string :surname, limit: 100, null: false
8
+ t.string :timezone, limit: 30, null: false
9
+ t.string :locale, limit: 10, null: false, default: 'ru-RU'
10
+ t.integer :timeout, null: false, default: 3600
11
+ t.string :phone, limit: 30
12
+ t.string :password_digest, limit: 60, null: false
13
+ t.string :auth_key, limit: 32
14
+ t.string :recover_key, limit: 32
15
+ t.integer :status, null: false, default: 0
16
+ t.references :tenant, index: true, foreign_key: true
17
+ t.binary :uuid_bin, limit: 16
18
+
19
+ t.timestamps
20
+ end
21
+ add_index :users, [:login], unique: true
22
+ add_index :users, [:email, :tenant_id], unique: true
23
+ add_index :users, [:uuid_bin], unique: true
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ class AddTitleToUsers < ActiveRecord::Migration[6.0]
2
+ def up
3
+ execute "ALTER TABLE users ADD title VARCHAR(250) AS (CONCAT(name, ' ', surname, ' (', email, ')'));"
4
+ execute "ALTER TABLE users ADD fi VARCHAR(250) AS (CONCAT(name, ' ', surname));"
5
+ end
6
+ def down
7
+ execute "ALTER TABLE users DROP fi;"
8
+ execute "ALTER TABLE users DROP title;"
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ class CreateMenus < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :menus do |t|
4
+ t.string :mode, limit: 200
5
+ t.string :action, limit: 50
6
+ t.references :menu, index: true, foreign_key: true
7
+ t.integer :tab, null: false, default: 0
8
+ t.integer :position, null: false, default: 0
9
+ t.integer :page_size, null: false, default: 0
10
+ t.integer :state, null: false, default: 0
11
+ t.integer :status, null: false, default: 0
12
+
13
+ t.timestamps
14
+ end
15
+ add_index :menus, [:mode], unique: true
16
+ add_index :menus, :tab
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ class CreateGroupMenus < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :group_menus do |t|
4
+ t.references :menu, index: true, foreign_key: true, default: 0
5
+ t.references :group, index: true, foreign_key: true, default: 0
6
+ t.integer :access
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :group_menus, [:menu_id, :group_id], unique: true
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSystemMenus < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :system_menus do |t|
4
+ t.references :system, foreign_key: true
5
+ t.references :menu, foreign_key: true
6
+
7
+ t.timestamps
8
+ end
9
+ add_index :system_menus, [:system_id, :menu_id], unique: true
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class CreateUserGroups < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :user_groups do |t|
4
+ t.references :user, foreign_key: true
5
+ t.references :group, foreign_key: true
6
+
7
+ t.timestamps
8
+ end
9
+ add_index :user_groups, [:user_id, :group_id], unique: true
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ class CreateMenuLocales < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :menu_locales do |t|
4
+ t.references :menu, foreign_key: true
5
+ t.integer :locale, null: false, default: 0
6
+ t.string :title, limit: 200
7
+ t.string :page_title, limit: 200
8
+ t.string :short_title, limit: 200
9
+
10
+ t.timestamps
11
+ end
12
+ add_index :menu_locales, [:menu_id, :locale], unique: true
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSystemLocales < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :system_locales do |t|
4
+ t.references :system, foreign_key: true
5
+ t.string :title, limit: 100
6
+ t.integer :locale
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class CreateGroupLocales < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :group_locales do |t|
4
+ t.references :group, foreign_key: true
5
+ t.string :title, limit: 100
6
+ t.integer :locale
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,268 @@
1
+ ##
2
+ # Additional procedures
3
+
4
+ def create_tenant(params = {})
5
+ return nil if !params.has_key? :ident
6
+ return nil if !params.has_key? :title
7
+
8
+ tenant = Anubis::Tenant::Tenant.find_or_create_by ident: params[:ident]
9
+ tenant.title = params[:title]
10
+ if params.has_key? :default
11
+ if params[:default]
12
+ tenant.state = Anubis::Tenant::Tenant.states[:default]
13
+ end
14
+ end
15
+ tenant.save
16
+
17
+ Anubis::Tenant::TenantSystem.find_or_create_by tenant: tenant, system_id: 1
18
+
19
+ return tenant
20
+ end
21
+
22
+ ##
23
+ # Create multi languages menu element
24
+ def create_menu(params = {})
25
+ return nil if !params.key? :mode
26
+ return nil if !params.key? :action
27
+
28
+ params[:access] = 'read' if !params.key? :access
29
+ params[:state] = 'visible' if !params.key? :state
30
+
31
+ prefix = 'install.menu.'+params[:mode].to_s
32
+
33
+ if get_anubis_type == 'tenant'
34
+ data = Anubis::Tenant::Menu.find_or_create_by(mode: params[:mode]) do |menu|
35
+ menu.action = params[:action]
36
+ menu.menu = params[:parent] if params.key? :parent
37
+ menu.page_size = params[:page_size] if params.key? :page_size
38
+ menu.state = params[:state]
39
+ end
40
+
41
+ I18n.available_locales.each do |locale|
42
+ I18n.locale = locale
43
+ Anubis::Tenant::MenuLocale.find_or_create_by(menu_id: data.id, locale: Anubis::Tenant::MenuLocale.locales[locale.to_s.to_sym]) do |menu_locale|
44
+ menu_locale.title = I18n.t(prefix+'.title')
45
+ menu_locale.page_title = I18n.t(prefix+'.page_title')
46
+ menu_locale.short_title = I18n.t(prefix+'.short_title', default: [(prefix+'.title').to_sym])
47
+ end
48
+ end
49
+
50
+ if params.has_key?(:group) && params.has_key?(:system)
51
+ if params[:system].is_a? Array
52
+ params[:system].each do |system|
53
+ Anubis::Tenant::SystemMenu.find_or_create_by system: system, menu: data
54
+ end
55
+ else
56
+ Anubis::Tenant::SystemMenu.find_or_create_by system: params[:system], menu: data
57
+ end
58
+
59
+ if params[:group].is_a? Array
60
+ params[:group].each do |group|
61
+ add_access_menu group: group, menu: data, access: params[:access]
62
+ end
63
+ else
64
+ add_access_menu group: params[:group], menu: data, access: params[:access]
65
+ end
66
+ end
67
+ end
68
+
69
+ if get_anubis_type == 'sso-client'
70
+ data = Anubis::Sso::Client::Menu.find_or_create_by(mode: params[:mode])
71
+
72
+ #puts data.to_json
73
+
74
+ if data
75
+ data.action = params[:action]
76
+ if params.key? :parent
77
+ data.menu = params[:parent]
78
+ else
79
+ data.menu_id = nil
80
+ end
81
+ if params.key? :page_size
82
+ data.page_size = params[:page_size]
83
+ else
84
+ data.page_size = 0
85
+ end
86
+ data.state = params[:state]
87
+
88
+ I18n.available_locales.each do |locale|
89
+ I18n.locale = locale
90
+ data.title = I18n.t(prefix + '.title')
91
+ data.page_title = I18n.t(prefix + '.page_title')
92
+ data.short_title = I18n.t(prefix + '.short_title', default: [(prefix + '.title').to_sym])
93
+ end
94
+
95
+ data.save
96
+ puts data.errors.full_messages
97
+
98
+
99
+ if params.has_key?(:group)
100
+ if params[:group].is_a? Array
101
+ params[:group].each do |group|
102
+ add_access_menu group: group, menu: data, access: params[:access]
103
+ end
104
+ else
105
+ add_access_menu group: params[:group], menu: data, access: params[:access]
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ return data
112
+ end
113
+
114
+ ##
115
+ # Create multi languages system
116
+ def create_system(params = {})
117
+ return nil if !params.has_key? :ident
118
+ return nil if !params.has_key? :translate
119
+
120
+ system = Anubis::Tenant::System.find_or_create_by ident: params[:ident]
121
+ if system
122
+ I18n.available_locales.each do |locale|
123
+ I18n.locale = locale
124
+ Anubis::Tenant::SystemLocale.find_or_create_by(system: system, locale: Anubis::Tenant::SystemLocale.locales[locale.to_s.to_sym]) do |system_locale|
125
+ system_locale.title = I18n.t(params[:translate])
126
+ end
127
+ end
128
+ end
129
+
130
+ if params.has_key? :tenant
131
+ if params[:tenant].is_a? Array
132
+ params[:tenant].each do |tenant|
133
+ Anubis::Tenant::TenantSystem.find_or_create_by tenant: tenant, system: system
134
+ end
135
+ else
136
+ Anubis::Tenant::TenantSystem.find_or_create_by tenant: params[:tenant], system: system
137
+ end
138
+ end
139
+
140
+ return system
141
+ end
142
+
143
+ ##
144
+ # Create multi languages group
145
+ def create_group(params = {})
146
+ return nil if !params.has_key? :ident
147
+ return nil if !params.has_key? :translate
148
+
149
+ if get_anubis_type == 'tenant'
150
+ return nil if !params.has_key? :system
151
+
152
+ group = Anubis::Tenant::Group.find_or_create_by ident: params[:ident], system: params[:system]
153
+ if group
154
+ I18n.available_locales.each do |locale|
155
+ I18n.locale = locale
156
+ Anubis::Tenant::GroupLocale.find_or_create_by(group: group, locale: Anubis::Tenant::GroupLocale.locales[locale.to_s.to_sym]) do |group_locale|
157
+ group_locale.title = I18n.t(params[:translate])
158
+ end
159
+ end
160
+ end
161
+
162
+ if params.has_key? :user
163
+ if params[:user].is_a? Array
164
+ params[:user].each do |user|
165
+ Anubis::Tenant::UserGroup.find_or_create_by group: group, user: user
166
+ end
167
+ else
168
+ Anubis::Tenant::UserGroup.find_or_create_by group: group, user: params[:user]
169
+ end
170
+ end
171
+ end
172
+
173
+ if get_anubis_type == 'sso-client'
174
+ group = Anubis::Sso::Client::Group.find_or_create_by ident: params[:ident]
175
+
176
+ if group
177
+ I18n.available_locales.each do |locale|
178
+ I18n.locale = locale
179
+ group.title = I18n.t(params[:translate])
180
+ end
181
+ group.save
182
+ end
183
+ end
184
+
185
+ return group
186
+ end
187
+
188
+ def add_access_menu(params = {})
189
+ return if !params.has_key? :group
190
+ return if !params.has_key? :menu
191
+
192
+ params[:access] = 'read' if !params.has_key? :access
193
+
194
+ if %w[tenant sso-client].include? get_anubis_type
195
+ group_menu_model = Anubis::Tenant::GroupMenu if get_anubis_type == 'tenant'
196
+ group_menu_model = Anubis::Sso::Client::GroupMenu if get_anubis_type == 'sso-client'
197
+
198
+ if params[:group].class == Array
199
+ params[:group].each do |group|
200
+ data = group_menu_model.find_or_create_by group: group, menu: params[:menu]
201
+ if group_menu_model.accesses[params[:access].to_sym] > group_menu_model.accesses[data.access.to_sym]
202
+ data.access = params[:access]
203
+ data.save
204
+ end
205
+ end
206
+ else
207
+ data = group_menu_model.find_or_create_by group: params[:group], menu: params[:menu]
208
+ if group_menu_model.accesses[params[:access].to_sym] > group_menu_model.accesses[data.access.to_sym]
209
+ data.access = params[:access]
210
+ data.save
211
+ end
212
+ end
213
+ end
214
+ end
215
+
216
+ def get_anubis_type
217
+ begin
218
+ type = Rails.configuration.anubis_type
219
+ rescue
220
+ type = 'tenant'
221
+ end
222
+
223
+ type
224
+ end
225
+
226
+
227
+ if get_anubis_type == 'tenant'
228
+ ##
229
+ # Create default system with id 1
230
+ system = Anubis::Tenant::System.find_by_id(1)
231
+ if !system
232
+ system = Anubis::Tenant::System.create(id: 1)
233
+ end
234
+ I18n.available_locales.each do |locale|
235
+ I18n.locale = locale
236
+ Anubis::Tenant::SystemLocale.find_or_create_by(system_id: system.id, locale: Anubis::Tenant::SystemLocale.locales[locale.to_s.to_sym]) do |system_locale|
237
+ system_locale.title = I18n.t('anubis.install.system_title')
238
+ end
239
+ end
240
+
241
+ ##
242
+ # Create default tenant with id 1
243
+ tenant = Anubis::Tenant::Tenant.find_by_id(1)
244
+ tenant = Anubis::Tenant::Tenant.create(id: 1, title: I18n.t('anubis.install.tenant_title'), state: Anubis::Tenant::Tenant.states[:default]) if !tenant
245
+
246
+ Anubis::Tenant::TenantSystem.find_or_create_by tenant: tenant, system: system
247
+
248
+ ##
249
+ # Load Administrator group of Main System
250
+ admin_group = Anubis::Tenant::Group.where(system: system, ident: 'admin').first
251
+ I18n.available_locales.each do |locale|
252
+ I18n.locale = locale
253
+ Anubis::Tenant::GroupLocale.find_or_create_by(group_id: admin_group.id, locale: Anubis::Tenant::GroupLocale.locales[locale.to_s.to_sym]) do |group_locale|
254
+ group_locale.title = I18n.t('anubis.install.admins_group')
255
+ end
256
+ end
257
+
258
+ ##
259
+ # Create main administrator with id 1
260
+ admin_user = Anubis::Tenant::User.find_by_id(1)
261
+ admin_user = Anubis::Tenant::User.create(id: 1, email: 'admin@local.local', name: I18n.t('anubis.install.admin_name'), surname: I18n.t('anubis.install.admin_surname'), timezone: 'GMT', status: 0, tenant: tenant) if !admin_user
262
+
263
+ Anubis::Tenant::UserGroup.find_or_create_by(user_id: admin_user.id, group_id: admin_group.id)
264
+
265
+ menu_0 = create_menu({ mode: 'anubis/admin', action: 'menu' })
266
+ menu_1 = create_menu({ mode: 'anubis/tenants', action: 'data', parent: menu_0, system: system, group: admin_group, access: 'write' })
267
+ menu_1 = create_menu({ mode: 'anubis/users', action: 'data', parent: menu_0, system: system, group: admin_group, access: 'write' })
268
+ end
@@ -0,0 +1,13 @@
1
+ module Anoubis
2
+ ##
3
+ # Main Anoubis Engine class
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Anoubis
6
+ config.generators.api_only = true
7
+
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ g.fixture_replacement :factory_bot, :dir => 'spec/factories'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Anoubis
2
+ ##
3
+ # Anoubis current version
4
+ VERSION = '1.0.0'
5
+ end