card 1.16.15 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/recaptcha.rb +21 -4
  4. data/db/migrate_core_cards/20130823192433_add_style_cards.rb +1 -1
  5. data/db/migrate_core_cards/20140512155840_add_script_cards.rb +1 -1
  6. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +2 -2
  7. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
  8. data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +1 -1
  9. data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +63 -0
  10. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
  11. data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +1 -1
  12. data/db/schema.rb +1 -1
  13. data/db/seed/new/card_actions.yml +602 -394
  14. data/db/seed/new/card_acts.yml +595 -1
  15. data/db/seed/new/card_changes.yml +26282 -10262
  16. data/db/seed/new/card_references.yml +1252 -1084
  17. data/db/seed/new/cards.yml +1899 -1423
  18. data/db/seed/test/fixtures/card_actions.yml +1653 -1413
  19. data/db/seed/test/fixtures/card_acts.yml +1063 -445
  20. data/db/seed/test/fixtures/card_changes.yml +29674 -13637
  21. data/db/seed/test/fixtures/card_references.yml +1976 -1815
  22. data/db/seed/test/fixtures/cards.yml +3194 -2719
  23. data/lib/card.rb +14 -13
  24. data/lib/card/auth.rb +10 -6
  25. data/lib/card/cache.rb +58 -120
  26. data/lib/card/cache/persistent.rb +50 -0
  27. data/lib/card/cache/temporary.rb +38 -0
  28. data/lib/card/chunk.rb +34 -25
  29. data/lib/card/content.rb +3 -3
  30. data/lib/card/env.rb +3 -0
  31. data/lib/card/format.rb +56 -53
  32. data/lib/card/migration.rb +6 -2
  33. data/lib/card/name.rb +9 -1
  34. data/lib/card/query.rb +1 -1
  35. data/lib/card/reference.rb +17 -11
  36. data/lib/card/set.rb +1 -1
  37. data/lib/card/subcards.rb +6 -6
  38. data/lib/card/view_cache.rb +45 -28
  39. data/lib/generators/card/migration/templates/card_migration.erb +1 -2
  40. data/mod/01_core/chunk/include.rb +71 -48
  41. data/mod/01_core/chunk/link.rb +6 -3
  42. data/mod/01_core/chunk/query_reference.rb +38 -29
  43. data/mod/01_core/chunk/reference.rb +23 -24
  44. data/mod/01_core/set/all/collection.rb +1 -1
  45. data/mod/01_core/set/all/fetch.rb +39 -12
  46. data/mod/01_core/set/all/permissions.rb +2 -4
  47. data/mod/01_core/set/all/references.rb +50 -75
  48. data/mod/01_core/set/all/rules.rb +19 -18
  49. data/mod/01_core/set/all/subcards.rb +1 -1
  50. data/mod/01_core/set/all/templating.rb +31 -88
  51. data/mod/01_core/set/all/tracked_attributes.rb +7 -14
  52. data/mod/01_core/set/all/utils.rb +77 -66
  53. data/mod/01_core/set_pattern/07_type_plus_right.rb +6 -3
  54. data/mod/01_core/spec/set/all/fetch_spec.rb +148 -96
  55. data/mod/01_core/spec/set/all/templating_spec.rb +49 -40
  56. data/mod/01_core/spec/set/all/trash_spec.rb +1 -1
  57. data/mod/01_history/set/all/actions.rb +1 -1
  58. data/mod/02_basic_types/set/all/base.rb +13 -7
  59. data/mod/02_basic_types/set/all/rss.rb +17 -22
  60. data/mod/02_basic_types/set/type/plain_text.rb +5 -2
  61. data/mod/02_basic_types/spec/set/all/base_spec.rb +1 -0
  62. data/mod/02_basic_types/spec/set/all/rss_spec.rb +7 -6
  63. data/mod/03_machines/lib/javascript/wagn.js.coffee +22 -9
  64. data/mod/03_machines/set/right/machine_output.rb +1 -1
  65. data/mod/04_settings/lib/card/setting.rb +45 -31
  66. data/mod/04_settings/set/right/structure.rb +47 -1
  67. data/mod/04_settings/set/self/default_html_view.rb +2 -0
  68. data/mod/04_settings/set/self/follow_fields.rb +2 -0
  69. data/mod/04_settings/set/self/recent_settings.rb +1 -1
  70. data/mod/05_standard/file/favicon/image-icon.png +0 -0
  71. data/mod/05_standard/file/favicon/image-large.png +0 -0
  72. data/mod/05_standard/file/favicon/image-medium.png +0 -0
  73. data/mod/05_standard/file/favicon/image-original.png +0 -0
  74. data/mod/05_standard/file/favicon/image-small.png +0 -0
  75. data/mod/05_standard/set/all/links.rb +27 -26
  76. data/mod/05_standard/set/all/rich_html/editing.rb +1 -1
  77. data/mod/05_standard/set/all/rich_html/toolbar.rb +1 -1
  78. data/mod/05_standard/set/rstar/rules.rb +20 -325
  79. data/mod/05_standard/set/rstar/rules_editor.rb +362 -0
  80. data/mod/05_standard/set/self/admin_info.rb +82 -0
  81. data/mod/05_standard/set/self/all.rb +16 -10
  82. data/mod/05_standard/set/self/head.rb +20 -19
  83. data/mod/05_standard/set/type/signup.rb +0 -1
  84. data/mod/05_standard/spec/set/all/account_spec.rb +44 -43
  85. data/mod/05_standard/spec/set/right/account_spec.rb +4 -2
  86. data/mod/05_standard/spec/set/type/search_type_spec.rb +8 -0
  87. data/mod/05_standard/spec/set/type/signup_spec.rb +24 -17
  88. data/mod/06_bootstrap/set/all/bootstrap/helper.rb +1 -1
  89. data/spec/lib/card/cache_spec.rb +64 -70
  90. data/spec/lib/card/content_spec.rb +236 -150
  91. data/spec/lib/card/reference_spec.rb +22 -38
  92. data/spec/lib/card/subcards_spec.rb +38 -0
  93. data/spec/lib/card/view_cache_spec.rb +8 -0
  94. data/spec/spec_helper.rb +1 -1
  95. data/tmpsets/set/mod001-01_core/all/collection.rb +77 -74
  96. data/tmpsets/set/mod001-01_core/all/content.rb +14 -16
  97. data/tmpsets/set/mod001-01_core/all/fetch.rb +137 -110
  98. data/tmpsets/set/mod001-01_core/all/name.rb +58 -40
  99. data/tmpsets/set/mod001-01_core/all/pattern.rb +12 -11
  100. data/tmpsets/set/mod001-01_core/all/permissions.rb +125 -117
  101. data/tmpsets/set/mod001-01_core/all/phases.rb +2 -1
  102. data/tmpsets/set/mod001-01_core/all/references.rb +52 -77
  103. data/tmpsets/set/mod001-01_core/all/rules.rb +47 -53
  104. data/tmpsets/set/mod001-01_core/all/templating.rb +31 -87
  105. data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +12 -21
  106. data/tmpsets/set/mod001-01_core/all/trash.rb +4 -1
  107. data/tmpsets/set/mod001-01_core/all/type.rb +23 -21
  108. data/tmpsets/set/mod001-01_core/all/utils.rb +80 -64
  109. data/tmpsets/set/mod002-01_history/all/actions.rb +20 -16
  110. data/tmpsets/set/mod002-01_history/all/history.rb +18 -13
  111. data/tmpsets/set/mod003-02_basic_types/all/base.rb +37 -10
  112. data/tmpsets/set/mod003-02_basic_types/all/rss.rb +17 -22
  113. data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +5 -2
  114. data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +51 -39
  115. data/tmpsets/set/mod004-03_machines/right/machine_output.rb +10 -6
  116. data/tmpsets/set/mod005-04_settings/abstract/permission.rb +10 -5
  117. data/tmpsets/set/mod005-04_settings/right/structure.rb +47 -1
  118. data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +1 -0
  119. data/tmpsets/set/mod005-04_settings/type/setting.rb +4 -1
  120. data/tmpsets/set/mod006-05_email/all/follow.rb +45 -54
  121. data/tmpsets/set/mod006-05_email/all/notify.rb +88 -73
  122. data/tmpsets/set/mod006-05_email/right/followers.rb +17 -14
  123. data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +22 -18
  124. data/tmpsets/set/mod006-05_email/type/email_template.rb +1 -1
  125. data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +94 -67
  126. data/tmpsets/set/mod007-05_standard/all/account.rb +18 -20
  127. data/tmpsets/set/mod007-05_standard/all/comment.rb +51 -29
  128. data/tmpsets/set/mod007-05_standard/all/error.rb +129 -99
  129. data/tmpsets/set/mod007-05_standard/all/links.rb +27 -26
  130. data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +115 -103
  131. data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +112 -78
  132. data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +123 -81
  133. data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +15 -58
  134. data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -2
  135. data/tmpsets/set/mod007-05_standard/right/account.rb +71 -75
  136. data/tmpsets/set/mod007-05_standard/right/email.rb +16 -13
  137. data/tmpsets/set/mod007-05_standard/right/password.rb +20 -12
  138. data/tmpsets/set/mod007-05_standard/right/status.rb +2 -2
  139. data/tmpsets/set/mod007-05_standard/right/token.rb +49 -2
  140. data/tmpsets/set/mod007-05_standard/rstar/rules.rb +20 -325
  141. data/tmpsets/set/mod007-05_standard/self/all.rb +16 -10
  142. data/tmpsets/set/mod007-05_standard/self/head.rb +76 -62
  143. data/tmpsets/set/mod007-05_standard/self/search.rb +45 -22
  144. data/tmpsets/set/mod007-05_standard/self/signin.rb +14 -12
  145. data/tmpsets/set/mod007-05_standard/type/cardtype.rb +13 -11
  146. data/tmpsets/set/mod007-05_standard/type/file.rb +1 -1
  147. data/tmpsets/set/mod007-05_standard/type/search_type.rb +3 -2
  148. data/tmpsets/set/mod007-05_standard/type/set.rb +20 -16
  149. data/tmpsets/set/mod007-05_standard/type/signup.rb +19 -25
  150. data/tmpsets/set/mod007-05_standard/type/user.rb +1 -1
  151. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +1 -1
  152. data/tmpsets/set_pattern/106-type_plus_right.rb +6 -3
  153. metadata +11 -2
