glib-web 3.27.0 → 3.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce0abd2e16afb07a3fd1a273acc664bde10d9355fb66e5aec0e26cb1fc568e9f
4
- data.tar.gz: e2c72cf8ff18e4ca3e711f8481a81fd7c03e5f3cea5b86da916bf6675a990af5
3
+ metadata.gz: 575e99be2d5c58f1f7c9422f254b6a4b5b24180c82b38496e84c8dec22c41bcc
4
+ data.tar.gz: 76e6c254672deb1e9cd34a9452978ef4c9c32fc276fb8ac3e1e6eec1cbe8df85
5
5
  SHA512:
6
- metadata.gz: 7b82ab5f93bf800bd5436c05e7e7ea1e54d3a9bf269a3d691f8a8591c31ab785bf6ed6d22b2992a0dee1de87b6efcc65358aaf4ac2a7de9804f5c056d6e7053a
7
- data.tar.gz: 594cfd8502b6d515bcab04423c8d327ffc5fddab9ce879d88f34a3ded04dcf500f77581f7865641b83877be90b2c5e29672a69e41888501f31de3b9569fc476b
6
+ metadata.gz: a32237713616d6611d7cc6e57f57d81e7ff02823a68ed1d633e5de7276d4894ce67f30ff1766bda40df3bde0d53a9d69db2c677b740b266ae040e98f91c72a0b
7
+ data.tar.gz: 5fb068a0f809fc0ab4245fcbf1116758c253b04629a378fe8bd262486dc18d55490ac1cd854e0b4c1494a98cc4414abb108eb7f60baf1a84752565f66b7049ff
@@ -57,6 +57,10 @@ module Glib::Auth
57
57
 
58
58
  end
59
59
 
60
+ def glib_raise_forbidden
61
+ raise UnauthorizedError
62
+ end
63
+
60
64
  private
61
65
  def raise_access_denied(record, policy)
62
66
  raise UnauthorizedError.new(record: record, policy: policy, query: "#{action_name}?")
@@ -11,28 +11,6 @@ module Glib::Auth
11
11
  params[:_dialog].present? # E.g. _dialog=v1
12
12
  end
13
13
 
14
- def __glib_error_dialog(title, message, bottom_views = [])
15
- {
16
- action: 'dialogs/show',
17
- # Don't show another dialog, just use the current one since it's a new dialog anyway, which means
18
- # that it wouldn't contain existing user data.
19
- updateExisting: glib_json_dialog_mode?,
20
- title: title,
21
- body: {
22
- childViews: [
23
- {
24
- view: 'label',
25
- text: message
26
- },
27
- ].concat(bottom_views),
28
- padding: {
29
- x: 20,
30
- y: 22,
31
- },
32
- }
33
- }
34
- end
35
-
36
14
  def json_ui_401_response(sign_in_url)
37
15
  {
38
16
  # Handle dialogs_open and windows_open
@@ -178,7 +178,7 @@ module Glib::Json::Libs
178
178
  # end
179
179
  # end
180
180
 
181
- def __glib_error_dialog(title, message)
181
+ def __glib_error_dialog(title, message, bottom_views = [])
182
182
  {
183
183
  action: 'dialogs/show',
184
184
  # Don't show another dialog, just use the current one since it's a new dialog anyway, which means
@@ -188,14 +188,21 @@ module Glib::Json::Libs
188
188
  body: {
189
189
  childViews: [
190
190
  {
191
- "view": "label",
192
- "text": message
193
- },
194
- ],
195
- "padding": {
196
- "x": 20,
197
- "y": 22,
198
- },
191
+ view: 'panels/vertical',
192
+ styleClasses: ['glib-error-dialog'],
193
+ childViews: [
194
+ {
195
+ view: 'label',
196
+ text: message
197
+ },
198
+ ].concat(bottom_views),
199
+ }
200
+ ]
201
+ # Set this in the project's custom CSS.
202
+ # padding: {
203
+ # x: 20,
204
+ # y: 22,
205
+ # },
199
206
  }
