pageflow 15.2.2 → 15.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pageflow might be problematic. Click here for more details.

Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +338 -85
  3. data/admins/pageflow/accounts.rb +1 -98
  4. data/admins/pageflow/entry.rb +21 -1
  5. data/admins/pageflow/entry_templates.rb +140 -0
  6. data/admins/pageflow/membership.rb +12 -0
  7. data/admins/pageflow/user.rb +5 -3
  8. data/app/assets/javascripts/pageflow/admin/entries.js +65 -0
  9. data/app/assets/javascripts/pageflow/admin/users.js +1 -1
  10. data/app/assets/javascripts/pageflow/asset_urls.js.erb +1 -0
  11. data/app/assets/javascripts/pageflow/base.js +0 -12
  12. data/app/assets/javascripts/pageflow/components.js +2 -6
  13. data/app/assets/javascripts/pageflow/dist/ui.js +47 -14
  14. data/app/assets/javascripts/pageflow/vendor.js +13 -10
  15. data/app/assets/stylesheets/pageflow/base.scss +0 -7
  16. data/app/assets/stylesheets/pageflow/editor/base.scss +2 -0
  17. data/app/assets/stylesheets/pageflow/editor/composables.scss +5 -1
  18. data/app/assets/stylesheets/pageflow/editor/emulation_mode_button.scss +44 -55
  19. data/app/assets/stylesheets/pageflow/editor/help.scss +2 -2
  20. data/app/assets/stylesheets/pageflow/ui/tooltip.scss +17 -3
  21. data/app/helpers/pageflow/admin/entries_helper.rb +16 -0
  22. data/app/helpers/pageflow/structured_data_helper.rb +0 -2
  23. data/app/models/pageflow/account.rb +21 -1
  24. data/app/models/pageflow/entry.rb +9 -2
  25. data/app/models/pageflow/entry_duplicate.rb +1 -0
  26. data/app/models/pageflow/entry_template.rb +16 -2
  27. data/app/policies/pageflow/account_policy.rb +10 -0
  28. data/app/policies/pageflow/entry_template_policy.rb +5 -1
  29. data/app/views/admin/accounts/_entry_template_details.html.arb +7 -5
  30. data/app/views/admin/accounts/_form.html.erb +3 -49
  31. data/app/views/admin/entries/_attributes_table.html.arb +5 -0
  32. data/app/views/admin/entries/_not_allowed_to_see_entry_types.json.jbuilder +2 -0
  33. data/app/views/admin/entries/entry_types.json.jbuilder +4 -0
  34. data/app/views/admin/entry_templates/_form.html.erb +58 -0
  35. data/app/views/admin/users/_not_allowed_to_see_user_quota.html.erb +3 -0
  36. data/app/views/components/pageflow/admin/entry_templates_tab.rb +48 -0
  37. data/app/views/pageflow/admin/users/_quota_exhausted.html.erb +1 -1
  38. data/config/initializers/admin_resource_tabs.rb +5 -0
  39. data/config/initializers/help_entries.rb +1 -5
  40. data/config/locales/de.yml +88 -155
  41. data/config/locales/en.yml +79 -143
  42. data/db/migrate/20200515112500_add_constraints_to_entry_templates.rb +21 -0
  43. data/db/migrate/20200807135200_rename_pageflow_entry_template_entry_type_to_entry_type_name.rb +7 -0
  44. data/entry_types/paged/app/assets/javascripts/pageflow_paged/components.js +7 -0
  45. data/entry_types/paged/app/assets/javascripts/pageflow_paged/dist/editor.js +1479 -1391
  46. data/entry_types/paged/app/assets/javascripts/pageflow_paged/dist/frontend.js +9218 -0
  47. data/{app/assets/javascripts/pageflow → entry_types/paged/app/assets/javascripts/pageflow_paged}/dist/react-client.js +1 -1
  48. data/{app/assets/javascripts/pageflow → entry_types/paged/app/assets/javascripts/pageflow_paged}/dist/react-server.js +3 -3
  49. data/entry_types/paged/app/assets/javascripts/pageflow_paged/frontend.js +6 -0
  50. data/entry_types/paged/app/assets/javascripts/pageflow_paged/server_rendering.js +9 -0
  51. data/entry_types/paged/app/assets/javascripts/pageflow_paged/vendor.js +8 -0
  52. data/entry_types/paged/app/controllers/pageflow_paged/application_controller.rb +2 -2
  53. data/{app/helpers/pageflow → entry_types/paged/app/helpers/pageflow_paged}/page_background_asset_helper.rb +4 -3
  54. data/{app/helpers/pageflow → entry_types/paged/app/helpers/pageflow_paged}/react_server_side_rendering_helper.rb +23 -2
  55. data/entry_types/paged/app/views/layouts/pageflow_paged/application.html.erb +2 -2
  56. data/entry_types/paged/app/views/pageflow_paged/editor/entries/_head.html.erb +2 -2
  57. data/entry_types/paged/app/views/pageflow_paged/entries/_entry.html.erb +1 -1
  58. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/page_background_asset/_element.html.erb +0 -0
  59. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/react/_widget.html.erb +0 -0
  60. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/react/page.html.erb +0 -0
  61. data/entry_types/paged/config/initializers/features.rb +1 -1
  62. data/entry_types/paged/config/initializers/help_entries.rb +17 -0
  63. data/entry_types/paged/config/locales/new/help.de.yml +162 -0
  64. data/entry_types/paged/config/locales/new/help.en.yml +153 -0
  65. data/entry_types/paged/lib/pageflow_paged/engine.rb +13 -0
  66. data/entry_types/paged/lib/pageflow_paged/plugin.rb +5 -1
  67. data/entry_types/paged/lib/pageflow_paged/react.rb +12 -0
  68. data/{lib/pageflow → entry_types/paged/lib/pageflow_paged}/react/page_type.rb +2 -2
  69. data/{lib/pageflow → entry_types/paged/lib/pageflow_paged}/react/widget_type.rb +2 -2
  70. data/entry_types/paged/vendor/assets/javascripts/development/pageflow_paged/vendor/react-server.js +20613 -0
  71. data/entry_types/paged/vendor/assets/javascripts/development/pageflow_paged/vendor/react.js +21495 -0
  72. data/entry_types/paged/vendor/assets/javascripts/production/pageflow_paged/vendor/react-server.js +24 -0
  73. data/entry_types/paged/vendor/assets/javascripts/production/pageflow_paged/vendor/react.js +24 -0
  74. data/entry_types/scrolled/app/assets/javascripts/pageflow_scrolled/legacy.js +0 -0
  75. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb +2 -2
  76. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/content_elements_controller.rb +14 -4
  77. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb +2 -2
  78. data/entry_types/scrolled/app/controllers/pageflow_scrolled/entries_controller.rb +8 -0
  79. data/entry_types/scrolled/app/helpers/pageflow_scrolled/editor/seed_html_helper.rb +6 -0
  80. data/entry_types/scrolled/app/helpers/pageflow_scrolled/entry_json_seed_helper.rb +2 -0
  81. data/entry_types/scrolled/app/helpers/pageflow_scrolled/react_server_side_rendering_helper.rb +33 -0
  82. data/entry_types/scrolled/app/helpers/pageflow_scrolled/themes_helper.rb +8 -0
  83. data/entry_types/scrolled/app/models/pageflow_scrolled/content_element.rb +38 -0
  84. data/entry_types/scrolled/app/views/pageflow_scrolled/editor/content_elements/batch.json.jbuilder +2 -0
  85. data/entry_types/scrolled/app/views/pageflow_scrolled/editor/entries/_head.html.erb +1 -7
  86. data/entry_types/scrolled/app/views/pageflow_scrolled/entries/show.html.erb +19 -3
  87. data/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder +3 -0
  88. data/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_theme.json.jbuilder +7 -0
  89. data/entry_types/scrolled/config/initializers/help_entries.rb +16 -0
  90. data/entry_types/scrolled/config/locales/new/de.yml +345 -13
  91. data/entry_types/scrolled/config/locales/new/en.yml +257 -14
  92. data/entry_types/scrolled/config/routes.rb +1 -0
  93. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/install_generator.rb +28 -0
  94. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/logoDesktop.svg +56 -0
  95. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/templates/theme/logoMobile.svg +22 -0
  96. data/entry_types/scrolled/lib/pageflow_scrolled/engine.rb +4 -0
  97. data/entry_types/scrolled/lib/pageflow_scrolled/plugin.rb +3 -1
  98. data/entry_types/scrolled/lib/pageflow_scrolled/seeds.rb +90 -30
  99. data/entry_types/scrolled/lib/tasks/pageflow_scrolled_tasks.rake +64 -27
  100. data/entry_types/scrolled/package/contentElements-editor.js +242 -183
  101. data/entry_types/scrolled/package/contentElements-frontend.css +1 -0
  102. data/entry_types/scrolled/package/contentElements-frontend.js +624 -279
  103. data/entry_types/scrolled/package/editor.js +2561 -363
  104. data/entry_types/scrolled/package/frontend-server.js +228 -0
  105. data/entry_types/scrolled/package/frontend/EditableText-4264c349.js +1993 -0
  106. data/entry_types/scrolled/package/frontend/Wavesurfer-c3c45324.js +378 -0
  107. data/entry_types/scrolled/package/frontend/components-cfe6a479.js +2115 -0
  108. data/entry_types/scrolled/package/frontend/getPrototypeOf-63c7c8e8.js +86 -0
  109. data/entry_types/scrolled/package/frontend/index.css +9 -0
  110. data/entry_types/scrolled/package/frontend/index.js +4425 -0
  111. data/entry_types/scrolled/package/package.json +17 -6
  112. data/entry_types/scrolled/spec/fixtures/audio.m4a +0 -0
  113. data/entry_types/scrolled/spec/fixtures/video.mp4 +0 -0
  114. data/lib/generators/pageflow/initializer/templates/pageflow.rb +20 -9
  115. data/lib/pageflow/ability_mixin.rb +14 -2
  116. data/lib/pageflow/configuration.rb +6 -5
  117. data/lib/pageflow/engine.rb +1 -0
  118. data/lib/pageflow/entry_type_configuration.rb +1 -0
  119. data/lib/pageflow/global_config_api.rb +5 -4
  120. data/lib/pageflow/react.rb +4 -2
  121. data/lib/pageflow/version.rb +1 -1
  122. data/{packages/pageflow → package}/config/jest/index.js +2 -1
  123. data/{packages/pageflow → package}/config/jest/transformers/jst.js +0 -0
  124. data/{packages/pageflow → package}/config/jest/transformers/upwardBabel.js +0 -0
  125. data/package/config/webpack.js +22 -0
  126. data/{packages/pageflow → package}/editor.js +480 -1129
  127. data/package/frontend.js +2525 -0
  128. data/{packages/pageflow → package}/package.json +3 -0
  129. data/{packages/pageflow → package}/testHelpers.js +114 -13
  130. data/{packages/pageflow → package}/ui.js +47 -14
  131. data/spec/factories/accounts.rb +3 -1
  132. data/spec/factories/entry_templates.rb +1 -0
  133. data/spec/factories/published_entries.rb +6 -1
  134. metadata +62 -26
  135. data/app/assets/javascripts/pageflow/dist/frontend.js +0 -5800
  136. data/config/initializers/entry_types.rb +0 -4
  137. data/entry_types/scrolled/package/frontend.js +0 -2879
  138. data/packages/pageflow/config/jest/transformers/cssModules.js +0 -1
  139. data/packages/pageflow/config/webpack.js +0 -14
