card 1.20.4 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/card.gemspec +9 -9
  4. data/db/migrate_core_cards/20170515101262_add_advanced_edit_cards.rb +20 -0
  5. data/db/migrate_core_cards/20170608083819_add_full_width_layout_card.rb +23 -0
  6. data/db/migrate_core_cards/20170608200649_add_input_options_codename.rb +8 -0
  7. data/db/seed/new/card_actions.yml +783 -791
  8. data/db/seed/new/card_acts.yml +65 -47
  9. data/db/seed/new/card_changes.yml +3198 -3177
  10. data/db/seed/new/card_references.yml +604 -534
  11. data/db/seed/new/cards.yml +2355 -2256
  12. data/db/seed/test/fixtures/card_actions.yml +1795 -1803
  13. data/db/seed/test/fixtures/card_acts.yml +264 -246
  14. data/db/seed/test/fixtures/card_changes.yml +6275 -6184
  15. data/db/seed/test/fixtures/card_references.yml +1305 -1263
  16. data/db/seed/test/fixtures/cards.yml +3393 -3298
  17. data/db/seed/test/seed.rb +2 -2
  18. data/db/version_core_cards.txt +1 -1
  19. data/lib/card.rb +4 -0
  20. data/lib/card/act_manager/subdirector_array.rb +1 -0
  21. data/lib/card/auth/current.rb +7 -3
  22. data/lib/card/env.rb +5 -0
  23. data/lib/card/env/success.rb +1 -1
  24. data/lib/card/format/names.rb +3 -13
  25. data/lib/card/model/save_helper.rb +4 -6
  26. data/lib/card/query.rb +2 -1
  27. data/lib/card/query/attributes.rb +34 -14
  28. data/lib/card/query/value.rb +3 -4
  29. data/lib/card/set/format.rb +29 -4
  30. data/lib/card/set/format/haml_views.rb +25 -13
  31. data/lib/card/set/trait.rb +1 -0
  32. data/lib/card/set_pattern.rb +17 -1
  33. data/lib/card/subcards.rb +3 -2
  34. data/lib/generators/card/format/format_generator.rb +2 -0
  35. data/lib/generators/card/set/set_generator.rb +2 -0
  36. data/lib/generators/card/template/USAGE +10 -0
  37. data/lib/generators/card/template/template_generator.rb +46 -0
  38. data/lib/generators/card/template/templates/haml_template.erb +1 -0
  39. data/mod/Modfile +1 -1
  40. data/mod/account/set/all/account.rb +9 -5
  41. data/mod/account/set/right/account.rb +17 -5
  42. data/mod/account/set/self/account_links.rb +1 -2
  43. data/mod/account/set/type/signup.rb +4 -5
  44. data/mod/account/set/type/user.rb +1 -1
  45. data/mod/account/spec/set/all/account_spec.rb +2 -2
  46. data/mod/account/spec/set/right/account_spec.rb +2 -2
  47. data/mod/account/spec/set/right/email_spec.rb +1 -1
  48. data/mod/account/spec/set/right/password_spec.rb +1 -1
  49. data/mod/account/spec/set/self/signin_spec.rb +2 -2
  50. data/mod/account/spec/set/type/signup_spec.rb +4 -0
  51. data/mod/ace_editor/set/abstract/ace_editor.rb +6 -3
  52. data/mod/ace_editor/set/self/script_ace.rb +1 -0
  53. data/mod/admin/set/self/admin.rb +1 -1
  54. data/mod/admin/set/self/version.rb +1 -0
  55. data/mod/basic_formats/format/css_format.rb +1 -0
  56. data/mod/basic_formats/format/csv_format.rb +1 -0
  57. data/mod/basic_formats/format/file_format.rb +1 -0
  58. data/mod/basic_formats/format/js_format.rb +1 -0
  59. data/mod/basic_formats/format/json_format.rb +1 -0
  60. data/mod/basic_formats/format/rss_format.rb +1 -0
  61. data/mod/basic_formats/format/xml_format.rb +1 -0
  62. data/mod/basic_formats/set/all/all_csv.rb +1 -1
  63. data/mod/basic_formats/set/all/base.rb +11 -3
  64. data/mod/basic_formats/set/all/json.rb +50 -8
  65. data/mod/basic_formats/set/all/rss.rb +21 -7
  66. data/mod/basic_formats/set/self/01_head/javascript.rb +1 -1
  67. data/mod/basic_formats/set/self/head.rb +1 -1
  68. data/mod/basic_formats/spec/set/all/base_spec.rb +13 -0
  69. data/mod/basic_types/set/type/html.rb +6 -2
  70. data/mod/basic_types/set/type/plain_text.rb +2 -3
  71. data/mod/bootstrap/lib/bootstrap.rb +2 -2
  72. data/mod/bootstrap/lib/bootstrap/basic_tags.rb +1 -1
  73. data/mod/bootstrap/lib/bootstrap/component.rb +2 -3
  74. data/mod/bootstrap/lib/bootstrap/component/form.rb +6 -5
  75. data/mod/bootstrap/lib/bootstrap/component/horizontal_form.rb +1 -1
  76. data/mod/bootstrap/lib/bootstrap/component/layout.rb +3 -3
  77. data/mod/bootstrap/lib/bootstrap/component_loader.rb +0 -2
  78. data/mod/bootstrap/lib/bootstrap/delegate.rb +2 -2
  79. data/mod/bootstrap/lib/bootstrapper.rb +1 -1
  80. data/mod/bootstrap/set/all/bootstrap/accordion.rb +1 -1
  81. data/mod/bootstrap/set/all/bootstrap/form.rb +2 -2
  82. data/mod/bootstrap/set/all/bootstrap/helper.rb +1 -0
  83. data/mod/bootstrap/set/all/bootstrap/wrapper.rb +1 -1
  84. data/mod/bootstrap/set/self/bootstrap_js.rb +1 -1
  85. data/mod/bootstrap/set/self/bootswatch_shared.rb +6 -6
  86. data/mod/bootstrap/set/self/script_mods.rb +1 -1
  87. data/mod/bootstrap/spec/set/all/bootstrap/bootstrap_builder_spec.rb +7 -6
  88. data/mod/bootstrap/spec/set/all/bootstrap/bootstrap_spec.rb +2 -1
  89. data/mod/bootstrap/spec/set/all/bootstrap/form_spec.rb +6 -3
  90. data/mod/bootstrap/spec/set/all/bootstrap/layout_spec.rb +3 -2
  91. data/mod/carrierwave/set/abstract/attachment.rb +1 -3
  92. data/mod/carrierwave/set/abstract/attachment/paths.rb +1 -1
  93. data/mod/carrierwave/set/abstract/attachment/storage_type.rb +11 -1
  94. data/mod/carrierwave/set/type/file.rb +3 -3
  95. data/mod/carrierwave/spec/lib/carrier_wave/file_card_uploader_spec.rb +3 -0
  96. data/mod/carrierwave/spec/set/type/file_spec.rb +24 -6
  97. data/mod/carrierwave/spec/set/type/image_spec.rb +3 -0
  98. data/mod/core/chunk/link.rb +1 -1
  99. data/mod/core/chunk/nest.rb +2 -1
  100. data/mod/core/chunk/query_reference.rb +1 -1
  101. data/mod/core/chunk/reference.rb +1 -0
  102. data/mod/core/chunk/uri.rb +4 -3
  103. data/mod/core/set/abstract/lock.rb +26 -0
  104. data/mod/core/set/all/assign_attributes.rb +8 -4
  105. data/mod/core/set/all/collection.rb +16 -7
  106. data/mod/core/set/all/content.rb +6 -0
  107. data/mod/core/set/all/event.rb +1 -1
  108. data/mod/core/set/all/fetch.rb +2 -2
  109. data/mod/core/set/all/haml.rb +5 -15
  110. data/mod/core/set/all/initialize.rb +2 -2
  111. data/mod/core/set/all/name.rb +1 -1
  112. data/mod/core/set/all/permissions.rb +28 -16
  113. data/mod/core/set/all/rules.rb +1 -2
  114. data/mod/core/set/all/subcards.rb +3 -3
  115. data/mod/core/set/all/templating.rb +5 -1
  116. data/mod/core/set/all/trash.rb +1 -1
  117. data/mod/core/set/all/utils.rb +1 -1
  118. data/mod/core/spec/set/all/actify_spec.rb +1 -1
  119. data/mod/core/spec/set/all/assign_attributes_spec.rb +2 -2
  120. data/mod/core/spec/set/all/collection_spec.rb +6 -3
  121. data/mod/core/spec/set/all/export_spec.rb +40 -112
  122. data/mod/core/spec/set/all/name_spec.rb +1 -1
  123. data/mod/core/spec/set/all/permissions_spec.rb +7 -7
  124. data/mod/core/spec/set/all/rules2_spec.rb +25 -25
  125. data/mod/core/spec/set/all/rules_spec.rb +2 -7
  126. data/mod/developer/set/all/event_viz.rb +1 -1
  127. data/mod/developer/set/right/debug.rb +1 -1
  128. data/mod/history/lib/card/act.rb +1 -0
  129. data/mod/history/lib/card/act/act_renderer.rb +23 -20
  130. data/mod/history/lib/card/act/act_renderer/absolute_act_renderer.rb +0 -1
  131. data/mod/history/lib/card/act/act_renderer/relative_act_renderer.rb +1 -0
  132. data/mod/history/lib/card/action.rb +1 -1
  133. data/mod/history/lib/card/action/action_renderer.rb +2 -2
  134. data/mod/history/lib/card/change.rb +2 -1
  135. data/mod/history/set/all/action_view.rb +1 -1
  136. data/mod/history/set/all/content_history.rb +7 -4
  137. data/mod/history/set/all/history.rb +6 -6
  138. data/mod/machines/file/all_script_machine_output/file.js +50 -34
  139. data/mod/machines/file/all_style_machine_output/file.css +1 -1
  140. data/mod/machines/lib/javascript/wagn.js.coffee +29 -18
  141. data/mod/machines/lib/javascript/wagn_layout.js.coffee +7 -3
  142. data/mod/machines/lib/stylesheets/style_cards.scss +10 -10
  143. data/mod/machines/set/abstract/machine.rb +5 -28
  144. data/mod/machines/set/abstract/script.rb +7 -4
  145. data/mod/machines/set/all/reset_machines.rb +1 -1
  146. data/mod/machines/set/self/script_jquery_helper.rb +2 -2
  147. data/mod/machines/set/self/script_slot.rb +1 -1
  148. data/mod/machines/set/type/coffee_script.rb +3 -2
  149. data/mod/machines/set/type/css.rb +7 -3
  150. data/mod/machines/set/type/scss.rb +7 -1
  151. data/mod/machines/spec/set/type/coffeescript_spec.rb +1 -1
  152. data/mod/machines/spec/set/type/javascript_spec.rb +1 -1
  153. data/mod/machines/spec/set/type/scss_spec.rb +3 -2
  154. data/mod/machines/spec/set/type/skin_spec.rb +1 -1
  155. data/mod/machines/spec/shared_examples/machine.rb +5 -3
  156. data/mod/machines/spec/shared_examples/machine_input.rb +1 -0
  157. data/mod/notifications/format/email_html_format.rb +1 -0
  158. data/mod/notifications/set/all/follow.rb +1 -1
  159. data/mod/notifications/set/all/observer.rb +1 -1
  160. data/mod/notifications/set/all/send_notifications.rb +2 -2
  161. data/mod/notifications/set/self/follow_defaults.rb +3 -8
  162. data/mod/notifications/set/type/email_template/email_config.rb +2 -2
  163. data/mod/notifications/set/type_plus_right/user/follow.rb +2 -2
  164. data/mod/notifications/spec/set/all/follow_spec.rb +7 -0
  165. data/mod/notifications/spec/set/all/notify_spec.rb +3 -0
  166. data/mod/notifications/spec/set/all/observer_spec.rb +1 -1
  167. data/mod/notifications/spec/set/right/followers_spec.rb +1 -0
  168. data/mod/pointer/set/abstract/00_paging_params.rb +11 -0
  169. data/mod/pointer/set/abstract/{00_paging.rb → 01_paging.rb} +10 -6
  170. data/mod/pointer/set/abstract/{00_paging → 01_paging}/paging_links.rb +0 -0
  171. data/mod/pointer/set/abstract/{01_pointer.rb → 02_pointer.rb} +26 -5
  172. data/mod/pointer/set/abstract/{01_pointer → 02_pointer}/edit.rb +3 -5
  173. data/mod/pointer/set/self/input_options.rb +12 -0
  174. data/mod/pointer/spec/set/self/input_options_spec.rb +8 -0
  175. data/mod/pointer/spec/set/type/pointer_spec.rb +3 -2
  176. data/mod/prosemirror_editor/set/abstract/prosemirror_editor.rb +1 -1
  177. data/mod/prosemirror_editor/set/self/script_prosemirror.rb +1 -0
  178. data/mod/settings/lib/card/setting.rb +1 -2
  179. data/mod/settings/set/abstract/permission.rb +1 -1
  180. data/mod/settings/set/self/add_help.rb +1 -1
  181. data/mod/settings/set/self/autoname.rb +1 -1
  182. data/mod/settings/set/self/csv_structure.rb +2 -0
  183. data/mod/settings/set/self/help.rb +1 -1
  184. data/mod/settings/set/self/input.rb +1 -2
  185. data/mod/settings/set/self/options.rb +2 -2
  186. data/mod/settings/set/self/options_label.rb +2 -2
  187. data/mod/settings/set/type/setting.rb +1 -1
  188. data/mod/settings/spec/set/right/script_spec.rb +1 -1
  189. data/mod/settings/spec/set/right/style_spec.rb +1 -1
  190. data/mod/solid_cache/set/abstract/solid_cache.rb +5 -3
  191. data/mod/solid_cache/spec/set/abstract/solid_cache_spec.rb +4 -3
  192. data/mod/standard/set/abstract/01_search_params.rb +4 -3
  193. data/mod/standard/set/abstract/search.rb +2 -1
  194. data/mod/standard/set/abstract/toolbar_split_button.rb +22 -0
  195. data/mod/standard/set/all/links.rb +3 -3
  196. data/mod/standard/set/all/rich_html/classy.rb +37 -0
  197. data/mod/standard/set/all/rich_html/editing.rb +6 -2
  198. data/mod/standard/set/all/rich_html/editor.rb +50 -0
  199. data/mod/standard/set/all/rich_html/form.rb +19 -12
  200. data/mod/standard/set/all/rich_html/form_elements.rb +2 -2
  201. data/mod/standard/set/all/rich_html/formgroup.rb +2 -1
  202. data/mod/standard/set/all/rich_html/header.rb +2 -27
  203. data/mod/standard/set/all/rich_html/menu.rb +1 -1
  204. data/mod/standard/set/all/rich_html/new.rb +5 -1
  205. data/mod/standard/set/all/rich_html/toolbar.rb +15 -60
  206. data/mod/standard/set/all/rich_html/wrapper.rb +6 -3
  207. data/mod/standard/set/right/when_created.rb +2 -2
  208. data/mod/standard/set/rstar/rules_editor.rb +10 -7
  209. data/mod/standard/set/self/activity_toolbar_button.rb +14 -0
  210. data/mod/standard/set/self/recent.rb +7 -2
  211. data/mod/standard/set/self/rules_toolbar_button.rb +42 -0
  212. data/mod/standard/set/self/search.rb +19 -6
  213. data/mod/standard/set/type/basic.rb +6 -6
  214. data/mod/standard/set/type/cardtype.rb +7 -3
  215. data/mod/standard/set/type/date.rb +2 -4
  216. data/mod/standard/set/type/layout_type.rb +1 -0
  217. data/mod/standard/set/type/list.rb +1 -1
  218. data/mod/standard/set/type/listed_by.rb +1 -2
  219. data/mod/standard/set/type/number.rb +4 -2
  220. data/mod/standard/set/type/phrase.rb +4 -2
  221. data/mod/standard/set/type/search_type.rb +11 -3
  222. data/mod/standard/set/type/set.rb +8 -8
  223. data/mod/standard/set/type/toggle.rb +1 -3
  224. data/mod/standard/set/type/uri.rb +6 -2
  225. data/mod/standard/spec/chunk/include_spec.rb +3 -2
  226. data/mod/standard/spec/chunk/query_reference_spec.rb +2 -2
  227. data/mod/standard/spec/set/all/history_spec.rb +1 -0
  228. data/mod/standard/spec/set/all/links_spec.rb +1 -0
  229. data/mod/standard/spec/set/all/rich_html/toolbar_spec.rb +2 -0
  230. data/mod/standard/spec/set/self/activity_toolbar_button_spec.rb +22 -0
  231. data/mod/standard/spec/set/type/email_template/email_config_spec.rb +10 -8
  232. data/mod/standard/spec/set/type/email_template_spec.rb +1 -0
  233. data/mod/standard/spec/set/type/list_spec.rb +2 -0
  234. data/mod/standard/spec/set/type/listed_by_spec.rb +5 -0
  235. data/mod/standard/spec/set/type/search_type_spec.rb +1 -1
  236. data/mod/standard/spec/set/type/toggle_spec.rb +1 -2
  237. data/mod/standard/spec/set/type/uri_spec.rb +0 -1
  238. data/mod/tinymce_editor/db/migrate_cards/20160804112560_add_tinymce_cards.rb +3 -1
  239. data/mod/tinymce_editor/set/abstract/tinymce_editor.rb +1 -1
  240. data/mod/tinymce_editor/set/self/script_tinymce.rb +1 -0
  241. data/mod/twitter/db/migrate_cards/20170305112346_add_twitter_cards.rb +1 -1
  242. data/mod/twitter/set/type/twitter_template.rb +1 -1
  243. data/spec/lib/card/format_spec.rb +26 -7
  244. data/spec/lib/card/loader_spec.rb +96 -35
  245. data/spec/lib/card/query_spec.rb +0 -1
  246. data/spec/support/card_spec_loader.rb +1 -0
  247. data/spec/support/helper/card_helper.rb +0 -36
  248. data/spec/support/helper/set_helper.rb +80 -0
  249. data/spec/support/matchers.rb +74 -0
  250. data/tmpsets/set/mod001-core/all/actify.rb +5 -6
  251. data/tmpsets/set/mod001-core/all/fetch.rb +14 -12
  252. data/tmpsets/set/mod001-core/all/name.rb +1 -1
  253. data/tmpsets/set/mod001-core/all/permissions.rb +12 -22
  254. data/tmpsets/set/mod001-core/all/tracked_attributes.rb +76 -0
  255. data/tmpsets/set/mod001-core/all/utils.rb +40 -3
  256. data/tmpsets/set/mod002-history/all/history.rb +1 -2
  257. data/tmpsets/set/mod008-solid_cache/abstract/solid_cache.rb +1 -1
  258. data/tmpsets/set/mod013-carrierwave/abstract/attachment.rb +282 -0
  259. data/tmpsets/set/mod013-carrierwave/type/file.rb +155 -0
  260. data/tmpsets/set/mod013-carrierwave/type/image.rb +96 -0
  261. data/tmpsets/set/mod014-admin/self/admin.rb +113 -0
  262. data/tmpsets/set/mod014-admin/self/admin_info.rb +110 -0
  263. data/tmpsets/set/mod014-admin/self/version.rb +15 -0
  264. data/tmpsets/set/mod015-developer/all/event_viz.rb +59 -0
  265. data/tmpsets/set/mod015-developer/all/view_viz.rb +30 -0
  266. data/tmpsets/set/mod015-developer/right/debug.rb +96 -0
  267. metadata +52 -22
