caboose-cms 0.2.78 → 0.2.79
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 +8 -8
- data/app/models/caboose/page.rb +245 -245
- data/app/models/caboose/user.rb +3 -4
- data/lib/caboose/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2UxYmI0MzAwNzhlYWY2OTE3NGFhYWNkMmNkMDI3YTdhMDkxY2ZkYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmUyOTQ4OWNhZGE3NTdiMDhjMDJhZTcwZTM1M2Y0ODE3MmI4MzZlYg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Mzc0OTQzNmE2NjgxYTJlYWI5MTg3OTlhMmZhZGVmNDBmMzcxYzcyMjgwY2Yz
|
10
|
+
OTRiNzg0NDhiNTA0ZTM3MWFkYTYyYWJmNDEwZTk1NDY3MWEzOWExMjcyNzc0
|
11
|
+
N2Y5Mjc2ZTA3ZjNjNDQ2MjYwMzFlZTVlMzgzMzM5ZWVjMTcyNDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTRjOGEzYjU2ODU5NzkzNzEwN2Y5MWZmODQ1ODZjOWE2NGJkN2RhNjcxZjg4
|
14
|
+
ZWJlMmM2OWFhNjM5NzczYmFkNDllZGEwZjZhN2QyMjYyZjE0NzU5Y2EzNDk1
|
15
|
+
NTgzODg4YzNiODU3M2M1ZjMyZTllMzEzMzQ2ZDRmMzk0MDhhMjc=
|
data/app/models/caboose/page.rb
CHANGED
@@ -55,257 +55,257 @@ class Caboose::Page < ActiveRecord::Base
|
|
55
55
|
return self.index_page if uri.length == 0
|
56
56
|
|
57
57
|
page = false
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
58
|
+
parts = uri.split('/')
|
59
|
+
|
60
|
+
# See where to start looking
|
61
|
+
page_ids = self.where(:alias => parts[0]).limit(1).pluck(:id)
|
62
|
+
page_id = !page_ids.nil? && page_ids.count > 0 ? page_ids[0] : false
|
63
|
+
|
64
|
+
# Search for the page
|
65
|
+
if (page_id)
|
66
|
+
page_id = self.page_with_uri_helper(parts, 1, page_id)
|
67
|
+
else
|
68
|
+
parent_id = self.index_page
|
69
|
+
page_id = self.page_with_uri_helper(parts, 0, parent_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
return false if page_id.nil?
|
73
|
+
|
74
|
+
page = self.find(page_id)
|
75
|
+
|
76
|
+
if (!get_closest_parent) # // Look for an exact match
|
77
|
+
return false if page.uri != uri
|
78
|
+
end
|
79
|
+
return page
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.page_with_uri_helper(parts, level, parent_id)
|
83
|
+
return parent_id if level >= parts.count
|
84
|
+
slug = parts[level]
|
85
|
+
page_ids = self.where(:parent_id => parent_id, :slug => slug).limit(1).pluck(:id)
|
86
|
+
return parent_id if page_ids.nil? || page_ids.count == 0
|
87
|
+
return self.page_with_uri_helper(parts, level+1, page_ids[0])
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.update_uri(page)
|
91
|
+
#return if page.redirect_url && page.redirect_url.length > 0
|
92
|
+
|
93
|
+
page.slug = self.slug(page.title) if page.slug.nil? || page.slug.strip.length == 0
|
94
|
+
page.uri = page.alias && page.alias.strip.length > 0 ? page.alias : (page.parent ? "#{page.parent.uri}/#{page.slug}" : "#{page.slug}")
|
95
95
|
page.uri[0] = '' if page.uri.starts_with?('/')
|
96
96
|
page.save
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
97
|
+
|
98
|
+
page.children.each { |p2| self.update_uri(p2) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.update_child_perms(page_id)
|
102
|
+
page = self.find(page_id)
|
103
|
+
|
104
|
+
viewers_ids = Role.roles_with_page_permission(page_id, 'view').collect {|r| r.id }
|
105
|
+
editors_ids = Role.roles_with_page_permission(page_id, 'edit').collect {|r| r.id }
|
106
|
+
approvers_ids = Role.roles_with_page_permission(page_id, 'approve').collect {|r| r.id }
|
107
|
+
|
108
|
+
self.update_child_perms_helper(page, viewer_ids, editor_ids, approver_ids)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.update_child_perms_helper(page, viewer_ids, editor_ids, approver_ids)
|
112
|
+
self.update_authorized_for_action(page.id, 'view' , viewer_ids)
|
113
|
+
self.update_authorized_for_action(page.id, 'edit' , editor_ids)
|
114
|
+
self.update_authorized_for_action(page.id, 'approve' , approver_ids)
|
115
115
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
116
|
+
page.children.each do |kid|
|
117
|
+
self.update_child_perms_helper(kid, viewer_ids, editor_ids, approver_ids)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.update_authorized_for_action(page_id, action, roles)
|
122
|
+
Caboose::PagePermission.where(:page_id => page_id, :action => action).destroy_all
|
123
|
+
if (!roles.nil?)
|
124
|
+
roles.each do |role|
|
125
|
+
role_id = role.is_a?(Integer) ? role : role.id
|
126
|
+
Caboose::PagePermission.create({
|
127
|
+
:page_id => page_id,
|
128
|
+
:role_id => role_id,
|
129
|
+
:action => action
|
130
|
+
})
|
131
|
+
end
|
132
|
+
end
|
133
|
+
return true
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.is_allowed(user, page_id, action)
|
137
|
+
user = User.logged_out_user if user.nil?
|
138
138
|
|
139
|
-
|
140
|
-
|
141
|
-
|
139
|
+
# Allow a user id to be sent instead of a user object
|
140
|
+
user = User.find(user) if user.is_a?(Integer)
|
141
|
+
user.role_ids = [Role.logged_out_role_id] if user.role_ids.nil?
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
143
|
+
t = PagePermission.table
|
144
|
+
reqs = nil
|
145
|
+
user.role_ids.each do |role_id|
|
146
|
+
if (reqs.nil?)
|
147
|
+
reqs = t[:role_id].eq(role_id)
|
148
|
+
else
|
149
|
+
reqs.or(t[:role_id].eq(role_id))
|
150
|
+
end
|
151
|
+
end
|
152
|
+
var params = { :page_id => page_id, :action => action }
|
153
|
+
params << reqs if !reqs.nil?
|
154
|
+
count = PagePermission.where(params).count
|
155
|
+
|
156
|
+
return true if count > 0
|
157
|
+
return false
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.roles_with_permission(page_id, action)
|
161
|
+
return Role.roles_with_page_permission(page_id, action)
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.permissible_actions(user, page_id)
|
165
|
+
if (user.is_a?(Integer))
|
166
|
+
user = Caboose::User.find(user)
|
167
|
+
end
|
168
|
+
actions = []
|
169
|
+
user.roles.each do |role|
|
170
|
+
actions + Caboose::PagePermission.where({
|
171
|
+
:role_id => role.id,
|
172
|
+
:page_id => page_id
|
173
|
+
}).pluck(:action)
|
174
|
+
end
|
175
|
+
return actions.uniq
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.page_ids_with_permission(user, action)
|
179
|
+
if (user.is_a?(Integer))
|
180
|
+
user = Caboose::User.find(user)
|
181
|
+
end
|
182
|
+
ids = []
|
183
|
+
user.roles.each do |role|
|
184
|
+
ids + Caboose::PagePermission.where({
|
185
|
+
:role_id => role.id,
|
186
|
+
:action => action
|
187
|
+
}).pluck(:page_id)
|
188
|
+
end
|
189
|
+
return ids.uniq
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.crumb_trail(page)
|
193
|
+
page_id = page.is_a?(Integer) ? page : page.id
|
194
|
+
|
195
|
+
arr = []
|
196
|
+
self.crumb_trail_helper(page_id, arr)
|
197
|
+
arr.reverse!
|
198
|
+
|
199
|
+
trail = arr.collect do |row|
|
200
|
+
Caboose::StdClass.new({
|
201
|
+
'href' => !row.uri.nil? && row.uri.length > 0 ? row.uri : '/',
|
202
|
+
'text' => !row.menu_title.nil? && row.menu_title.length > 0 ? row.menu_title : row.title
|
203
|
+
})
|
204
|
+
end
|
205
|
+
return trail
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.crumb_trail_helper(page_id, arr)
|
209
|
+
return if page_id.nil? || page_id <= 0
|
210
|
+
p = self.find_with_fields(page_id, [:parent_id, :title, :menu_title, :uri])
|
211
|
+
return if p.nil?
|
212
|
+
arr << p
|
213
|
+
self.crumb_trail_helper(p.parent_id, arr)
|
214
|
+
end
|
215
|
+
|
216
|
+
def self.subnav(page, use_redirect_urls = true, user = false)
|
217
|
+
|
218
|
+
# Be nice and allow page ids to be sent
|
219
|
+
if (page.is_a?(Integer))
|
220
|
+
page = self.find_with_fields(page, [:title, :menu_title, :custom_sort_children])
|
221
|
+
end
|
222
|
+
|
223
|
+
block = Caboose::MenuBlock.new
|
224
|
+
block.title = !page.menu_title.nil? && page.menu_title.length > 0 ? page.menu_title : page.title
|
225
|
+
block.title_id = page.id
|
226
|
+
|
227
|
+
pages = self.select([:id, :title, :menu_title, :alias, :slug, :uri, :redirect_url, :sort_order]).where(:parent_id => page.id, :hide => false).reorder(:sort_order).all
|
228
|
+
if (page.custom_sort_children)
|
229
|
+
pages.sort! {|x,y| x.sort_order <=> y.sort_order }
|
230
|
+
else
|
231
|
+
pages.sort! {|x,y| x.order_title <=> y.order_title }
|
232
|
+
end
|
233
|
+
|
234
|
+
if (pages.nil? || pages.count == 0) # No children, go up a level
|
235
|
+
parent = self.find_with_fields(page.parent_id, [:title, :menu_title, :custom_sort_children])
|
236
|
+
return block if parent.nil? # If we happen to be at the top page
|
237
|
+
|
238
|
+
block.title = !parent.menu_title.nil? && parent.menu_title.length > 0 ? parent.menu_title : parent.title
|
239
|
+
block.title_id = parent.id
|
240
|
+
|
241
|
+
pages = self.select([
|
242
|
+
:id, :title, :menu_title, :alias, :slug, :uri, :redirect_url, :sort_order
|
243
|
+
]).where(:parent_id => page.parent_id, :hide => false)
|
244
|
+
if (parent.custom_sort_children)
|
245
|
+
pages.sort! {|x,y| x.sort_order <=> y.sort_order }
|
246
|
+
else
|
247
|
+
pages.sort! {|x,y| x.order_title <=> y.order_title }
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
block.links = []
|
252
|
+
pages.each do |p|
|
253
|
+
link = Caboose::StdClass.new({
|
254
|
+
'href' => !p.redirect_url.nil? && p.redirect_url.length > 0 ? p.redirect_url : p.uri,
|
255
|
+
'text' => !p.menu_title.nil? && p.menu_title.length > 0 ? p.menu_title : p.title,
|
256
|
+
'is_current' => p.id == page.id
|
257
|
+
})
|
258
|
+
if (!use_redirect_urls && self.is_allowed(user, p.id, 'edit'))
|
259
|
+
link.href = row.uri
|
260
|
+
end
|
261
|
+
block.links << link
|
262
|
+
end
|
263
|
+
return block
|
264
|
+
end
|
265
|
+
|
266
|
+
def self.url(page_id)
|
267
|
+
arr = []
|
268
|
+
self.url_helper(page_id, arr)
|
269
|
+
arr.reverse!
|
270
|
+
|
271
|
+
path = []
|
272
|
+
arr.each do |row|
|
273
|
+
if (row.alias.length > 0)
|
274
|
+
path = [row.alias]
|
275
|
+
elsif (row.slug.length > 0)
|
276
|
+
path << row.slug
|
277
|
+
end
|
278
|
+
end
|
279
|
+
return path.join('/')
|
280
|
+
end
|
281
|
+
|
282
|
+
def self.url_helper(page_id, arr)
|
283
|
+
return if page_id <= 0
|
284
|
+
|
285
|
+
p = self.find_with_fields(page_id, [:id, :parent_id, :title, :menu_title, :alias, :slug])
|
286
|
+
return if p.nil?
|
287
287
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
288
|
+
arr << p
|
289
|
+
self.url_helper(p.parent_id, arr)
|
290
|
+
end
|
291
|
+
|
292
|
+
def self.slug(str)
|
293
|
+
return str.downcase.gsub(' ', '-').gsub(/[^\w-]/, '')
|
294
|
+
end
|
295
|
+
|
296
|
+
def self.has_children(page_id)
|
297
|
+
count = self.where(:parent_id => page_id).count
|
298
|
+
return count > 0
|
299
|
+
end
|
300
|
+
|
301
|
+
def self.is_child(parent_id, child_id)
|
302
|
+
pid = self.where(:id => child_id).limit(1).pluck(:parent_id)[0]
|
303
|
+
return false if pid.nil? || pid <= 0
|
304
|
+
return true if pid == parent_id
|
305
|
+
return self.is_child(parent_id, pid)
|
306
|
+
end
|
307
307
|
|
308
|
-
|
308
|
+
def linked_resources_map
|
309
309
|
resources = { js: [], css: [] }
|
310
310
|
return resources if self.linked_resources.nil?
|
311
311
|
self.linked_resources.each_line do |r|
|
@@ -318,6 +318,6 @@ class Caboose::Page < ActiveRecord::Base
|
|
318
318
|
end
|
319
319
|
end
|
320
320
|
return resources
|
321
|
-
|
321
|
+
end
|
322
322
|
|
323
323
|
end
|
data/app/models/caboose/user.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
class Caboose::User < ActiveRecord::Base
|
3
2
|
self.table_name = "users"
|
4
3
|
has_and_belongs_to_many :roles
|
@@ -22,18 +21,18 @@ class Caboose::User < ActiveRecord::Base
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def self.validate_token(token)
|
25
|
-
user =
|
24
|
+
user = self.where('token' => token).first
|
26
25
|
return user
|
27
26
|
end
|
28
27
|
|
29
28
|
def add_to_role_with_name(role_name)
|
30
|
-
r = Role.where(:name => role_name).first
|
29
|
+
r = Caboose::Role.where(:name => role_name).first
|
31
30
|
return false if r.nil?
|
32
31
|
return add_to_role(r.id)
|
33
32
|
end
|
34
33
|
|
35
34
|
def add_to_role(role_id)
|
36
|
-
r = Role.find(role_id)
|
35
|
+
r = Caboose::Role.find(role_id)
|
37
36
|
return false if r.nil?
|
38
37
|
|
39
38
|
if (!is_member?(r.id))
|
data/lib/caboose/version.rb
CHANGED