card 1.16.3 → 1.16.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/card.gemspec +1 -1
- data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
- data/db/migrate_core_cards/20150824135418_update_file_history.rb +20 -0
- data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +13 -0
- data/db/seed/new/card_actions.yml +16 -0
- data/db/seed/new/card_acts.yml +1 -1
- data/db/seed/new/card_changes.yml +56 -80
- data/db/seed/new/card_references.yml +282 -58
- data/db/seed/new/cards.yml +1348 -1312
- data/db/seed/test/fixtures/card_actions.yml +884 -868
- data/db/seed/test/fixtures/card_acts.yml +250 -250
- data/db/seed/test/fixtures/card_changes.yml +1935 -1959
- data/db/seed/test/fixtures/card_references.yml +1024 -800
- data/db/seed/test/fixtures/cards.yml +2402 -2366
- data/db/version_core_cards.txt +1 -1
- data/lib/card.rb +3 -1
- data/lib/card/cache.rb +5 -5
- data/lib/card/chunk.rb +2 -0
- data/lib/card/env.rb +1 -1
- data/lib/card/query/card_clause.rb +59 -58
- data/lib/card/set.rb +7 -0
- data/lib/card/success.rb +143 -0
- data/mod/01_core/chunk/query_reference.rb +16 -7
- data/mod/01_core/chunk/reference.rb +3 -3
- data/mod/01_core/set/all/collection.rb +1 -1
- data/mod/01_core/set/all/name.rb +2 -1
- data/mod/01_core/set/all/phases.rb +12 -2
- data/mod/01_core/set/all/type.rb +5 -5
- data/mod/01_history/set/all/actions.rb +6 -2
- data/mod/01_history/set/all/content_history.rb +17 -2
- data/mod/01_history/set/all/history.rb +1 -1
- data/mod/02_basic_types/set/all/file.rb +0 -31
- data/mod/03_machines/lib/javascript/jquery.fileupload.js +539 -182
- data/mod/03_machines/lib/javascript/wagn.js.coffee +3 -0
- data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +20 -18
- data/mod/03_machines/lib/stylesheets/style_cards.scss +28 -1
- data/mod/05_email/set/all/notify.rb +1 -1
- data/mod/05_standard/file/favicon/image-icon.png +0 -0
- data/mod/05_standard/file/favicon/image-large.png +0 -0
- data/mod/05_standard/file/favicon/image-medium.png +0 -0
- data/mod/05_standard/file/favicon/image-original.png +0 -0
- data/mod/05_standard/file/favicon/image-small.png +0 -0
- data/mod/05_standard/lib/carrier_wave/cardmount.rb +25 -6
- data/mod/05_standard/lib/file_uploader.rb +27 -11
- data/mod/05_standard/lib/image_uploader.rb +7 -4
- data/mod/05_standard/set/abstract/attachment.rb +132 -14
- data/mod/05_standard/set/right/account.rb +2 -2
- data/mod/05_standard/set/self/signin.rb +0 -1
- data/mod/05_standard/set/type/file.rb +48 -19
- data/mod/05_standard/set/type/image.rb +9 -12
- data/mod/05_standard/spec/chunk/include_spec.rb +13 -12
- data/mod/05_standard/spec/chunk/query_reference_spec.rb +50 -0
- data/mod/05_standard/spec/set/right/account_spec.rb +24 -25
- data/mod/05_standard/spec/set/type/file_spec.rb +1 -1
- data/spec/lib/card/reference_spec.rb +14 -0
- data/spec/lib/card/success_spec.rb +142 -0
- data/tmpsets/set/mod001-01_core/all/collection.rb +1 -1
- data/tmpsets/set/mod001-01_core/all/name.rb +2 -1
- data/tmpsets/set/mod001-01_core/all/phases.rb +12 -2
- data/tmpsets/set/mod001-01_core/all/type.rb +5 -5
- data/tmpsets/set/mod002-01_history/all/actions.rb +6 -2
- data/tmpsets/set/mod002-01_history/all/content_history.rb +17 -2
- data/tmpsets/set/mod002-01_history/all/history.rb +1 -1
- data/tmpsets/set/mod003-02_basic_types/all/file.rb +0 -24
- data/tmpsets/set/mod003-02_basic_types/all/rss.rb +8 -5
- data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +2 -2
- data/tmpsets/set/mod005-04_settings/right/structure.rb +7 -2
- data/tmpsets/set/mod006-05_email/all/notify.rb +1 -1
- data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +132 -14
- data/tmpsets/set/mod007-05_standard/all/links.rb +8 -0
- data/tmpsets/set/mod007-05_standard/all/rich_html/header.rb +5 -7
- data/tmpsets/set/mod007-05_standard/right/account.rb +2 -2
- data/tmpsets/set/mod007-05_standard/self/signin.rb +0 -1
- data/tmpsets/set/mod007-05_standard/type/file.rb +49 -20
- data/tmpsets/set/mod007-05_standard/type/image.rb +9 -12
- data/tmpsets/set/mod007-05_standard/type/search_type.rb +40 -22
- data/tmpsets/set/mod008-06_bootstrap/self/bootswatch_shared.rb +1 -1
- metadata +10 -4
data/db/version_core_cards.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
20150903130006
|
data/lib/card.rb
CHANGED
@@ -47,14 +47,16 @@ class Card < ActiveRecord::Base
|
|
47
47
|
:comment, :comment_author, # obviated soon
|
48
48
|
:update_referencers, # wrong mechanism for this
|
49
49
|
:update_all_users, # if the above is wrong then this one too
|
50
|
+
:silent_change, # and this probably too
|
50
51
|
:remove_rule_stash,
|
51
52
|
:last_action_id_before_edit
|
52
53
|
|
53
54
|
attr_accessor :follower_stash
|
54
55
|
|
55
56
|
|
56
|
-
define_callbacks :approve, :store, :stored, :extend, :subsequent
|
57
|
+
define_callbacks :prepare, :approve, :store, :stored, :extend, :subsequent, :select_action
|
57
58
|
|
59
|
+
before_validation :prepare
|
58
60
|
before_validation :approve
|
59
61
|
around_save :store
|
60
62
|
after_save :extend
|
data/lib/card/cache.rb
CHANGED
@@ -15,17 +15,17 @@ class Card
|
|
15
15
|
|
16
16
|
class Cache
|
17
17
|
|
18
|
-
TEST_ENVS
|
19
|
-
@@prepopulating
|
20
|
-
@@
|
21
|
-
@@cache_by_class
|
18
|
+
TEST_ENVS = %w{test cucumber}
|
19
|
+
@@prepopulating = TEST_ENVS.include? Rails.env
|
20
|
+
@@no_rails_cache = TEST_ENVS.include?(Rails.env) || ENV['NO_RAILS_CACHE']
|
21
|
+
@@cache_by_class = {}
|
22
22
|
|
23
23
|
cattr_reader :cache_by_class
|
24
24
|
|
25
25
|
class << self
|
26
26
|
def [] klass
|
27
27
|
raise "nil klass" if klass.nil?
|
28
|
-
cache_by_class[klass] ||= new :class=>klass, :store=>(@@
|
28
|
+
cache_by_class[klass] ||= new :class=>klass, :store=>(@@no_rails_cache ? nil : Cardio.cache)
|
29
29
|
end
|
30
30
|
|
31
31
|
def renew
|
data/lib/card/chunk.rb
CHANGED
@@ -60,6 +60,8 @@ class Card
|
|
60
60
|
attr_reader :text, :process_chunk
|
61
61
|
|
62
62
|
class << self
|
63
|
+
|
64
|
+
# if the prefix regex matched check that chunk against the full regex
|
63
65
|
def full_match content, prefix=nil
|
64
66
|
# warn "attempting full match on #{content}. class = #{self}"
|
65
67
|
content.match full_re( prefix )
|
data/lib/card/env.rb
CHANGED
@@ -14,7 +14,6 @@ class Card
|
|
14
14
|
self[:ajax] = c.request.xhr? || c.request.params[:simulate_xhr]
|
15
15
|
self[:host] = Card.config.override_host || c.request.env['HTTP_HOST']
|
16
16
|
self[:protocol] = Card.config.override_protocol || c.request.protocol
|
17
|
-
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -35,6 +34,7 @@ class Card
|
|
35
34
|
self[:session] ||= {}
|
36
35
|
end
|
37
36
|
|
37
|
+
|
38
38
|
def ajax?
|
39
39
|
self[:ajax]
|
40
40
|
end
|
@@ -2,20 +2,21 @@
|
|
2
2
|
class Card
|
3
3
|
class Query
|
4
4
|
class CardClause < Clause
|
5
|
-
|
5
|
+
PLUS_ATTRIBUTES = %w{ plus left_plus right_plus }
|
6
|
+
|
6
7
|
ATTRIBUTES = {
|
7
|
-
:basic => %w{ name type_id content id key updater_id left_id right_id creator_id updater_id codename },
|
8
|
+
:basic => %w{ name type_id content id key updater_id left_id right_id creator_id updater_id codename },
|
8
9
|
:relational => %w{ type part left right editor_of edited_by last_editor_of last_edited_by creator_of created_by member_of member },
|
9
|
-
:plus_relational =>
|
10
|
+
:plus_relational => PLUS_ATTRIBUTES,
|
10
11
|
:ref_relational => %w{ refer_to referred_to_by link_to linked_to_by include included_by },
|
11
12
|
:conjunction => %w{ and or all any },
|
12
13
|
:special => %w{ found_by not sort match complete extension_type },
|
13
14
|
:ignore => %w{ prepend append view params vars size }
|
14
15
|
}.inject({}) {|h,pair| pair[1].each {|v| h[v.to_sym]=pair[0] }; h }
|
15
|
-
|
16
|
+
|
16
17
|
DEFAULT_ORDER_DIRS = { :update => "desc", :relevance => "desc" }
|
17
18
|
CONJUNCTIONS = { :any=>:or, :in=>:or, :or=>:or, :all=>:and, :and=>:and }
|
18
|
-
|
19
|
+
|
19
20
|
attr_reader :sql, :query, :rawclause, :selfname
|
20
21
|
attr_accessor :joins, :join_count
|
21
22
|
|
@@ -38,7 +39,7 @@ class Card
|
|
38
39
|
@vars.symbolize_keys!
|
39
40
|
@query = clean(@query)
|
40
41
|
@rawclause = @query.deep_clone
|
41
|
-
|
42
|
+
|
42
43
|
@sql.distinct = 'DISTINCT' if @parent
|
43
44
|
|
44
45
|
self
|
@@ -48,7 +49,7 @@ class Card
|
|
48
49
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
49
50
|
# QUERY CLEANING - strip strings, absolutize names, interpret contextual parameters
|
50
51
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
51
|
-
|
52
|
+
|
52
53
|
|
53
54
|
def clean query
|
54
55
|
query = query.symbolize_keys
|
@@ -74,11 +75,11 @@ class Card
|
|
74
75
|
else ; raise BadQuery, "unknown WQL value type: #{val.class}"
|
75
76
|
end
|
76
77
|
end
|
77
|
-
|
78
|
+
|
78
79
|
def root
|
79
80
|
@parent ? @parent.root : self
|
80
81
|
end
|
81
|
-
|
82
|
+
|
82
83
|
def absolute_name name
|
83
84
|
name =~ /\b_/ ? name.to_name.to_absolute(root.selfname) : name
|
84
85
|
end
|
@@ -87,7 +88,7 @@ class Card
|
|
87
88
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
88
89
|
# MERGE - reduce query to basic attributes and SQL subconditions
|
89
90
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
90
|
-
|
91
|
+
|
91
92
|
|
92
93
|
def merge s
|
93
94
|
s = hashify s
|
@@ -96,7 +97,7 @@ class Card
|
|
96
97
|
@clause.merge! s
|
97
98
|
self
|
98
99
|
end
|
99
|
-
|
100
|
+
|
100
101
|
def hashify s
|
101
102
|
case s
|
102
103
|
when String; { :key => s.to_name.key }
|
@@ -134,21 +135,21 @@ class Card
|
|
134
135
|
val = clause.delete key
|
135
136
|
is_array = Array===val
|
136
137
|
case ATTRIBUTES[keyroot]
|
137
|
-
when :ignore #noop
|
138
|
+
when :ignore #noop
|
138
139
|
when :relational, :special, :conjunction ; relate is_array, keyroot, val, :send
|
139
140
|
when :ref_relational ; relate is_array, keyroot, val, :refclause
|
140
141
|
when :plus_relational
|
141
142
|
# Arrays can have multiple interpretations for these, so we have to look closer...
|
142
143
|
subcond = is_array && ( Array===val.first || conjunction(val.first) )
|
143
|
-
|
144
|
+
|
144
145
|
relate subcond, keyroot, val, :send
|
145
146
|
else ; raise BadQuery, "Invalid attribute #{key}"
|
146
147
|
end
|
147
148
|
end
|
148
149
|
end
|
149
|
-
|
150
|
+
|
150
151
|
end
|
151
|
-
|
152
|
+
|
152
153
|
def relate subcond, key, val, method
|
153
154
|
if subcond
|
154
155
|
conj = conjunction( val.first ) ? conjunction( val.shift ) : :and
|
@@ -162,7 +163,7 @@ class Card
|
|
162
163
|
end
|
163
164
|
end
|
164
165
|
|
165
|
-
def refclause key, val
|
166
|
+
def refclause key, val
|
166
167
|
add_join :ref, RefClause.new( key, val, self ).to_sql, :id, :ref_id
|
167
168
|
end
|
168
169
|
|
@@ -177,7 +178,7 @@ class Card
|
|
177
178
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
178
179
|
# ATTRIBUTE METHODS - called during merge
|
179
180
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
180
|
-
|
181
|
+
|
181
182
|
|
182
183
|
#~~~~~~ RELATIONAL
|
183
184
|
|
@@ -190,15 +191,15 @@ class Card
|
|
190
191
|
subcondition :left=>val, :right=>right, :conj=>:or
|
191
192
|
end
|
192
193
|
|
193
|
-
|
194
|
+
|
194
195
|
def left val
|
195
196
|
restrict :left_id, val
|
196
197
|
end
|
197
|
-
|
198
|
+
|
198
199
|
def right val
|
199
200
|
restrict :right_id, val
|
200
201
|
end
|
201
|
-
|
202
|
+
|
202
203
|
def editor_of val
|
203
204
|
action_clause :actor_id, "card_actions.card_id", val
|
204
205
|
end
|
@@ -206,14 +207,14 @@ class Card
|
|
206
207
|
def edited_by val
|
207
208
|
action_clause "card_actions.card_id", :actor_id, val
|
208
209
|
end
|
209
|
-
|
210
|
+
|
210
211
|
def last_editor_of val
|
211
212
|
restrict_by_join :id, val, :return=>'updater_id'
|
212
213
|
end
|
213
214
|
|
214
215
|
def last_edited_by val
|
215
216
|
restrict :updater_id, val
|
216
|
-
end
|
217
|
+
end
|
217
218
|
|
218
219
|
def creator_of val
|
219
220
|
restrict_by_join :id, val, :return=>'creator_id'
|
@@ -226,7 +227,7 @@ class Card
|
|
226
227
|
def member_of val
|
227
228
|
merge field(:right_plus) => [RolesID, {:refer_to=>val}]
|
228
229
|
end
|
229
|
-
|
230
|
+
|
230
231
|
def member val
|
231
232
|
merge field(:referred_to_by) => {:left=>val, :right=>RolesID }
|
232
233
|
end
|
@@ -245,30 +246,30 @@ class Card
|
|
245
246
|
def plus val
|
246
247
|
any( { :left_plus=>val, :right_plus=>val.deep_clone } )
|
247
248
|
end
|
248
|
-
|
249
|
+
|
249
250
|
def junction side, val
|
250
251
|
part_clause, junction_clause = val.is_a?(Array) ? val : [ val, {} ]
|
251
252
|
restrict_by_join :id, junction_clause, side=>part_clause, :return=>"#{ side==:left ? :right : :left}_id"
|
252
253
|
end
|
253
|
-
|
254
|
-
|
254
|
+
|
255
|
+
|
255
256
|
#~~~~~~~ CONJUNCTION
|
256
|
-
|
257
|
+
|
257
258
|
def and val
|
258
259
|
subcondition val
|
259
260
|
end
|
260
261
|
alias :all :and
|
261
|
-
|
262
|
+
|
262
263
|
def or val
|
263
264
|
subcondition val, :conj=>:or
|
264
265
|
end
|
265
266
|
alias :any :or
|
266
|
-
|
267
|
+
|
267
268
|
#~~~~~~ SPECIAL
|
268
269
|
|
269
270
|
|
270
271
|
def found_by val
|
271
|
-
|
272
|
+
|
272
273
|
cards = if Hash===val
|
273
274
|
Query.new(val).run
|
274
275
|
else
|
@@ -284,10 +285,10 @@ class Card
|
|
284
285
|
restrict_by_join :id, CardClause.new(c.get_query).rawclause
|
285
286
|
end
|
286
287
|
end
|
287
|
-
|
288
|
+
|
288
289
|
def not val
|
289
290
|
subselect = CardClause.build(:return=>:id, :_parent=>self).merge(val).to_sql
|
290
|
-
join_alias = add_join :not, subselect, :id, :id, :side=>'LEFT'
|
291
|
+
join_alias = add_join :not, subselect, :id, :id, :side=>'LEFT'
|
291
292
|
merge field(:cond) => SqlCond.new("#{join_alias}.id is null")
|
292
293
|
end
|
293
294
|
|
@@ -319,18 +320,18 @@ class Card
|
|
319
320
|
cs.sql.fields << "#{cs.table_alias}.#{join_field} as sort_join_field"
|
320
321
|
join_table = add_join :sort, cs.to_sql, :id, :sort_join_field, :side=>'LEFT'
|
321
322
|
@mods[:sort] ||= "#{join_table}.#{val[:return]}"
|
322
|
-
|
323
|
+
|
323
324
|
end
|
324
325
|
|
325
326
|
def match(val)
|
326
327
|
cxn, val = match_prep val
|
327
328
|
val.gsub! /[^#{Card::Name::OK4KEY_RE}]+/, ' '
|
328
329
|
return nil if val.strip.empty?
|
329
|
-
|
330
|
+
|
330
331
|
|
331
332
|
cond = begin
|
332
333
|
val_list = val.split(/\s+/).map do |v|
|
333
|
-
name_or_content = ["replace(#{self.table_alias}.name,'+',' ')","#{self.table_alias}.db_content"].map do |field|
|
334
|
+
name_or_content = ["replace(#{self.table_alias}.name,'+',' ')","#{self.table_alias}.db_content"].map do |field|
|
334
335
|
%{#{field} #{ cxn.match quote("[[:<:]]#{v}[[:>:]]") }}
|
335
336
|
end
|
336
337
|
"(#{name_or_content.join ' OR '})"
|
@@ -340,8 +341,8 @@ class Card
|
|
340
341
|
|
341
342
|
merge field(:cond)=>SqlCond.new(cond)
|
342
343
|
end
|
343
|
-
|
344
|
-
|
344
|
+
|
345
|
+
|
345
346
|
def complete(val)
|
346
347
|
no_plus_card = (val=~/\+/ ? '' : "and right_id is null") #FIXME -- this should really be more nuanced -- it breaks down after one plus
|
347
348
|
merge field(:cond) => SqlCond.new(" lower(name) LIKE lower(#{quote(val.to_s+'%')}) #{no_plus_card}")
|
@@ -349,10 +350,10 @@ class Card
|
|
349
350
|
|
350
351
|
def extension_type val
|
351
352
|
# DEPRECATED LONG AGO!!!
|
352
|
-
Rails.logger.info "using DEPRECATED extension_type in WQL"
|
353
|
+
Rails.logger.info "using DEPRECATED extension_type in WQL"
|
353
354
|
merge field(:right_plus) => AccountID
|
354
355
|
end
|
355
|
-
|
356
|
+
|
356
357
|
|
357
358
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
358
359
|
# ATTRIBUTE METHOD HELPERS - called by attribute methods above
|
@@ -365,7 +366,7 @@ class Card
|
|
365
366
|
@parent ? @parent.table_alias : "t"
|
366
367
|
when @parent
|
367
368
|
@parent.table_alias + "x"
|
368
|
-
else
|
369
|
+
else
|
369
370
|
"t"
|
370
371
|
end
|
371
372
|
end
|
@@ -375,7 +376,7 @@ class Card
|
|
375
376
|
join_alias = "#{name}_#{root.join_count}"
|
376
377
|
on = "#{table_alias}.#{cardfield} = #{join_alias}.#{otherfield}"
|
377
378
|
#is_subselect = !table.is_a?( Symbol )
|
378
|
-
|
379
|
+
|
379
380
|
if @mods[:conj] == 'or' #and is_subselect
|
380
381
|
opts[:side] ||= 'LEFT'
|
381
382
|
merge field(:cond) => SqlCond.new(on)
|
@@ -400,8 +401,8 @@ class Card
|
|
400
401
|
cardclause = CardClause.build( args )
|
401
402
|
merge field(:cond) => cardclause.merge(val)
|
402
403
|
self.joins.merge! cardclause.joins
|
403
|
-
end
|
404
|
-
|
404
|
+
end
|
405
|
+
|
405
406
|
def action_clause(field, linkfield, val)
|
406
407
|
card_select = CardClause.build(:_parent=>self, :return=>'id').merge(val).to_sql
|
407
408
|
sql = "(SELECT DISTINCT #{field} AS join_card_id FROM card_acts INNER JOIN card_actions ON card_acts.id = card_act_id "
|
@@ -415,7 +416,7 @@ class Card
|
|
415
416
|
when String ; Card.fetch_id(clause)
|
416
417
|
end
|
417
418
|
end
|
418
|
-
|
419
|
+
|
419
420
|
def restrict id_field, val, opts={}
|
420
421
|
if id = id_from_clause(val)
|
421
422
|
merge field(id_field) => id
|
@@ -423,13 +424,13 @@ class Card
|
|
423
424
|
restrict_by_join id_field, val, opts
|
424
425
|
end
|
425
426
|
end
|
426
|
-
|
427
|
+
|
427
428
|
def restrict_by_join id_field, val, opts={}
|
428
429
|
opts.reverse_merge!(:return=>:id, :_parent=>self)
|
429
430
|
subselect = CardClause.build(opts).merge(val).to_sql
|
430
431
|
add_join "card_#{id_field}", subselect, id_field, opts[:return]
|
431
432
|
end
|
432
|
-
|
433
|
+
|
433
434
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
434
435
|
# SQL GENERATION - translate merged hash into complete SQL statement.
|
435
436
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
@@ -437,12 +438,12 @@ class Card
|
|
437
438
|
|
438
439
|
def to_sql *args
|
439
440
|
sql.conditions << basic_conditions
|
440
|
-
|
441
|
+
|
441
442
|
if @mods[:return]=='condition'
|
442
443
|
conds = sql.conditions.last
|
443
444
|
return conds.blank? ? nil : "(#{conds})"
|
444
445
|
end
|
445
|
-
|
446
|
+
|
446
447
|
if pconds = permission_conditions
|
447
448
|
sql.conditions << pconds
|
448
449
|
end
|
@@ -453,7 +454,7 @@ class Card
|
|
453
454
|
sql.joins += @joins.values
|
454
455
|
|
455
456
|
sql.conditions << "#{table_alias}.trash is false"
|
456
|
-
|
457
|
+
|
457
458
|
sql.group = "GROUP BY #{safe_sql(@mods[:group])}" if !@mods[:group].blank?
|
458
459
|
unless @parent or @mods[:return]=='count'
|
459
460
|
if @mods[:limit].to_i > 0
|
@@ -464,21 +465,21 @@ class Card
|
|
464
465
|
|
465
466
|
sql.to_s
|
466
467
|
end
|
467
|
-
|
468
|
+
|
468
469
|
def basic_conditions
|
469
470
|
@clause.map { |key, val| val.to_sql field_root(key) }.compact.join " #{ current_conjunction } "
|
470
471
|
end
|
471
|
-
|
472
|
+
|
472
473
|
def current_conjunction
|
473
474
|
@mods[:conj].blank? ? :and : @mods[:conj]
|
474
475
|
end
|
475
|
-
|
476
|
+
|
476
477
|
def permission_conditions
|
477
478
|
unless Auth.always_ok? #or ( Card::Query.root_perms_only && !root? )
|
478
479
|
read_rules = Auth.as_card.read_rules
|
479
480
|
read_rule_list = read_rules.nil? ? 1 : read_rules.join(',')
|
480
481
|
"(#{table_alias}.read_rule_id IN (#{ read_rule_list }))"
|
481
|
-
end
|
482
|
+
end
|
482
483
|
end
|
483
484
|
|
484
485
|
def fields_to_sql
|
@@ -495,10 +496,10 @@ class Card
|
|
495
496
|
|
496
497
|
def sort_to_sql
|
497
498
|
#fail "order_key = #{@mods[:sort]}, class = #{order_key.class}"
|
498
|
-
|
499
|
+
|
499
500
|
return nil if @parent or @mods[:return]=='count' #FIXME - extend to all root-only clauses
|
500
501
|
order_key ||= @mods[:sort].blank? ? "update" : @mods[:sort]
|
501
|
-
|
502
|
+
|
502
503
|
order_directives = [order_key].flatten.map do |key|
|
503
504
|
dir = @mods[:dir].blank? ? (DEFAULT_ORDER_DIRS[key.to_sym]||'asc') : safe_sql(@mods[:dir]) #wonky
|
504
505
|
sort_field key, @mods[:sort_as], dir
|
@@ -506,7 +507,7 @@ class Card
|
|
506
507
|
"ORDER BY #{order_directives}"
|
507
508
|
|
508
509
|
end
|
509
|
-
|
510
|
+
|
510
511
|
def sort_field key, as, dir
|
511
512
|
order_field = case key
|
512
513
|
when "id"; "#{table_alias}.id"
|
@@ -514,13 +515,13 @@ class Card
|
|
514
515
|
when "create"; "#{table_alias}.created_at"
|
515
516
|
when /^(name|alpha)$/; "LOWER( #{table_alias}.key )"
|
516
517
|
when 'content'; "#{table_alias}.db_content"
|
517
|
-
when "relevance"; "#{table_alias}.updated_at" #deprecated
|
518
|
+
when "relevance"; "#{table_alias}.updated_at" #deprecated
|
518
519
|
else
|
519
520
|
safe_sql(key)
|
520
521
|
end
|
521
522
|
order_field = "CAST(#{order_field} AS #{cast_type(as)})" if as
|
522
523
|
"#{order_field} #{dir}"
|
523
|
-
|
524
|
+
|
524
525
|
end
|
525
526
|
end
|
526
527
|
end
|