@@ -18,6 +18,12 @@ format do
18
18
  end
19
19
  end
20
20
 
21
+ format :html do
22
+ view :hidden_content_field, tags: :unknown_ok do
23
+ hidden_field :content, class: "card-content"
24
+ end
25
+ end
26
+
21
27
  def label
22
28
  name
23
29
  end
@@ -1,4 +1,4 @@
1
- EVENT_CONDITIONS = [:set, :on, :changed, :when].freeze
1
+ EVENT_CONDITIONS = %i[set on changed when].freeze
2
2
 
3
3
  def event_applies? opts
4
4
  EVENT_CONDITIONS.all? do |key|
@@ -351,13 +351,13 @@ def append_missing_view_cache_keys
351
351
  end
352
352
 
353
353
  def hard_write_view_cache_keys
354
- # puts "WRITE VIEW CACHE KEYS (#{name}): #{view_cache_keys}"
354
+ # puts "WRITE VIEW CACHE KEYS (#{name}): #{view_cache_keys}"
355
355
  return unless Card.cache.hard
356
356
  Card.cache.hard.write_attribute key, :view_cache_keys, @view_cache_keys
357
357
  end
358
358
 
359
359
  def expire_views
360
- # puts "EXPIRE VIEW CACHE (#{name}): #{view_cache_keys}"
360
+ # puts "EXPIRE VIEW CACHE (#{name}): #{view_cache_keys}"
361
361
  return unless view_cache_keys.present?