@@ -4,18 +4,20 @@ class Card; module Set; module All; module Name; extend Card::Set
4
4
  require 'uuid'
5
5
 
6
6
  module ClassMethods
7
- def uniquify_name name, rename=false
8
- return name unless Card[name]
7
+ def uniquify_name name, rename=:new
8
+ return name unless Card.exists?(name)
9
9
  uniq_name = "#{name} 1"
10
- while Card[uniq_name]
10
+ while Card.exists?(uniq_name)
11
11
  uniq_name.next!
12
12
  end
13
- return uniq_name unless rename
14
-
15
- Card[name].update_attributes! name: uniq_name,
16
- update_referencers: true
17
- # name conflict resolved; original name can be used
18
- name
13
+ if rename == :old
14
+ # name conflict resolved; original name can be used
15
+ Card[name].update_attributes! name: uniq_name,
16
+ update_referencers: true
17
+ name
18
+ else
19
+ uniq_name
20
+ end
19
21
  end
20
22
  end
21
23
 
@@ -122,24 +124,42 @@ def left_or_new args={}
122
124
  left(args) || Card.new(args.merge(name: cardname.left))
123
125
  end
124
126
 
127
+ def fields
128
+ field_names.map { |name| Card[name] }
129
+ end
130
+
131
+ def field_names parent_name=nil
132
+ child_names parent_name, :left
133
+ end
134
+
125
135
  def children