200
207
  }
201
208
  end
@@ -229,7 +236,9 @@ module Glib::Json::Libs
229
236
  end
230
237
 
231
238
  def json_ui_redirect_to(url)
232
- on_response = { action: 'windows/open', url: url }
239
+ # Use windows_reload instead of windows_open so clicking back will skip the bridging page.
240
+ # on_response = { action: 'windows/open', url: url }
241
+ on_response = { action: 'windows/reload', url: url }
233
242
 
234
243
  if glib_json_dialog_mode?
235
244
  # Only do this in dialog mode because this seems to add to the rendering time
@@ -308,7 +317,23 @@ module Glib::Json::Libs
308
317
  format.json do
309
318
  render json: {
310
319
  glib_json_dialog_mode? ? :onLoad : :onResponse => __glib_error_dialog(
311
- 'Your session has expired', 'Please refresh the page and retry.')
320
+ 'Your session has expired', 'Please refresh the page and retry.', [
321
+ {
322
+ view: 'button',
323
+ text: 'Refresh',
324
+ onClick: {
325
+ action: 'dialogs/close',
326
+ onClose: {
327
+ action: 'windows/reload',
328
+ onReload: {
329
+ action: 'snackbars/alert',
330
+ message: 'Refreshed. You can try again now.'
331
+ }
332
+ }
333
+ }
334
+ },
335
+ ]
336
+ )
312
337
  }
313
338
  end
314
339
  end
@@ -54,9 +54,11 @@ class Glib::JsonUi::ActionBuilder
54
54
  bool :updateExisting
55
55
  end
56
56
 
57
- # deprecated
57
+ # Deprecation canceled. This is still useful for a scenario where the previous dialog
58
+ # was unknown, so we simply want to reload its content.
58
59
  class Reload < Action
59
- panels_builder :content, :body
60
+ # Deprecated. Should just use dialogs_show or dialogs_open if
61
+ # these attributes are needed.
60
62
  string :url, cache: true
61
63
  bool :showClose # deprecated
62
64
  bool :disableCloseButton
@@ -68,6 +70,10 @@ class Glib::JsonUi::ActionBuilder
68
70
  action :onClose
69
71
  end
70
72
 
73
+ class CloseAll < Action
74
+ action :onClose
75
+ end
76
+
71
77
  class Oauth < Action
72
78
  hash :provider
73
79
  action :onSuccess
@@ -30,6 +30,18 @@ class Glib::JsonUi::ActionBuilder
30
30
  required :fallbackUrl
31
31
  end
32
32
 
33
+ class CloseWithOpen < Action
34
+ string :url
35
+ action :onOpen
36
+
37
+ required :url
38
+ end
39
+
40
+ class CloseAllWithOpen < Action
41
+ string :url
42
+ action :onOpen
43
+ end
44
+
33
45
  # Any component can listen to the refresh_state event and react appropriately.
34
46
  # E.g. Stripe credit card component can refresh its token to make sure it is not stale.
35
47
  class RefreshState < Action
@@ -107,6 +107,8 @@ module Glib
107
107
  json.url options[:url]
108
108
  json.inputName options[:inputName]
109
109
  json.strategy options[:strategy]
110
+ json.storagePrefix options[:storagePrefix]
111
+ json.metadata options[:metadata]
110
112
  end
111
113
  end
112
114
 
@@ -235,7 +237,7 @@ module Glib
235
237
  def form(options = {})
236
238
  form = Glib::JsonUi::ViewBuilder::Panels::Form.new(json, self)
237
239
  form.childViews(->(view_builder) { })
238
- panel_options = options.slice!(:url, :method, :local, :onSubmit, :paramNameForFormData, :model)
240
+ panel_options = options.slice!(:url, :method, :local, :onSubmit, :paramNameForFormData, :model, :onChange)
239
241
 
240
242
  json.fullPageForm do
241
243
  json.view 'panels/fullPageForm'
@@ -289,6 +289,8 @@ class Glib::JsonUi::ViewBuilder
289
289
  string :uploadIcon # deprecated
