symphonia 2.1.7

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/LICENSE +674 -0
  3. data/README.md +16 -0
  4. data/Rakefile +44 -0
  5. data/app/assets/images/bg-checker.png +0 -0
  6. data/app/assets/images/bullet.gif +0 -0
  7. data/app/assets/images/close.png +0 -0
  8. data/app/assets/images/loading.gif +0 -0
  9. data/app/assets/images/next.png +0 -0
  10. data/app/assets/images/prev.png +0 -0
  11. data/app/assets/javascripts/ckeditor/plugins/autogrow/plugin.js +232 -0
  12. data/app/assets/javascripts/ckeditor/plugins/autogrow/samples/autogrow.html +102 -0
  13. data/app/assets/javascripts/ckeditor/plugins/image_chooser/icons/addimage.png +0 -0
  14. data/app/assets/javascripts/ckeditor/plugins/image_chooser/plugin.js +15 -0
  15. data/app/assets/javascripts/symphonia/Sortable.js +1249 -0
  16. data/app/assets/javascripts/symphonia/_core.js +45 -0
  17. data/app/assets/javascripts/symphonia/application.js.erb +147 -0
  18. data/app/assets/javascripts/symphonia/filters.js +44 -0
  19. data/app/assets/javascripts/symphonia/symphonia_bootstrap_dialog.js +136 -0
  20. data/app/assets/javascripts/symphonia/symphonia_ckeditor.js +55 -0
  21. data/app/assets/stylesheets/symphonia/application.css +4 -0
  22. data/app/assets/stylesheets/symphonia/basic.scss +218 -0
  23. data/app/assets/stylesheets/symphonia/filters.scss +19 -0
  24. data/app/assets/stylesheets/symphonia/symphonia_bootstrap.scss +56 -0
  25. data/app/channels/application_cable/channel.rb +5 -0
  26. data/app/controllers/symphonia/accounts_controller.rb +169 -0
  27. data/app/controllers/symphonia/admin_controller.rb +22 -0
  28. data/app/controllers/symphonia/api_controller.rb +64 -0
  29. data/app/controllers/symphonia/application_controller.rb +8 -0
  30. data/app/controllers/symphonia/attachments_controller.rb +37 -0
  31. data/app/controllers/symphonia/filters_controller.rb +23 -0
  32. data/app/controllers/symphonia/images_controller.rb +16 -0
  33. data/app/controllers/symphonia/login_controller.rb +80 -0
  34. data/app/controllers/symphonia/roles_controller.rb +100 -0
  35. data/app/controllers/symphonia/user_sessions_controller.rb +16 -0
  36. data/app/controllers/symphonia/users_controller.rb +168 -0
  37. data/app/helpers/symphonia/application_helper.rb +422 -0
  38. data/app/helpers/symphonia/bootstrap_modal_helper.rb +59 -0
  39. data/app/helpers/symphonia/form_helper.rb +50 -0
  40. data/app/helpers/symphonia/renderer_helper.rb +85 -0
  41. data/app/mailers/symphonia/application_mailer.rb +6 -0
  42. data/app/mailers/symphonia/notifier.rb +42 -0
  43. data/app/models/symphonia/admin_module.rb +18 -0
  44. data/app/models/symphonia/application_record.rb +14 -0
  45. data/app/models/symphonia/attachment.rb +16 -0
  46. data/app/models/symphonia/common_file.rb +9 -0
  47. data/app/models/symphonia/email_preference.rb +5 -0
  48. data/app/models/symphonia/image.rb +46 -0
  49. data/app/models/symphonia/preference.rb +12 -0
  50. data/app/models/symphonia/role.rb +55 -0
  51. data/app/models/symphonia/swagger/error_model.rb +19 -0
  52. data/app/models/symphonia/swagger/responses.rb +27 -0
  53. data/app/models/symphonia/user.rb +141 -0
  54. data/app/models/symphonia/user_session.rb +19 -0
  55. data/app/views/common/403.html.erb +5 -0
  56. data/app/views/common/404.html.erb +2 -0
  57. data/app/views/layouts/symphonia/_modal.html.erb +19 -0
  58. data/app/views/layouts/symphonia/_query.html.erb +51 -0
  59. data/app/views/layouts/symphonia/application.html.erb +45 -0
  60. data/app/views/layouts/symphonia/application.pdf.erb +15 -0
  61. data/app/views/layouts/symphonia/mailer.html.erb +13 -0
  62. data/app/views/symphonia/accounts/_detail.html.erb +65 -0
  63. data/app/views/symphonia/accounts/_form.html.erb +14 -0
  64. data/app/views/symphonia/accounts/edit.html.erb +9 -0
  65. data/app/views/symphonia/accounts/edit.js.erb +5 -0
  66. data/app/views/symphonia/accounts/lost_password.html.erb +6 -0
  67. data/app/views/symphonia/accounts/lost_password.js.erb +3 -0
  68. data/app/views/symphonia/accounts/new_activation.html.erb +11 -0
  69. data/app/views/symphonia/accounts/new_activation.js.erb +6 -0
  70. data/app/views/symphonia/accounts/register.html.erb +20 -0
  71. data/app/views/symphonia/accounts/reset_password.html.erb +18 -0
  72. data/app/views/symphonia/accounts/update.js.erb +1 -0
  73. data/app/views/symphonia/admin/index.html.erb +15 -0
  74. data/app/views/symphonia/attachments/destroy.js.erb +1 -0
  75. data/app/views/symphonia/common/_editable_images_grid.html.erb +12 -0
  76. data/app/views/symphonia/common/_filters.html.erb +23 -0
  77. data/app/views/symphonia/common/_locale_chooser.html.erb +16 -0
  78. data/app/views/symphonia/common/_share_links.html.erb +5 -0
  79. data/app/views/symphonia/filters/options.html.erb +36 -0
  80. data/app/views/symphonia/filters/options.js.erb +9 -0
  81. data/app/views/symphonia/filters/table.html.erb +21 -0
  82. data/app/views/symphonia/login/_form.html.erb +19 -0
  83. data/app/views/symphonia/login/new.html.erb +11 -0
  84. data/app/views/symphonia/login_sessions/new.html.erb +1 -0
  85. data/app/views/symphonia/notifier/activation_user.html.erb +7 -0
  86. data/app/views/symphonia/notifier/activation_user.text.erb +3 -0
  87. data/app/views/symphonia/notifier/reset_password_user.html.erb +7 -0
  88. data/app/views/symphonia/notifier/reset_password_user.text.erb +3 -0
  89. data/app/views/symphonia/notifier/test_mail.html.erb +2 -0
  90. data/app/views/symphonia/notifier/test_mail.text.erb +3 -0
  91. data/app/views/symphonia/notifier/user_change_to_active.html.erb +3 -0
  92. data/app/views/symphonia/notifier/user_change_to_active.text.erb +1 -0
  93. data/app/views/symphonia/notifier/user_registered.html.erb +13 -0
  94. data/app/views/symphonia/notifier/user_registered.text.erb +8 -0
  95. data/app/views/symphonia/roles/_form.html.erb +30 -0
  96. data/app/views/symphonia/roles/edit.html.erb +5 -0
  97. data/app/views/symphonia/roles/index.html.erb +6 -0
  98. data/app/views/symphonia/roles/new.html.erb +4 -0
  99. data/app/views/symphonia/roles/show.html.erb +5 -0
  100. data/app/views/symphonia/users/_form.html.erb +13 -0
  101. data/app/views/symphonia/users/edit.html.erb +26 -0
  102. data/app/views/symphonia/users/edit.js.erb +3 -0
  103. data/app/views/symphonia/users/edit_current.html.erb +7 -0
  104. data/app/views/symphonia/users/index.html.erb +5 -0
  105. data/app/views/symphonia/users/new.html.erb +8 -0
  106. data/app/views/symphonia/users/show.html.erb +63 -0
  107. data/config/locales/cs.yml +233 -0
  108. data/config/locales/en.yml +47 -0
  109. data/config/routes.rb +52 -0
  110. data/db/migrate/20130714140500_create_users.rb +49 -0
  111. data/db/migrate/20130714140501_create_roles.rb +16 -0
  112. data/db/migrate/20130714140502_create_preferences.rb +26 -0
  113. data/db/migrate/20130828175114_create_attachments.rb +20 -0
  114. data/db/migrate/20141213204351_create_admin_modules.rb +20 -0
  115. data/db/seeds.rb +12 -0
  116. data/lib/generators/symphonia/entity_controller/entity_controller_generator.rb +48 -0
  117. data/lib/generators/symphonia/entity_controller/templates/controller.rb +100 -0
  118. data/lib/generators/symphonia/query/query_generator.rb +37 -0
  119. data/lib/generators/symphonia/setup/setup_generator.rb +52 -0
  120. data/lib/generators/symphonia/setup/templates/404.html +26 -0
  121. data/lib/generators/symphonia/setup/templates/500.html +37 -0
  122. data/lib/generators/symphonia/setup/templates/Gemfile +18 -0
  123. data/lib/generators/symphonia/setup/templates/base_layout.html.erb +46 -0
  124. data/lib/generators/symphonia/setup/templates/design.scss +4 -0
  125. data/lib/generators/symphonia/setup/templates/settings.rb +65 -0
  126. data/lib/generators/symphonia/setup/templates/spec_helper.rb +18 -0
  127. data/lib/symphonia/action_cable/connection.rb +31 -0
  128. data/lib/symphonia/admin_constraint.rb +9 -0
  129. data/lib/symphonia/attachable.rb +35 -0
  130. data/lib/symphonia/base_controller.rb +96 -0
  131. data/lib/symphonia/bootstrap_link_render.rb +69 -0
  132. data/lib/symphonia/controller_extensions.rb +200 -0
  133. data/lib/symphonia/engine.rb +137 -0
  134. data/lib/symphonia/form_builder.rb +137 -0
  135. data/lib/symphonia/menu_manager.rb +23 -0
  136. data/lib/symphonia/model_attributes/attribute.rb +137 -0
  137. data/lib/symphonia/model_attributes.rb +102 -0
  138. data/lib/symphonia/model_filters/base.rb +82 -0
  139. data/lib/symphonia/model_filters/boolean_filter.rb +26 -0
  140. data/lib/symphonia/model_filters/date_filter.rb +81 -0
  141. data/lib/symphonia/model_filters/integer_filter.rb +18 -0
  142. data/lib/symphonia/model_filters/select_filter.rb +48 -0
  143. data/lib/symphonia/model_filters/string_filter.rb +18 -0
  144. data/lib/symphonia/model_filters.rb +10 -0
  145. data/lib/symphonia/object.rb +31 -0
  146. data/lib/symphonia/permissions.rb +93 -0
  147. data/lib/symphonia/query.rb +275 -0
  148. data/lib/symphonia/query_columns/attribute_column.rb +43 -0
  149. data/lib/symphonia/query_columns/generic_column.rb +165 -0
  150. data/lib/symphonia/query_columns.rb +8 -0
  151. data/lib/symphonia/spec_helper.rb +4 -0
  152. data/lib/symphonia/user_management.rb +58 -0
  153. data/lib/symphonia/version.rb +4 -0
  154. data/lib/symphonia.rb +20 -0
  155. data/spec/controllers/account_controller_spec.rb +90 -0
  156. data/spec/controllers/admin_controller_spec.rb +35 -0
  157. data/spec/controllers/api_controller_spec.rb +9 -0
  158. data/spec/controllers/filters_controller_spec.rb +35 -0
  159. data/spec/controllers/images_controller_spec.rb +5 -0
  160. data/spec/controllers/login_controller_spec.rb +20 -0
  161. data/spec/controllers/roles_controller_spec.rb +12 -0
  162. data/spec/controllers/users_controller_spec.rb +47 -0
  163. data/spec/factories/factories.rb +52 -0
  164. data/spec/helpers/symphonia/application_helper_spec.rb +62 -0
  165. data/spec/mailers/previews/symphonia/notifier_preview.rb +27 -0
  166. data/spec/mailers/symphonia/notifier_spec.rb +76 -0
  167. data/spec/models/attachment_spec.rb +22 -0
  168. data/spec/models/query/attribute_spec.rb +8 -0
  169. data/spec/models/query/symphonia_query_spec.rb +70 -0
  170. data/spec/models/role_spec.rb +13 -0
  171. data/spec/models/user_spec.rb +10 -0
  172. data/spec/rails_helper.rb +13 -0
  173. data/spec/requests/accounts_spec.rb +118 -0
  174. data/spec/requests/attachments_controller_spec.rb +23 -0
  175. data/spec/requests/login_spec.rb +26 -0
  176. data/spec/requests/roles_spec.rb +10 -0
  177. data/spec/requests/users_spec.rb +50 -0
  178. data/spec/spec_helper.rb +101 -0
  179. data/spec/support/common_file.txt +2 -0
  180. data/spec/support/query.rb +36 -0
  181. data/spec/support/shared.rb +62 -0
  182. data/spec/support/shared_controllers.rb +31 -0
  183. data/spec/support/stub_users.rb +32 -0
  184. data/spec/support/symphonia.jpg +0 -0
  185. data/spec/support/wait_for_ajax.rb +15 -0
  186. data/spec/version_spec.rb +5 -0
  187. data/spec/views/filters/options.html.erb_spec.rb +14 -0
  188. metadata +697 -0