126
- Card.search((simple? ? :part : :left) => name).to_a
136
+ child_names.map { |name| Card[name] }
127
137
  end
128
138
 
129
- def dependents
130
- return [] if new_card?
139
+ def child_names parent_name=nil, side=nil
140
+ # eg, A+B is a child of A and B
141
+ parent_name ||= name
142
+ side ||= parent_name.to_name.simple? ? :part : :left
143
+ Card.search({ side => parent_name, return: :name },
144
+ "(#{side}) children of #{parent_name}")
145
+ end
131
146
 
132
- if @dependents.nil?
133
- @dependents =
134
- Auth.as_bot do
135
- deps = children
136
- deps.inject(deps) do |array, card|
137
- array + card.dependents
138
- end
139
- end
140
- # Rails.logger.warn "dependents[#{inspect}] #{@dependents.inspect}"
147
+ def descendant_names parent_name=nil
148
+ return [] if new_card?
149
+ parent_name ||= name
150
+ Auth.as_bot do
151
+ deps = child_names parent_name
152
+ deps.inject(deps) do |array, childname|
153
+ array + descendant_names(childname)
154
+ end
141
155
  end
142
- @dependents
156
+ end
157
+
158
+ def descendants
159
+ # children and children's children
160
+ # NOTE - set modules are not loaded
161
+ # -- should only be used for name manipulations
162
+ @descendants ||= descendant_names.map { |name| Card.quick_fetch name }
143
163
  end