@@ -30,9 +30,6 @@ module Pageflow
30
30
  membership_role_with_tooltip(own_role, scope: 'own_account_role')
31
31
  end
32
32
  end
33
- column :default_theming do |account|
34
- account.first_paged_entry_template.theme_name if authorized?(:read, account)
35
- end
36
33
  end
37
34
 
38
35
  csv do
@@ -63,7 +60,6 @@ module Pageflow
63
60
  show :title => :name do |account|
64
61
  render 'account_details', :account => account
65
62
  render 'theming_details', :account => account
66
- render 'entry_template_details', account: account
67
63
 
68
64
  tabs_view(Pageflow.config.admin_resource_tabs.find_by_resource(account.default_theming),
69
65
  i18n: 'pageflow.admin.resource_tabs',
@@ -76,76 +72,25 @@ module Pageflow
76
72
  helper Pageflow::Admin::FormHelper
77
73
  helper Pageflow::Admin::LocalesHelper
78
74
  helper Pageflow::Admin::MembershipsHelper
79
- helper Pageflow::Admin::WidgetsHelper
80
75
  helper ThemesHelper
81
76
 
82
77
  def new
83
78
  @account = Account.new
84
79
  @account.build_default_theming
85
- @entry_template = @account.entry_templates.build(
86
- default_locale: current_user.locale,
87
- share_providers: Pageflow.config.default_share_providers,
88
- entry_type: 'paged'
89
- )
90
80
  end
91
81
 
92
82
  def create
93
- account_params = (permitted_params[:account] || {})
94
- .except(:paged_entry_template_attributes)
83
+ account_params = permitted_params[:account] || {}
95
84
  @account = Account.new(account_params)
96
85
  @account.build_default_theming(permitted_params.fetch(:account, {})[
97
86
  :default_theming_attributes])
98
- @entry_template = @account.entry_templates.build({entry_type: 'paged'}
99
- .merge(entry_template_params))
100
-
101
- super
102
- update_widgets('paged')
103
- end
104
-
105
- def edit
106
- @entry_template = resource.first_paged_entry_template
107
87
  super
108
88
  end
109
89
 
110
90
  def update
111
- @entry_template = resource.entry_templates.find_or_initialize_by(
112
- entry_type: 'paged'
113
- )
114
- @entry_template.assign_attributes(entry_template_params)
115
- @entry_template.save
116
91
  update! do |success, failure|
117
92
  success.html { redirect_to(admin_account_path(resource, params.permit(:tab))) }
118
93
  end
119
- update_widgets('paged')
120
- end
121
-
122
- def entry_template_params
123
- current_params = permitted_params_with_entry_template_attributes.fetch(:account, {})[
124
- :paged_entry_template_attributes]&.to_hash
125
- if current_params
126
- config = true_false_strings_to_booleans_or_numbers(
127
- current_params['configuration']
128
- )
129
- share_providers = true_false_strings_to_booleans_or_numbers(
130
- current_params['share_providers']
131
- )
132
- current_params.merge('configuration' => config, 'share_providers' => share_providers)
133
- else
134
- {}
135
- end
136
- end
137
-
138
- def update_widgets(entry_type)
139
- if @account.valid?
140
- EntryTemplate.find_by(account_id: @account.id, entry_type: entry_type)
141
- &.widgets&.batch_update!(widgets_params)
142
- end
143
- end
144
-
145
- def widgets_params
146
- (params[:widgets].try(:permit!).to_h || {}).map do |role, type_name|
147
- {role: role, type_name: type_name}
148
- end
149
94
  end
150
95
 
151
96
  def permitted_params
@@ -154,12 +99,6 @@ module Pageflow
154
99
  with_permitted_feature_states(result)
155
100
  end
156
101
 
157
- def permitted_params_with_entry_template_attributes
158
- result = params.permit(account: permitted_account_attributes_plus_entry_template)
159
-
160
- with_permitted_feature_states(result)
161
- end
162
-
163
102
  def scoped_collection
164
103
  super.includes(:default_theming)
165
104
  end
@@ -172,25 +111,6 @@ module Pageflow
172
111
  result
173
112
  end
174
113
 
175
- def true_false_strings_to_booleans_or_numbers(hash)
176
- hash&.map { |k, v| [k, to_boolean_or_number(v)] }&.to_h
177
- end
178
-
179
- def to_boolean_or_number(value)
180
- case value
181
- when 'false'
182
- false
183
- when 'true'
184
- true
185
- when '0'
186
- 0
187
- when '1'
188
- 1
189
- else
190
- value
191
- end
192
- end
193
-
194
114
  def permitted_account_attributes
195
115
  [
196
116
  :name,
@@ -200,11 +120,6 @@ module Pageflow
200
120
  permitted_attributes_for(:account)
201
121
  end
202
122
 
203
- def permitted_account_attributes_plus_entry_template
204
- permitted_account_attributes +
205
- [paged_entry_template_attributes: permitted_entry_template_attributes]
206
- end
207
-
208
123
  def permitted_theming_attributes
209
124
  [
210
125
  :cname,
@@ -219,18 +134,6 @@ module Pageflow
219
134
  permitted_attributes_for(:theming)
220
135
  end
221
136
 
222
- def permitted_entry_template_attributes
223
- [
224
- :theme_name,
225
- :default_author,
226
- :default_publisher,
227
- :default_keywords,
228
- :default_locale,
229
- share_providers: {},
230
- configuration: {}
231
- ]
232
- end
233
-
234
137
  def permitted_attributes_for(resource_name)
235
138
  if params[:id]
236
139
  Pageflow.config_for(resource).admin_form_inputs.permitted_attributes_for(resource_name)
@@ -130,6 +130,14 @@ module Pageflow
130
130
  input_html: {style: 'width: 200px'})
131
131
  end
132
132
 
133
+ if f.object.new_record?
134
+ f.input :type_name,
135
+ as: :select,
136
+ include_blank: false,
137
+ collection: entry_type_collection,
138
+ wrapper_html: {style: 'display: none'}
139
+ end
140
+
133
141
  if authorized?(:configure_folder_for, resource)
134
142
  folder_collection = collection_for_folders(resource.account, resource.folder)
135
143
  f.input(:folder,
@@ -168,6 +176,18 @@ module Pageflow
168
176
  end
169
177
  end
170
178
 
179
+ collection_action :entry_types do
180
+ account = Pageflow::Account.find(params[:account_id])
181
+
182
+ if authorized?(:see_entry_types, account)
183
+ @entry_types = helpers.entry_type_collection_for_account(account)
184
+
185
+ render(layout: false)
186
+ else
187
+ render(partial: 'not_allowed_to_see_entry_types', status: 403)
188
+ end
189
+ end
190
+
171
191
  member_action :duplicate, method: :post do
172
192
  entry = Entry.find(params[:id])
173
193
  authorize!(:duplicate, entry)
@@ -251,7 +271,7 @@ module Pageflow
251
271
  end
252
272
 
253
273
  def permitted_attributes
254
- result = [:title]
274
+ result = [:title, :type_name]
255
275
  target = if !params[:id] && current_user.admin?
256
276
  Account.first
257
277
  elsif params[:id]
@@ -0,0 +1,140 @@
1
+ module Pageflow
2
+ ActiveAdmin.register EntryTemplate, as: 'EntryTemplate' do
3
+ menu false
4
+ config.batch_actions = false
5
+ actions :index, :new, :create, :edit, :update
6
+ form partial: 'form'
7
+
8
+ belongs_to :account, parent_class: Pageflow::Account
9
+
10
+ breadcrumb do
11
+ breadcrumb_links.first 3
12
+ end
13
+
14
+ controller do
15
+ helper Pageflow::Admin::FormHelper
16
+ helper Pageflow::Admin::WidgetsHelper
17
+
18
+ def index
19
+ redirect_to redirect_path
20
+ end
21
+
22
+ def new
23
+ account = Account.find(params[:account_id])
24
+ @entry_template = EntryTemplate.new(
25
+ account: account,
26
+ entry_type_name: params[:entry_type_name]
27
+ )
28
+
29
+ @page_title = page_title('new', params[:entry_type_name])
30
+
31
+ super
32
+ end
33
+
34
+ def create
35
+ @entry_template = EntryTemplate.new(
36
+ entry_template_params.merge(account_id: permitted_params[:account_id])
37
+ )
38
+ @page_title = page_title('new', @entry_template.entry_type_name)
39
+ authorize!(:create, @entry_template)
40
+ create! { redirect_path }
41
+ update_widgets if @entry_template.errors.empty?
42
+ end
43
+
44
+ def edit
45
+ @page_title = page_title('edit', resource.entry_type_name)
46
+ super
47
+ end
48
+
49
+ def update
50
+ @entry_template = EntryTemplate.find(params[:id])
51
+ @entry_template.assign_attributes(entry_template_params)
52
+ @page_title = page_title('edit', @entry_template.entry_type_name)
53
+ params[:entry_template].delete('share_providers')
54
+ params[:entry_template].delete('configuration')
55
+ authorize!(:update, @entry_template)
56
+ update! { redirect_path }
57
+ update_widgets if @entry_template.errors.empty?
58
+ end
59
+
60
+ private
61
+
62
+ def page_title(rest_verb, entry_type_name)
63
+ "#{I18n.t('pageflow.admin.entry_templates.page_title.' + rest_verb)} "\
64
+ "#{I18n.t('activerecord.values.pageflow/entry.type_names.' + entry_type_name)}"
65
+ end
66
+
67
+ def permitted_params
68
+ params.permit(
69
+ :account_id,
70
+ entry_template: permitted_entry_template_attributes
71
+ )
72
+ end
73
+
74
+ def permitted_entry_template_attributes
75
+ [
76
+ :id,
77
+ :account_id,
78
+ :entry_type_name,
79
+ :theme_name,
80
+ :default_author,
81
+ :default_publisher,
82
+ :default_keywords,
83
+ :default_locale,
84
+ share_providers: {},
85
+ configuration: {}
86
+ ]
87
+ end
88
+
89
+ def redirect_path
90
+ admin_account_path(params[:account_id], tab: 'entry_templates')
91
+ end
92
+
93
+ def entry_template_params
94
+ current_params = permitted_params[:entry_template]&.to_hash
95
+
96
+ if current_params
97
+ config = true_false_strings_to_booleans_or_numbers(
98
+ current_params['configuration']
99
+ )
100
+ share_providers = true_false_strings_to_booleans_or_numbers(
101
+ current_params['share_providers']
102
+ )
103
+ current_params.merge('configuration' => config,
104
+ 'share_providers' => share_providers)
105
+ else
106
+ {}
107
+ end
108
+ end
109
+
110
+ def true_false_strings_to_booleans_or_numbers(hash)
111
+ hash&.map { |k, v| [k, to_boolean_or_number(v)] }&.to_h
112
+ end
113
+
114
+ def to_boolean_or_number(value)
115
+ case value
116
+ when 'false'
117
+ false
118
+ when 'true'
119
+ true
120
+ when '0'
121
+ 0
122
+ when '1'
123
+ 1
124
+ else
125
+ value
126
+ end
127
+ end
128
+
129
+ def update_widgets
130
+ resource.widgets&.batch_update!(widgets_params)
131
+ end
132
+
133
+ def widgets_params
134
+ (params[:widgets].try(:permit!).to_h || {}).map do |role, type_name|
135
+ {role: role, type_name: type_name}
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -64,6 +64,18 @@ module Pageflow
64
64
  end)
65
65
 
66
66
  controller do
67
+ # We put the `belongs_to` call in the controller block to work
68
+ # around the issue that ActiveAdmin does not yet support
69
+ # polymorphic nested resources [1]. This works since the
70
+ # underlying InheritedResources library does support polymorphic
71
+ # nesting [2]. As mentioned in the ActiveAdmin issue, we need to
72
+ # set up routes manually then, though. This is done in
73
+ # `Pageflow.routes` [3].
74
+ #
75
+ # [1] activeadmin/activeadmin#221
76
+ # [2] https://github.com/activeadmin/inherited_resources#polymorphic-belongs-to
77
+ # [3] https://github.com/codevise/pageflow/blob/023fdb7c5b3b917bb94f4adafa18a31f8bd9c753/lib/pageflow.rb#L10
78
+
67
79
  belongs_to :entry, parent_class: Pageflow::Entry, polymorphic: true
68
80
  belongs_to :account, parent_class: Pageflow::Account, polymorphic: true
69
81
  belongs_to :user, parent_class: User, polymorphic: true
@@ -122,9 +122,11 @@ module Pageflow
122
122
 
123
123
  collection_action :quota_state do
124
124
  @account = Pageflow::Account.find(params[:account_id])
125
- authorize!(:add_member_to, @account)
126
-
127
- render(layout: false)
125
+ if authorized?(:see_user_quota, @account)
126
+ render(layout: false)
127
+ else
128
+ render(partial: 'not_allowed_to_see_user_quota')
129
+ end
128
130
  end
129
131
 
130
132
  collection_action 'me', title: I18n.t('pageflow.admin.users.account'), method: [:get, :patch] do
@@ -85,4 +85,69 @@ jQuery(function($) {
85
85
  return $(folder).data('role') === 'all';
86
86
  }
87
87
  });
88
+
89
+ $('.admin_entries form.entry').each(function() {
90
+ var accountSelect = $('#entry_account_id', this);
91
+ var entryTypeInput = $('#entry_type_name_input', this);
92
+ var entryTypeSelect = $('#entry_type_name', this);
93
+ var entryTypeOptions = $('#entry_type_name option', this);
94
+
95
+ function updateEntryTypeOptions() {
96
+ var selectedAccountId = accountSelect.val();
97
+ hideAllOptions();
98
+
99
+ $.get('/admin/entries/entry_types?account_id=' + selectedAccountId)
100
+ .done(function(response) {
101
+ var typeNames = response.map(function(item) {
102
+ return item.type_name;
103
+ });
104
+ updateForm(typeNames);
105
+ if (currentSelectedUnavailable(typeNames)) {
106
+ updateSelected(typeNames[0]);
107
+ }
108
+ if (response.length < 2) {
109
+ hideInput();
110
+ } else {
111
+ showInput();
112
+ }
113
+ });
114
+ }
115
+
116
+ function updateForm(entryTypes) {
117
+ entryTypes.forEach(showOption);
118
+ }
119
+
120
+ function currentSelectedUnavailable(entryTypes) {
121
+ var selectedEntryType = entryTypeSelect.children('option:selected').val();
122
+
123
+ return !entryTypes.includes(selectedEntryType);
124
+ }
125
+
126
+ function updateSelected(firstAvailable) {
127
+ entryTypeSelect.val(firstAvailable);
128
+ }
129
+
130
+ function hideInput() {
131
+ entryTypeInput.hide();
132
+ }
133
+
134
+ function showInput() {
135
+ entryTypeInput.show();
136
+ }
137
+
138
+ function hideAllOptions() {
139
+ entryTypeOptions.each(function() {
140
+ $(this).hide();
141
+ });
142
+ }
143
+
144
+ function showOption(entryType) {
145
+ $('#entry_type_name option[value=' + entryType + ']').show();
146
+ }
147
+
148
+ if (entryTypeOptions.length > 1) {
149
+ accountSelect.on('change', updateEntryTypeOptions);
150
+ updateEntryTypeOptions();
151
+ }
152
+ });
88
153
  });