glib-web 4.22.0 → 4.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/glib/auth/policy.rb +35 -42
- data/app/controllers/concerns/glib/json/libs.rb +5 -1
- data/app/helpers/glib/json_ui/action_builder/dialogs.rb +2 -0
- data/app/helpers/glib/json_ui/view_builder/fields.rb +3 -0
- data/app/policies/glib/application_policy.rb +12 -13
- data/app/views/json_ui/garage/actions/_dialogs.json.jbuilder +8 -1
- data/app/views/json_ui/garage/actions/_dialogs_show.json.jbuilder +3 -1
- data/app/views/json_ui/garage/forms/_basic_content.json.jbuilder +7 -0
- data/app/views/json_ui/garage/forms/pickers.json.jbuilder +8 -2
- data/app/views/json_ui/garage/forms/selects.json.jbuilder +8 -0
- data/app/views/json_ui/garage/tables/pagination.json.jbuilder +1 -1
- data/app/views/json_ui/garage/test_page/selectable.json.jbuilder +7 -0
- data/app/views/json_ui/garage/views/icons.json.jbuilder +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c33aad966e5d6ae0b3307117b099a75ee339bc8ba6036dea5998cde02ea60b80
|
4
|
+
data.tar.gz: 36ac5225fad837a784439dfb946bce3c2998fb31f48dd0bbcbb4dbc1799c633a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 649051e63a8b1f637225e337b6955a4c148860a1c83bdb556e7a926b0b06c7546731ec49eeae86ec3bb33f4fb03fb399f74adfc8e93453515b81d749e008ea53
|
7
|
+
data.tar.gz: 669dca7c9e488c5f6b5b7e33b88afcbe0a0b0a8e6c290d79679eb25eb579089da9cc8a0af5b20210a2a78da719662fcc9f7dbc84e691d002b213c91a014d2bfc
|
@@ -22,8 +22,7 @@ module Glib::Auth
|
|
22
22
|
end
|
23
23
|
|
24
24
|
module Overrides
|
25
|
-
|
26
|
-
public # Override
|
25
|
+
# Override
|
27
26
|
def policy(record, policy_name = nil, context = nil)
|
28
27
|
policy_name ||= record
|
29
28
|
|
@@ -50,11 +49,10 @@ module Glib::Auth
|
|
50
49
|
end
|
51
50
|
|
52
51
|
# Expose protected method
|
53
|
-
|
52
|
+
# Override
|
54
53
|
def policy_scope(*args, **opts)
|
55
54
|
super
|
56
55
|
end
|
57
|
-
|
58
56
|
end
|
59
57
|
|
60
58
|
def glib_raise_forbidden
|
@@ -71,13 +69,11 @@ module Glib::Auth
|
|
71
69
|
policy(record, nil, context).send("#{action}?")
|
72
70
|
end
|
73
71
|
|
74
|
-
public
|
75
72
|
def cannot?(action, record, context = nil)
|
76
73
|
!policy(record, nil, context).send("#{action}?")
|
77
74
|
end
|
78
75
|
|
79
76
|
# Inspired from https://github.com/ryanb/cancan/wiki/Non-RESTful-Controllers
|
80
|
-
public
|
81
77
|
def glib_authorize_resource(*args)
|
82
78
|
options = args.extract_options!
|
83
79
|
resource_name = args.first
|
@@ -104,14 +100,11 @@ module Glib::Auth
|
|
104
100
|
raise_access_denied(resource_instance, policy_instance) unless policy_instance.public_send(query)
|
105
101
|
end
|
106
102
|
|
107
|
-
|
108
|
-
|
109
103
|
class UnauthorizedError < Pundit::NotAuthorizedError
|
110
104
|
end
|
111
105
|
|
112
|
-
|
113
|
-
|
114
106
|
module ClassMethods
|
107
|
+
# rubocop:disable Style/ClassVars
|
115
108
|
def glib_auth_init
|
116
109
|
@@__glib_auth_init = true
|
117
110
|
|
@@ -122,40 +115,40 @@ module Glib::Auth
|
|
122
115
|
def glib_auth_inited?
|
123
116
|
@@__glib_auth_init ||= false
|
124
117
|
end
|
118
|
+
# rubocop:enable Style/ClassVars
|
125
119
|
|
126
120
|
# TODO: Consider deprecating
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
121
|
+
# def authorize_resource(*args)
|
122
|
+
# options = args.extract_options!
|
123
|
+
# resource_name = args.first
|
124
|
+
|
125
|
+
# self.before_action(options.slice(:only, :except, :if, :unless)) do |controller|
|
126
|
+
# resource_name ||= resource_name_from_controller
|
127
|
+
|
128
|
+
# begin
|
129
|
+
# if !(resource_key = options[:class]).nil?
|
130
|
+
# resource = case resource_key
|
131
|
+
# when false
|
132
|
+
# resource_name.to_sym
|
133
|
+
# when Symbol, Class
|
134
|
+
# resource_key
|
135
|
+
# else
|
136
|
+
# raise "Invalid resource class: #{resource_key}"
|
137
|
+
# end
|
138
|
+
|
139
|
+
# authorize resource
|
140
|
+
# elsif (resource_instance = controller.instance_variable_get("@#{resource_name}"))
|
141
|
+
# authorize resource_instance
|
142
|
+
# else
|
143
|
+
# authorize resource_name.camelize.constantize
|
144
|
+
# end
|
145
|
+
# rescue Pundit::NotAuthorizedError => e
|
146
|
+
# raise_access_denied(e.record, e.policy)
|
147
|
+
# end
|
148
|
+
|
149
|
+
# verify_authorized
|
150
|
+
# end
|
151
|
+
# end
|
159
152
|
end
|
160
153
|
|
161
154
|
def resource_name_from_controller
|
@@ -7,7 +7,7 @@ module Glib::Json::Libs
|
|
7
7
|
helper_method :json_ui_app_bundle_id, :json_ui_app_build_version, :json_ui_app_device_os
|
8
8
|
helper_method :json_ui_app_is_android?, :json_ui_app_is_ios?, :json_ui_app_is_web?
|
9
9
|
# helper_method :json_ui_redirect_back_or_to
|
10
|
-
helper_method :delete_redirect_back_url
|
10
|
+
helper_method :delete_redirect_back_url, :redirect_back_url
|
11
11
|
|
12
12
|
include Glib::Auth::Response
|
13
13
|
helper_method :glib_json_dialog_mode?
|
@@ -171,6 +171,10 @@ module Glib::Json::Libs
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
+
def redirect_back_url
|
175
|
+
session[REDIRECT_BACK_KEY]
|
176
|
+
end
|
177
|
+
|
174
178
|
def __delete_redirect_back_url(url)
|
175
179
|
session.delete(REDIRECT_BACK_KEY) || url
|
176
180
|
end
|
@@ -15,6 +15,7 @@ class Glib::JsonUi::ActionBuilder
|
|
15
15
|
length :width
|
16
16
|
bool :closeOnBlur
|
17
17
|
bool :updateExisting
|
18
|
+
action :onClose
|
18
19
|
|
19
20
|
# def initialize(json, page)
|
20
21
|
# @json = json
|
@@ -34,6 +35,7 @@ class Glib::JsonUi::ActionBuilder
|
|
34
35
|
length :height
|
35
36
|
bool :closeOnBlur
|
36
37
|
bool :updateExisting
|
38
|
+
action :onClose
|
37
39
|
end
|
38
40
|
|
39
41
|
class Reload < Action
|
@@ -13,6 +13,7 @@ class Glib::JsonUi::ViewBuilder
|
|
13
13
|
string :paramNameForFormData
|
14
14
|
string :paramNameForFieldName
|
15
15
|
bool :rounded
|
16
|
+
string :autocomplete # https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
|
16
17
|
|
17
18
|
def default_url_options
|
18
19
|
{ only_path: true }
|
@@ -438,6 +439,7 @@ class Glib::JsonUi::ViewBuilder
|
|
438
439
|
bool :clearable
|
439
440
|
bool :buttonTemplate # TODO: Remove
|
440
441
|
hash :template, required: [:type]
|
442
|
+
string :time_zone
|
441
443
|
|
442
444
|
# Override
|
443
445
|
def value(value)
|
@@ -451,6 +453,7 @@ class Glib::JsonUi::ViewBuilder
|
|
451
453
|
date_time :min
|
452
454
|
date_time :max
|
453
455
|
bool :clearable
|
456
|
+
string :time_zone
|
454
457
|
|
455
458
|
bool :buttonTemplate # TODO: Remove
|
456
459
|
hash :template, required: [:type]
|
@@ -6,6 +6,7 @@ module Glib
|
|
6
6
|
attr_reader :user, :record, :policy_name, :controller, :request, :params
|
7
7
|
|
8
8
|
private
|
9
|
+
# rubocop:disable Metrics/ParameterLists
|
9
10
|
def initialize(user, record, policy_name, controller, request, params)
|
10
11
|
@user = user
|
11
12
|
@record = record
|
@@ -16,13 +17,14 @@ module Glib
|
|
16
17
|
@params = params
|
17
18
|
@policy_name = policy_name
|
18
19
|
end
|
20
|
+
# rubocop:enable Metrics/ParameterLists
|
19
21
|
|
20
22
|
class << self
|
21
23
|
attr_reader :catch_all
|
22
24
|
|
23
25
|
# This is to define the authorization logic for an action (or a group of actions). It's different from controller's
|
24
26
|
# authorize().
|
25
|
-
private
|
27
|
+
private # Used by child
|
26
28
|
def authorize(*actions, &block)
|
27
29
|
actions.each do |action|
|
28
30
|
if action == :glib_all
|
@@ -33,19 +35,17 @@ module Glib
|
|
33
35
|
# Avoid accidentally redefining multiple times from child policies. But it's okay if the child policy
|
34
36
|
# wants to override the parent's authorization method.
|
35
37
|
raise "Action authorization has been declared: #{action}" if instance_methods(false).include?(method_name.to_sym)
|
38
|
+
|
36
39
|
define_method method_name, &block
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
40
|
-
|
41
43
|
end
|
42
44
|
|
43
|
-
private
|
44
45
|
def catch_all
|
45
46
|
self.class.catch_all
|
46
47
|
end
|
47
48
|
|
48
|
-
private
|
49
49
|
# To ensure the block is called on the policy's instance instead class.
|
50
50
|
def call_catch_all
|
51
51
|
instance_eval(&catch_all)
|
@@ -100,14 +100,17 @@ module Glib
|
|
100
100
|
|
101
101
|
public
|
102
102
|
def method_missing(name, *args, &block)
|
103
|
-
if
|
103
|
+
if respond_to_missing?(name) && catch_all
|
104
104
|
call_catch_all
|
105
105
|
else
|
106
106
|
super
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
|
110
|
+
def respond_to_missing?(method_name, include_private = false)
|
111
|
+
method_name.to_s.end_with?('?') || super
|
112
|
+
end
|
113
|
+
|
111
114
|
def scope
|
112
115
|
policy_scope_class = Pundit::PolicyFinder.new(@policy_name).scope
|
113
116
|
return unless policy_scope_class
|
@@ -115,15 +118,11 @@ module Glib
|
|
115
118
|
controller.policy_scope(record.class, policy_scope_class: policy_scope_class)
|
116
119
|
end
|
117
120
|
|
118
|
-
public
|
119
121
|
def self.args_builder
|
120
|
-
|
122
|
+
proc { |_controller| [] }
|
121
123
|
end
|
122
124
|
|
123
|
-
|
124
|
-
def helpers
|
125
|
-
controller.helpers
|
126
|
-
end
|
125
|
+
delegate :helpers, to: :controller
|
127
126
|
|
128
127
|
class Scope
|
129
128
|
attr_reader :user, :scope
|
@@ -143,7 +142,7 @@ module Glib
|
|
143
142
|
end
|
144
143
|
end
|
145
144
|
|
146
|
-
private
|
145
|
+
private # Used by child
|
147
146
|
def everyone
|
148
147
|
true
|
149
148
|
end
|
@@ -49,7 +49,14 @@ section.rows builder: ->(template) do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
template.thumbnail title: 'dialogs/open', onClick: ->(action) do
|
52
|
-
action.dialogs_open
|
52
|
+
action.dialogs_open \
|
53
|
+
width: 950,
|
54
|
+
url: json_ui_garage_url(path: 'forms/basic', mode: 'dialog'),
|
55
|
+
disableCloseButton: true,
|
56
|
+
closeOnBlur: true,
|
57
|
+
onClose: ->(saction) do
|
58
|
+
saction.snackbars_alert message: 'dialog closed'
|
59
|
+
end
|
53
60
|
end
|
54
61
|
|
55
62
|
template.thumbnail title: 'dialogs/open (fullscreen on mobile)', onClick: ->(action) do
|
@@ -12,7 +12,9 @@ end
|
|
12
12
|
|
13
13
|
include_form = local_assigns[:include_form]
|
14
14
|
|
15
|
-
action.send "dialogs_#{dialog_mode}", **options,
|
15
|
+
action.send "dialogs_#{dialog_mode}", **options,
|
16
|
+
onClose: ->(action) { action.snackbars_alert message: 'dialog closed' },
|
17
|
+
content: ->(dialog) do
|
16
18
|
dialog.body padding: glib_json_padding_body, childViews: ->(body) do
|
17
19
|
body.markdown text: markdown
|
18
20
|
|
@@ -5,6 +5,13 @@ panel.panels_form url: json_ui_garage_url(path: 'forms/basic_post'), method: 'po
|
|
5
5
|
form.fields_password name: 'user[password]', width: 'matchParent', label: 'Password', disableDirtyCheck: disable_dirty_check
|
6
6
|
form.fields_text name: 'user[title]', width: 'matchParent', label: 'Title', disableDirtyCheck: disable_dirty_check
|
7
7
|
|
8
|
+
form.fields_timeZone \
|
9
|
+
name: 'user[time_zone]',
|
10
|
+
width: 'matchParent',
|
11
|
+
label: 'Time zone',
|
12
|
+
disableDirtyCheck: disable_dirty_check,
|
13
|
+
value: 'America/Chicago'
|
14
|
+
|
8
15
|
form.fields_select width: 'matchParent', name: 'user[types]', options: [
|
9
16
|
{ value: 1, text: 'One' },
|
10
17
|
{ value: 2, text: 'Two' }
|
@@ -61,6 +61,14 @@ page.form \
|
|
61
61
|
min: '2018-06-09T00:00',
|
62
62
|
max: '2018-06-17T00:00',
|
63
63
|
value: '2018-06-15T19:30'
|
64
|
+
form.fields_datetime \
|
65
|
+
name: 'user[date_time]',
|
66
|
+
width: 'matchParent',
|
67
|
+
label: 'Date Time (Asia/Taipei)',
|
68
|
+
min: '2018-06-09T00:00',
|
69
|
+
max: '2018-06-17T00:00',
|
70
|
+
value: '2025-01-26T13:49:00.000+05:00',
|
71
|
+
time_zone: 'Asia/Taipei' # +8
|
64
72
|
form.fields_date \
|
65
73
|
name: 'user[month]',
|
66
74
|
width: 'matchParent',
|
@@ -70,8 +78,6 @@ page.form \
|
|
70
78
|
max: '2021-03-01',
|
71
79
|
value: '2021-11'
|
72
80
|
|
73
|
-
|
74
|
-
|
75
81
|
if record.present?
|
76
82
|
form.fields_datetime \
|
77
83
|
prop: :created_at,
|
@@ -189,6 +189,14 @@ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', p
|
|
189
189
|
form.label text: 'The select field defaults to the device\'s time zone.'
|
190
190
|
form.spacer height: 6
|
191
191
|
form.fields_timeZone name: 'user[time_zone]', width: 'matchParent', label: 'Time Zone', clearable: true
|
192
|
+
form.spacer height: 6
|
193
|
+
form.fields_timeZone \
|
194
|
+
name: 'user[new_time_zone]',
|
195
|
+
width: 'matchParent',
|
196
|
+
label: 'Time Zone',
|
197
|
+
clearable: true,
|
198
|
+
value: 'America/Chicago'
|
199
|
+
# value: 'Australia/Melbourne'
|
192
200
|
|
193
201
|
|
194
202
|
form.button text: 'Submit', onClick: ->(action) { action.forms_submit }
|
@@ -9,7 +9,7 @@ per_page = 20
|
|
9
9
|
page_index = params[:page]&.to_i || 1
|
10
10
|
|
11
11
|
page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
|
12
|
-
scroll.panels_table
|
12
|
+
scroll.panels_table firstSection: ->(section) do
|
13
13
|
section.header cellViews: ->(header) do
|
14
14
|
header.label text: 'Name'
|
15
15
|
header.label text: 'Status'
|
@@ -79,6 +79,13 @@ page.body padding: glib_json_padding_body, childViews: ->(body) do
|
|
79
79
|
form.fields_check id: 'check3', name: 'user[foo][]', label: 'Option 3', checkValue: true
|
80
80
|
|
81
81
|
form.spacer height: 8
|
82
|
+
|
83
|
+
form.h2 text: 'Timezone'
|
84
|
+
form.fields_timeZone name: 'user[timezone]', label: 'Timezone', value: 'Asia/Shanghai'
|
85
|
+
form.fields_timeZone name: 'user[timezone_with_current_local]', label: 'Local Timezone'
|
86
|
+
|
87
|
+
form.spacer height: 8
|
88
|
+
|
82
89
|
form.fields_submit text: 'Submit'
|
83
90
|
end
|
84
91
|
end
|
@@ -24,7 +24,9 @@ page.form padding: glib_json_padding_body, childViews: ->(scroll) do
|
|
24
24
|
}
|
25
25
|
end
|
26
26
|
scroll.icon id: 'icon1', name: 'home', color: '#9370DB'
|
27
|
-
scroll.icon name: 'home', color: '#9370DB80'
|
27
|
+
scroll.icon name: 'home', color: '#9370DB80', onClick: ->(action) do
|
28
|
+
action.snackbars_alert message: 'Icon clicked!'
|
29
|
+
end
|
28
30
|
|
29
31
|
scroll.spacer height: 20
|
30
32
|
scroll.h2 text: 'Icon with badge'
|