144
164
 
145
165
  def repair_key
@@ -157,7 +177,7 @@ def repair_key
157
177
  saved ||= (self.cardname = current_key) && self.save!
158
178
 
159
179
  if saved
160
- dependents.each(&:repair_key)
180
+ descendants.each(&:repair_key)
161
181
  else
162
182
  Rails.logger.debug "FAILED TO REPAIR BROKEN KEY: #{key}"
163
183
  self.name = "BROKEN KEY: #{name}"
@@ -215,8 +235,9 @@ end
215
235
  event :set_autoname, before: :validate_name, on: :create do
216
236
  if name.blank? && (autoname_card = rule_card(:autoname))
217
237
  self.name = autoname autoname_card.content
218
- # FIXME: should give placeholder on new, do next and save on create
219
- Auth.as_bot { autoname_card.refresh.update_attributes! content: name }
238
+ # FIXME: should give placeholder in approve phase
239
+ # and finalize/commit change in store phase
240
+ autoname_card.refresh.update_column :db_content, name
220
241
  end
221
242
  end
222
243
 
@@ -278,28 +299,25 @@ event :cascade_name_changes, after: :store, on: :update, changed: :name do
278
299
  self.update_referencers = false if update_referencers == 'false'
279
300
  Card::Reference.update_on_rename self, name, self.update_referencers
280
301
 
281
- deps = dependents
282
- # warn "-------------------#{name_was}---- CASCADE #{self.name} -> deps: " \
283
- # " #{deps.map(&:name)*', '} -----------------------"
284
-
285
- @dependents = nil # reset
302
+ des = descendants
303
+ @descendants = nil # reset
286
304
 
287
- deps.each do |dep|
305
+ des.each do |de|
288
306
  # here we specifically want NOT to invoke recursive cascades on these
289
307
  # cards, have to go this low level to avoid callbacks.
290
- Rails.logger.info "cascading name: #{dep.name}"
291
- Card.expire dep.name # old name
292
- newname = dep.cardname.replace_part name_was, name
293
- Card.where(id: dep.id).update_all name: newname.to_s, key: newname.key
294
- Card::Reference.update_on_rename dep, newname, update_referencers
308
+ Rails.logger.info "cascading name: #{de.name}"
309
+ Card.expire de.name # old name
310
+ newname = de.cardname.replace_part name_was, name
311
+ Card.where(id: de.id).update_all name: newname.to_s, key: newname.key
312
+ Card::Reference.update_on_rename de, newname, update_referencers
295
313
  Card.expire newname
296
314
  end
297
- execute_referencers_update(deps) if update_referencers
315
+ execute_referencers_update(des) if update_referencers
298
316
  end
299
317
 
300
- def execute_referencers_update dependents
318
+ def execute_referencers_update descendants
301
319
  Auth.as_bot do
302
- [name_referencers(name_was) + dependents.map(&:referencers)]
320
+ [name_referencers(name_was) + descendants.map(&:referencers)]
303
321
  .flatten.uniq.each do |card|
304
322
  # FIXME: using 'name_referencers' instead of plain 'referencers' for self
305
323
  # because there are cases where trunk and tag
@@ -310,7 +328,7 @@ def execute_referencers_update dependents
310
328
  # so at this time X is still including Y, which does not exist.
311
329
  # therefore #referencers doesn't find it, but name_referencers(old_name)
312
330
  # does.
313
- # some even more complicated scenario probably breaks on the dependents,
331
+ # some even more complicated scenario probably breaks on the descendants,
314
332
  # so this probably needs a more thoughtful refactor
315
333
  # aligning the dependent saving with the name cascading
316
334
 
@@ -22,26 +22,28 @@ def reset_patterns_if_rule saving=false
22
22
  set.reset_patterns
23
23
  set.include_set_modules
24
24
 
