glib-web 3.22.1 → 3.22.2

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: 7bdf7c0b808e5d7dd817d1546bf7bddba4a90e770d4743e9ab72b21679520741
4
- data.tar.gz: 77713543dc8529f1e324947297d7114ac51c774b33649032191b9746e9932af1
3
+ metadata.gz: 806df354ed58edcee98f342d40209e0f42b16343f79427941accd17b796d6c33
4
+ data.tar.gz: 8b0de205b315c74ad1a773cf6963f461e2952cf1fbf5f36e63aea66c648c4640
5
5
  SHA512:
6
- metadata.gz: df71f8031865db335bda02625aed6e77c1b14c065cc292cc2a146c200e45c8e9d8aadeceb553838a323ab0f345e5e2d6bdba0c2f0a8e5341b67eb27c9a50063e
7
- data.tar.gz: f09047258852d6eb4e46b0af5f5611f6597ab8a6e41bdb313a25c024a1d104ce3bd8f485896819cd56f328a30ca7436d06e4bfe90b094e965e6bdfa605a2618c
6
+ metadata.gz: 5e9062feefed9651443c3a128de05df41e63a755cafdc10b66167f60643b9bf847a1dc4c68af9f95e8b9eff4f7a0f3b52d31fa61907575a6f09de7903dffb684
7
+ data.tar.gz: 651ae04bd671192239d8bc08e144733a011f6777e6b33347739579ec7511c7ff9bd9d0f23ff36ff110076242424606ac0500cb80ba0212b4487f788b177b7f55
@@ -62,14 +62,27 @@ module Glib::Json::Libs
62
62
  JSON.parse(render_to_string(template, locals: args))
63
63
  end
64
64
 
65
- def glib_redirect_to(url)
65
+ def glib_html_url(url)
66
+ url = url.include?('?') ? url.sub(/.json\?/, '?') : url.sub(/.json$/, '')
67
+
68
+ # As much as possible, try retaining the front fragment by matching the back, because
69
+ # the front could be either a `?` or `&`
70
+ url = url.sub(/format=json\&/, '');
71
+
72
+ # If no match, then we replace the front fragment
73
+ url.sub(/[\&\?]format=json/, '');
74
+ end
75
+
76
+ def glib_redirect_to(url, return_to_previous: false)
77
+ url = __delete_redirect_back_url(url) if return_to_previous
78
+
66
79
  respond_to do |format|
67
80
  format.html do
68
81
  redirect_to url
69
82
  end
70
83
  format.json do
71
84
  if __json_ui_rendering?
72
- redirect_to url
85
+ redirect_to glib_html_url(url)
73
86
  return
74
87
  end
75
88
 
@@ -147,10 +160,10 @@ module Glib::Json::Libs
147
160
  session.delete(REDIRECT_BACK_KEY) || url
148
161
  end
149
162
 
150
- def html_ui_redirect_back_or_to(default_url)
151
- redirect_url = __delete_redirect_back_url(default_url)
152
- redirect_to redirect_url
153
- end
163
+ # def html_ui_redirect_back_or_to(default_url)
164
+ # redirect_url = __delete_redirect_back_url(default_url)
165
+ # redirect_to redirect_url
166
+ # end
154
167
 
155
168
  def json_ui_redirect_back_or_to(default_url, json_action)
156
169
  redirect_url = __delete_redirect_back_url(default_url)
@@ -210,9 +223,15 @@ module Glib::Json::Libs
210
223
  end
211
224
 
212
225
  def json_ui_redirect_to(url)
213
- render json: {
214
- onResponse: { action: 'dialogs/close', onClose: { action: 'windows/open', url: url } }
215
- }
226
+ # `onLoad` also executes in `onResponse` situation, e.g. form submit.
227
+ on_load = { action: 'windows/open', url: url }
228
+
229
+ if glib_json_dialog_mode?
230
+ # Only do this in dialog mode because this seems to add to the rendering time
231
+ # (i.e. longer flicker time), presumably due to the use of things like `nextTick()`.
232
+ on_load = { action: 'dialogs/close', onClose: on_load }
233
+ end
234
+ render json: { onLoad: on_load }
216
235
  end
217
236
 
218
237
  module ClassMethods
@@ -1,7 +1,7 @@
1
1
  module Glib
2
2
  module UrlsHelper
3
- def glib_url_current(new_params = {})
4
- url_for(params.to_unsafe_h.merge(new_params.merge(only_path: false)))
3
+ def glib_url_current(override_params: params.to_unsafe_h, extra_params: {})
4
+ url_for(override_params.merge(extra_params.merge(only_path: false)))
5
5
  end
6
6
 
7
7
  def glib_url_equals_current?(url)
@@ -1,5 +1,6 @@
1
+ # Deprecated. Use Glib::Crypt instead.
1
2
  module Glib
2
- module Crypt
3
+ class Crypt
3
4
  class Utils
4
5
  def self.encrypt(original_message, encryption_secret, encryption_salt)
5
6
  encryptor = message_encryptor(encryption_secret, encryption_salt)
data/lib/glib/crypt.rb CHANGED
@@ -1 +1,28 @@
1
1
  require_relative './crypt/utils'
2
+
3
+ # A replacement of Glib::Crypt::Utils
4
+ module Glib
5
+ class Crypt
6
+ # Recommended digest: 'SHA256'
7
+ def self.encrypt(original_message, encryption_secret, encryption_salt, digest)
8
+ encryptor = message_encryptor(encryption_secret, encryption_salt, digest)
9
+ CGI.escape(encryptor.encrypt_and_sign(original_message))
10
+ end
11
+
12
+ def self.decrypt(encrypted_message, encryption_secret, encryption_salt, digest)
13
+ encryptor = message_encryptor(encryption_secret, encryption_salt, digest)
14
+ begin
15
+ encryptor.decrypt_and_verify(CGI.unescape(encrypted_message))
16
+ rescue ActiveSupport::MessageEncryptor::InvalidMessage
17
+ nil
18
+ end
19
+ end
20
+
21
+ private
22
+ def self.message_encryptor(encryption_secret, encryption_salt, digest)
23
+ key_generator = ActiveSupport::KeyGenerator.new(encryption_secret, iterations: 1000)
24
+ key_secret = key_generator.generate_key(encryption_salt, 32)
25
+ ActiveSupport::MessageEncryptor.new(key_secret, digest: digest, serializer: JSON)
26
+ end
27
+ end
28
+ 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.22.1
4
+ version: 3.22.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''