symphonia 3.3.2 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -4
  3. data/CHANGELOG.md +30 -0
  4. data/README.md +16 -0
  5. data/app/controllers/symphonia/admin_controller.rb +1 -4
  6. data/app/models/symphonia/user.rb +0 -3
  7. data/app/views/symphonia/accounts/_form.html.erb +5 -0
  8. data/app/views/symphonia/admin/index.html.erb +1 -11
  9. data/db/migrate/20130714140501_create_roles.rb +6 -4
  10. data/db/migrate/20200428180001_add_uuid_to_users.rb +4 -2
  11. data/db/migrate/20210509141420_roles_change_permissions_to_json.rb +18 -0
  12. data/db/migrate/20210509180525_roles_change_permissions_to_native_json.rb +7 -0
  13. data/lib/generators/symphonia/setup/setup_generator.rb +17 -14
  14. data/lib/generators/symphonia/setup/templates/{settings.rb → app/config/initializers/settings.rb.tt} +0 -0
  15. data/lib/generators/symphonia/setup/templates/{404.html → public/404.html.tt} +2 -2
  16. data/lib/generators/symphonia/setup/templates/{500.html → public/500.html.tt} +2 -2
  17. data/lib/generators/symphonia/setup/templates/{spec_helper.rb → spec/spec_helper.rb.tt} +3 -2
  18. data/lib/symphonia.rb +4 -1
  19. data/lib/symphonia/controller_extensions.rb +2 -2
  20. data/lib/symphonia/model_attributes/attribute.rb +30 -14
  21. data/lib/symphonia/model_filters/base.rb +13 -15
  22. data/lib/symphonia/model_filters/boolean_filter.rb +10 -11
  23. data/lib/symphonia/model_filters/date_filter.rb +32 -31
  24. data/lib/symphonia/model_filters/integer_filter.rb +4 -5
  25. data/lib/symphonia/model_filters/select_filter.rb +19 -17
  26. data/lib/symphonia/model_filters/string_filter.rb +4 -5
  27. data/lib/symphonia/query.rb +10 -34
  28. data/lib/symphonia/query_columns.rb +1 -2
  29. data/lib/symphonia/query_columns/attribute_column.rb +59 -5
  30. data/lib/symphonia/spec_helper.rb +5 -3
  31. data/lib/symphonia/user_management.rb +5 -3
  32. data/lib/symphonia/version.rb +3 -1
  33. data/spec/controllers/account_controller_spec.rb +66 -69
  34. data/spec/controllers/admin_controller_spec.rb +24 -25
  35. data/spec/libs/some_lib_spec.rb +5 -0
  36. data/spec/rails_helper.rb +4 -3
  37. data/spec/spec_helper.rb +3 -8
  38. metadata +69 -168
  39. data/app/models/symphonia/admin_module.rb +0 -18
  40. data/app/views/symphonia/filters/table.html.erb +0 -21
  41. data/db/migrate/20130828175114_create_attachments.rb +0 -20
  42. data/db/migrate/20141213204351_create_admin_modules.rb +0 -20
  43. data/lib/symphonia/query_columns/generic_column.rb +0 -165
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81d7e486f9226d136f252f53841733cf7fd1f76a84a27b80ff0472cfc574ae30
4
- data.tar.gz: 39fa3ee78ed46669f2dcd583179818e7288fd392c54556b943d7ca2a9b1b312b
3
+ metadata.gz: 2322f8cb18f3e42a829515f52bdc92a2482526b0da5b53c0718306ecc5337193
4
+ data.tar.gz: be02650248988af53b2b65742d574117b980e18887ab24993aab73ec545154bf
5
5
  SHA512:
6
- metadata.gz: 16fa7bf6a6fbfbb875f0d6bf84c554ecd48ba9d2aacf2c259b361c3e5cb90ac57d448bd1da3c95ab3a1918f18b1a22a05ed3db1517bb36dcc34a4d10e30b7577
7
- data.tar.gz: 4fd6defbf9b4128295eb1c5d90c9ec9476c08e4d80adb58fdcd275cc5998190adad1db771d496cbb97f6ed128d6fafa46109b9b96b320ec892544ebb6c5a3743
6
+ metadata.gz: 794e07fb7ff554fae811519e79d2c01d1221a23ab76283d600af8ac35e92a37e9dcbbc3ebae39e735fa74a1c43ea57d761d33056ebbd1a0a82ae6929ed44ff2e
7
+ data.tar.gz: 10afddd10e24493ea09a9a26e9e66322101e6be643ef8074fc8712cd826cb1f026b28d230ab0dd2a512a7caafc0146aea3746fec1f5f20e395d24fb4ed8def93
data/.rubocop.yml CHANGED
@@ -1,5 +1,10 @@
1
+ require:
2
+ - rubocop-rails
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
6
  TargetRubyVersion: 2.5