362
362
  Array.wrap(@view_cache_keys).each do |view_cache_key|
363
363
  Card::View.cache.delete view_cache_key
@@ -65,22 +65,12 @@ format do
65
65
  # def view_template_path view
66
66
  # super(view, __FILE__)
67
67
  # end
68
- def view_template_path view, tmp_set_path=__FILE__
69
- basename = ::File.basename(tmp_set_path, ".rb")
70
- try_view_template_path("../#{view}", tmp_set_path) ||
71
- try_view_template_path("../#{basename}/#{view}", tmp_set_path) ||
72
- raise(Card::Error, "can't find haml template for #{view}")
73
- end
74
68
 
75
- def try_view_template_path template_path, tmp_set_path, ext="haml"
76
- path = ::File.expand_path("#{template_path}.#{ext}", tmp_set_path)
77
- .gsub(%r{/tmp/set/mod\d+-([^/]+)/}, '/mod/\1/view/')
78
- ::File.exist?(path) && path
79
- end
69
+ include Card::Set::Format::HamlViews
80
70
 
81
- def haml_to_html haml, locals, a_binding=nil
82
- a_binding ||= binding
83
- ::Haml::Engine.new(haml).render a_binding, locals || {}
71
+ def view_template_path view, tmp_set_path=__FILE__
72
+ set_path =
73
+ tmp_set_path.gsub(%r{/tmp/set/mod\d+-([^/]+)/}, '/mod/\1/template/')
74
+ haml_template_path view, set_path
84
75
  end
