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.
- 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
data/lib/anoubis.rb
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
require "anoubis/engine"
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# Anoubis library
|
|
5
|
+
module Anoubis
|
|
6
|
+
module HasManualOrder
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module ClassMethods
|
|
14
|
+
def has_manual_order(params = {})
|
|
15
|
+
send :cattr_accessor, :manual_order_options
|
|
16
|
+
send :before_create, :manual_order_before_create_element
|
|
17
|
+
send :before_update, :manual_order_before_update_element
|
|
18
|
+
send :after_save, :manual_order_after_save_element
|
|
19
|
+
send :after_destroy, :manual_order_after_destroy
|
|
20
|
+
|
|
21
|
+
self.manual_order_options = params if params.is_a?(Hash)
|
|
22
|
+
include Anubis::HasManualOrder::LocalInstanceMethods
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module LocalInstanceMethods
|
|
27
|
+
# Check presence of position
|
|
28
|
+
def manual_order_before_create_element
|
|
29
|
+
# puts 'manual_order_before_create_element'
|
|
30
|
+
position = self.manual_order_options[:field].to_sym # set order field for simplicity
|
|
31
|
+
if !self[position]
|
|
32
|
+
data = self.class.where(manual_order_get_where).maximum(position)
|
|
33
|
+
data = if data then data + 1 else 0 end
|
|
34
|
+
self[position] = data
|
|
35
|
+
else
|
|
36
|
+
self[position] = 0 if self[position].to_i < 0 # position must be 0 or greater
|
|
37
|
+
manual_order_check_order_position 0
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def manual_order_before_update_element
|
|
42
|
+
# puts self.id.to_s+'> manual_order_before_update_element'
|
|
43
|
+
if manual_order_changed_orders
|
|
44
|
+
position = self.manual_order_options[:field].to_sym # set order field for simplicity
|
|
45
|
+
if !manual_order_changed_group
|
|
46
|
+
# puts self.id.to_s+'> Group was not changed'
|
|
47
|
+
was_position = eval('self.'+position.to_s+'_was')
|
|
48
|
+
# puts self.id.to_s+'> Position changed: '+was_position.to_s+' -> '+self[position].to_s
|
|
49
|
+
if self[position] > was_position
|
|
50
|
+
order_where = manual_order_get_where
|
|
51
|
+
order_where[position] = was_position.to_i
|
|
52
|
+
data = self.class.where(order_where).where.not(:id => self.id).first
|
|
53
|
+
if !data
|
|
54
|
+
# puts self.id.to_s+'> Update attributes'
|
|
55
|
+
self.update_columns position => self[position]
|
|
56
|
+
order_where[position] = [was_position.to_i..self[position].to_i]
|
|
57
|
+
self.class.where(order_where).where.not(:id => self.id).order(position).all.each do |element|
|
|
58
|
+
# puts self.id.to_s+'> Element id: '+element.id.to_s+' -> '+element[position].to_s
|
|
59
|
+
element[position] -= 1
|
|
60
|
+
begin
|
|
61
|
+
element.current_user = self.current_user
|
|
62
|
+
rescue
|
|
63
|
+
puts 'Cant set current_user'
|
|
64
|
+
end
|
|
65
|
+
element.save
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
if self[self.manual_order_options[:field].to_sym] != 0
|
|
72
|
+
manual_order_check_order_position self.id
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Check manual order position
|
|
78
|
+
def manual_order_check_order_position (id)
|
|
79
|
+
# puts self.id.to_s+'> manual_order_check_order_position'
|
|
80
|
+
position = self.manual_order_options[:field].to_sym # set order field for simplicity
|
|
81
|
+
if self[position].to_i > 0
|
|
82
|
+
order_where = manual_order_get_where
|
|
83
|
+
# Check if elements present for order conditions (before current element position)
|
|
84
|
+
order_where[position] = [0..self[position].to_i-1]
|
|
85
|
+
data = self.class.where(order_where).where.not(:id => id).maximum(position)
|
|
86
|
+
if !data
|
|
87
|
+
self[position] = 0 # if elements not found then position equal 0
|
|
88
|
+
else
|
|
89
|
+
self[position] = data+1 if self[position] != data+1 # if previous elements ends before position-1 then correct current position
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Recalculate position of elements after set current position
|
|
95
|
+
def manual_order_after_save_element
|
|
96
|
+
if manual_order_changed_orders
|
|
97
|
+
# puts self.id.to_s+'> manual_order_after_save_element'
|
|
98
|
+
position = self.manual_order_options[:field].to_sym # set order field for simplicity
|
|
99
|
+
order_where = manual_order_get_where
|
|
100
|
+
order_where[position] = self[position]
|
|
101
|
+
count = 0
|
|
102
|
+
self.class.where(order_where).where.not(:id => self.id).find_each do |element|
|
|
103
|
+
# puts self.id.to_s+'> Increment element position: '+element.id.to_s
|
|
104
|
+
element[position] = self[position]+1
|
|
105
|
+
begin
|
|
106
|
+
element.current_user = self.current_user
|
|
107
|
+
rescue
|
|
108
|
+
puts 'Cant set current_user'
|
|
109
|
+
end
|
|
110
|
+
element.save
|
|
111
|
+
count += 1
|
|
112
|
+
end
|
|
113
|
+
if manual_order_changed_group
|
|
114
|
+
order_where = manual_order_get_where_was
|
|
115
|
+
pos = eval('self.'+position.to_s+'_was').to_i
|
|
116
|
+
order_where[position] = [pos..Float::INFINITY]
|
|
117
|
+
self.class.where(order_where).order(position).all.each do |element|
|
|
118
|
+
element[position] = pos
|
|
119
|
+
begin
|
|
120
|
+
element.current_user = self.current_user
|
|
121
|
+
rescue
|
|
122
|
+
puts 'Cant set current_user'
|
|
123
|
+
end
|
|
124
|
+
element.save
|
|
125
|
+
pos += 1
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
#if count == 0
|
|
129
|
+
# order_where[position] = [self[position]+2..Float::INFINITY]
|
|
130
|
+
# data = self.class.where(order_where).where.not(:id => self.id).order(position).first
|
|
131
|
+
# if data
|
|
132
|
+
# data[position] = self[position]+1
|
|
133
|
+
# data.save
|
|
134
|
+
# end
|
|
135
|
+
# end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Recalculate positions after destroy element
|
|
140
|
+
def manual_order_after_destroy
|
|
141
|
+
position = self.manual_order_options[:field].to_sym # set order field for simplicity
|
|
142
|
+
order_where = manual_order_get_where
|
|
143
|
+
pos = self[position]
|
|
144
|
+
order_where[position] = [pos..Float::INFINITY]
|
|
145
|
+
self.class.where(order_where).order(position).all.each do |element|
|
|
146
|
+
element[position] = pos
|
|
147
|
+
begin
|
|
148
|
+
element.current_user = self.current_user
|
|
149
|
+
rescue
|
|
150
|
+
puts 'Cant set current_user'
|
|
151
|
+
end
|
|
152
|
+
element.save
|
|
153
|
+
pos += 1
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Check if element's position was changed (or changed order group)
|
|
158
|
+
def manual_order_changed_orders
|
|
159
|
+
changed = eval('self.'+self.manual_order_options[:field].to_s+'_changed?')
|
|
160
|
+
if self.manual_order_options.key? :groups
|
|
161
|
+
self.manual_order_options[:groups].each do |key|
|
|
162
|
+
# puts 'self.'+key.to_s+'_changed?'
|
|
163
|
+
changed = eval('self.'+key.to_s+'_changed?') if !changed
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
# puts 'manual_order_changed_orders: '+changed.to_s
|
|
167
|
+
return changed
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Check if element's position changed in current order group
|
|
171
|
+
def manual_order_changed_group
|
|
172
|
+
changed = false
|
|
173
|
+
if self.manual_order_options.key? :groups
|
|
174
|
+
self.manual_order_options[:groups].each do |key|
|
|
175
|
+
# puts 'self.'+key.to_s+'_changed?'
|
|
176
|
+
changed = eval('self.'+key.to_s+'_changed?') if !changed
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
# puts 'manual_order_changed_group: '+changed.to_s
|
|
180
|
+
return changed
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def manual_order_get_where
|
|
184
|
+
where = {}
|
|
185
|
+
if self.manual_order_options.key? :groups
|
|
186
|
+
self.manual_order_options[:groups].each do |key|
|
|
187
|
+
where[key.to_sym] = self[key.to_sym]
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
return where
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def manual_order_get_where_was
|
|
194
|
+
where = {}
|
|
195
|
+
if self.manual_order_options.key? :groups
|
|
196
|
+
self.manual_order_options[:groups].each do |key|
|
|
197
|
+
str = 'self.class.'+key.to_s.pluralize
|
|
198
|
+
begin
|
|
199
|
+
# puts str+'[(self.'+key.to_s+'_was).to_sym]'
|
|
200
|
+
where[key.to_sym] = eval(str+'[(self.'+key.to_s+'_was).to_sym]')
|
|
201
|
+
rescue
|
|
202
|
+
# puts 'self.'+key.to_s+'_was'
|
|
203
|
+
where[key.to_sym] = eval('self.'+key.to_s+'_was')
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
return where
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
ActiveRecord::Base.send :include, Anoubis::HasManualOrder
|
data/spec/anubis_spec.rb
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
module Anubis
|
|
4
|
+
RSpec.describe IndexController, type: :controller do
|
|
5
|
+
render_views
|
|
6
|
+
|
|
7
|
+
context "when request sets accept => application/json" do
|
|
8
|
+
it "should login" do
|
|
9
|
+
request.accept = "application/json"
|
|
10
|
+
post :login, params: { use_route: 'api/1', login: 'admin@local.local.sys', password: 'admin', version: 1 }
|
|
11
|
+
user = JSON.parse(response.body, { symbolize_names: true })
|
|
12
|
+
expect(response.status).to eq 200
|
|
13
|
+
expect(user[:result]).to eq 0
|
|
14
|
+
expect(user.has_key? :message).to eq true
|
|
15
|
+
expect(user.has_key? :token).to eq true
|
|
16
|
+
expect(user.has_key? :name).to eq true
|
|
17
|
+
expect(user.has_key? :surname).to eq true
|
|
18
|
+
expect(user.has_key? :email).to eq true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "has incorrect login" do
|
|
22
|
+
request.accept = "application/json"
|
|
23
|
+
post :login, params: { use_route: 'api/1', login: 'admin@local.local.sys', password: 'admin1', version: 1 }
|
|
24
|
+
user = JSON.parse(response.body, { symbolize_names: true })
|
|
25
|
+
expect(response.status).to eq 422
|
|
26
|
+
expect(user[:result]).to eq -2
|
|
27
|
+
expect(user.has_key? :token).to eq false
|
|
28
|
+
expect(user.has_key? :message).to eq true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "has invalid login parameters" do
|
|
32
|
+
request.accept = "application/json"
|
|
33
|
+
post :login, params: { use_route: 'api/1', login: 'admin@local.local.sys', version: 1 }
|
|
34
|
+
user = JSON.parse(response.body, { symbolize_names: true })
|
|
35
|
+
expect(response.status).to eq 422
|
|
36
|
+
expect(user[:result]).to eq -1
|
|
37
|
+
expect(user.has_key? :token).to eq false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "can get menu for logged in user" do
|
|
41
|
+
request.accept = "application/json"
|
|
42
|
+
post :login, params: { use_route: 'api/1', login: 'admin@local.local.sys', password: 'admin', version: 1 }
|
|
43
|
+
user = JSON.parse(response.body, { symbolize_names: true })
|
|
44
|
+
request.headers['Authorization'] = 'Bearer '+user[:token]
|
|
45
|
+
get :menu, params: { use_route: 'api/1', version: 1 }
|
|
46
|
+
menu = JSON.parse(response.body, { symbolize_names: true })
|
|
47
|
+
expect(response.status).to eq 200
|
|
48
|
+
expect(menu[:result]).to eq 0
|
|
49
|
+
expect(menu.has_key? :menu).to eq true
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "can't get menu for unauthorized user" do
|
|
53
|
+
request.accept = "application/json"
|
|
54
|
+
get :menu, params: { use_route: 'api/1', version: 1 }
|
|
55
|
+
JSON.parse(response.body, { symbolize_names: true })
|
|
56
|
+
expect(response.status).to eq 422
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "can logout" do
|
|
60
|
+
request.accept = "application/json"
|
|
61
|
+
post :login, params: { use_route: 'api/1', login: 'admin@local.local.sys', password: 'admin', version: 1 }
|
|
62
|
+
data = JSON.parse(response.body, { symbolize_names: true })
|
|
63
|
+
expect(response.status).to eq 200
|
|
64
|
+
expect(data[:result]).to eq 0
|
|
65
|
+
user = JSON.parse(response.body, { symbolize_names: true })
|
|
66
|
+
request.headers['Authorization'] = 'Bearer '+user[:token]
|
|
67
|
+
get :logout, params: { use_route: 'api/1', version: 1 }
|
|
68
|
+
data = JSON.parse(response.body, { symbolize_names: true })
|
|
69
|
+
expect(response.status).to eq 200
|
|
70
|
+
expect(data[:result]).to eq 0
|
|
71
|
+
get :menu, params: { use_route: 'api/1', version: 1 }
|
|
72
|
+
JSON.parse(response.body, { symbolize_names: true })
|
|
73
|
+
expect(response.status).to eq 422
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require rails-ujs
|
|
14
|
+
//= require activestorage
|
|
15
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= yield %>
|
data/spec/dummy/bin/rake
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
include FileUtils
|
|
4
|
+
|
|
5
|
+
# path to your application root.
|
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
|
7
|
+
|
|
8
|
+
def system!(*args)
|
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
chdir APP_ROOT do
|
|
13
|
+
# This script is a starting point to setup your application.
|
|
14
|
+
# Add necessary setup steps to this file.
|
|
15
|
+
|
|
16
|
+
puts '== Installing dependencies =='
|
|
17
|
+
system! 'gem install bundler --conservative'
|
|
18
|
+
system('bundle check') || system!('bundle install')
|
|
19
|
+
|
|
20
|
+
# puts "\n== Copying sample files =="
|
|
21
|
+
# unless File.exist?('config/database.yml')
|
|
22
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
|
23
|
+
# end
|
|
24
|
+
|
|
25
|
+
puts "\n== Preparing database =="
|
|
26
|
+
system! 'bin/rails db:setup'
|
|
27
|
+
|
|
28
|
+
puts "\n== Removing old logs and tempfiles =="
|
|
29
|
+
system! 'bin/rails log:clear tmp:clear'
|
|
30
|
+
|
|
31
|
+
puts "\n== Restarting application server =="
|
|
32
|
+
system! 'bin/rails restart'
|
|
33
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
include FileUtils
|
|
4
|
+
|
|
5
|
+
# path to your application root.
|
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
|
7
|
+
|
|
8
|
+
def system!(*args)
|
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
chdir APP_ROOT do
|
|
13
|
+
# This script is a way to update your development environment automatically.
|
|
14
|
+
# Add necessary update steps to this file.
|
|
15
|
+
|
|
16
|
+
puts '== Installing dependencies =='
|
|
17
|
+
system! 'gem install bundler --conservative'
|
|
18
|
+
system('bundle check') || system!('bundle install')
|
|
19
|
+
|
|
20
|
+
puts "\n== Updating database =="
|
|
21
|
+
system! 'bin/rails db:migrate'
|
|
22
|
+
|
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
|
24
|
+
system! 'bin/rails log:clear tmp:clear'
|
|
25
|
+
|
|
26
|
+
puts "\n== Restarting application server =="
|
|
27
|
+
system! 'bin/rails restart'
|
|
28
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# MySQL. Versions 5.1.10 and up are supported.
|
|
2
|
+
#
|
|
3
|
+
# Install the MySQL driver
|
|
4
|
+
# gem install mysql2
|
|
5
|
+
#
|
|
6
|
+
# Ensure the MySQL gem is defined in your Gemfile
|
|
7
|
+
# gem 'mysql2'
|
|
8
|
+
#
|
|
9
|
+
# And be sure to use new-style password hashing:
|
|
10
|
+
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
|
|
11
|
+
#
|
|
12
|
+
default: &default
|
|
13
|
+
adapter: mysql2
|
|
14
|
+
encoding: utf8
|
|
15
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
|
16
|
+
username: ruby
|
|
17
|
+
password: ruby
|
|
18
|
+
socket: /var/run/mysqld/mysqld.sock
|
|
19
|
+
|
|
20
|
+
development:
|
|
21
|
+
<<: *default
|
|
22
|
+
database: anoubis_dummy_development
|
|
23
|
+
|
|
24
|
+
# Warning: The database defined as "test" will be erased and
|
|
25
|
+
# re-generated from your development database when you run "rake".
|
|
26
|
+
# Do not set this db to the same as development or production.
|
|
27
|
+
test:
|
|
28
|
+
<<: *default
|
|
29
|
+
database: anoubis_dummy_test
|
|
30
|
+
|
|
31
|
+
# As with config/secrets.yml, you never want to store sensitive information,
|
|
32
|
+
# like your database password, in your source code. If your source code is
|
|
33
|
+
# ever seen by anyone, they now have access to your database.
|
|
34
|
+
#
|
|
35
|
+
# Instead, provide the password as a unix environment variable when you boot
|
|
36
|
+
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
|
37
|
+
# for a full rundown on how to provide these environment variables in a
|
|
38
|
+
# production deployment.
|
|
39
|
+
#
|
|
40
|
+
# On Heroku and other platform providers, you may have a full connection URL
|
|
41
|
+
# available as an environment variable. For example:
|
|
42
|
+
#
|
|
43
|
+
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
|
|
44
|
+
#
|
|
45
|
+
# You can use this database configuration with:
|
|
46
|
+
#
|
|
47
|
+
# production:
|
|
48
|
+
# url: <%= ENV['DATABASE_URL'] %>
|
|
49
|
+
#
|
|
50
|
+
production:
|
|
51
|
+
<<: *default
|
|
52
|
+
database: dummy_production
|
|
53
|
+
username: dummy
|
|
54
|
+
password: <%= ENV['DUMMY_DATABASE_PASSWORD'] %>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Rails.application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
|
3
|
+
|
|
4
|
+
# In the development environment your application's code is reloaded on
|
|
5
|
+
# every request. This slows down response time but is perfect for development
|
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
|
7
|
+
config.cache_classes = false
|
|
8
|
+
|
|
9
|
+
# Do not eager load code on boot.
|
|
10
|
+
config.eager_load = false
|
|
11
|
+
|
|
12
|
+
# Show full error reports.
|
|
13
|
+
config.consider_all_requests_local = true
|
|
14
|
+
|
|
15
|
+
# Enable/disable caching. By default caching is disabled.
|
|
16
|
+
# Run rails dev:cache to toggle caching.
|
|
17
|
+
if Rails.root.join('tmp', 'caching-dev.txt').exist?
|
|
18
|
+
config.action_controller.perform_caching = true
|
|
19
|
+
|
|
20
|
+
config.cache_store = :memory_store
|
|
21
|
+
config.public_file_server.headers = {
|
|
22
|
+
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
config.action_controller.perform_caching = false
|
|
26
|
+
|
|
27
|
+
config.cache_store = :null_store
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Store uploaded files on the local file system (see config/storage.yml for options)
|
|
31
|
+
config.active_storage.service = :local
|
|
32
|
+
|
|
33
|
+
# Don't care if the mailer can't send.
|
|
34
|
+
config.action_mailer.raise_delivery_errors = false
|
|
35
|
+
|
|
36
|
+
config.action_mailer.perform_caching = false
|
|
37
|
+
|
|
38
|
+
# Print deprecation notices to the Rails logger.
|
|
39
|
+
config.active_support.deprecation = :log
|
|
40
|
+
|
|
41
|
+
# Raise an error on page load if there are pending migrations.
|
|
42
|
+
config.active_record.migration_error = :page_load
|
|
43
|
+
|
|
44
|
+
# Highlight code that triggered database queries in logs.
|
|
45
|
+
config.active_record.verbose_query_logs = true
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Raises error for missing translations
|
|
49
|
+
# config.action_view.raise_on_missing_translations = true
|
|
50
|
+
|
|
51
|
+
# Use an evented file watcher to asynchronously detect changes in source code,
|
|
52
|
+
# routes, locales, etc. This feature depends on the listen gem.
|
|
53
|
+
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
|
54
|
+
end
|