25
- #this is really messy.
26
- if saving
27
- self.add_to_read_rule_update_queue( set.item_cards limit: 0 ) if right.id == Card::ReadID
25
+ # FIXME: should be in right/read.rb
26
+ if saving && right.id == Card::ReadID
27
+ self.add_to_read_rule_update_queue(set.item_cards limit: 0)
28
28
  end
29
29
  end
30
30
  end
31
31
 
32
32
  def safe_set_keys
33
- patterns.map( &:safe_key ).reverse * " "
33
+ patterns.map(&:safe_key).reverse * " "
34
34
  end
35
35
 
36
36
  def set_modules
37
- @set_modules ||= patterns_without_new[0..-2].reverse.map(&:module_list).flatten.compact
37
+ @set_modules ||=
38
+ patterns_without_new[0..-2].reverse.map(&:module_list).flatten.compact
38
39
  end
39
40
 
40
41
  def set_format_modules klass
41
42
  @set_format_modules ||= {}
42
- @set_format_modules[klass] = patterns_without_new[0..-2].reverse.map do |pattern|
43
- pattern.format_module_list klass
44
- end.flatten.compact
43
+ @set_format_modules[klass] =
44
+ patterns_without_new[0..-2].reverse.map do |pattern|
45
+ pattern.format_module_list klass
46
+ end.flatten.compact
45
47
  end
46
48
 
47
49
  def set_names
@@ -53,11 +55,10 @@ def set_names
53
55
  end
54
56
 
55
57
  def rule_set_keys
56
- set_names #this triggers set_members cache. need better solution!
57
- @rule_set_keys ||= patterns.map( &:rule_set_key ).compact
58
+ set_names # this triggers set_members cache. need better solution!
59
+ @rule_set_keys ||= patterns.map(&:rule_set_key).compact
58
60
  end
59
61
 
60
62
 
61
-
62
63
  # ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/pattern.rb ~~~~~~~~~~~
63
64
  end;end;end;end;
@@ -2,17 +2,17 @@
2
2
  class Card; module Set; module All; module Permissions; extend Card::Set
3
3
  # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/permissions.rb ~~~~~~~~~~~
4
4
 
5
- Card.error_codes.merge! permission_denied: [:denial, 403], captcha: [:errors,449]
6
-
5
+ Card.error_codes.merge! permission_denied: [:denial, 403],
6
+ captcha: [:errors, 449]
7
7
 
8
8
  # ok? and ok! are public facing methods to approve one action at a time
9
9
  #
10
10
  # fetching: if the optional :trait parameter is supplied, it is passed
11
11
  # to fetch and the test is perfomed on the fetched card, therefore:
12
12
  #
13
- # trait: :account would fetch this card plus a tag codenamed :account
14
- # trait: :roles, new: {} would initialize a new card with default ({}) options.
15
-
13
+ # trait: :account would fetch this card plus a tag codenamed :account
14
+ # trait: :roles, new: {} would initialize a new card with default ({})
15
+ # options.
16
16
 
17
17
  def ok? action
18
18
  @action_ok = true
@@ -24,39 +24,50 @@ def ok_with_fetch? action, opts={}
24
24
  card = opts[:trait].nil? ? self : fetch(opts)
25
25
  card && card.ok_without_fetch?(action)
26
26
  end
27
- alias_method_chain :ok?, :fetch # note: method is chained so that we can return the instance variable @action_ok
28
27
 
28
+ # note: method is chained so that we can return the instance variable @action_ok
29
+ alias_method_chain :ok?, :fetch
29
30
 
30
31
  def ok! action, opts={}
31
32
  raise Card::PermissionDenied.new self unless ok? action, opts
32
33
  end
33
34
 
34
35
  def who_can action
35
- #warn "who_can[#{name}] #{(prc=permission_rule_card(action)).inspect}, #{prc.first.item_cards.map(&:id)}" if action == :update
36
- permission_rule_card(action).first.item_cards.map &:id
36
+ # warn "who_can[#{name}] #{(prc=permission_rule_card(action)).inspect},
37
+ # #{prc.first.item_cards.map(&:id)}" if action == :update
38
+ permission_rule_card(action).item_cards.map &:id
37
39
  end
38
40
 