85
76
  end
86
-
@@ -1,10 +1,10 @@
1
- JUNK_INIT_ARGS = %w(missing skip_virtual id).freeze
1
+ JUNK_INIT_ARGS = %w[missing skip_virtual id].freeze
2
2
 
3
3
  module ClassMethods
4
4
  def new args={}, _options={}
5
5
  args = (args || {}).stringify_keys
6
6
  JUNK_INIT_ARGS.each { |a| args.delete(a) }
7
- %w(type type_code).each { |k| args.delete(k) if args[k].blank? }
7
+ %w[type type_code].each { |k| args.delete(k) if args[k].blank? }
8
8
  args.delete("content") if args["attach"] # should not be handled here!
9
9
  super args
10
10
  end
@@ -220,7 +220,7 @@ end
220
220
  event :set_left_and_right, :store,
221
221
  changed: :name, on: :save do
222
222
  if cardname.junction?
223
- [:left, :right].each do |side|
223
+ %i[left right].each do |side|
224
224
  sidename = cardname.send "#{side}_name"
225
225
  sidecard = Card[sidename]
226
226
 
@@ -4,9 +4,8 @@ Card.error_codes.merge! permission_denied: [:denial, 403],
4
4
 
5
5
  module ClassMethods
6
6
  def repair_all_permissions