7
+ NewCops: enable
3
8
 
4
9
  Layout/EmptyLinesAroundClassBody:
5
10
  EnforcedStyle: empty_lines_special
@@ -12,15 +17,13 @@ Metrics/AbcSize:
12
17
  Enabled: false
13
18
  Metrics/BlockLength:
14
19
  Enabled: false
15
- #Metrics/LineLength:
16
- # Enabled: false
17
20
  Metrics/MethodLength:
18
21
  Enabled: false
19
22
 
20
- #Style/BracesAroundHashParameters:
21
- # EnforcedStyle: context_dependent
22
23
  Style/Documentation:
23
24
  Enabled: false
25
+ Style/FrozenStringLiteralComment:
26
+ Enabled: false
24
27
  Style/MutableConstant:
25
28
  Enabled: false
26
29
  Style/NegatedIf:
data/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+ ### Added
9
+ - rubocop-rails
10
+ - rubocop-rspec
11
+ ### Removed
12
+ - mini_racer
13
+
14
+ ## [4.0.0] - 2021-05-18
15
+ ### Removed
16
+ - development dependency in gemspec replaced by `symphonia_spec` gem
17
+ - GenericColumn in Query
18
+ - AdminModule class/table = its not used, its not working
19
+ ### Changed
20
+ - Rails 6.1 support
21
+ - Query#to_params boolean argument to named
22
+ - update generators
23
+ - use native JSON columns instead of serializations
24
+ ### Added
25
+ - Gemfile.lock
26
+
27
+ ## [3.4.0] - 2021-03-22
28
+ ### Changed
29
+ - upgrade authlogic to 6.4.1 (rails6.1 compatible)
30
+
31
+ ## [3.3.4] - 2020-12-28
32
+ ### Fixed
33
+ - default responses (render_40x) works for any format
34
+ ## [3.3.3] - 2020-10-24
35
+ ### Changed
36
+ - prefill login from email
37
+ - allow login edit for legacy accounts
8
38
  ## [3.3.2] - 2020-10-17
9
39
  ### Added
10
40
  - `render_super` for templates
data/README.md CHANGED
@@ -14,3 +14,19 @@ after `bundle install` run post-installation: `rails g symphonia:setup`
14
14
  > Setup prepare `config/initializers/settings.rb`, create `spec/spec_helper.rb`, add stylesheets and javascripts references and copy basic layout.
15
15
 
16
16
 
17
+ ## Upgrade to v4.0
18
+ 1. update Gemfile:
19
+ ```ruby
20
+ gem 'rails', '~> 6.1'
21
+ gem 'symphonia', '~> 4.0'
22
+ source "https://gems.luk4s.cz" do
23
+ gem 'symphonia_spec', group: %i[development test]
24
+ end
25
+ ```
26
+ And `bundle update`
27
+ 2. upgrade rails:
28
+ https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
29
+ ```bash
30
+ export THOR_MERGE=vimdiff
31
+ rails app:update
32
+ ```
@@ -3,9 +3,6 @@ module Symphonia
3
3
  before_action :login_require
4
4
 
5
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
6
  respond_to do |format|
10
7
  format.html
11
8
  end
@@ -19,4 +16,4 @@ module Symphonia
19
16
 
20
17
  end
21
18
 
22
- end
19
+ end
@@ -50,9 +50,6 @@ module Symphonia
50
50
  before_save do |model|
51
51
  Rails.cache.delete_matched('user_allowed_to*') if model.role_id_changed?
52
52
  end
53
- before_validation do |model|
54
- model.login ||= model.email
55
- end
56
53
 
57
54
  def allowed_to?(action)
58
55
  return true if admin?
@@ -1,4 +1,9 @@
1
1
  <div class="row justify-content-center">
2
+ <% if f.object.login != f.object.email %>
3
+ <div class="col-lg-8">
4
+ <%= f.text_field :login, required: true %>
5
+ </div>
6
+ <% end %>
2
7
  <div class="col-lg-8">