41
+ def permission_rule_id_and_class action
42
+ direct_rule_id = rule_card_id action
43
+ require_permission_rule! direct_rule_id, action
44
+ direct_rule = Card.fetch direct_rule_id, skip_modules: true
45
+ [applicable_permission_rule_id(direct_rule, action),
46
+ direct_rule.rule_class_name]
47
+ end
39
48
 
40
- def permission_rule_card action
41
- opcard = rule_card action
42
-
43
- unless opcard # RULE missing. should not be possible. generalize this to handling of all required rules
44
- errors.add :permission_denied, "No #{action} rule for #{name}"
45
- raise Card::PermissionDenied.new(self)
46
- end
47
-
48
- rcard = Auth.as_bot do
49
- if ['_left','[[_left]]'].member?(opcard.db_content) && self.junction? # compound cards can inherit permissions from left parent
50
- lcard = left_or_new( skip_virtual: true, skip_modules: true )
51
- if action==:create && lcard.real? && !lcard.action==:create
52
- action = :update
53
- end
54
- lcard.permission_rule_card(action).first
55
- else
56
- opcard
49
+ def applicable_permission_rule_id direct_rule, action
50
+ if junction? && direct_rule.db_content =~ /^\[?\[?_left\]?\]?$/
51
+ lcard = left_or_new(skip_virtual: true, skip_modules: true)
52
+ if action == :create && lcard.real? && !lcard.action == :create
53
+ action = :update
57
54
  end
55
+ lcard.permission_rule_id_and_class(action).first
56
+ else
57
+ direct_rule.id
58
58
  end
59
- return rcard, opcard.rule_class_name
59
+ end
60
+
61
+ def permission_rule_card action
62
+ Card.fetch permission_rule_id_and_class(action).first
63
+ end
64
+
65
+ def require_permission_rule! rule_id, action
66
+ return if rule_id
67
+ # RULE missing. should not be possible.
68
+ # generalize this to handling of all required rules
69
+ errors.add :permission_denied, "No #{action} rule for #{name}"
70
+ raise Card::PermissionDenied.new(self)
60
71
  end
61
72
 
62
73
  def rule_class_name
@@ -67,67 +78,61 @@ def you_cant what
67
78
  "You don't have permission to #{what}"
68
79
  end
69
80
 
70
-
71
81
  def deny_because why
72
82
  @permission_errors << why if @permission_errors
73
83
  @action_ok = false
74
84
  end
75
85
 
76
86
  def permitted? action
87
+ return if Card.config.read_only
88
+ return true if action != :comment and Auth.always_ok?
77
89
 
78
- if !Card.config.read_only
79
- return true if action != :comment and Auth.always_ok?
80
-
81
- permitted_ids = who_can action
82
- if action == :comment && Auth.always_ok?
83
- # admin can comment if anyone can
84
- !permitted_ids.empty?
85
- else
86
- Auth.among? permitted_ids
87
- end
90
+ permitted_ids = who_can action
91
+ if action == :comment && Auth.always_ok?
92
+ # admin can comment if anyone can
93
+ !permitted_ids.empty?
94
+ else
95
+ Auth.among? permitted_ids
88
96
  end
89
97
  end
90
98
 
91
99
  def permit action, verb=nil
92
-
93
100
  if Card.config.read_only # not called by ok_to_read
94
- deny_because "Currently in read-only mode"
101
+ deny_because 'Currently in read-only mode'
95
102
  end
96
103
 
104
+ return if permitted? action
97
105
  verb ||= action.to_s
98
- unless permitted? action
99
- deny_because you_cant("#{verb} #{name.present? ? name : 'this'}")
100
- end
106
+ deny_because you_cant("#{verb} #{name.present? ? name : 'this'}")
101
107
  end
102
108
 
103
109
  def ok_to_create
104
110
  permit :create
105
- if @action_ok and junction?
106
- [:left, :right].each do |side|
107
- next if side==:left && @superleft # left is supercard; create permissions will get checked there.
108
- part_card = send side, new: {}
109
- if part_card && part_card.new_card? # if no card, there must be other errors
110
- unless part_card.ok? :create
111
- deny_because you_cant("create #{part_card.name}")
112
- end
111
+ return if !@action_ok || !junction?
112
+
113
+ [:left, :right].each do |side|
114
+ # left is supercard; create permissions will get checked there.
115
+ next if side == :left && @superleft
116
+ part_card = send side, new: {}
117
+ if part_card && part_card.new_card? # if no card, there must be other errors
118
+ unless part_card.ok? :create
119
+ deny_because you_cant("create #{part_card.name}")
113
120
  end