7
- Card.where(
8
- "(read_rule_class is null or read_rule_id is null) and trash is false"
9
- ).each do |broken_card|
7
+ Card.where("(read_rule_class is null or read_rule_id is null) and trash is false")
8
+ .each do |broken_card|
10
9
  broken_card.include_set_modules
11
10
  broken_card.repair_permissions!
12
11
  end
@@ -53,10 +52,19 @@ def anyone_can? action
53
52
  who_can(action).include? Card::AnyoneID
54
53
  end
55
54
 
56
- def permission_rule_id_and_class action
55
+ def direct_rule_card action
57
56
  direct_rule_id = rule_card_id action
58
57
  require_permission_rule! direct_rule_id, action
59
- direct_rule = Card.fetch direct_rule_id, skip_modules: true
58
+ Card.fetch direct_rule_id, skip_modules: true
59
+ end
60
+
61
+ def permission_rule_id action
62
+ direct_rule = direct_rule_card action
63
+ applicable_permission_rule_id direct_rule, action
64
+ end
65
+
66
+ def permission_rule_id_and_class action
67
+ direct_rule = direct_rule_card action
60
68
  [
61
69
  applicable_permission_rule_id(direct_rule, action),
62
70
  direct_rule.rule_class_name
@@ -65,18 +73,22 @@ end
65
73
 
66
74
  def applicable_permission_rule_id direct_rule, action
67
75
  if junction? && direct_rule.db_content =~ /^\[?\[?_left\]?\]?$/
68
- lcard = left_or_new(skip_virtual: true, skip_modules: true)
69
- if action == :create && lcard.real? && !lcard.action == :create
70
- action = :update
71
- end
72
- lcard.permission_rule_id_and_class(action).first
76
+ left_permission_rule_id action
73
77
  else
74
78
  direct_rule.id
75
79
  end
76
80
  end
77
81
 
82
+ def left_permission_rule_id action
83
+ lcard = left_or_new(skip_virtual: true, skip_modules: true)
84
+ if action == :create && lcard.real? && lcard.action != :create
85
+ action = :update
86
+ end
87
+ lcard.permission_rule_id action
88
+ end
89
+
78
90
  def permission_rule_card action
79
- Card.fetch permission_rule_id_and_class(action).first
91
+ Card.fetch permission_rule_id(action)
80
92
  end
81
93
 
82
94
  def require_permission_rule! rule_id, action
@@ -126,7 +138,7 @@ def ok_to_create
126
138
  permit :create
127
139
  return if !@action_ok || !junction?
128
140
 
129
- [:left, :right].each do |side|
141
+ %i[left right].each do |side|
130
142
  # left is supercard; create permissions will get checked there.
131
143
  next if side == :left && @superleft
132
144
  part_card = send side, new: {}
@@ -140,7 +152,7 @@ end
140
152
 
141
153
  def ok_to_read
142
154
  return if Auth.always_ok?
143
- @read_rule_id ||= permission_rule_id_and_class(:read).first
155
+ @read_rule_id ||= permission_rule_id(:read)
144
156
  return if Auth.as_card.read_rules.member? @read_rule_id
145
157
  deny_because you_cant "read this"
146
158
  end
@@ -169,7 +181,7 @@ event :clear_read_rule, :store, on: :delete do
169
181
  end
170
182
 
171
183
  event :set_read_rule, :store,
172
- on: :save, changed: [:type_id, :name] do
184
+ on: :save, changed: %i[type_id name] do
173
185
  read_rule_id, read_rule_class = permission_rule_id_and_class(:read)
174
186
  self.read_rule_id = read_rule_id
175
187
  self.read_rule_class = read_rule_class
@@ -303,9 +315,9 @@ module Follow
303
315
  end
304
316
 
305
317
  def permit action, verb=nil
306
- if [:create, :delete, :update].include?(action) && Auth.signed_in? &&
318
+ if %i[create delete update].include?(action) && Auth.signed_in? &&
307
319
  (user = rule_user) && Auth.current_id == user.id
308
- return true
320
+ true
309
321
  else
310
322
  super action, verb
311
323
  end
@@ -215,8 +215,7 @@ module ClassMethods
215
215
  left: {
216
216
  left: { type_id: SetID }, right: user_name
217
217
  },
218
- return: :name
219
- }, "preference cards for user: #{user_name}"
218
+ return: :name }, "preference cards for user: #{user_name}"
220
219
  )