3
8
  <%= f.email_field :email, required: true %>
4
9
  </div>
@@ -1,15 +1,5 @@
1
1
  <%= title 'Administrace' %>
2
- <% @admin_modules.each_with_index do |admin_module, _index| %>
3
- <div class="col-lg-<%= @modules_count == 1 ? '12' : '6' %>" id="<%= dom_id(admin_module) %>">
4
- <h3><%= t(admin_module.title, scope: [:admin_module, :titles], default: admin_module.title) %></h3>
5
- <% if admin_module.body_path.is_a?(Symbol) %>
6
- <%= render(partial: "admin_modules/#{admin_module.body_path}", locals: { admin_module: admin_module }) -%>
7
- <% else %>
8
- <%= format_text(admin_module.body_path) -%>
9
- <% end -%>
10
- </div>
11
- <% end -%>
12
2
 
13
3
  <%= content_for :meta_tags do %>
14
4
  <meta name="turbolinks-root" content="/admin">
15
- <% end %>
5
+ <% end %>
@@ -1,10 +1,11 @@
1
- class CreateRoles < ActiveRecord::Migration[5.1]
1
+ class CreateRoles < ActiveRecord::Migration[6.1]
2
+
2
3
  def up
3
4
  create_table :roles do |t|
4
- t.string :name, :null => false
5
- t.text :description, :null => true
5
+ t.string :name, null: false
6
+ t.text :description, null: true
6
7
 
7
- t.text :permissions
8
+ t.text :permissions
8
9
 
9
10
  t.timestamps
10
11
  end
@@ -13,4 +14,5 @@ class CreateRoles < ActiveRecord::Migration[5.1]
13
14
  def down
14
15
  drop_table :roles
15
16
  end
17
+
16
18
  end
@@ -1,6 +1,8 @@
1
1
  class AddUuidToUsers < ActiveRecord::Migration[6.0]
2
+
2
3
  def change
3
- uuid_type = connection.adapter_name =~ /PostgreSQL/i ? :uuid : :string
4
- add_column :users, :uuid, uuid_type
4
+ # uuid_type = connection.adapter_name =~ /PostgreSQL/i ? :uuid : :string
5
+ add_column :users, :uuid, :uuid
5
6
  end
7
+
6
8
  end
@@ -0,0 +1,18 @@
1
+ class RolesChangePermissionsToJson < ActiveRecord::Migration[6.1]
2
+
3
+ def up
4
+ say_with_time "Convert 'roles.permissions' YAML to JSON" do
5
+ i = 0
6
+ Symphonia::Role.where.not(permissions: nil).each do |role|
7
+ yaml = product.read_attribute_before_type_cast :permissions
8
+ next unless yaml.start_with? "---"
9
+
10
+ role.update_columns permissions: YAML.safe_load(yaml)
11
+ i += 1
12
+ end
13
+
14
+ i
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,7 @@
1
+ class RolesChangePermissionsToNativeJson < ActiveRecord::Migration[6.1]
2
+
3
+ def up
4
+ change_column :roles, :permissions, :jsonb, using: 'permissions::jsonb'
5
+ end
6
+
7
+ end
@@ -2,17 +2,16 @@ require 'rails/generators'
2
2
 
3
3
  module Symphonia
4
4
  class SetupGenerator < Rails::Generators::Base
5
- # include Rails::Generators::Migration
6
5
 
7
6
  source_root File.expand_path('templates', __dir__)
8
7
 
9
8
  def create_settings
10
- copy_file 'settings.rb', 'config/initializers/settings.rb'
9
+ template 'config/initializers/settings.rb'
11
10
  end
12
11
 
13
12
  def copy_static
14
- copy_file '404.html', 'public/404.html'
15
- copy_file '500.html', 'public/500.html'
13
+ template 'public/404.html'
14
+ template 'public/500.html'
16
15
  end
17
16
 
18
17
  def copy_assets
@@ -22,16 +21,14 @@ module Symphonia
22
21
  end
23
22
 
24
23
  def copy_rspec
25
- copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
24
+ template 'spec/spec_helper.rb'
26
25
 
27
26
  create_file '.rspec' do
28
- '--require spec_helper'
29
- '--format documentation'
27
+ "--require spec_helper"
30
28
  end
31
29
  end
