anoubis 1.0.0

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.
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
@@ -0,0 +1,101 @@
1
+ module Anubis
2
+ module Output
3
+ ##
4
+ # Output subclass that represents data for default index action
5
+ class Data < Basic
6
+ ##
7
+ # Output subclass that represents data for default index action
8
+
9
+ # @!attribute [rw] count
10
+ # @return [String] the model's row count
11
+ class_attribute :count
12
+
13
+ # @!attribute [rw] offset
14
+ # @return [Integer] output offset for rows were returned
15
+ class_attribute :offset
16
+
17
+ # @!attribute [rw] limit
18
+ # @return [Integer] output limit fro returns rows
19
+ class_attribute :limit
20
+
21
+ # @!attribute [rw] data
22
+ # @return [Array] array of output data
23
+ class_attribute :data
24
+
25
+ # @!attribute [rw] fields
26
+ # @return [Array] array of output fields
27
+ class_attribute :fields
28
+
29
+ # @!attribute [rw] filter
30
+ # @return [Array] array of filter fields
31
+ class_attribute :filter
32
+
33
+ # @!attribute [rw]
34
+ # @return [String] order filed name
35
+ # Returns order field for current output data.
36
+ class_attribute :sort
37
+
38
+ # @!attribute [rw]
39
+ # @return [String] order filed type
40
+ # Returns order type current output data ('asc' or 'desc').
41
+ class_attribute :order
42
+
43
+ # @!attribute [rw]
44
+ # @return [String] field name for manual order table or nil if table can't be sorted
45
+ # Returns name for manual table order
46
+ class_attribute :sortable
47
+
48
+ ##
49
+ # Initializes output data. Generates default values.
50
+ def initialize
51
+ super
52
+ self.data = nil
53
+ self.fields = nil
54
+ self.filter = nil
55
+ self.count = 0
56
+ self.offset = 0
57
+ self.limit = 20
58
+ self.sort = nil
59
+ self.order = ''
60
+ self.sortable = nil
61
+ end
62
+
63
+ ##
64
+ # Generates hash representation of output class
65
+ # @return [Hash] hash representation of all data
66
+ def to_h
67
+ result = super.to_h
68
+ return result if self.result != 0
69
+ result.merge!({
70
+ count: self.count,
71
+ offset: self.offset,
72
+ limit: self.limit
73
+ })
74
+ if self.sort
75
+ result[:sort] = self.sort
76
+ result[:order] = self.order
77
+ end
78
+
79
+ result.merge!({ fields: self.fields}) if self.fields
80
+ result.merge!({ filter: self.filter}) if self.filter
81
+ result.merge!({ data: self.data}) if self.data
82
+ result[:sortable] = self.sortable if self.sortable
83
+ result
84
+ end
85
+
86
+ ##
87
+ # Generates output message based on {#result self.result} variable.
88
+ # @return [String] output message
89
+ def message1
90
+ case self.result
91
+ when -1
92
+ return I18n.t('errors.invalid_login_parameters')
93
+ when -2
94
+ return I18n.t('errors.invalid_login_or_password')
95
+ else
96
+ return super
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,41 @@
1
+ module Anubis
2
+ module Output
3
+ ##
4
+ # Output subclass that represents data for destroy action
5
+ class Delete < Basic
6
+ # @!attribute [rw]
7
+ # @return [Array<String>] hash of errors
8
+ class_attribute :errors, default: []
9
+
10
+ # @!attribute [rw]
11
+ # @return [Number] deleted id
12
+ class_attribute :id, default: nil
13
+
14
+ ##
15
+ # Initializes menu output data. Generates default values.
16
+ def initialize
17
+ super
18
+ self.id = nil
19
+ self.errors = []
20
+ end
21
+
22
+ ##
23
+ # Generates hash representation of output class
24
+ # @return [Hash] hash representation of all data
25
+ def to_h
26
+ result = super.to_h
27
+ result[:id] = self.id if self.id
28
+ result[:errors] = self.errors if self.errors.length > 0
29
+ result
30
+ end
31
+
32
+ ##
33
+ # Returns customized message if {#result} code equal -4. Another way returns standard message
34
+ # @return [String] customized message
35
+ def message
36
+ return I18n.t('errors.delete_error') if self.result == -4
37
+ return super
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,55 @@
1
+ module Anubis
2
+ module Output
3
+ ##
4
+ # Output subclass that represents data for edit(new) action
5
+ class Edit < Basic
6
+ # @!attribute [rw]
7
+ # @return [String] the title of edit data
8
+ class_attribute :title
9
+
10
+ # @!attribute [rw] fields
11
+ # @return [Array] array of output fields
12
+ class_attribute :fields
13
+
14
+ # @!attribute [rw]
15
+ # @return [Hash] the hash of defined fields.
16
+ class_attribute :values, default: {}
17
+
18
+ # @!attribute [rw]
19
+ # @return [Hash] the hash of additional field options.
20
+ class_attribute :options, default: {}
21
+
22
+ # @!attribute [rw]
23
+ # @return [String] additional action after update
24
+ class_attribute :action
25
+
26
+
27
+ ##
28
+ # Initializes menu output data. Generates default values.
29
+ def initialize
30
+ super
31
+ self.title = ''
32
+ self.fields = nil
33
+ self.values = {}
34
+ self.options = {}
35
+ self.action = ''
36
+ end
37
+
38
+ ##
39
+ # Generates hash representation of output class
40
+ # @return [Hash] hash representation of all data
41
+ def to_h
42
+ result = super.to_h
43
+ return result if self.result != 0
44
+ result[:title] = self.title if self.title != ''
45
+ result[:fields] = self.fields if self.fields
46
+ result[:action] = self.action if self.action != ''
47
+ result.merge!({
48
+ values: self.values,
49
+ options: self.options_to_json(self.options)
50
+ })
51
+ result
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,227 @@
1
+ module Anubis
2
+ module Output
3
+ ##
4
+ # Output subclass that represents data for frame action
5
+ class Frame < Basic
6
+ # @!attribute [rw] short
7
+ # @return [string] the short title of current loaded frame.
8
+ class_attribute :short
9
+
10
+ # @!attribute [rw] mode
11
+ # @return [string] the identificator for current frame.
12
+ class_attribute :mode
13
+
14
+ # @!attribute [rw] access
15
+ # @return [String] the access to the menu element for current user ('read', 'write').
16
+ class_attribute :access
17
+
18
+ # @!attribute [rw] tab_items
19
+ # @return [Array] the array of tab elements {Anubis::Output::TabItem}.
20
+ class_attribute :tab_items
21
+
22
+ # @!attribute [rw] tabs
23
+ # @return [Hash] the hash of menu elements {Anubis::Output::TabItem} with 'mode' as a key.
24
+ class_attribute :tabs
25
+
26
+ ##
27
+ # Initializes menu output data. Generates default values.
28
+ def initialize
29
+ super
30
+ self.title = ''
31
+ self.short = ''
32
+ self.mode = ''
33
+ self.access = 'read'
34
+ self.tab_items = []
35
+ self.tabs = {}
36
+ end
37
+
38
+ ##
39
+ # Adds new tab into tabs hash
40
+ # @param [Hash] options the tab element options
41
+ # @option options [String] :key The identifier of the tab element.
42
+ # @option options [String] :title The title of the tab element.
43
+ # @option options [String] :hint The hint for the tab element.
44
+ def addTab(options)
45
+ tab = TabItem.new options
46
+ self.tab_items.push tab
47
+ self.tabs[tab.tab.to_s.to_sym] = self.tab_items[self.tab_items.count-1]
48
+ end
49
+
50
+ ##
51
+ # Generates hash representation of output class
52
+ # @return [Hash] hash representation of all data
53
+ def to_h
54
+ result = super.to_h
55
+ return result if self.result != 0
56
+ result[:short] = self.short
57
+ result[:mode] = self.mode
58
+ result[:access] = self.access
59
+ result[:tabs] = []
60
+ self.tab_items.each { |item|
61
+ result[:tabs].push(item.to_h) if item
62
+ }
63
+ result
64
+ end
65
+ end
66
+
67
+ ##
68
+ # Subclass of tab element.
69
+ class TabItem
70
+ # @!attribute [rw] tab
71
+ # @return [string] the tab identificator.
72
+ class_attribute :tab
73
+
74
+ # @!attribute [rw] title
75
+ # @return [string] the tab title.
76
+ class_attribute :title
77
+
78
+ # @!attribute [rw] hint
79
+ # @return [string] the tab hint (value may not be present).
80
+ class_attribute :hint
81
+
82
+ # @!attribute [rw] button_items
83
+ # @return [Array] the array of tab elements {Anubis::Output::FrameButtonItem}.
84
+ class_attribute :button_items
85
+
86
+ # @!attribute [rw] buttons
87
+ # @return [Hash] the hash of menu elements {Anubis::Output::FrameButtonItem} with 'key' as a key.
88
+ class_attribute :buttons
89
+
90
+ # @!attribute [rw] filter
91
+ # @return [Boolean] sets into true when tab has filter button
92
+ class_attribute :filter
93
+
94
+ # @!attribute [rw] export
95
+ # @return [Boolean] sets into true when tab has export button
96
+ class_attribute :export
97
+
98
+ ##
99
+ # Initializes tab element data. Generates default values.
100
+ def initialize(options = {})
101
+ if options.has_key? :tab
102
+ self.tab = options[:tab].to_s
103
+ else
104
+ self.tab = ''
105
+ end
106
+
107
+ if options.has_key? :title
108
+ self.title = options[:title]
109
+ else
110
+ self.title = ''
111
+ end
112
+
113
+ if options.has_key? :hint
114
+ self.hint = options[:hint]
115
+ else
116
+ self.hint = ''
117
+ end
118
+
119
+ if options.has_key? :filter
120
+ self.filter = options[:filter]
121
+ else
122
+ self.filter = true
123
+ end
124
+
125
+ if options.has_key? :export
126
+ self.export = options[:export]
127
+ else
128
+ self.export = true
129
+ end
130
+
131
+ self.button_items = []
132
+ self.buttons = {}
133
+
134
+ if options.has_key? :buttons
135
+ options[:buttons].each do |key, button|
136
+ button[:key] = key.to_s
137
+ self.addButton(button)
138
+ end
139
+ end
140
+ end
141
+
142
+ ##
143
+ # Adds new button into frame buttons hash hash
144
+ # @param [Hash] options the button element options
145
+ # @option options [String] :key The identifier of the button element.
146
+ # @option options [String] :type The type of the button ('primary', 'danger', 'default')
147
+ # @option options [String] :mode The button action object ('single', 'multiple')
148
+ def addButton(options)
149
+ button = FrameButtonItem.new options
150
+ self.button_items.push button
151
+ self.buttons[button.key.to_s.to_sym] = self.button_items[self.button_items.count-1]
152
+ end
153
+
154
+ ##
155
+ # Generates hash representation of output class
156
+ # @return [Hash] hash representation of all data
157
+ def to_h
158
+ result = {
159
+ tab: self.tab,
160
+ title: self.title,
161
+ buttons: [],
162
+ filter: self.filter,
163
+ export: self.export
164
+ }
165
+ result[:hint] = self.hint if self.hint != ''
166
+ self.button_items.each { |item|
167
+ result[:buttons].push(item.to_h) if item
168
+ }
169
+ result
170
+ end
171
+ end
172
+
173
+ ##
174
+ # Subclass of frame button element.
175
+ class FrameButtonItem
176
+ # @!attribute [rw] key
177
+ # @return [string] the button identificator.
178
+ class_attribute :key
179
+
180
+ # @!attribute [rw] title
181
+ # @return [string] the button title.
182
+ class_attribute :title
183
+
184
+ # @!attribute [rw] hint
185
+ # @return [string] the button hint.
186
+ class_attribute :hint
187
+
188
+ # @!attribute [rw] mode
189
+ # @return [string] the button action object ('single', 'multiple')
190
+ class_attribute :mode, default: 'single'
191
+
192
+ # @!attribute [rw] type
193
+ # @return [string] the type of the button ('primary', 'danger', 'default')
194
+ class_attribute :type, default: 'default'
195
+
196
+ # @!attribute [rw] decorate
197
+ # @return [string] button decoration ('none', 'space')
198
+ class_attribute :decoration, default: 'none'
199
+
200
+ ##
201
+ # Initializes button element data. Generates default values.
202
+ def initialize(options = {})
203
+ self.key = options.key?(:key) ? options[:key].to_s : ''
204
+ self.type = options.key?(:type) ? options[:type].to_s : 'default'
205
+ self.mode = options.key?(:mode) ? options[:mode].to_s : 'single'
206
+ self.title = options.key?(:title) ? options[:title].to_s : ''
207
+ self.hint = options.key?(:hint) ? options[:hint].to_s : ''
208
+ self.decoration = options.key?(:decoration) ? options[:decoration] : 'none'
209
+ end
210
+
211
+ ##
212
+ # Generates hash representation of output class
213
+ # @return [Hash] hash representation of all data
214
+ def to_h
215
+ result = {
216
+ key: self.key,
217
+ mode: self.mode,
218
+ type: self.type,
219
+ decoration: self.decoration
220
+ }
221
+ result[:title] = self.title if self.title != ''
222
+ result[:hint] = self.hint if self.hint != ''
223
+ result
224
+ end
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,71 @@
1
+ module Anubis
2
+ module Output
3
+ ##
4
+ # Output subclass that represents data for login action
5
+ class Login < Basic
6
+ ##
7
+ # Output subclass that represents data for login action
8
+
9
+ # @!attribute [rw] token
10
+ # @return [String] the resulting login token.
11
+ class_attribute :token
12
+
13
+ # @!attribute [rw] name
14
+ # @return [String] the name of the user
15
+ class_attribute :name
16
+
17
+ # @!attribute [rw] surname
18
+ # @return [String] the surname of the user
19
+ class_attribute :surname
20
+
21
+ # @!attribute [rw] email
22
+ # @return [String] the email of the user
23
+ class_attribute :email
24
+
25
+ # @!attribute [rw] locale
26
+ # @return [String] the user's locale
27
+ class_attribute :locale
28
+
29
+ ##
30
+ # Initializes login output data. Generates default values.
31
+ def initialize
32
+ super
33
+ self.token = ''
34
+ self.name = ''
35
+ self.surname = ''
36
+ self.email = ''
37
+ self.locale = ''
38
+ end
39
+
40
+ ##
41
+ # Generates hash representation of output class
42
+ # @return [Hash] hash representation of all data
43
+ def to_h
44
+ result = super.to_h
45
+ return result if self.result != 0
46
+ result.merge!({
47
+ token: self.token,
48
+ name: self.name,
49
+ surname: self.surname,
50
+ email: self.email,
51
+ locale: self.locale
52
+ })
53
+ result
54
+ end
55
+
56
+ ##
57
+ # Generates output message based on {#result self.result} variable.
58
+ # @return [String] output message
59
+ def message
60
+ case self.result
61
+ when -1
62
+ return I18n.t('errors.invalid_login_parameters')
63
+ when -2
64
+ return I18n.t('errors.invalid_login_or_password')
65
+ else
66
+ return super
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end