221
220
  end
222
221
 
@@ -10,7 +10,7 @@ def subfield field_name
10
10
  subcards.field field_name
11
11
  end
12
12
 
13
- # phase_method :add_subcard, before: :store do |name_or_card, args=nil|
13
+ # phase_method :attach_subcard, before: :store do |name_or_card, args=nil|
14
14
  # TODO: handle differently in different stages
15
15
  def attach_subcard name_or_card, args={}
16
16
  subcards.add name_or_card, args
@@ -23,7 +23,7 @@ def attach_subcard! name_or_card, args={}
23
23
  subcard
24
24
  end
25
25
 
26
- # phase_method :add_subfield, before: :approve do |name_or_card, args=nil|
26
+ # phase_method :attach_subfield, before: :approve do |name_or_card, args=nil|
27
27
  def attach_subfield name_or_card, args={}
28
28
  subcards.add_field name_or_card, args
29
29
  end
@@ -66,7 +66,7 @@ end
66
66
  event :handle_subcard_errors do
67
67
  subcards.each do |subcard|
68
68
  subcard.errors.each do |field, err|
69
- err = "#{field} #{err}" unless [:content, :abort].member? field
69
+ err = "#{field} #{err}" unless %i[content abort].member? field
70
70
  errors.add subcard.relative_name.s, err
71
71
  end
72
72
  end
@@ -21,11 +21,15 @@ def template
21
21
  end
22
22
  end
23
23
 
24
+ def default_type_id default_card=nil
25
+ default_card ? default_card.type_id : Card.default_type_id
26
+ end
27
+
24
28
  def new_card_template
25
29
  default = rule_card :default, skip_modules: true
26
30
 
27
31
  dup_card = dup
28
- dup_card.type_id = default ? default.type_id : Card.default_type_id
32
+ dup_card.type_id = default_type_id default
29
33
 
30
34
  if (structure = dup_card.structure_rule_card)
31
35
  @virtual = true if junction?
@@ -81,7 +81,7 @@ event :validate_delete, :validate, on: :delete do
81
81
  end
82
82
 
83
83
  undeletable_all_rules_tags =
84
- %w(default style layout create read update delete)
84
+ %w[default style layout create read update delete]
85
85
  # FIXME: HACK! should be configured in the rule
86
86
 
87
87
  if junction? && (l = left) && l.codename == "all" &&
@@ -39,7 +39,7 @@ module ClassMethods
39
39
  def merge name, attribs={}, opts={}
40
40
  # puts "merging #{name}"
41
41
  card = fetch name, new: {}