32
30
 
33
31
  def copy_setup_file
34
-
35
32
  copy_file 'base_layout.html.erb', 'app/views/layouts/application.html.erb'
36
33
 
37
34
  append_to_file 'db/seeds.rb', 'Symphonia::Engine.load_seed'
@@ -40,14 +37,20 @@ module Symphonia
40
37
  inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do
41
38
  " mount Symphonia::Engine => '/'"
42
39
  end
40
+ end
41
+
42
+ def rubocop
43
+ create_file '.rubocop.yml' do
44
+ "inherit_gem:\n symphonia: .rubocop.yml"
45
+ end
46
+ end
47
+
48
+ def setup_gemfile
49
+ append_to_file 'Gemfile' do
50
+ "gem 'symphonia-spec', source: 'https://gems.luk4s.cz', group: %w[development test]"
51
+ end
43
52
 
44
53
  end
45
54
 
46
- # def setup_gemfile
47
- # append_to_file 'Gemfile' do
48
- # File.read(File.join(File.dirname(__FILE__), 'templates/Gemfile'))
49
- # end
50
- #
51
- # end
52
55
  end
53
56
  end
@@ -4,8 +4,8 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>404 STránka nenalezena</title>
7
- <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />
8
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
7
+ <link rel="stylesheet" href="//stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
8
+ <link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
9
9
  </head>
10
10
 
11
11
  <body>
@@ -26,10 +26,10 @@
26
26
  <h3>Lukáš Pokorný</h3>
27
27
  </li>
28
28
  <li>
29
- <i class="fa fa-li fa fa-envelope"></i>e-mail: <a href="mailto:admin@lagrace.cz">admin@lagrace.cz</a>
29
+ <i class="fa fa-li fa-envelope"></i>e-mail: <a href="mailto:admin@lagrace.cz">admin@luk4s.cz</a>
30
30
  </li>
31
31
  <li>
32
- <i class="fa fa-li fa fa-mobile-phone"></i>tel: 604484983
32
+ <i class="fa fa-li fa-mobile-phone"></i>tel: 604484983
33
33
  </li>
34
34
  </ul>
35
35
  </div>
@@ -1,11 +1,11 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
- require File.expand_path('../../config/environment', __FILE__)
2
+ require_relative '../../config/environment'
3
3
  # Prevent database truncation if the environment is production
4
4
  abort('The Rails environment is running in production mode!') if Rails.env.production?
5
5
 
6
6
  # require 'symphonia'
7
7
  RSpec.configure do |config|
8
- Dir.glob(File.join(__dir__, 'support', '*.rb')).each { |f| require f }
8
+ Dir.glob(File.join(__dir__, 'support', '*.rb')).sort.each { |f| require f }
9
9
 
10
10
  require 'symphonia/spec_helper'
11
11
 
@@ -15,4 +15,5 @@ RSpec.configure do |config|
15
15
 
16
16
  config.infer_spec_type_from_file_location!
17
17
  config.filter_rails_from_backtrace!
18
+ config.profile_examples = true
18
19
  end
data/lib/symphonia.rb CHANGED
@@ -1,5 +1,5 @@
1
- # Dir[File.dirname(__FILE__) + '/symphonia/*.rb'].each {|file| require file }
2
1
  module Symphonia
2
+
3
3
  include ::ActiveSupport::Configurable
4
4
 
5
5
  autoload :BaseController, 'symphonia/base_controller'
@@ -13,8 +13,11 @@ module Symphonia
13
13
  autoload :QueryColumns, 'symphonia/query_columns'
14
14
 
15
15
  module ActionCable
16
+
16
17
  autoload :Connection, 'symphonia/action_cable/connection'
18
+
17
19
  end
20
+
18
21
  end
19
22
 
20
23
  require 'symphonia/engine'
@@ -127,14 +127,14 @@ module Symphonia
127
127
  respond_to do |format|
128
128
  format.html { render template: 'common/403', message: :notice_not_authorized, status: 403 }
129
129
  format.js { render plain: "alert('#{t :text_access_deny}')", message: :notice_not_authorized, status: 403 }
130
- format.json { head 403, message: :notice_not_authorized }
130
+ format.any { head 403, message: :notice_not_authorized }
131
131
  end
132
132
  end
133
133
 
134
134
  def render_404
135
135
  respond_to do |format|