290
290
  hash :placeholderView
291
291
  hash :infoSpec
292
+ string :storagePrefix
293
+ hash :metadata
292
294
 
293
295
  def buttonLabels(obj)
294
296
  @buttonLabels = ActiveSupport::HashWithIndifferentAccess.new(obj)
@@ -334,6 +336,9 @@ class Glib::JsonUi::ViewBuilder
334
336
  string :strategy # can be "delegate" or "dropUpload"
335
337
  string :url # http post end point if you don't want to use onFinishUpload
336
338
 
339
+ string :storagePrefix
340
+ hash :metadata
341
+
337
342
  required :accepts, :directUploadUrl
338
343
 
339
344
  # deprecated
@@ -391,6 +396,17 @@ class Glib::JsonUi::ViewBuilder
391
396
  end
392
397
  end
393
398
 
399
+ class Sign < AbstractField
400
+ string :directUploadUrl
401
+
402
+ required :directUploadUrl
403
+
404
+ # Override
405
+ # Signature field doesn't have default value
406
+ def value(value)
407
+ end
408
+ end
409
+
394
410
  # TODO
395
411
  # class MultiImage < Text
396
412
  # # file_rules = { fileType: 'image/*', maxFileSize: 5000 }
@@ -334,6 +334,8 @@ module Glib
334
334
  hash :items
335
335
  hash :dropData
336
336
  string :strategy
337
+ string :storagePrefix
338
+ hash :metadata
337
339
  end
338
340
  end
339
341
  end
@@ -66,6 +66,15 @@ section.rows builder: ->(template) do
66
66
  action.dialogs_open fullscreen: 'mobile', url: json_ui_garage_url(path: 'forms/basic', mode: 'dialog')
67
67
  end
68
68
 
69
+ template.thumbnail title: 'dialogs/reload (without url)', onClick: ->(action) do
70
+ action.runMultiple childActions: ->(saction) do
71
+ saction.dialogs_open url: json_ui_garage_url(path: 'forms/dialogs_form')
72
+ saction.timeouts_set interval: 1000, onTimeout: ->(ssaction) do
73
+ ssaction.dialogs_reload
74
+ end
75
+ end
76
+ end
77
+
69
78
  if !Rails.env.test? # Prevent test failure
70
79
  template.thumbnail title: 'dialogs/open (page with error)', onClick: ->(action) do
71
80
  action.dialogs_open url: json_ui_garage_url(path: 'forms/non_existent', mode: 'dialog')
@@ -96,6 +105,16 @@ section.rows builder: ->(template) do
96
105
  action.dialogs_open url: json_ui_garage_url(path: 'forms/dialogs_form')
97
106
  end
98
107
 
108
+ template.thumbnail title: 'dialogs/closeAll', onClick: ->(action) do
109
+ action.runMultiple childActions: ->(saction) do
110
+ saction.dialogs_open url: json_ui_garage_url(path: 'forms/dialogs_form')
111
+ saction.dialogs_open url: json_ui_garage_url(path: 'forms/dialogs_form')
112
+ saction.timeouts_set interval: 1000, onTimeout: ->(ssaction) do
113
+ ssaction.dialogs_closeAll
114
+ end
115
+ end
116
+ end
117
+
99
118
  template.thumbnail title: 'dialogs/oauth', onClick: ->(action) do
100
119
  if respond_to?(:user_facebook_omniauth_authorize_url)
