symphonia 4.2.0 → 5.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +31 -1
- data/app/assets/javascripts/symphonia/application.js +3 -3
- data/app/assets/stylesheets/symphonia/_font_awesome.scss +8 -6
- data/app/assets/stylesheets/symphonia/_layout.scss +33 -1
- data/app/assets/stylesheets/symphonia/application.css +1 -1
- data/app/assets/stylesheets/symphonia/basic.scss +3 -99
- data/app/assets/stylesheets/symphonia/filters.scss +3 -5
- data/app/assets/stylesheets/symphonia/symphonia_bootstrap.scss +1 -1
- data/app/controllers/symphonia/accounts_controller.rb +7 -3
- data/app/controllers/symphonia/application_controller.rb +2 -1
- data/app/controllers/symphonia/users_controller.rb +17 -29
- data/app/helpers/symphonia/application_helper.rb +48 -26
- data/app/models/symphonia/preference.rb +5 -5
- data/app/models/symphonia/user.rb +3 -35
- data/app/models/symphonia/user_ability.rb +46 -0
- data/app/views/common/403.html.erb +4 -3
- data/app/views/layouts/symphonia/application.html.erb +4 -4
- data/app/views/symphonia/accounts/_detail.html.erb +21 -18
- data/app/views/symphonia/common/_filters.html.erb +15 -15
- data/app/views/symphonia/common/_share_links.html.erb +2 -3
- data/app/views/symphonia/users/_form.html.erb +1 -6
- data/app/views/symphonia/users/show.html.erb +15 -20
- data/config/locales/cs.yml +3 -2
- data/db/migrate/20130714140500_create_users.rb +0 -2
- data/db/seeds.rb +3 -3
- data/lib/generators/symphonia/entity_controller/entity_controller_generator.rb +2 -2
- data/lib/generators/symphonia/entity_controller/templates/{controller.rb → controller.rb.tt} +0 -0
- data/lib/symphonia/admin_constraint.rb +1 -1
- data/lib/symphonia/base_controller.rb +9 -17
- data/lib/symphonia/controller_extensions.rb +5 -15
- data/lib/symphonia/engine.rb +10 -42
- data/lib/symphonia/form_builder.rb +17 -16
- data/lib/symphonia/menu_manager.rb +15 -11
- data/lib/symphonia/object.rb +9 -9
- data/lib/symphonia/spec_helper.rb +8 -4
- data/lib/symphonia/user_management.rb +1 -1
- data/lib/symphonia/version.rb +1 -1
- data/lib/symphonia.rb +12 -9
- data/spec/factories/factories.rb +0 -4
- data/spec/models/user_spec.rb +39 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/stub_users.rb +7 -7
- metadata +54 -111
- data/app/controllers/symphonia/roles_controller.rb +0 -39
- data/app/models/symphonia/role.rb +0 -55
- data/app/views/symphonia/roles/_form.html.erb +0 -26
- data/app/views/symphonia/roles/edit.html.erb +0 -5
- data/app/views/symphonia/roles/index.html.erb +0 -6
- data/app/views/symphonia/roles/new.html.erb +0 -4
- data/app/views/symphonia/roles/show.html.erb +0 -11
- data/db/migrate/20130714140501_create_roles.rb +0 -18
- data/db/migrate/20210509141420_roles_change_permissions_to_json.rb +0 -18
- data/db/migrate/20210509180525_roles_change_permissions_to_native_json.rb +0 -7
- data/lib/symphonia/permissions.rb +0 -93
- data/spec/controllers/roles_controller_spec.rb +0 -12
- data/spec/models/role_spec.rb +0 -13
- data/spec/requests/roles_spec.rb +0 -10
@@ -11,7 +11,6 @@ module Symphonia
|
|
11
11
|
add_attribute :last_name
|
12
12
|
add_attribute :email, :mail, default: true
|
13
13
|
add_attribute :status, :enum, filter: "select"
|
14
|
-
add_attribute :role, :reference
|
15
14
|
add_attribute :admin, :boolean
|
16
15
|
add_attribute :login_count
|
17
16
|
add_attribute :last_login_ip
|
@@ -34,8 +33,7 @@ module Symphonia
|
|
34
33
|
|
35
34
|
has_and_belongs_to_many :preferences, foreign_key: 'user_id'
|
36
35
|
|
37
|
-
belongs_to :edited_by, class_name: 'Symphonia::User',
|
38
|
-
belongs_to :role, required: false
|
36
|
+
belongs_to :edited_by, class_name: 'Symphonia::User', optional: true
|
39
37
|
|
40
38
|
accepts_nested_attributes_for :preferences
|
41
39
|
|
@@ -46,29 +44,6 @@ module Symphonia
|
|
46
44
|
|
47
45
|
alias_attribute :mail, :email
|
48
46
|
|
49
|
-
|
50
|
-
before_save do |model|
|
51
|
-
Rails.cache.delete_matched('user_allowed_to*') if model.role_id_changed?
|
52
|
-
end
|
53
|
-
|
54
|
-
def allowed_to?(action)
|
55
|
-
return true if admin?
|
56
|
-
|
57
|
-
Rails.cache.fetch([:user_allowed_to, self, action]) do
|
58
|
-
role_id && role.allowed_to?(action)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def authorize?(controller, action)
|
63
|
-
return true if admin?
|
64
|
-
|
65
|
-
if role_id
|
66
|
-
role.authorize?(controller, action)
|
67
|
-
else
|
68
|
-
false
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
47
|
# def form_path
|
73
48
|
# 'symphonia/users/form'
|
74
49
|
# end
|
@@ -97,14 +72,6 @@ module Symphonia
|
|
97
72
|
'anonym@nothing'
|
98
73
|
end
|
99
74
|
|
100
|
-
def allowed_to?(_action)
|
101
|
-
false
|
102
|
-
end
|
103
|
-
|
104
|
-
def authorize?(_controller, _action)
|
105
|
-
false
|
106
|
-
end
|
107
|
-
|
108
75
|
def save
|
109
76
|
false
|
110
77
|
end
|
@@ -117,7 +84,7 @@ module Symphonia
|
|
117
84
|
false
|
118
85
|
end
|
119
86
|
|
120
|
-
|
87
|
+
alias admin? admin
|
121
88
|
|
122
89
|
def logged_in?
|
123
90
|
false
|
@@ -130,6 +97,7 @@ module Symphonia
|
|
130
97
|
def language
|
131
98
|
nil
|
132
99
|
end
|
100
|
+
|
133
101
|
end
|
134
102
|
|
135
103
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Symphonia
|
4
|
+
class UserAbility
|
5
|
+
include CanCan::Ability
|
6
|
+
|
7
|
+
def initialize(user)
|
8
|
+
return unless user.logged_in?
|
9
|
+
|
10
|
+
can :update, User, id: user.id
|
11
|
+
can :read, User, id: user.id
|
12
|
+
return unless user.admin?
|
13
|
+
|
14
|
+
can :archive, User, status: :active
|
15
|
+
can :activate, User, status: :pending
|
16
|
+
can :unarchive, User, status: :archived
|
17
|
+
|
18
|
+
can %i[read create update destroy], :all
|
19
|
+
# Define abilities for the user here. For example:
|
20
|
+
#
|
21
|
+
# return unless user.present?
|
22
|
+
# can :read, :all
|
23
|
+
# return unless user.admin?
|
24
|
+
# can :manage, :all
|
25
|
+
#
|
26
|
+
# The first argument to `can` is the action you are giving the user
|
27
|
+
# permission to do.
|
28
|
+
# If you pass :manage it will apply to every action. Other common actions
|
29
|
+
# here are :read, :create, :update and :destroy.
|
30
|
+
#
|
31
|
+
# The second argument is the resource the user can perform the action on.
|
32
|
+
# If you pass :all it will apply to every resource. Otherwise pass a Ruby
|
33
|
+
# class of the resource.
|
34
|
+
#
|
35
|
+
# The third argument is an optional hash of conditions to further filter the
|
36
|
+
# objects.
|
37
|
+
# For example, here the user can only update published articles.
|
38
|
+
#
|
39
|
+
# can :update, Article, published: true
|
40
|
+
#
|
41
|
+
# See the wiki for details:
|
42
|
+
# https://github.com/CanCanCommunity/cancancan/blob/develop/docs/define_check_abilities.md
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
<p class="
|
1
|
+
<%= page_header 403 %>
|
2
|
+
<p class="alert alert-danger">
|
3
|
+
<i class="fa fa-hand-stop-o fa-5x"></i>
|
3
4
|
<%= t :text_access_deny %>
|
4
5
|
</p>
|
5
|
-
<%= link_to icon('back', t(:button_back)), :back, class: 'btn btn-link' %>
|
6
|
+
<%= link_to icon('back', t(:button_back)), :back, class: 'btn btn-link' %>
|
@@ -8,9 +8,9 @@
|
|
8
8
|
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': true %>
|
9
9
|
<%= yield :stylesheet_tags %>
|
10
10
|
<%= javascript_include_tag 'application', 'data-turbolinks-track': true %>
|
11
|
-
<script type="text/javascript"
|
12
|
-
Symphonia.routes.reorderImagesPath = '
|
13
|
-
</script
|
11
|
+
<!-- <script type="text/javascript">-->
|
12
|
+
<!-- Symphonia.routes.reorderImagesPath = '<%#= symphonia.reorder_attachment_path %>';-->
|
13
|
+
<!-- </script>-->
|
14
14
|
<%= yield :javascript_tags %>
|
15
15
|
<%= csrf_meta_tags %>
|
16
16
|
</head>
|
@@ -19,7 +19,7 @@
|
|
19
19
|
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
|
20
20
|
<!--<a class="navbar-brand" href="#">Navbar</a>-->
|
21
21
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
22
|
-
<%=
|
22
|
+
<%= icon('bars') %>
|
23
23
|
</button>
|
24
24
|
|
25
25
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
@@ -1,16 +1,17 @@
|
|
1
|
+
<%= ActiveSupport::Deprecation.warn "View 'accounts/_detail' partial should not use anymore" %>
|
1
2
|
<div class="buttons contextual">
|
2
3
|
<% if Symphonia::User.current.admin? %>
|
3
4
|
<% controller = account.class.name.underscore.pluralize %>
|
4
5
|
<%= link_to(icon('edit', t(:button_edit)), edit_polymorphic_path(account), class: 'btn btn-primary') %>
|
5
6
|
<% if use_service_buttons %>
|
6
7
|
<% if account.active? %>
|
7
|
-
|
8
|
+
<%#= link_to(icon('lock', text: t(:button_archive)), polymorphic_path([controller_name, 'archive', account], back_url: polymorphic_path(account)), class: 'btn btn-secondary', data: { method: 'post', confirm: t(:text_are_you_sure) }) %>
|
8
9
|
<% elsif account.status_new? %>
|
9
|
-
<%= link_to(
|
10
|
+
<%= link_to(icon('bolt', text: t(:button_active)), { controller: controller, action: 'unarchive', id: account, back_url: polymorphic_path(account) }, class: 'btn btn-secondary', data: { method: 'post', confirm: t(:text_are_you_sure) + "\n #{t(:text_confirm_send_unlock_mail)}" }) %>
|
10
11
|
<% else %>
|
11
|
-
<%= link_to(
|
12
|
+
<%= link_to(icon('unlock', text: t(:button_unarchive)), { controller: controller, action: 'unarchive', id: account, back_url: polymorphic_path(account) }, class: 'btn btn-secondary', data: { method: 'post', confirm: t(:text_are_you_sure) + "\n #{t(:text_confirm_send_unlock_mail)}" }) %>
|
12
13
|
<% end %>
|
13
|
-
<%= link_to(
|
14
|
+
<%= link_to(icon('delete', text: t(:button_delete)), account, class: 'btn btn-danger', method: 'delete', data: { :confirm => t(:text_are_you_sure) }) %>
|
14
15
|
<% end -%>
|
15
16
|
<% else %>
|
16
17
|
<%= link_to(icon('edit', t(:button_edit)), edit_polymorphic_path(controller_name.singularize, id: account.id), :class => 'btn btn-primary', :remote => true) %>
|
@@ -24,29 +25,31 @@
|
|
24
25
|
<div class="col-md-4">
|
25
26
|
<div class="row">
|
26
27
|
<div class="col-md-6"><b><%= account.class.human_attribute_name(:login) %></b></div>
|
27
|
-
<div class="col-md-6"><span
|
28
|
+
<div class="col-md-6"><span><%= account.login %></span></div>
|
28
29
|
</div>
|
29
30
|
</div>
|
30
31
|
<div class="col-md-4">
|
31
32
|
<div class="row">
|
32
33
|
<div class="col-md-6"><b><%= account.class.human_attribute_name(:email) %></b></div>
|
33
|
-
<div class="col-md-6"><span
|
34
|
+
<div class="col-md-6"><span><%= account.format_value(:email, self) %></span></div>
|
34
35
|
</div>
|
35
36
|
</div>
|
36
37
|
</div>
|
37
38
|
|
38
39
|
<div id="customer_detail" style="display: none">
|
39
40
|
<div class="clearfix">
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
<b class="col-xs-6"><%= account.class.human_attribute_name(:current_login_at) %></b>
|
42
|
+
<div class="col-xs-6"><%= account.current_login_at ? time_tag(account.current_login_at) : '-' %></div>
|
43
|
+
<b class="col-xs-6"><%= account.class.human_attribute_name(:current_login_ip) %></b>
|
44
|
+
<div class="col-xs-6"><%= account.current_login_ip || '-' %></div>
|
45
|
+
<b class="col-xs-6"><%= account.class.human_attribute_name(:last_login_at) %></b>
|
46
|
+
<div class="col-xs-6"><%= account.last_login_at ? time_tag(account.last_login_at.localtime) : '-' %></div>
|
47
|
+
<b class="col-xs-6"><%= account.class.human_attribute_name(:last_login_ip) %></b>
|
48
|
+
<div class="col-xs-6"><%= account.last_login_ip || '-' %></div>
|
49
|
+
<b class="col-xs-6"><%= account.class.human_attribute_name(:single_access_token) %></b>
|
50
|
+
<div class="col-xs-6">
|
51
|
+
<%= text_field_tag(:token, account.single_access_token, style: 'border:none') %>
|
52
|
+
</div>
|
50
53
|
</div>
|
51
54
|
</div>
|
52
55
|
|
@@ -54,7 +57,7 @@
|
|
54
57
|
SymphoniaUserDetail = {
|
55
58
|
popup: {
|
56
59
|
dialog: null,
|
57
|
-
show: function() {
|
60
|
+
show: function () {
|
58
61
|
if (!this.dialog) {
|
59
62
|
this.dialog = new SymphoniaDialog("customer_detail");
|
60
63
|
}
|
@@ -62,4 +65,4 @@
|
|
62
65
|
}
|
63
66
|
}
|
64
67
|
};
|
65
|
-
</script>
|
68
|
+
</script>
|
@@ -1,23 +1,23 @@
|
|
1
1
|
<% if @query %>
|
2
2
|
<%#= bootstrap_form_tag(url: {set_filter: 1}, method: :get, class: 'form-horizontal', id: 'symphonia_filters_form') do |f| %>
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
</div>
|
14
|
-
|
3
|
+
<div class="row hidden-print">
|
4
|
+
<% if @query.search? %>
|
5
|
+
<div class="col-sm-12">
|
6
|
+
<div class="input-group input-group-sm">
|
7
|
+
<%= search_field_tag(:q, params[:q], class: 'form-control input-sm', id: 'symphonia_query_q', placeholder: t(:label_search), autofocus: params[:q].present? || nil, data: { remote: local_assigns[:remote] }, onchange: 'submitSymphoniaQueryQ(this)') %>
|
8
|
+
<div class="input-group-append">
|
9
|
+
<div class="input-group-text">
|
10
|
+
<%= link_to(icon('search'), 'javascript:void(0)', { onclick: 'Symphonia.filters.search(document.getElementById("symphonia_query_q"))', title: t(:button_search) }) %>
|
11
|
+
<%= link_to(icon('filter'), symphonia.filters_options_path(@query.model.name, @query.to_params.merge(path: j(request.url))), remote: true, title: t(:title_advanced_filters)) unless local_assigns.key?(:hide_advanced_filter) %>
|
12
|
+
<%= link_to(icon('false'), 'javascript:void(0)', onclick: 'Symphonia.filters.resetSearch(document.getElementById("symphonia_query_q"))') if params[:q] %>
|
15
13
|
</div>
|
14
|
+
|
16
15
|
</div>
|
17
16
|
</div>
|
18
|
-
|
19
|
-
|
17
|
+
</div>
|
18
|
+
<% end %>
|
19
|
+
</div>
|
20
20
|
<%# end %>
|
21
21
|
<% else %>
|
22
|
-
<%=
|
22
|
+
<%= render_no_data t(:text_error_query_not_init) %>
|
23
23
|
<% end -%>
|
@@ -1,5 +1,4 @@
|
|
1
1
|
<span class="share-buttons">
|
2
|
-
<%= link_to(
|
3
|
-
<%= link_to(
|
4
|
-
<%= link_to(fa_icon("google-plus-square #{icon_css}"), "https://plus.google.com/share?url=#{url}", :title => t(:google_plus, :scope => [:share_on, :title]), :target => '_blank') %>
|
2
|
+
<%= link_to(icon("facebook-square #{icon_css}"), "http://www.facebook.com/share.php?u=#{url}&title=#{name}", title: t("share_on.title.facebook"), target: '_blank') %>
|
3
|
+
<%= link_to(icon("twitter-square #{icon_css}"), "http://twitter.com/home?status=#{name}+#{url}", title: t("share_on.title.twitter"), target: '_blank') %>
|
5
4
|
</span>
|
@@ -2,12 +2,7 @@
|
|
2
2
|
<% if Symphonia::User.current.admin? %>
|
3
3
|
<div class="row justify-content-center">
|
4
4
|
<div class="col-8">
|
5
|
-
<%= f.check_box :admin, id: 'user_admin'
|
5
|
+
<%= f.check_box :admin, id: 'user_admin' %>
|
6
6
|
</div>
|
7
|
-
<% if @roles.any? %>
|
8
|
-
<div class="col-9">
|
9
|
-
<%= f.select(:role_id, options_from_collection_for_select(@roles, :id, :name, selected: @user.role_id), include_blank: true, layout: :horizontal) %>
|
10
|
-
</div>
|
11
|
-
<% end -%>
|
12
7
|
</div>
|
13
8
|
<% end %>
|
@@ -5,17 +5,12 @@
|
|
5
5
|
<h4 class="card-title"><%= html_title(@user.name).join %></h4>
|
6
6
|
<div class="card-text row">
|
7
7
|
<div class="col-sm-8">
|
8
|
-
<% %i
|
8
|
+
<% %i[login email admin].each do |attribute| %>
|
9
9
|
<% next if @user.send(attribute).to_s.blank? %>
|
10
10
|
<dt><%= @user.class.human_attribute_name attribute %></dt>
|
11
11
|
<dd><%= @user.format_value(attribute, self) %></dd>
|
12
12
|
<% end %>
|
13
13
|
|
14
|
-
<% if @user.role %>
|
15
|
-
<dt><%= @user.class.human_attribute_name :role %></dt>
|
16
|
-
<dd><%= @user.format_value(:role, Symphonia::User.current.admin? && self || nil) %></dd>
|
17
|
-
<% end %>
|
18
|
-
|
19
14
|
<% if @user.preferences.any? %>
|
20
15
|
<dt><%= t(:label_user_notifications) %></dt>
|
21
16
|
<% @user.preferences.each do |p| %>
|
@@ -25,20 +20,20 @@
|
|
25
20
|
</div>
|
26
21
|
<div class="col-sm-4">
|
27
22
|
|
28
|
-
<% if
|
23
|
+
<% if can? :edit, @user %>
|
29
24
|
<%= link_to(icon('edit', t(:button_edit)), edit_user_path(@user), class: 'btn btn-primary btn-block') %>
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
<%
|
41
|
-
<%= link_to(icon('
|
25
|
+
<% end %>
|
26
|
+
<% if can? :archive, @user %>
|
27
|
+
<%= link_to(icon('lock', t(:button_archive)), archive_user_path(@user, back_url: polymorphic_path(@user)), data: { method: 'post', confirm: t(:text_are_you_sure) }, class: 'btn btn-secondary btn-block') %>
|
28
|
+
<% end %>
|
29
|
+
<% if can? :activate, @user %>
|
30
|
+
<%= link_to(icon('bolt', t(:button_active)), unarchive_user_path(@user, back_url: polymorphic_path(@user)), class: 'btn btn-secondary btn-block', data: { method: 'post', confirm: t(:text_are_you_sure) + "\n #{t(:text_confirm_send_unlock_mail)}" }) %>
|
31
|
+
<% end %>
|
32
|
+
<% if can? :unarchive, @user %>
|
33
|
+
<%= link_to(icon('unlock', t(:button_unarchive)), unarchive_user_path(@user, back_url: polymorphic_path(@user)), class: 'btn btn-secondary btn-block', data: { method: 'post', confirm: t(:text_are_you_sure) + "\n #{t(:text_confirm_send_unlock_mail)}" }) %>
|
34
|
+
<% end %>
|
35
|
+
<% if can? :destroy, @user %>
|
36
|
+
<%= link_to(icon('delete', t(:button_delete)), @user, class: 'btn btn-danger btn-block', method: 'delete', data: { confirm: t(:text_are_you_sure) }) %>
|
42
37
|
<% end %>
|
43
38
|
<%= link_to(icon('key', t(:detail)), 'javascript:void(0)', onclick: %q{Symphonia.dialog.show('customer_detail')}, class: 'btn btn-info btn-block') %>
|
44
39
|
</div>
|
@@ -60,4 +55,4 @@
|
|
60
55
|
<%= content_tag(:strong, @user.class.human_attribute_name(:single_access_token), :class => 'col-xs-6') %>
|
61
56
|
<%= content_tag(:div, text_field_tag(:token, @user.single_access_token, :style => 'border:none'), :class => 'col-xs-6') %>
|
62
57
|
</div>
|
63
|
-
</div>
|
58
|
+
</div>
|
data/config/locales/cs.yml
CHANGED
@@ -25,8 +25,9 @@ cs:
|
|
25
25
|
present: Současnot
|
26
26
|
future: Budoucnost
|
27
27
|
formats:
|
28
|
-
default: "%d. %B %Y %H:%M"
|
28
|
+
# default: "%d. %B %Y %H:%M"
|
29
29
|
short: "%-d. %-m. %Y %H:%M"
|
30
|
+
long: "%-d. %-m. %Y %H:%M"
|
30
31
|
attributes:
|
31
32
|
updated_at: Aktualizováno
|
32
33
|
created_at: Vytvořeno
|
@@ -50,7 +51,7 @@ cs:
|
|
50
51
|
attachment: Příloha
|
51
52
|
errors:
|
52
53
|
template:
|
53
|
-
body: "Formulář obsahuje
|
54
|
+
body: "Formulář obsahuje chyby:"
|
54
55
|
attributes:
|
55
56
|
attachment:
|
56
57
|
attachment_file_name: Název souboru
|
data/db/seeds.rb
CHANGED
@@ -3,11 +3,11 @@ u.attributes = {
|
|
3
3
|
login: 'admin',
|
4
4
|
first_name: 'Lukáš',
|
5
5
|
last_name: 'Pokorný',
|
6
|
-
email: 'luk4s.
|
6
|
+
email: 'admin@luk4s.cz',
|
7
7
|
password: 'admin',
|
8
8
|
# password_confirmation: 'admin',
|
9
9
|
admin: true,
|
10
|
-
avatar_url: "https://secure.gravatar.com/avatar/3657d5f0e9747c1c21eb2b689a8dba0b?s=64"
|
10
|
+
avatar_url: "https://secure.gravatar.com/avatar/3657d5f0e9747c1c21eb2b689a8dba0b?s=64",
|
11
11
|
}
|
12
12
|
u.single_access_token = SecureRandom.hex(20)
|
13
|
-
u.save!(validate: false)
|
13
|
+
u.save!(validate: false) if Symphonia::User.where(login: "admin").none?
|
@@ -19,7 +19,7 @@ module Generators
|
|
19
19
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
20
20
|
|
21
21
|
def create_controller_files
|
22
|
-
template_file = options.api? ? "api_controller.rb" : "controller.rb"
|
22
|
+
template_file = options.api? ? "api_controller.rb.tt" : "controller.rb.tt"
|
23
23
|
template template_file, File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
|
24
24
|
end
|
25
25
|
|
@@ -45,4 +45,4 @@ module Generators
|
|
45
45
|
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
data/lib/generators/symphonia/entity_controller/templates/{controller.rb → controller.rb.tt}
RENAMED
File without changes
|
@@ -4,7 +4,7 @@ module Symphonia
|
|
4
4
|
def matches?(request)
|
5
5
|
return false if (credentials = request.session["symphonia/user_credentials"]).blank?
|
6
6
|
|
7
|
-
user = User.
|
7
|
+
user = User.find_by(persistence_token: credentials.split(':')[0])
|
8
8
|
user&.admin?
|
9
9
|
end
|
10
10
|
|
@@ -13,16 +13,14 @@ module Symphonia
|
|
13
13
|
# %i[]
|
14
14
|
# end
|
15
15
|
#
|
16
|
-
|
17
|
-
# false # => for disable swagger
|
18
|
-
# "/my-custom-path" # => for custom route
|
19
|
-
# end
|
16
|
+
|
20
17
|
module BaseController
|
18
|
+
|
21
19
|
extend ActiveSupport::Concern
|
22
20
|
|
23
21
|
included do
|
24
22
|
# before_action :authorize
|
25
|
-
before_action :find_entity, only: [
|
23
|
+
before_action :find_entity, only: %i[show edit update destroy]
|
26
24
|
|
27
25
|
include Rails::Pagination
|
28
26
|
helper Symphonia::BootstrapModalHelper
|
@@ -30,11 +28,9 @@ module Symphonia
|
|
30
28
|
|
31
29
|
# @param [Class] model
|
32
30
|
class_attribute :model
|
33
|
-
|
34
31
|
end
|
35
32
|
|
36
33
|
class_methods do
|
37
|
-
|
38
34
|
# def model=(klass)
|
39
35
|
# @model = klass
|
40
36
|
# end
|
@@ -76,11 +72,11 @@ module Symphonia
|
|
76
72
|
end
|
77
73
|
|
78
74
|
def new
|
79
|
-
@entity ||= instance_variable_set(:"@#{model_name}",
|
75
|
+
@entity ||= instance_variable_set(:"@#{model_name}",
|
76
|
+
model.new(params.fetch(model_name, {}).permit(safe_attributes)))
|
80
77
|
end
|
81
78
|
|
82
|
-
def edit
|
83
|
-
end
|
79
|
+
def edit; end
|
84
80
|
|
85
81
|
def create
|
86
82
|
@entity ||= instance_variable_set(:"@#{model_name}", model.new(entity_params))
|
@@ -119,7 +115,7 @@ module Symphonia
|
|
119
115
|
end
|
120
116
|
|
121
117
|
def model_name
|
122
|
-
model.name.demodulize.underscore
|
118
|
+
model.name.demodulize.underscore
|
123
119
|
end
|
124
120
|
|
125
121
|
private
|
@@ -138,13 +134,9 @@ module Symphonia
|
|
138
134
|
params.require(model_name).permit(safe_attributes)
|
139
135
|
end
|
140
136
|
|
141
|
-
def after_create
|
142
|
-
|
143
|
-
end
|
137
|
+
def after_create; end
|
144
138
|
|
145
|
-
def after_update
|
146
|
-
|
147
|
-
end
|
139
|
+
def after_update; end
|
148
140
|
|
149
141
|
end
|
150
142
|
end
|
@@ -17,7 +17,7 @@ module Symphonia
|
|
17
17
|
add_flash_types :error
|
18
18
|
|
19
19
|
rescue_from ::ActiveRecord::RecordNotFound, with: :render_404
|
20
|
-
rescue_from Unauthorized, with: :render_403
|
20
|
+
rescue_from Unauthorized, CanCan::AccessDenied, with: :render_403
|
21
21
|
|
22
22
|
helper_method :current_user, :back_url
|
23
23
|
end
|
@@ -117,7 +117,7 @@ module Symphonia
|
|
117
117
|
|
118
118
|
# Renders a 200 response for successful updates or deletions via the API
|
119
119
|
def render_api_ok
|
120
|
-
|
120
|
+
render_api_head :ok
|
121
121
|
end
|
122
122
|
|
123
123
|
# Renders a head API response
|
@@ -143,20 +143,10 @@ module Symphonia
|
|
143
143
|
end
|
144
144
|
|
145
145
|
def authorize
|
146
|
-
if Symphonia::User.current.
|
147
|
-
|
148
|
-
elsif Symphonia::User.current.logged_in?
|
149
|
-
raise Unauthorized
|
150
|
-
else
|
151
|
-
respond_to do |format|
|
152
|
-
format.html do
|
153
|
-
return redirect_to(symphonia.login_path(back_url: request.path), error: t(:text_error_login_required))
|
154
|
-
end
|
155
|
-
format.any { return head 401 }
|
156
|
-
end
|
157
|
-
end
|
146
|
+
return true if Symphonia::User.current.admin?
|
147
|
+
raise Unauthorized if Symphonia::User.current.logged_in?
|
158
148
|
|
159
|
-
|
149
|
+
login_require
|
160
150
|
end
|
161
151
|
|
162
152
|
def handle_unverified_request
|
data/lib/symphonia/engine.rb
CHANGED
@@ -1,51 +1,37 @@
|
|
1
1
|
require 'symphonia/object'
|
2
|
-
require 'symphonia/menu_manager'
|
3
|
-
require 'symphonia/permissions'
|
4
|
-
require 'symphonia/user_management'
|
5
2
|
|
6
|
-
require 'rails-i18n'
|
7
|
-
require 'turbolinks'
|
8
3
|
require 'authlogic'
|
4
|
+
require 'cancancan'
|
9
5
|
require 'scrypt'
|
10
|
-
require 'bootstrap'
|
11
6
|
|
12
7
|
require 'will_paginate'
|
13
8
|
require 'api-pagination'
|
14
|
-
|
15
|
-
require '
|
16
|
-
require 'jquery-ui-rails'
|
9
|
+
|
10
|
+
require 'rails_i18n'
|
17
11
|
require 'rdiscount'
|
18
12
|
require 'sortable-table'
|
19
13
|
require 'bootstrap_form'
|
20
|
-
require 'bootstrap-datepicker-rails'
|
21
|
-
# require 'wicked_pdf'
|
22
|
-
# require 'swagger/blocks'
|
23
14
|
|
24
15
|
module Symphonia
|
25
16
|
|
26
17
|
class Engine < ::Rails::Engine
|
27
18
|
isolate_namespace Symphonia
|
28
19
|
|
20
|
+
config.autoload_paths << File.expand_path("..", __dir__)
|
21
|
+
|
29
22
|
config.generators do |g|
|
30
23
|
g.test_framework :rspec, fixture: false
|
31
24
|
g.fixture_replacement :factory_bot, dir: 'spec/factories'
|
32
25
|
end
|
33
26
|
|
34
|
-
# Rails 5
|
35
|
-
# ActionController::Base.class_eval do
|
36
|
-
# include Symphonia::ApplicationController
|
37
|
-
# end
|
38
|
-
|
39
|
-
|
40
27
|
initializer :symphonia_extensions do
|
28
|
+
ActiveSupport.on_load(:action_controller_base) do
|
29
|
+
# prepend Symphonia::ApplicationController
|
30
|
+
helper Symphonia::ApplicationHelper
|
31
|
+
helper Symphonia::BootstrapModalHelper
|
32
|
+
end
|
41
33
|
end
|
42
34
|
|
43
|
-
# ActiveSupport::Reloader.to_prepare do
|
44
|
-
# ::ApplicationController.send :helper, Symphonia::ApplicationHelper
|
45
|
-
# ::ApplicationMailer.send :helper, Symphonia::ApplicationHelper
|
46
|
-
# BootstrapForm::FormBuilder.prepend(Symphonia::FormBuilder)
|
47
|
-
# end
|
48
|
-
|
49
35
|
initializer :symphonia_setup do |_app|
|
50
36
|
Mime::Type.register 'application/pdf', :pdf
|
51
37
|
config.i18n.available_locales ||= %i[cs en]
|
@@ -69,31 +55,13 @@ module Symphonia
|
|
69
55
|
end
|
70
56
|
end
|
71
57
|
|
72
|
-
# include helpers
|
73
58
|
initializer :load_helper, before: :load_config_initializers do |app|
|
74
|
-
# config.active_record.raise_in_transactional_callbacks = false
|
75
59
|
if Rails.env.development?
|
76
60
|
config.action_mailer.default_url_options ||= { host: 'symphonia.app' }
|
77
61
|
config.action_mailer.preview_path = "{#{app.root.join('spec/mailers/previews')},#{root.join('spec/mailers/previews')}}"
|
78
62
|
end
|
79
63
|
end
|
80
64
|
|
81
|
-
initializer :assets do |_app|
|
82
|
-
config.assets.precompile << 'symphonia/application.css'
|
83
|
-
#if defined?(::Ckeditor)
|
84
|
-
# config.assets.precompile << 'ckeditor/**/*'
|
85
|
-
# config.assets.precompile << 'symphonia/symphonia_ckeditor.js'
|
86
|
-
#end
|
87
|
-
end
|
88
|
-
|
89
|
-
initializer :symphonia_general_permissions do |_app|
|
90
|
-
Symphonia::Permissions.map do |m|
|
91
|
-
m.register(:view_users).add(:users, %i[index show])
|
92
|
-
m.register(:manage_users).add(:users, %i[create update destroy new edit])
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
65
|
# initializer :wicked_pdf do |_app|
|
98
66
|
# WickedPdf.config = {
|
99
67
|
# layout: 'application.pdf',
|