42
- [:image, :file].each do |attach|
42
+ %i[image file].each do |attach|
43
43
  next unless attribs[attach] && attribs[attach].is_a?(String)
44
44
  attribs[attach] = ::File.open(attribs[attach])
45
45
  end
@@ -116,7 +116,7 @@ describe "act API" do
116
116
  end
117
117
  Card["A"].update_attributes! name: "new name"
118
118
  end
119
- expect(@called_events).to eq([:i_name, :iwd_name])
119
+ expect(@called_events).to eq(%i[i_name iwd_name])
120
120
  end
121
121
  end
122
122
 
@@ -155,8 +155,8 @@ RSpec.describe Card::Set::All::AssignAttributes do
155
155
  end
156
156
 
157
157
  it "test_update_descendants" do
158
- old_names = %w(One+Two One+Two+Three Four+One Four+One+Five)
159
- new_names = %w(Uno+Two Uno+Two+Three Four+Uno Four+Uno+Five)
158
+ old_names = %w[One+Two One+Two+Three Four+One Four+One+Five]
159
+ new_names = %w[Uno+Two Uno+Two+Three Four+Uno Four+Uno+Five]
160
160
  card_list = old_names.map { |name| Card[name] }
161
161
 
162
162
  assert_equal old_names, card_list.map(&:name)
@@ -6,9 +6,10 @@ describe Card::Set::All::Collection do
6
6
  item_names_args = @context ? { context: @context } : {}
7
7
  Card.new(@args).item_names(item_names_args)
8
8
  end
9
+
9
10
  it "returns item for each line of basic content" do
10
11
  @args = { name: "foo", content: "X\nY" }
11
- is_expected.to eq(%w(X Y))
12
+ is_expected.to eq(%w[X Y])
12
13
  end
13
14
 
14
15
  it "returns list of card names for search" do
@@ -54,7 +55,9 @@ describe Card::Set::All::Collection do
54
55
  end
55
56
 
56
57
  describe "#contextual_content" do
57
- let(:context_card) { Card["A"] } # refers to 'Z'
58
+ let(:context_card) { Card["A"] }
59
+
60
+ # refers to 'Z'
58
61
  it "processes nests relative to context card" do
59
62
  c = create "foo", content: "{{_self+B|core}}"
60
63
  expect(c.contextual_content(context_card)).to eq("AlphaBeta")
@@ -67,7 +70,7 @@ describe Card::Set::All::Collection do
67
70
  expect(c.contextual_content(context_card)).to eq("AlphaBeta")
68
71
  end
69
72
 
70
- it "it doesn't use chunk list of context card" do
73
+ it "doesn't use chunk list of context card" do
71
74
  c = create "foo", content: "test@email.com", type: "HTML"
72
75
  expect(c.contextual_content(context_card)).not_to have_tag "a"
73
76
  end
@@ -1,134 +1,62 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  describe Card::Set::All::Export do
4
- before do
5
- login_as "joe_user"
6
- end
7
4
  describe "rendering json in export mode" do
8
- subject do
9
- big_blind = Card.create! name: "special means special",
10
- type_id: Card::PointerID,
11
- content: "[[#{@collection_card.name}]]"
12
- big_blind.format(:json).render_export
5
+ def export_pointer content, type=:pointer
6
+ export_name = "#{type} export card"
7
+ create export_name, type: type, content: content
8
+
9
+ create("export pointer", type_id: Card::PointerID, content: export_name)
10
+ .format(:json).render_export
13
11
  end
12
+
14
13
  context "pointer card" do
15
14
  it "contains cards in the pointer card and its children" do
16
- small_blind = Card.create! name: "Elbert Hubbard",
17
- type_id: Card::BasicID,
18
- content: "Do not take life too seriously."
19
- small_blind_1 =
20
- Card.create! name: "Elbert Hubbard+hello world",
21
- type_id: Card::BasicID,
22
- content: "You will never get out of it alive."
23
- @collection_card =
24
- Card.create! name: "normal pointer", type_id: Card::PointerID,
25
- content: "[[#{small_blind.name}]]\r\n"\
26
- "[[#{small_blind_1.name}]]"
27
-
28
- is_expected.to include(name: "normal pointer",
29
- type: "Pointer",
30
- content: "[[Elbert Hubbard]]\n"\
31
- "[[Elbert Hubbard+hello world]]")
32
- is_expected.to include(name: "Elbert Hubbard",
33
- type: "Basic",
34
- content: "Do not take life too seriously.")
35
- is_expected.to include(name: "Elbert Hubbard+hello world",
36
- type: "Basic",
37
- content: "You will never get out of it alive.")
15
+ expect(export_pointer(%w[T A+B])).to include(
16
+ a_hash_including(name: "pointer export card", type: "Pointer",
17
+ content: "[[T]]\n[[A+B]]"),
18
+ a_hash_including(name: "T", type: "Basic", content: "Theta"),
19
+ a_hash_including(name: "A+B", type: "Basic", content: "AlphaBeta")
20
+ )
38
21
  end
39
22
  it "handles multi levels pointer cards" do