@@ -0,0 +1,56 @@
1
+ // require _bootstrap
2
+ // *= require rails_bootstrap_forms
3
+ // *= require bootstrap-datepicker3
4
+ //@import "bootstrap-sprockets";
5
+ @import "bootstrap";
6
+ @import "bootstrap-datepicker3";
7
+
8
+ //@media (min-width: $screen-sm) {
9
+ // #internal_static_page_sign {
10
+ // font-size: 20em;
11
+ // }
12
+ //}
13
+ //
14
+ //@media (min-width: $screen-md) {
15
+ // #internal_static_page_sign {
16
+ // font-size: 25em;
17
+ // }
18
+ //}
19
+ //
20
+ //@media (min-width: $screen-lg) {
21
+ // #internal_static_page_sign {
22
+ // font-size: 30em;
23
+ // }
24
+ //}
25
+
26
+ body > .container {
27
+ padding-top: 80px; // fixed navbar
28
+ }
29
+ footer.footer {
30
+ //position: absolute;
31
+ height: 40px;
32
+ line-height: 40px;
33
+ bottom: 0;
34
+ width: 100%;
35
+ }
36
+
37
+ @keyframes highlight {
38
+ from {
39
+ background-color: map-get($theme-colors, warning);
40
+ }
41
+ to {
42
+ background-color: inherit;
43
+ }
44
+ }
45
+
46
+ @media print {
47
+ .contextual {
48
+ @extend .d-print-none;
49
+ }
50
+ a[href]:after {
51
+ content: none
52
+ }
53
+ .btn {
54
+ @extend .d-print-none;
55
+ }
56
+ }
@@ -0,0 +1,5 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,169 @@
1
+ module Symphonia
2
+ class AccountsController < ApplicationController
3
+
4
+ before_action :login_require, only: [:show, :edit, :update]
5
+ before_action -> { menu_item(:my_account) }, only: [:show, :edit, :update]
6
+ before_action :prepare_user, only: [:register, :create]
7
+
8
+ helper Recaptcha::ClientHelper if defined? Recaptcha
9
+
10
+ def show
11
+ @user = current_account
12
+
13
+ respond_to do |format|
14
+ format.html { render(template: "#{@user.class.name.underscore.pluralize}/show") }
15
+ format.json { render json: @user }
16
+ end
17
+ end
18
+
19
+ def register
20
+ menu_item(:register)
21
+ end
22
+
23
+ def create
24
+ menu_item(:register)
25
+ @user.attributes = user_params
26
+ if Symphonia.config[:self_activation_enabled]
27
+ @user.status = @user.class.statuses[:active]
28
+ else
29
+ @user.status = @user.class.statuses[:pending]
30
+ end
31
+ respond_to do |format|
32
+ verified = if defined?(Recaptcha)
33
+ @user.valid? && verify_recaptcha(model: @user)
34
+ else
35
+ true
36
+ end
37
+ if verified && @user.save
38
+ Notifier.activation_user(@user).deliver_now
39
+ Notifier.user_registered(@user).deliver_now
40
+ format.html { redirect_to '/', notice: t(:text_user_registered) }
41
+ format.json { render status: :created }
42
+ else
43
+ format.html {
44
+ render action: 'register'
45
+ }
46
+ format.json { render json: @user.errors, status: :unprocessable_entity }
47
+ end
48
+ end
49
+ end
50
+
51
+ def edit
52
+ @user = current_account
53
+ end
54
+
55
+ def update
56
+ @user = current_account
57
+ @user.attributes = user_params
58
+ respond_to do |format|
59
+ @user.edited_by = User.current.logged_in? && User.current
60
+ @user.edited_at = Time.now
61
+ if @user.save
62
+ format.html { redirect_to({ action: 'show' }, notice: t(:text_updated)) }
63
+ format.json { head :no_content }
64
+ format.js
65
+ else
66
+ format.html {
67
+ render action: 'edit'
68
+ }
69
+ format.json { render json: @user.errors, status: :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ #----
75
+
76
+ def new_activation
77
+ end
78
+
79
+ def resend_activation
80
+ @user = find_account_by_mail(params.require(:mail))
81
+ if @user
82
+ if @user.active?
83
+ redirect_to root_path, flash: { error: t(:text_user_alerady_active) }
84
+ else
85
+ @user.reset_perishable_token!
86
+ Notifier.activation_user(@user).deliver_later
87
+ redirect_to root_path, notice: t(:text_activation_resend)
88
+ end
89
+ else
90
+ redirect_to root_path, flash: { error: t(:text_user_not_found) }
91
+ end
92
+ end
93
+
94
+ def activation
95
+ @user = find_account_by_token(params[:activation_code])
96
+ if @user
97
+ @user.activate!
98
+ redirect_to(login_path, notice: t(:text_activation_success))
99
+ else
100
+ redirect_to root_path, flash: { error: t(:text_user_not_found_or_token_invalid) }
101
+ end
102
+ end
103
+
104
+ def current
105
+
106
+ end
107
+
108
+ def admin
109
+
110
+ end
111
+
112
+ def reset_password
113
+ @user = find_account_by_token(params.require(:id))
114
+ return render_404 if @user.nil?
115
+
116
+ if params[:password] && params[:password_confirmation]
117
+ @user.password = params[:password]
118
+ @user.password_confirmation = params[:password_confirmation]
119
+ end
120
+
121
+ if @user.changed? && @user.save
122
+ return redirect_to(user_current_path, notice: t(:text_updated))
123
+ end
124
+ end
125
+
126
+ def lost_password
127
+ @user = find_account_by_mail(params[:mail]) if params[:mail]
128
+ if @user
129
+ if @user.active?
130
+ @user.reset_perishable_token!
131
+ Notifier.reset_password_user(@user).deliver_later
132
+ redirect_to login_path, notice: t(:text_reset_password_resend)
133
+ else
134
+ redirect_to login_path, flash: { error: t("authlogic.error_messages.not_active") }
135
+ end
136
+ else
137
+ respond_to do |format|
138
+ format.html
139
+ format.js
140
+ end
141
+ end
142
+ end
143
+
144
+ private
145
+
146
+ def prepare_user
147
+ return render_403 unless Symphonia.config[:allow_registrations]
148
+ @user = User.new
149
+ end
150
+
151
+ def user_params
152
+ params.require(:user).permit(:login, :first_name, :last_name, :password, :password_confirmation, :email, :mail, preference_ids: [])
153
+ end
154
+
155
+ def current_account
156
+ User.current
157
+ end
158
+
159
+ def find_account_by_mail(mail)
160
+ User.where(email: mail).first
161
+ end
162
+
163
+ def find_account_by_token(id)
164
+ User.find_using_perishable_token(id, 1.week)
165
+ end
166
+
167
+ end
168
+
169
+ end
@@ -0,0 +1,22 @@
1
+ module Symphonia
2
+ class AdminController < ApplicationController
3
+ before_action :login_require
4
+
5
+ def index
6
+ @admin_modules = AdminModule.where(user_id: [nil, current_user.id]).order(:position).all
7
+ @modules_count = @admin_modules.count
8
+
9
+ respond_to do |format|
10
+ format.html
11
+ end
12
+ end
13
+
14
+ def test_mail
15
+ Notifier.test_mail(current_user.id).deliver_later
16
+
17
+ redirect_to symphonia.root_path, notice: 'Test mail'
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,64 @@
1
+ module Symphonia
2
+ class ApiController < ApplicationController
3
+ include ::Swagger::Blocks
4
+ # https://github.com/fotinakis/swagger-blocks
5
+ swagger_root do
6
+ key :swagger, '2.0'
7
+ info do
8
+ key :version, '1.0.0'
9
+ key :title, 'Symphonia API'
10
+ key :description, ''
11
+ # key :termsOfService, 'http://helloreverb.com/terms/'
12
+ contact do
13
+ key :name, 'Lukas Pokorny'
14
+ key :email, 'pokorny@luk4s.cz'
15
+ end
16
+ license do
17
+ key :name, 'GPLv3'
18
+ end
19
+ end
20
+ # tag do
21
+ # key :name, 'pet'
22
+ # key :description, 'Pets operations'
23
+ # externalDocs do
24
+ # key :description, 'Find more info here'
25
+ # key :url, 'https://swagger.io'
26
+ # end
27
+ # end
28
+ # key :host, 'petstore.swagger.wordnik.com'
29
+ key :basePath, '/'
30
+ key :consumes, ['application/json']
31
+ key :produces, ['application/json']
32
+
33
+ security_definition :token do
34
+ key :type, :apiKey
35
+ key :name, :Authorization
36
+ key :in, :header
37
+ end
38
+ security do
39
+ key :token, []
40
+ end
41
+ # security_definition :petstore_auth do
42
+ # key :type, :oauth2
43
+ # key :authorizationUrl, 'http://swagger.io/api/oauth/dialog'
44
+ # key :flow, :implicit
45
+ # scopes do
46
+ # key 'write:pets', 'modify pets in your account'
47
+ # key 'read:pets', 'read your pets'
48
+ # end
49
+ # end
50
+ end
51
+
52
+ # A list of all classes that have swagger_* declarations.
53
+ SWAGGERED_CLASSES = [
54
+ UsersController,
55
+ User,
56
+ Swagger::ErrorModel,
57
+ self
58
+ ]
59
+
60
+ def index
61
+ render json: ::Swagger::Blocks.build_root_json(SWAGGERED_CLASSES)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,8 @@
1
+ module Symphonia
2
+ class ApplicationController < ::ActionController::Base
3
+
4
+ include ControllerExtensions
5
+
6
+ helper Symphonia::BootstrapModalHelper
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ module Symphonia
2
+ class AttachmentsController < ApplicationController
3
+
4
+ before_action :require_login, :find_attachment
5
+
6
+ def show
7
+ # find_attachment
8
+ render(plain: @attachment.attachment.url(:original), layout: false)
9
+ end
10
+
11
+ def destroy
12
+ # find_attachment
13
+ @attachment.destroy
14
+ respond_to do |format|
15
+ format.html do
16
+ flash[:notice] = t(:"text_#{@attachment.type.underscore}_successfully_destroy")
17
+ redirect_back_or_default(polymorphic_path(@attachment.attachable))
18
+ end
19
+ format.js
20
+ end
21
+ end
22
+
23
+ def reorder
24
+ # find_attachment
25
+ new_position = params.require(:position).to_i
26
+ @attachment.insert_at(new_position)
27
+ head :ok
28
+ end
29
+
30
+ private
31
+
32
+ def find_attachment
33
+ @attachment = Attachment.find(params.require(:id))
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,23 @@
1
+ module Symphonia
2
+ class FiltersController < ApplicationController
3
+ before_action :require_login
4
+ before_action :find_filters
5
+
6
+ def options
7
+ respond_to do |format |
8
+ format.html
9
+ format.js
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def find_filters
16
+ _type = params.delete(:type)
17
+ @query = _type.constantize.query.new
18
+ rescue StandardError => e
19
+ Rails.logger.debug e.message
20
+ render_404
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module Symphonia
2
+ class ImagesController < ApplicationController
3
+ # before_action :require_login
4
+
5
+ # raise '??? images ??'
6
+ # def index
7
+ # @images = Image.order(created_at: :asc)
8
+ # @images = @images.like(params[:q]) if params[:q].present?
9
+ # @images = @images.page(params[:page])
10
+ # respond_to do |format|
11
+ # format.html
12
+ # format.js
13
+ # end
14
+ # end
15
+ end
16
+ end
@@ -0,0 +1,80 @@
1
+ module Symphonia
2
+ class LoginController < ApplicationController
3
+
4
+ before_action { menu_item(:login) }
5
+
6
+ def index
7
+ if current_model.constantize.current.logged_in?
8
+ return destroy
9
+ else
10
+ return new
11
+ end
12
+ end
13
+
14
+ def new
15
+ if current_model.constantize.current.logged_in?
16
+ return redirect_to(after_login_path)
17
+ end
18
+ @model_session = "#{current_model}Session".constantize.new
19
+ render :new
20
+ end
21
+
22
+ def create
23
+ @model_session = "#{current_model}Session".constantize.new(login_session_params)
24
+ if @model_session.save
25
+ current_model.constantize.current = @model_session.user
26
+ redirect_to after_login_path
27
+ else
28
+ render :new
29
+ end
30
+ end
31
+
32
+ def login_session_params
33
+ params.require(:login_session).permit(:login, :password, :remember_me).to_h
34
+ end
35
+
36
+ def destroy
37
+ current_session && current_session.destroy
38
+ redirect_to '/', notice: t(:text_successfully_logout)
39
+ end
40
+
41
+ private
42
+
43
+ def current_model
44
+ raise NotImplementedError
45
+ end
46
+
47
+ def current_session
48
+ raise NotImplementedError
49
+ end
50
+
51
+ def after_login_path
52
+ path = session[:return_to].presence
53
+ path ||= Symphonia.config.after_login_path.presence
54
+ path ||= get_first_menu_item_path(Symphonia::MenuManager.menu(:top_menu).values) || :admin_path
55
+ case path
56
+ when Symbol
57
+ main_app.send(path)
58
+ when Proc
59
+ path.call(self)
60
+ else
61
+ path
62
+ end
63
+ end
64
+
65
+ def get_first_menu_item_path(menu_items)
66
+ menu_items.detect do |item|
67
+ if (submenu = item[:children]).present?
68
+ if (subitem = get_first_menu_item_path(submenu.values))
69
+ return subitem
70
+ break
71
+ end
72
+ else
73
+ item[:if].nil? || item[:if].call
74
+ end
75
+ end.try(:[], :url)
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,100 @@
1
+ module Symphonia
2
+ class RolesController < ApplicationController
3
+
4
+ include BaseController
5
+
6
+ def model
7
+ Role
8
+ end
9
+
10
+ def safe_attributes
11
+ [:name, :description, permissions: []]
12
+ end
13
+ # helper Symphonia::RendererHelper
14
+ #
15
+ # before_action :authorize
16
+ before_action :load_permissions, only: [:new, :edit, :update, :create]
17
+ #
18
+ # #layout 'admin'
19
+ #
20
+ # def index
21
+ # @query = Symphonia::Role.query.new(self)
22
+ # @entities = @query.entities
23
+ # respond_to do |format|
24
+ # format.html do
25
+ # @entities = @entities.page(params[:page])
26
+ # render layout: !request.xhr?
27
+ # end
28
+ # format.xml { render xml: @entities.all }
29
+ # format.json { render json: @entities.all }
30
+ # end
31
+ # end
32
+ #
33
+ # def show
34
+ # @role = Role.find(params[:id])
35
+ # respond_to do |format|
36
+ # format.html
37
+ # format.json { render json: @role }
38
+ # end
39
+ # end
40
+ #
41
+ # def new
42
+ # @role = Role.new
43
+ # end
44
+ #
45
+ # def edit
46
+ # @role = Role.find(params[:id])
47
+ # end
48
+
49
+ def create
50
+ @entity = @role = Role.new(entity_params)
51
+ @role.permissions = Symphonia::Permissions.find_all(params[:permissions]).map(&:name)
52
+ super
53
+ # respond_to do |format|
54
+ # if @role.save
55
+ # format.html { redirect_to((params[:continue] ? new_role_path : roles_path), notice: t(:text_created)) }
56
+ # format.json { render(json: @role, status: :created, location: @role) }
57
+ # else
58
+ # format.html { render(action: 'new') }
59
+ # format.json { render(json: @role.errors, status: :unprocessable_entity) }
60
+ # end
61
+ # end
62
+ end
63
+
64
+ def update
65
+ @entity = @role = Role.find(params[:id])
66
+ @role.permissions = Symphonia::Permissions.find_all(params[:permissions]).map(&:name)
67
+ super
68
+ # respond_to do |format|
69
+ # if @role.update_attributes(role_params)
70
+ # format.html { redirect_to(edit_role_path(@role), notice: t(:text_updated)) }
71
+ # format.json { head(:no_content) }
72
+ # else
73
+ # format.html { render(action: 'edit') }
74
+ # format.json { render(json: @role.errors, status: :unprocessable_entity) }
75
+ # end
76
+ # end
77
+ end
78
+
79
+ # def destroy
80
+ # @role = Role.find(params[:id])
81
+ # @role.destroy
82
+ # respond_to do |format|
83
+ # format.html { redirect_to(roles_url, notice: t(:text_destroyed)) }
84
+ # format.json { head :no_content }
85
+ # format.js { render js: "Symphonia.filters.removeRow('#{view_context.dom_id(@role)}')"}
86
+ # end
87
+ # end
88
+ #
89
+ private
90
+ #
91
+ def load_permissions
92
+ @permissions = Symphonia::Permissions.all
93
+ end
94
+ #
95
+ # def role_params
96
+ # params.require(:role).permit(:name, :description, permissions: [])
97
+ # end
98
+ end
99
+
100
+ end
@@ -0,0 +1,16 @@
1
+ module Symphonia
2
+ class UserSessionsController < LoginController
3
+ private
4
+
5
+ def current_model
6
+ @model = User
7
+ @model.name
8
+ end
9
+
10
+ def current_session
11
+ current_user_session
12
+ end
13
+
14
+ end
15
+
16
+ end