136
136
  format.html { render template: 'common/404', message: :notice_page_not_found, status: 404 }
137
- format.json { head 404, message: :not_found }
137
+ format.any { head 404, message: :not_found }
138
138
  end
139
139
  end
140
140
 
@@ -1,9 +1,9 @@
1
1
  module Symphonia
2
2
  module ModelAttributes
3
+
3
4
  class Attribute
4
5
 
5
- attr_reader :name, :options
6
- attr_reader :format_options, :sort_column
6
+ attr_reader :name, :options, :format_options, :sort_column
7
7
  attr_accessor :filter
8
8
 
9
9
  def initialize(name, klass, options, formatter)
@@ -78,27 +78,34 @@ module Symphonia
78
78
  def format_value(_view, value, _entity)
79
79
  value.to_s
80
80
  end
81
+
81
82
  end
82
83
 
83
84
 
84
85
  class TextAttribute < Attribute
85
- def format_value(view, value, entity)
86
+
87
+ def format_value(view, value, _entity)
86
88
  view.format_text(value)
87
89
  end
88
90
 
89
91
  def input_field
90
92
  :text_area
91
93
  end
94
+
92
95
  end
96
+
93
97
  class DecimalAttribute < Attribute
94
- def format_value(view, value, entity)
98
+
99
+ def format_value(view, value, _entity)
95
100
  view.format_price(value)
96
101
  end
102
+
97
103
  end
98
104
 
99
105
  class EnumAttribute < Attribute
106
+
100
107
  # TODO: @klass.name || @klass.base_class.name || entity.class.name
101
- def format_value(view, value, entity)
108
+ def format_value(view, value, _entity)
102
109
  view.t("#{@klass.name.underscore}.#{name.to_s.pluralize}.#{value}", format_options)
103
110
  end
104
111
 
@@ -109,26 +116,27 @@ module Symphonia
109
116
  def input_options
110
117
  []
111
118
  end
119
+
112
120
  end
113
121
 
114
122
  class LinkAttribute < Attribute
123
+
115
124
  def format_value(view, value, entity)
116
125
  view.link_to value.to_s, entity, format_options
117
126
  end
127
+
118
128
  end
119
129
 
120
130
  class MailAttribute < Attribute
121
- def format_value(view, value, entity)
131
+
132
+ def format_value(view, value, _entity)
122
133
  view.mail_to value.to_s, value.to_s, format_options
123
134
  end
135
+
124
136
  end
125
137
 
126
138
  class ReferenceAttribute < Attribute
127
139
 
128
- def initialize(name, klass, options, formatter)
129
- super
130
- end
131
-
132
140
  def title
133
141
  if (ref = @klass.reflect_on_association(name)).macro == :belongs_to
134
142
  @klass.human_attribute_name(ref.foreign_key, @options[:i18n] || {})
@@ -138,7 +146,7 @@ module Symphonia
138
146
 
139
147
  end
140
148
 
141
- def format_value(view, value, entity)
149
+ def format_value(view, value, _entity)
142
150
  if value.is_a?(ActiveRecord::Associations::CollectionProxy) || value.is_a?(Array)
143
151
  value.collect { |v| view.link_to v.to_s, v, format_options }.join("\n").html_safe
144
152
  else
@@ -153,7 +161,8 @@ module Symphonia
153
161
  end
154
162
 
155
163
  class BooleanAttribute < Attribute
156
- def format_value(view, value, entity)
164
+
165
+ def format_value(view, value, _entity)
157
166
  if value.to_boolean
158
167
  view.icon('true', view.t(:true))
159
168
  else
@@ -164,21 +173,28 @@ module Symphonia
164
173
  def input_field
165
174
  :check_box
166
175
  end
176
+
167
177
  end
168
178
 
169
179
  class DateAttribute < Attribute
170
- def format_value(view, value, entity)
180
+
181
+ def format_value(view, value, _entity)
171
182
  value && view.l(value.to_date, format_options)
172
183
  end
184
+
173
185
  end
174
186
 
175
187
  class DateTimeAttribute < Attribute
176
- def format_value(view, value, entity)
188
+
189
+ def format_value(view, value, _entity)
177
190
  value && view.l(value.localtime, format_options)
178
191
  end
192
+
179
193
  end
194
+
180
195
  class DatetimeAttribute < DateTimeAttribute
181
196
  # alias
182
197
  end
198
+
183
199
  end
184
200
  end