40
- small_blind = Card.create! name: "Elbert Hubbard",
41
- type_id: Card::BasicID,
42
- content: "Do not take life too seriously."
43
- inner_pointer_card = Card.create! name: "inner pointer",
44
- type_id: Card::PointerID,
45
- content: "[[#{small_blind.name}]]"
46
- small_blind_1 = Card.create! name: "Elbert Hubbard+hello world",
47
- type_id: Card::BasicID,
48
- content: "You will never get out of it"\
49
- " alive."
50
- @collection_card =
51
- Card.create! name: "normal pointer",
52
- type_id: Card::PointerID,
53
- content: "[[#{inner_pointer_card.name}""]]\r\n"\
54
- "[[#{small_blind_1.name}]]"
55
-
56
- is_expected.to include(name: "normal pointer",
57
- type: "Pointer",
58
- content: "[[inner pointer]]\n"\
59
- "[[Elbert Hubbard+hello world]]")
60
- is_expected.to include(name: "inner pointer",
61
- type: "Pointer",
62
- content: "[[Elbert Hubbard]]")
63
- is_expected.to include(name: "Elbert Hubbard",
64
- type: "Basic",
65
- content: "Do not take life too seriously.")
66
- is_expected.to include(name: "Elbert Hubbard+hello world",
67
- type: "Basic",
68
- content: "You will never get out of it alive.")
23
+ inner_pointer = create "inner pointer", type: :pointer, content: "T"
24
+ expect(export_pointer([inner_pointer.name, "A+B"])).to include(
25
+ a_hash_including(name: "pointer export card", type: "Pointer",
26
+ content: "[[inner pointer]]\n[[A+B]]"),
27
+ a_hash_including(name: "inner pointer", type: "Pointer",
28
+ content: "[[T]]"),
29
+ a_hash_including(name: "T", type: "Basic", content: "Theta"),
30
+ a_hash_including(name: "A+B", type: "Basic", content: "AlphaBeta")
31
+ )
69
32
  end
70
33
  it "stops while the depth count > 10" do
71
- @collection_card = Card.create! name: "normal pointer",
72
- type_id: Card::PointerID,
73
- content: "[[normal pointer]]"
74
- is_expected.to include(name: "normal pointer", type: "Pointer",
75
- content: "[[normal pointer]]")
34
+ expect(export_pointer("pointer export card")).to include(
35
+ name: "pointer export card", type: "Pointer",
36
+ content: "[[pointer export card]]"
37
+ )
76
38
  end
77
39
  end
78
- context "Skin card" do
79
- it "contains cards in the pointer card and its children" do
80
- Card::Auth.as_bot do
81
- small_blind =
82
- Card.create! name: "Elbert Hubbard",
83
- type_id: Card::BasicID,
84
- content: "The best thing about a boolean is "\
85
- "even if you are wrong,"\
86
- " you are only off by a bit"
87
- @collection_card = Card.create! name: "normal pointer",
88
- type_id: Card::SkinID,
89
- content: "[[#{small_blind.name}]]"
90
40
 
91
- is_expected.to include(name: "normal pointer",
92
- type: "Skin", content: "[[Elbert Hubbard]]")
93
- is_expected.to include(name: "Elbert Hubbard",
94
- type: "Basic",
95
- content: "The best thing about"\
96
- " a boolean is even if you are wrong, "\
97
- "you are only off by a bit")
98
- end
41
+ context "skin card" do
42
+ it "contains cards in the pointer card and its children" do
43
+ export = export_pointer("[[T]]", :skin)
44
+ expect(export).to include(
45
+ a_hash_including(name: "skin export card", type: "Skin",
46
+ content: "[[T]]"),
47
+ a_hash_including(name: "T", type: "Basic", content: "Theta")
48
+ )
99
49
  end
100
50
  end
51
+
101
52
  context "search card" do
102
53
  it "contains cards from search card and its children" do
103
- Card.create!(
104
- name: "Elbert Hubbard",
105
- type_id: Card::BasicID,
106
- content: "Do not take life too seriously."
54
+ expect(export_pointer('{"left":"A"}', :search_type)).to include(
55
+ a_hash_including(name: "search_type export card", type: "Search",
56
+ content: '{"left":"A"}'),
57
+ a_hash_including(name: "A+B", content: "AlphaBeta", type: "Basic"),
58
+ a_hash_including(name: "A+C", type: "Basic")
107
59
  )
108
- Card.create!(
109
- name: "Elbert Hubbard+hello world",
110
- type_id: Card::BasicID,
111
- content: "You will never get out of it alive."
112
- )
113
- Card.create!(
114
- name: "Elbert Hubbard+quote",
115
- type_id: Card::BasicID,
116
- content: "Procrastination is the art of keeping up with yesterday."
117
- )
118
- @collection_card = Card.create! name: "search card",
119
- type_id: Card::SearchTypeID,
120
- content: %({"left":"Elbert Hubbard"})
121
-
122
- is_expected.to include(name: "search card",
123
- type: "Search",
124
- content: %({"left":"Elbert Hubbard"}))
125
- is_expected.to include(name: "Elbert Hubbard+hello world",
126
- type: "Basic",
127
- content: "You will never get out of it alive.")
128
- is_expected.to include(name: "Elbert Hubbard+quote",
129
- type: "Basic",
130
- content: "Procrastination is the art of keeping"\
131
- " up with yesterday.")
132
60
  end
133
61
  end
134
62
  end