101
120
  provider = {
@@ -14,6 +14,11 @@ section.rows builder: ->(template) do
14
14
  action.windows_open url: json_ui_garage_url(path: 'home/blank')
15
15
  end
16
16
 
17
+ template.thumbnail title: 'windows/closeAllWithOpen', onClick: ->(action) do
18
+ action.windows_closeAllWithOpen url: json_ui_garage_url(path: 'home/index')
19
+
20
+ end
21
+
17
22
  template.thumbnail title: 'windows/openWeb', onClick: ->(action) do
18
23
  action.windows_openWeb url: 'http://www.google.com'
19
24
  end
@@ -46,6 +46,11 @@ page.form options.merge(childViews: ->(form) do
46
46
  directUploadUrl: rails_direct_uploads_url,
47
47
  uploadTitle: 'Files uploaded:',
48
48
  uploadFailedText: '(UPLOAD FAILED)',
49
+ storagePrefix: 'glib',
50
+ metadata: {
51
+ foo: 'bar',
52
+ zoo: 'baz'
53
+ },
49
54
  files: [
50
55
  { name: 'File (Example)', signed_id: ActiveStorage::Attachment.last&.signed_id }
51
56
  ]
@@ -61,5 +66,13 @@ page.form options.merge(childViews: ->(form) do
61
66
  uploadFailedText: '(UPLOAD FAILED)',
62
67
  onFinishUpload: ->(action) { action.forms_submit }
63
68
  form.spacer height: 16
69
+ form.label text: 'Sign'
70
+ form.spacer height: 8
71
+ form.fields_sign \
72
+ name: 'user[sign]',
73
+ directUploadUrl: rails_direct_uploads_url,
74
+ width: 300, height: 150,
75
+ validation: { required: { message: 'add your signature!' } }
76
+ form.spacer height: 24
64
77
  form.fields_submit text: 'Submit'
65
78
  end)
data/lib/glib/blob.rb ADDED
@@ -0,0 +1,15 @@
1
+ ::ActiveStorage::Blob.class_eval do
2
+ def service_headers_for_direct_upload
3
+ service.headers_for_direct_upload key, filename: filename, content_type: content_type, content_length: byte_size, checksum: checksum
4
+ end
5
+
6
+ class << self
7
+ def create_before_direct_upload!(key: nil, filename:, byte_size:, checksum:, content_type: nil, metadata: nil, service_name: nil, record: nil, prefix: nil)
8
+ key_name = key || generate_unique_secure_token
9
+ if prefix.present?
10
+ key_name = "#{prefix}/#{key_name}"
11
+ end
12
+ create! key: key_name, filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type, metadata: metadata, service_name: service_name
13
+ end
14
+ end
15
+ end
@@ -2,7 +2,10 @@
2
2
  # include Rails.application.routes.url_helpers
3
3
  before_action :authenticate_user!
4
4
 
5
- rescue_from StandardError do
5
+ rescue_from StandardError do |e|
6
+ if !Rails.env.production?
7
+ raise e
8
+ end
6
9
  render json: { message: 'Upload failed' }, status: 500
7
10
  end
8
11
 
@@ -14,11 +17,16 @@
14
17
  render json: { message: 'Session expired. Please refresh page' }, status: 401
15
18
  end
16
19
 
17
- def authenticate_user!
18
- current_user.present? ? nil : raise_error
19
- end
20
+ private
21
+ def blob_args
22
+ params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, :prefix, metadata: {}).to_h.symbolize_keys
23
+ end
20
24
 
21
- def raise_error
22
- raise Glib::Auth::Policy::UnauthorizedError
23
- end
25
+ def authenticate_user!
26
+ current_user.present? ? nil : raise_error
27
+ end
28
+
29
+ def raise_error
30
+ raise Glib::Auth::Policy::UnauthorizedError
31
+ end
24
32
  end
data/lib/glib/engine.rb CHANGED
@@ -5,6 +5,7 @@ module Glib
5
5
 
6
6
  # modify direct upload
7
7
  config.to_prepare do
8
+ require_relative 'blob'
8
9
  require_relative 'direct_uploads_controller'
9
10
  end
10
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.27.0
4
+ version: 3.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -307,6 +307,7 @@ files:
307
307
  - lib/generators/templates/database.yml
308
308
  - lib/generators/templates/dynamic_text.rb
309
309
  - lib/glib-web.rb
310
+ - lib/glib/blob.rb
310
311
  - lib/glib/crypt/utils.rb
311
312
  - lib/glib/direct_uploads_controller.rb
312
313
  - lib/glib/dynamic_text.rb