114
121
  end
115
122
  end
116
123
  end
117
124
 
118
125
  def ok_to_read
119
- if !Auth.always_ok?
120
- @read_rule_id ||= permission_rule_card(:read).first.id.to_i
121
- if !Auth.as_card.read_rules.member? @read_rule_id
122
- deny_because you_cant "read this"
123
- end
124
- end
126
+ return if Auth.always_ok?
127
+ @read_rule_id ||= permission_rule_id_and_class(:read).first
128
+ return if Auth.as_card.read_rules.member? @read_rule_id
129
+ deny_because you_cant 'read this'
125
130
  end
126
131
 
127
132
  def ok_to_update
128
133
  permit :update
129
- if @action_ok and type_id_changed? and !permitted? :create
130
- deny_because you_cant( "change to this type (need create permission)" )
134
+ if @action_ok && type_id_changed? && !permitted?(:create)
135
+ deny_because you_cant('change to this type (need create permission)')
131
136
  end
132
137
  ok_to_read if @action_ok
133
138
  end
@@ -138,51 +143,51 @@ end
138
143
 
139
144
  def ok_to_comment
140
145
  permit :comment, 'comment on'
141
- if @action_ok
142
- deny_because "No comments allowed on templates" if is_template?
143
- deny_because "No comments allowed on structured content" if structure
144
- end
146
+ return unless @action_ok
147
+ deny_because 'No comments allowed on templates' if is_template?
148
+ deny_because 'No comments allowed on structured content' if structure
145
149
  end
146
150
 
151
+ event :clear_read_rule, before: :store, on: :delete do
152
+ self.read_rule_id = self.read_rule_class = nil
153
+ end
147
154
 
148
- event :set_read_rule, before: :store do
149
- if trash == true
150
- self.read_rule_id = self.read_rule_class = nil
151
- else
152
- # avoid doing this on simple content saves?
153
- rcard, rclass = permission_rule_card(:read)
154
- self.read_rule_id = rcard.id
155
- self.read_rule_class = rclass
156
- #find all cards with me as trunk and update their read_rule (because of *type plus right)
157
- # skip if name is updated because will already be resaved
158
-
159
- if !new_card? && type_id_changed?
160
- Auth.as_bot do
161
- Card.search(left: self.name).each do |plus_card|
162
- plus_card = plus_card.refresh.update_read_rule
163
- end
164
- end
155
+ event :set_read_rule, before: :store, on: :save do
156
+ # avoid doing this on simple content saves?
157
+ read_rule_id, read_rule_class = permission_rule_id_and_class(:read)
158
+ self.read_rule_id = read_rule_id
159
+ self.read_rule_class = read_rule_class
160
+ end
161
+
162
+ event :set_field_read_rules,
163
+ after: :set_read_rule, on: :update, changed: :type_id do
164
+ # find all cards with me as trunk and update their read_rule
165
+ # (because of *type plus right)
166
+ # skip if name is updated because will already be resaved
167
+
168
+ Auth.as_bot do
169
+ fields.each do |field|
170
+ field.refresh.update_read_rule
165
171
  end
166
172
  end
167
173
  end
168
174
 
169
175
  def update_read_rule
170
176
  Card.record_timestamps = false
171
-
172
177
  reset_patterns # why is this needed?
173
178
  rcard, rclass = permission_rule_card :read
174
- self.read_rule_id = rcard.id #these two are just to make sure vals are correct on current object
175
- #warn "updating read rule for #{inspect} to #{rcard.inspect}, #{rclass}"
176
-
179
+ # these two are just to make sure vals are correct on current object
180
+ self.read_rule_id = rcard.id
177
181
  self.read_rule_class = rclass
178
- Card.where(id: self.id).update_all(read_rule_id: rcard.id, read_rule_class: rclass)
179
- expire
182
+ Card.where(id: id).update_all read_rule_id: rcard.id, read_rule_class: rclass
183
+ expire_hard
180
184
 
181
- # currently doing a brute force search for every card that may be impacted. may want to optimize(?)
185
+ # currently doing a brute force search for every card that may be impacted.
186
+ # may want to optimize(?)
182
187
  Auth.as_bot do
183
- Card.search(left: self.name).each do |plus_card|
184
- if plus_card.rule(:read) == '_left'
185
- plus_card.update_read_rule
188
+ fields.each do |field|
189
+ if field.rule(:read) == '_left'
190
+ field.update_read_rule
186
191
  end
187
192
  end
188
193
  end
@@ -191,17 +196,18 @@ ensure
191
196
  Card.record_timestamps = true
192
197
  end
193
198
 
199
+
194
200
  def add_to_read_rule_update_queue updates
195
201
  @read_rule_update_queue = Array.wrap(@read_rule_update_queue).concat updates
196
202
  end
197
203
 
198
-
199
204
  event :check_permissions, after: :approve do
200
- task = if @action != :delete && comment #will be obviated by new comment handling
201
- :comment
202
- else
203
- @action
204
- end
205
+ task =
206
+ if @action != :delete && comment # will be obviated by new comment handling
207
+ :comment
208
+ else
209
+ @action
210
+ end
205
211
  track_permission_errors do
206
212
  ok? task
207
213
  end
@@ -219,19 +225,22 @@ def track_permission_errors
219
225
  result
220
226
  end
221
227
 
222
-
223
228
  def recaptcha_on?
224
229
  have_recaptcha_keys? &&
225
- Env[:controller] &&
226
- !Auth.signed_in? &&
227
- !Auth.needs_setup? &&
228
- !Auth.always_ok? &&
229
- Card.toggle( rule :captcha )
230
+ Env[:controller] &&
231
+ !Auth.signed_in? &&
232
+ !Auth.needs_setup? &&
233
+ !Auth.always_ok? &&
234
+ Card.toggle(rule :captcha)
230
235
  end
231
236
 
232
237
  def have_recaptcha_keys?
233
- @@have_recaptcha_keys = defined?(@@have_recaptcha_keys) ? @@have_recaptcha_keys :
234
- !!( Card.config.recaptcha_public_key && Card.config.recaptcha_private_key )
238
+ @@have_recaptcha_keys =
239
+ if defined?(@@have_recaptcha_keys)
240
+ @@have_recaptcha_keys
241
+ else
242
+ !!(Card.config.recaptcha_public_key && Card.config.recaptcha_private_key)
243
+ end
235
244
  end
236
245
 
237
246
  event :recaptcha, before: :approve do
@@ -242,21 +251,23 @@ event :recaptcha, before: :approve do
242
251
  end
243
252
 
244
253
  module Accounts
245
- # This is a short-term hack that is used in account-related cards to allow a permissions pattern where
246
- # permissions are restricted to the owner of the account (and, by default, Admin)
247
- # That pattern should be permitted by our card representation (without creating
248
- # separate rules for each account holder) but is not yet.
254
+ # This is a short-term hack that is used in account-related cards to allow a
255
+ # permissions pattern where permissions are restricted to the owner of the
256
+ # account (and, by default, Admin)
257
+ # That pattern should be permitted by our card representation
258
+ # (without creating separate rules for each account holder) but is not yet.
249
259
 
250
260
  def permit action, verb=nil
251
261
  case
252
- when action==:comment ; @action_ok = false
253
- when action==:create ; @superleft ? true : super( action, verb )
254
- #restricts account creation to subcard handling on permitted card (unless explicitly permitted)
255
- when is_own_account? ; true
256
- else ; super action, verb
262
+ when action == :comment then @action_ok = false
263
+ when action == :create then @superleft ? true : super(action, verb)
264
+ # restricts account creation to subcard handling on permitted card
265
+ # (unless explicitly permitted)
266
+ when own_account? then true
267
+ else
268
+ super action, verb
257
269
  end
258
270
  end
259
-
260
271
  end
261
272
 
262
273
  module Follow
@@ -274,17 +285,14 @@ module Follow
274
285
 
275
286
  def permit action, verb=nil
276
287
  if [:create, :delete, :update].include?(action) && Auth.signed_in? &&
277
- (user = rule_user) && Auth.current_id == user.id
288
+ (user = rule_user) && Auth.current_id == user.id
278
289
  return true
279
290
  else
280
291
  super action, verb
281
292
  end
282
293
  end
283
-
284
294
  end
285
295
 
286
296
 
287
-
288
-
289
297
  # ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/permissions.rb ~~~~~~~~~~~
290
298
  end;end;end;end;