card 1.99.1 → 1.99.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/01_core_extensions/array.rb +1 -0
  4. data/config/initializers/01_core_extensions/persistent_identifiers.rb +1 -1
  5. data/config/initializers/02_patches/zeitwerk.rb +13 -0
  6. data/config/initializers/patches.rb +7 -0
  7. data/config/initializers/recaptcha.rb +1 -2
  8. data/config/initializers/zeitwerk.rb +5 -0
  9. data/config/locales/de.yml +1 -1
  10. data/config/locales/en.yml +1 -1
  11. data/config/locales/es.yml +1 -1
  12. data/db/migrate/20110511221913_require_earlier_migrations.rb +0 -3
  13. data/db/migrate/20141001105348_move_revisions_to_actions.rb +1 -1
  14. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +5 -5
  15. data/db/migrate_core_cards/20141120120605_fix_notification_html_message.rb +1 -1
  16. data/db/migrate_core_cards/20141204061304_watchers_to_following.rb +1 -1
  17. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +2 -2
  18. data/db/migrate_core_cards/20150317162412_bootstrap_themes.rb +4 -4
  19. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
  20. data/db/migrate_core_cards/20190204195039_add_rule_card.rb +1 -1
  21. data/db/migrate_core_cards/20191008201046_fixture_fix.rb +3 -1
  22. data/db/migrate_core_cards/20191028135243_add_link_editor_to_tiny_mce_config.rb +8 -0
  23. data/db/migrate_core_cards/20191115160748_history_cleanup.rb +27 -0
  24. data/db/migrate_core_cards/20191118145629_codename_fixes.rb +6 -0
  25. data/db/seed/new/card_actions.yml +874 -874
  26. data/db/seed/new/card_acts.yml +2 -2
  27. data/db/seed/new/card_references.yml +2 -2
  28. data/db/seed/new/cards.yml +1576 -1576
  29. data/db/seed/new/schema_migrations_core_cards.yml +8 -0
  30. data/db/seed/test/fixtures/card_actions.yml +1815 -1815
  31. data/db/seed/test/fixtures/card_acts.yml +499 -499
  32. data/db/seed/test/fixtures/card_changes.yml +66 -66
  33. data/db/seed/test/fixtures/card_references.yml +634 -634
  34. data/db/seed/test/fixtures/cards.yml +2730 -2730
  35. data/db/seed/test/fixtures/schema_migrations_core_cards.yml +8 -0
  36. data/db/test_seed.rb +10 -11
  37. data/lib/card.rb +9 -30
  38. data/lib/card/act_manager.rb +0 -2
  39. data/lib/card/auth.rb +0 -5
  40. data/lib/card/auth/current.rb +32 -59
  41. data/lib/card/auth/setup.rb +1 -1
  42. data/lib/card/codename.rb +5 -6
  43. data/lib/card/content.rb +5 -8
  44. data/lib/card/content/chunk.rb +0 -78
  45. data/lib/card/content/chunk/abstract.rb +88 -0
  46. data/lib/card/content/clean.rb +3 -3
  47. data/lib/card/content/diff/{lcs.rb → l_c_s.rb} +5 -7
  48. data/lib/card/content/diff/{processor.rb → l_c_s/processor.rb} +0 -0
  49. data/lib/card/content/parser.rb +1 -1
  50. data/lib/card/dirty.rb +25 -31
  51. data/lib/card/dirty/method_factory.rb +15 -0
  52. data/lib/card/env.rb +0 -3
  53. data/lib/card/error.rb +6 -2
  54. data/lib/card/format.rb +5 -5
  55. data/lib/card/format/nest/fetch.rb +2 -1
  56. data/lib/card/mark.rb +1 -0
  57. data/lib/card/migration.rb +4 -0
  58. data/lib/card/mod.rb +2 -5
  59. data/lib/card/mod/dirs.rb +1 -0
  60. data/lib/card/mod/load_strategy.rb +23 -12
  61. data/lib/card/mod/loader.rb +13 -13
  62. data/lib/card/mod/loader/set_loader.rb +7 -1
  63. data/lib/card/mod/loader/set_pattern_loader.rb +2 -2
  64. data/lib/card/mod/module_template.rb +1 -5
  65. data/lib/card/mod_inflector.rb +16 -0
  66. data/lib/card/model/save_helper.rb +2 -2
  67. data/lib/card/name.rb +2 -2
  68. data/lib/card/name/name_variants.rb +19 -0
  69. data/lib/card/query.rb +4 -2
  70. data/lib/card/query/card_query/reference_attributes.rb +2 -2
  71. data/lib/card/query/sql_statement.rb +4 -0
  72. data/lib/card/set.rb +18 -3
  73. data/lib/card/set/abstract.rb +6 -0
  74. data/lib/card/set/event.rb +13 -11
  75. data/lib/card/set/event/delayed_event.rb +2 -0
  76. data/lib/card/set/format.rb +3 -3
  77. data/lib/card/set/helpers.rb +20 -8
  78. data/lib/card/set/loader.rb +1 -1
  79. data/lib/card/set/pattern.rb +47 -0
  80. data/lib/card/{set_pattern.rb → set/pattern/base.rb} +11 -92
  81. data/lib/card/set/required_field.rb +64 -30
  82. data/lib/card/set/trait.rb +3 -2
  83. data/lib/card/set/type.rb +46 -0
  84. data/lib/card/subcards.rb +0 -4
  85. data/lib/card/tasks/card.rake +1 -0
  86. data/lib/card/tasks/card/migrate.rake +1 -1
  87. data/lib/card/view.rb +2 -7
  88. data/lib/card/view/cache.rb +3 -0
  89. data/lib/card/view/cache/stub.rb +5 -0
  90. data/lib/cardio.rb +73 -46
  91. data/mod/account/set/abstract/accountable.rb +49 -0
  92. data/mod/account/set/all/account.rb +3 -3
  93. data/mod/account/set/right/account.rb +1 -1
  94. data/mod/account/set/self/signin.rb +2 -2
  95. data/mod/account/set/type/role.rb +1 -1
  96. data/mod/account/set/type/signup.rb +2 -2
  97. data/mod/account/set/type/signup/views.rb +1 -1
  98. data/mod/account/set/type/user.rb +1 -1
  99. data/mod/account/spec/set/abstract/accountable_spec.rb +7 -0
  100. data/mod/account/spec/set/all/account_spec.rb +3 -3
  101. data/mod/account/spec/set/right/account_spec.rb +1 -1
  102. data/mod/account/spec/set/type/signup_spec.rb +4 -4
  103. data/mod/admin/set/self/admin.rb +1 -1
  104. data/mod/admin/set/self/admin_info.rb +2 -2
  105. data/mod/admin/set/self/version.rb +1 -1
  106. data/mod/basic_types/set/type/json.rb +4 -0
  107. data/mod/basic_types/spec/set/type/html_spec.rb +1 -1
  108. data/mod/bootstrap/db/migrate_core_cards/data/20181108181219_migrate_classic_skins_to_bootstrap.rb +2 -2
  109. data/mod/bootstrap/lib/bootstrap/component_loader.rb +1 -1
  110. data/mod/bootstrap/lib/stylesheets/style_bootstrap_cards.scss +1 -0
  111. data/mod/bootstrap/set/abstract/bootswatch_theme.rb +1 -1
  112. data/mod/bootstrap/set/all/bootstrap/tabs.rb +4 -4
  113. data/mod/bootstrap/set/type/customized_bootswatch_skin.rb +5 -4
  114. data/mod/carrierwave/config/core_initializers/carrierwave.rb +1 -3
  115. data/mod/carrierwave/lib/carrier_wave/{cardmount.rb → card_mount.rb} +2 -2
  116. data/mod/carrierwave/lib/carrier_wave/file_card_uploader.rb +27 -12
  117. data/mod/carrierwave/set/abstract/attachment.rb +0 -2
  118. data/mod/carrierwave/set/all/file_utils.rb +5 -1
  119. data/mod/carrierwave/set/self/admin.rb +1 -1
  120. data/mod/core/chunk/link.rb +99 -91
  121. data/mod/core/chunk/nest.rb +2 -2
  122. data/mod/core/chunk/query_reference.rb +79 -74
  123. data/mod/core/chunk/view_stub.rb +10 -1
  124. data/mod/core/format/html_format.rb +1 -1
  125. data/mod/core/set/abstract/code_file.rb +6 -6
  126. data/mod/core/set/all/content.rb +1 -1
  127. data/mod/core/set/all/event_conditions.rb +1 -2
  128. data/mod/core/set/all/fetch.rb +22 -19
  129. data/mod/core/set/all/fetch_helper.rb +7 -5
  130. data/mod/core/set/all/initialize.rb +35 -9
  131. data/mod/core/set/all/item.rb +16 -6
  132. data/mod/core/set/all/name.rb +19 -15
  133. data/mod/core/set/all/pattern.rb +4 -0
  134. data/mod/core/set/all/permissions.rb +13 -11
  135. data/mod/core/set/all/rename.rb +1 -0
  136. data/mod/core/set/all/rules.rb +4 -4
  137. data/mod/core/set/all/subcards.rb +36 -1
  138. data/mod/core/set/all/type.rb +1 -1
  139. data/mod/core/set_pattern/03_type.rb +2 -0
  140. data/mod/core/spec/chunk/nest_spec.rb +7 -2
  141. data/mod/core/spec/set/all/fetch_spec.rb +1 -1
  142. data/mod/core/spec/set/all/permissions_spec.rb +11 -12
  143. data/mod/core/spec/set/all/rules_spec.rb +3 -3
  144. data/mod/edit/set/all/bridge.rb +1 -3
  145. data/mod/edit/set/all/bridge/tab_views.rb +0 -7
  146. data/mod/edit/set/all/bridge/tab_visibility.rb +5 -7
  147. data/mod/edit/set/all/form_buttons.rb +1 -1
  148. data/mod/edit/set/all/form_elements.rb +1 -0
  149. data/mod/edit/set/all/new.rb +2 -2
  150. data/mod/edit/spec/set/all/bridge/tab_views_spec.rb +1 -1
  151. data/mod/edit/spec/set/all/{nest_editor → reference_editor/nest_editor}/nest_parser_spec.rb +1 -1
  152. data/mod/edit/spec/set/all/{nest_editor_spec.rb → reference_editor/nest_editor_spec.rb} +6 -3
  153. data/mod/edit/spec/set/all/{nest_image_spec.rb → reference_editor/nest_image_spec.rb} +1 -1
  154. data/mod/email/set/abstract/test_context.rb +1 -1
  155. data/mod/email/set/type/email_template/email_config.rb +1 -1
  156. data/mod/follow/set/all/notify.rb +1 -1
  157. data/mod/follow/set/all/notify/base_views.rb +1 -1
  158. data/mod/follow/set/right/account.rb +8 -6
  159. data/mod/follow/set/right/followers.rb +2 -5
  160. data/mod/follow/set/right/following.rb +1 -1
  161. data/mod/follow/spec/set/all/follow_spec.rb +3 -3
  162. data/mod/follow/spec/set/all/notify_spec.rb +1 -1
  163. data/mod/follow/spec/set/right/followers_spec.rb +2 -2
  164. data/mod/history/lib/card/act.rb +3 -1
  165. data/mod/history/lib/card/action.rb +3 -3
  166. data/mod/history/lib/card/action/admin.rb +0 -11
  167. data/mod/history/set/all/history_bridge.rb +1 -1
  168. data/mod/machines/file/all_script_machine_output/file.js +38415 -69
  169. data/mod/machines/file/all_style_machine_output/file.css +2 -2
  170. data/mod/machines/file/script_html5shiv_printshiv_machine_output/file.js +1 -1
  171. data/mod/machines/lib/javascript/decko/filter.js.coffee +7 -1
  172. data/mod/machines/lib/javascript/decko/filter_links.js.coffee +13 -2
  173. data/mod/machines/lib/javascript/decko/link_editor.js.coffee +64 -0
  174. data/mod/machines/lib/javascript/decko/mod.js.coffee +3 -0
  175. data/mod/machines/lib/javascript/decko/nest_editor.js.coffee +49 -29
  176. data/mod/machines/lib/javascript/decko/nest_editor_name.js.coffee +30 -7
  177. data/mod/machines/lib/javascript/decko/slot.js.coffee +4 -1
  178. data/mod/machines/lib/stylesheets/style_cards.scss +31 -19
  179. data/mod/machines/set/abstract/machine/output_cache.rb +1 -1
  180. data/mod/machines/set/abstract/machine/output_update.rb +1 -1
  181. data/mod/machines/set/all/reset_machines.rb +2 -2
  182. data/mod/machines/set/self/script_decko.rb +1 -0
  183. data/mod/media/set/abstract/media.rb +1 -1
  184. data/mod/media/set/type/image.rb +1 -1
  185. data/mod/navbar/set/abstract/account_dropdown.rb +5 -1
  186. data/mod/navbar/set/right/enabled_roles.rb +1 -1
  187. data/mod/navbar/set/self/account_links.rb +1 -1
  188. data/mod/pointer/set/abstract/02_pointer.rb +1 -1
  189. data/mod/pointer/set/abstract/02_pointer/events.rb +30 -10
  190. data/mod/pointer/set/abstract/02_pointer/html_views.rb +6 -2
  191. data/mod/pointer/set/abstract/02_pointer/html_views/autocomplete_input.haml +1 -1
  192. data/mod/pointer/set/abstract/02_pointer/html_views/filter.rb +1 -1
  193. data/mod/pointer/set/abstract/02_pointer/item_api.rb +51 -31
  194. data/mod/pointer/set/abstract/id_pointer.rb +21 -0
  195. data/mod/pointer/set/type/link_list.rb +1 -1
  196. data/mod/pointer/set/type/mirror_list.rb +1 -1
  197. data/mod/pointer/set/type/mirrored_list.rb +2 -2
  198. data/mod/pointer/spec/set/abstract/paging_params_spec.rb +1 -1
  199. data/mod/pointer/spec/set/abstract/pointer/item_api_spec.rb +1 -1
  200. data/mod/recaptcha/set/all/recaptcha.rb +4 -9
  201. data/mod/rules/set/rule/editor.rb +2 -2
  202. data/mod/rules/set/type/set/html_views/rule_lists.rb +1 -1
  203. data/mod/rules/spec/set/type/set_spec.rb +1 -1
  204. data/mod/search/set/abstract/03_filter/filter_form.haml +1 -1
  205. data/mod/search/set/abstract/03_filter/filter_form.rb +23 -2
  206. data/mod/search/set/abstract/03_filter/quick_filters.haml +7 -10
  207. data/mod/search/template/abstract/search/checkbox_item.haml +5 -6
  208. data/mod/settings/set/abstract/permission.rb +2 -2
  209. data/mod/settings/set/right/input_type.rb +3 -3
  210. data/mod/settings/set/right/structure.rb +1 -1
  211. data/mod/settings/set/right/style.rb +1 -1
  212. data/mod/settings/set/type/setting.rb +2 -2
  213. data/mod/standard/set/all/rich_html/html_views/guide.rb +1 -1
  214. data/mod/standard/set/all/rich_html/menu.rb +6 -5
  215. data/mod/standard/set/self/cardtype.rb +1 -1
  216. data/mod/standard/set/type/cardtype.rb +33 -17
  217. data/mod/standard/set/type/session.rb +12 -0
  218. data/mod/standard/spec/set/type/email_template/email_config_spec.rb +1 -2
  219. data/mod/standard/spec/set/type/email_template_spec.rb +1 -3
  220. data/mod/tinymce_editor/lib/javascript/script_tinymce_config.js.coffee +3 -2
  221. data/mod/tinymce_editor/public/assets/tinymce/plugins/nest/plugin.min.js +1 -1
  222. data/mod/tinymce_editor/set/all/reference_editor.rb +23 -0
  223. data/mod/tinymce_editor/set/all/reference_editor/_link_editor.haml +18 -0
  224. data/mod/tinymce_editor/set/all/reference_editor/_nest_editor.haml +17 -0
  225. data/mod/tinymce_editor/set/all/reference_editor/link_editor.rb +33 -0
  226. data/mod/tinymce_editor/set/all/reference_editor/link_editor/link_parser.rb +35 -0
  227. data/mod/tinymce_editor/set/all/reference_editor/nest_editor.rb +174 -0
  228. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_help.haml +0 -0
  229. data/mod/tinymce_editor/set/all/reference_editor/nest_editor/_options.haml +12 -0
  230. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_options_select.haml +0 -0
  231. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_options_select_row.haml +0 -0
  232. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/nest_parser.rb +7 -1
  233. data/mod/tinymce_editor/set/all/reference_editor/nest_image.rb +70 -0
  234. data/mod/tinymce_editor/set/all/reference_editor/reference_editor.haml +18 -0
  235. metadata +39 -21
  236. data/mod/account/set/abstract/accounted.rb +0 -15
  237. data/mod/edit/set/all/bridge/account_section.rb +0 -16
  238. data/mod/edit/set/all/nest_editor.rb +0 -122
  239. data/mod/edit/set/all/nest_editor/_options.haml +0 -12
  240. data/mod/edit/set/all/nest_editor/nest_editor.haml +0 -31
  241. data/mod/edit/set/all/nest_image.rb +0 -37
@@ -307,3 +307,11 @@ schema_migrations_core_cards_153:
307
307
  version: '20190927112151'
308
308
  schema_migrations_core_cards_154:
309
309
  version: '20191008201046'
310
+ schema_migrations_core_cards_155:
311
+ version: '20191014204655'
312
+ schema_migrations_core_cards_156:
313
+ version: '20191028135243'
314
+ schema_migrations_core_cards_157:
315
+ version: '20191115160748'
316
+ schema_migrations_core_cards_158:
317
+ version: '20191118145629'
@@ -4,7 +4,6 @@ require "timecop"
4
4
 
5
5
  # noinspection RubyResolve
6
6
  class SharedData
7
- require_relative "../lib/card/model/save_helper"
8
7
  extend Card::Model::SaveHelper
9
8
 
10
9
  USERS = [
@@ -96,11 +95,11 @@ class SharedData
96
95
  Card.create! type_id: Card::CardtypeID, name: "UserForm"
97
96
  create "UserForm+*type+*structure", "{{+name}} {{+age}} {{+description}}"
98
97
 
99
- Card::Auth.current_id = Card["joe_user"].id
98
+ Card::Auth.signin "joe_user"
100
99
  create "JoeLater", "test"
101
100
  create "JoeNow", "test"
102
101
 
103
- Card::Auth.current_id = Card::WagnBotID
102
+ Card::Auth.signin Card::WagnBotID
104
103
 
105
104
  create_cardtype "Book"
106
105
  create "Book+*type+*structure", "by {{+author}}, design by {{+illustrator}}"
@@ -169,10 +168,10 @@ class SharedData
169
168
  end
170
169
 
171
170
  # noinspection RubyResolve
172
- Card["Joe Admin"].fetch(trait: :roles, new: { type_code: "pointer" })
171
+ Card["Joe Admin"].fetch(:roles, new: { type_code: "pointer" })
173
172
  .items = [Card::AdministratorID, Card::SharkID, Card::HelpDeskID]
174
173
 
175
- Card["Joe User"].fetch(trait: :roles, new: { type_code: "pointer" })
174
+ Card["Joe User"].fetch(:roles, new: { type_code: "pointer" })
176
175
  .items = [Card::SharkID]
177
176
 
178
177
  create_user "u1", email: "u1@user.com", password: "u1_pass"
@@ -184,9 +183,9 @@ class SharedData
184
183
  r3 = create_role "r3"
185
184
  r4 = create_role "r4"
186
185
 
187
- Card["u1"].fetch(trait: :roles, new: { type_code: "pointer" }).items = [r1, r2, r3]
188
- Card["u2"].fetch(trait: :roles, new: {}).items = [r1, r2, r4]
189
- Card["u3"].fetch(trait: :roles, new: {}).items = [r1, r4, Card::AdministratorID]
186
+ Card["u1"].fetch(:roles, new: { type_code: "pointer" }).items = [r1, r2, r3]
187
+ Card["u2"].fetch(:roles, new: {}).items = [r1, r2, r4]
188
+ Card["u3"].fetch(:roles, new: {}).items = [r1, r4, Card::AdministratorID]
190
189
  end
191
190
 
192
191
 
@@ -244,14 +243,14 @@ class SharedData
244
243
  create "John Following+her"
245
244
  magnifier = create "Magnifier+lens"
246
245
 
247
- Card::Auth.current_id = Card["Narcissist"].id
246
+ Card::Auth.signin "Narcissist"
248
247
  magnifier.update! content: "zoom in"
249
248
  create_optic "Sunglasses", "{{+tint}}{{+lens}}"
250
249
 
251
- Card::Auth.current_id = Card["Optic fan"].id
250
+ Card::Auth.signin "Optic fan"
252
251
  create_optic "Google glass", "{{+price}}"
253
252
 
254
- Card::Auth.current_id = Card::WagnBotID
253
+ Card::Auth.signin Card::WagnBotID
255
254
  create "Google glass+*self+*follow_fields", ""
256
255
  create "Sunglasses+*self+*follow_fields", "[[#{Card[:nests].name}]]\n[[_self+price]]\n[[_self+producer]]"
257
256
  create "Sunglasses+tint"
@@ -1,8 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- Object.const_remove_if_defined :Card
4
3
  ActiveSupport.run_load_hooks(:before_card, self)
5
- # ActiveSupport::Dependencies.loaded.clear
6
4
 
7
5
  # Cards are wiki-inspired building blocks.
8
6
  #
@@ -93,28 +91,12 @@ ActiveSupport.run_load_hooks(:before_card, self)
93
91
  # You can see the current user with `Card::Auth.current`. The permissions of a proxy user can be temporarily assumed using `Card::Auth#as`.
94
92
  #
95
93
  # {Card::Auth More on accounts}
96
- #
97
94
  class Card < ApplicationRecord
98
- require_dependency "card/mark"
99
- extend Mark
95
+ extend ::Card::Mark
96
+ extend ::Card::Dirty::MethodFactory
97
+ include ::Card::Dirty
100
98
 
101
- require_dependency "card/name"
102
- require_dependency "card/codename"
103
- require_dependency "card/query"
104
- require_dependency "card/format"
105
- require_dependency "card/error"
106
- require_dependency "card/auth"
107
- require_dependency "card/mod"
108
- require_dependency "card/content"
109
- require_dependency "card/action"
110
- require_dependency "card/act"
111
- require_dependency "card/change"
112
- require_dependency "card/reference"
113
- require_dependency "card/subcards"
114
- require_dependency "card/view"
115
- require_dependency "card/act_manager"
116
- require_dependency "card/dirty"
117
- require_dependency "card/layout"
99
+ Card::Cache
118
100
 
119
101
  has_many :references_in, class_name: :Reference, foreign_key: :referee_id
120
102
  has_many :references_out, class_name: :Reference, foreign_key: :referer_id
@@ -159,33 +141,30 @@ class Card < ApplicationRecord
159
141
 
160
142
  attr_accessor :follower_stash
161
143
 
162
- define_callbacks(
144
+ STAGE_CALLBACKS = [
163
145
  :select_action, :show_page, :act,
164
-
165
146
  # VALIDATION PHASE
166
147
  :initialize_stage, :prepare_to_validate_stage, :validate_stage,
167
148
  :initialize_final_stage, :prepare_to_validate_final_stage,
168
149
  :validate_final_stage,
169
-
170
150
  # STORAGE PHASE
171
151
  :prepare_to_store_stage, :store_stage, :finalize_stage,
172
152
  :prepare_to_store_final_stage, :store_final_stage, :finalize_final_stage,
173
-
174
153
  # INTEGRATION PHASE
175
154
  :integrate_stage, :integrate_with_delay_stage,
176
155
  :integrate_final_stage,
177
156
  :after_integrate_stage,
178
157
  :after_integrate_final_stage, :integrate_with_delay_final_stage
179
- )
158
+ ].freeze
159
+ define_callbacks(*STAGE_CALLBACKS)
180
160
 
181
161
  # Validation and integration phase are only called for the act card
182
162
  # The act card starts those phases for all its subcards
183
163
  before_validation :validation_phase, unless: -> { only_storage_phase? }
184
164
  around_save :storage_phase
185
165
  after_commit :integration_phase, unless: -> { only_storage_phase? }
186
- # after_rollback :clean_up, unless: -> { only_storage_phase? }
166
+ # after_rollback :clean_up, unless: -> { only_storage_phase? }
187
167
 
188
168
  ActiveSupport.run_load_hooks(:card, self)
189
169
  end
190
-
191
- ActiveSupport.run_load_hooks(:after_card, self)
170
+ ActiveSupport.run_load_hooks :after_card, self
@@ -1,5 +1,3 @@
1
- require_dependency "card/act_manager/stage_director"
2
-
3
1
  class Card
4
2
  # Manages the whole process of creating an {act Card::Act} ie. changing
5
3
  # a card and attached subcards.
@@ -1,10 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- require_dependency "card/auth/permissions"
4
- require_dependency "card/auth/proxy"
5
- require_dependency "card/auth/setup"
6
- require_dependency "card/auth/token"
7
-
8
3
  class Card
9
4
  # Singleton methods for account authentication and contextualization.
10
5
  #
@@ -3,7 +3,8 @@ class Card
3
3
  # methods for setting current account
4
4
  module Current
5
5
  # set current user in process and session
6
- def signin signin_id
6
+ def signin cardish
7
+ signin_id = Card.id(cardish) || Card::AnonymousID
7
8
  self.current_id = signin_id
8
9
  set_session_user signin_id
9
10
  end
@@ -30,37 +31,9 @@ class Card
30
31
  end
31
32
  end
32
33
 
33
- # set the id of the current user.
34
- def current_id= card_id
35
- @current = @as_id = @as_card = @current_roles = nil
36
- card_id = card_id.to_i if card_id.present?
37
- @current_id = card_id
38
- end
39
-
40
- # set current user from email or id
41
- # @return [Integer]
42
- def current= mark
43
- self.current_id =
44
- if mark.to_s =~ /@/
45
- account = Auth.find_account_by_email mark
46
- account && account.active? ? account.left_id : Card::AnonymousID
47
- else
48
- mark
49
- end
50
- end
51
-
52
34
  def current_roles
53
35
  @current_roles ||= [Card.fetch_name(:anyone_signed_in),
54
- current.fetch(trait: :roles)&.item_names].flatten.compact
55
- end
56
-
57
- def no_special_roles?
58
- Auth.current_roles.size == 1 # &&
59
- # Auth.current_roles.first == Card.fetch_name(:anyone_signed_in)
60
- end
61
-
62
- def clear_current_roles
63
- @current_roles = nil
36
+ current.fetch(:roles)&.item_names].flatten.compact
64
37
  end
65
38
 
66
39
  def serialize
@@ -71,11 +44,8 @@ class Card
71
44
  # @option auth_data [Integer] current_id
72
45
  # @option auth_data [Integer] as_id
73
46
  def with auth_data
74
- case auth_data
75
- when Integer
76
- auth_data = { current_id: auth_data }
77
- when String
78
- auth_data = { current_id: Card.fetch_id(auth_data) }
47
+ if auth_data.is_a?(Integer) || auth_data.is_a?(String)
48
+ auth_data = { current_id: Card.id(auth_data) }
79
49
  end
80
50
 
81
51
  tmp_current_id = current_id
@@ -102,68 +72,62 @@ class Card
102
72
  Card::Env.session
103
73
  end
104
74
 
105
- # set current from token or session
106
- def set_current opts={}
75
+ # set current from token, api_key, or session
76
+ def signin_with opts={}
107
77
  if opts[:token]
108
- set_current_from_token opts[:token]
78
+ signin_with_token opts[:token]
109
79
  elsif opts[:api_key]
110
- set_current_from_api_key opts[:api_key]
80
+ signin_with_api_key opts[:api_key]
111
81
  else
112
- set_current_from_session
82
+ signin_with_session
113
83
  end
114
84
  end
115
85
 
116
86
  # set the current user based on token
117
- def set_current_from_token token
87
+ def signin_with_token token
118
88
  payload = Token.validate! token
119
- self.current_id = payload[:anonymous] ? Card::AnonymousID : payload[:user_id]
89
+ signin payload[:anonymous] ? Card::AnonymousID : payload[:user_id]
120
90
  end
121
91
 
122
92
  # set the current user based on api_key
123
- def set_current_from_api_key api_key
93
+ def signin_with_api_key api_key
124
94
  account = find_account_by_api_key api_key
125
95
  unless account&.validate_api_key! api_key
126
96
  raise Card::Error::PermissionDenied, "API key authentication failed"
127
97
  end
128
98
 
129
- self.current = account.left_id
99
+ signin account.left_id
130
100
  end
131
101
 
132
102
  # get :user id from session and set Auth.current_id
133
- def set_current_from_session
134
- self.current_id =
135
- if (card_id = session_user) && Card.exists?(card_id)
136
- card_id
137
- else
138
- set_session_user Card::AnonymousID
139
- end
103
+ def signin_with_session
104
+ card_id = session_user
105
+ signin(card_id && Card.exists?(card_id) ? card_id : nil)
140
106
  end
141
107
 
142
108
  # find +\*account card by +\*api card
143
109
  # @param token [String]
144
110
  # @return [+*account card, nil]
145
111
  def find_account_by_api_key api_key
146
- find_account_by "api_key", Card::ApiKeyID, api_key.strip
112
+ find_account_by :api_key, api_key.strip
147
113
  end
148
114
 
149
115
  # find +\*account card by +\*email card
150
116
  # @param email [String]
151
117
  # @return [+*account card, nil]
152
118
  def find_account_by_email email
153
- find_account_by "email", Card::EmailID, email.strip.downcase
119
+ find_account_by :email, email.strip.downcase
154
120
  end
155
121
 
156
122
  # general pattern for finding +\*account card based on field cards
157
- # @param fieldname [String] right name of field card (for WQL comment)
158
- # @param field_id [Integer] card id of field's simple card
123
+ # @param fieldcode [Symbol] code of account field
159
124
  # @param value [String] content of field
160
125
  # @return [+*account card, nil]
161
- def find_account_by fieldname, field_id, value
126
+ def find_account_by fieldcode, value
162
127
  Auth.as_bot do
163
128
  Card.search({ right_id: Card::AccountID,
164
- right_plus: [{ id: field_id },
165
- { content: value }] },
166
- "find +:account for #{fieldname} (#{value})").first
129
+ right_plus: [Card::Codename.id(fieldcode), { content: value }] },
130
+ "find +:account with +#{fieldcode} (#{value})").first
167
131
  end
168
132
  end
169
133
 
@@ -182,6 +146,15 @@ class Card
182
146
  def database
183
147
  Rails.configuration.database_configuration.dig Rails.env, "database"
184
148
  end
149
+
150
+ private
151
+
152
+ # set the id of the current user.
153
+ def current_id= card_id
154
+ @current = @as_id = @as_card = @current_roles = nil
155
+ card_id = card_id.to_i if card_id.present?
156
+ @current_id = card_id
157
+ end
185
158
  end
186
159
  end
187
160
  end
@@ -42,7 +42,7 @@ class Card
42
42
  end
43
43
 
44
44
  def user_account_wql
45
- { right_id: AccountID, creator_id: ["ne", WagnBotID] }
45
+ { right_id: Card::AccountID, creator_id: ["ne", Card::WagnBotID] }
46
46
  end
47
47
 
48
48
  def user_account_count
@@ -1,8 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- require_dependency "card/cache"
4
- require_dependency "card/name"
5
-
6
3
  class Card
7
4
  # {Card}'s names can be changed, and therefore _names_ should not be directly mentioned
8
5
  # in code, lest a name change break the application.
@@ -46,7 +43,9 @@ class Card
46
43
  end
47
44
  end
48
45
 
49
- def name codename
46
+ def name codename=nil
47
+ return super() if codename.nil?
48
+
50
49
  name! codename
51
50
  rescue Error::CodenameNotFound => _e
52
51
  yield if block_given?
@@ -75,7 +74,7 @@ class Card
75
74
  # clear cache both locally and in cache
76
75
  def reset_cache
77
76
  @codehash = nil
78
- Card.cache.delete "CODEHASH"
77
+ ::Card.cache.delete "CODEHASH"
79
78
  end
80
79
 
81
80
  # @param codename [Symbol, String]
@@ -112,7 +111,7 @@ class Card
112
111
 
113
112
  # generate Hash for @codehash and put it in the cache
114
113
  def load_codehash
115
- Card.cache.fetch("CODEHASH") do
114
+ ::Card.cache.fetch("CODEHASH") do
116
115
  generate_codehash
117
116
  end
118
117
  end
@@ -1,10 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- require_dependency "card/content/chunk"
4
- require_dependency "card/content/parser"
5
- require_dependency "card/content/clean"
6
- require_dependency "card/content/truncate"
7
-
8
3
  class Card
9
4
  # Content objects support the parsing of content strings into arrays that
10
5
  # contain semantically meaningful "chunks" like nests, links, urls, etc.
@@ -12,8 +7,10 @@ class Card
12
7
  # Each chunk has an object whose class inherits from {Card::Content::Chunk::Abstract}
13
8
  #
14
9
  class Content < SimpleDelegator
15
- extend Card::Content::Clean
16
- extend Card::Content::Truncate
10
+ extend Clean
11
+ extend Truncate
12
+
13
+ Chunk
17
14
 
18
15
  attr_reader :revision, :format, :chunks, :opts
19
16
 
@@ -46,7 +43,7 @@ class Card
46
43
  end
47
44
 
48
45
  def has_chunk? chunk_type
49
- each_chunk.any { |chunk| chunk.is_a?(chunk_type)}
46
+ each_chunk.any { |chunk| chunk.is_a?(chunk_type) }
50
47
  end
51
48
 
52
49
  # sends &block to #process_chunk on each Chunk object
@@ -89,84 +89,6 @@ class Card
89
89
  register_list :nest_only, [:Nest]
90
90
  register_list :query, [:QueryReference]
91
91
  register_list :stub, [:ViewStub]
92
-
93
- class Abstract
94
- class_attribute :config
95
- attr_reader :text, :process_chunk
96
-
97
- class << self
98
- # if the prefix regex matched check that chunk against the full regex
99
- def full_match content, prefix=nil
100
- content.match full_re(prefix)
101
- end
102
-
103
- def full_re _prefix
104
- config[:full_re]
105
- end
106
-
107
- def context_ok? _content, _chunk_start
108
- true
109
- end
110
- end
111
-
112
- def reference_code
113
- "I"
114
- end
115
-
116
- def initialize match, content
117
- match = self.class.full_match(match) if match.is_a? String
118
- @text = match[0]
119
- @processed = nil
120
- @content = content
121
- interpret match, content
122
- self
123
- end
124
-
125
- def interpret _match_string, _content
126
- Rails.logger.info "no #interpret method found for chunk class: " \
127
- "#{self.class}"
128
- end
129
-
130
- def format
131
- @content.format
132
- end
133
-
134
- def card
135
- @content.card
136
- end
137
-
138
- def to_s
139
- result
140
- end
141
-
142
- def result
143
- burn_read || @process_chunk || @processed || @text
144
- end
145
-
146
- def burn_read
147
- return unless @burn_read
148
-
149
- tmp = @burn_read
150
- @burn_read = nil
151
- tmp
152
- end
153
-
154
- # Temporarily overrides the processed nest content for single-use
155
- # After using the nest's result
156
- # (for example via `to_s`) the original result is restored
157
- def burn_after_reading text
158
- @burn_read = text
159
- end
160
-
161
- def inspect
162
- "<##{self.class}##{self}>"
163
- end
164
-
165
- def as_json _options={}
166
- burn_read || @process_chunk || @processed ||
167
- "not rendered #{self.class}, #{card&.name}"
168
- end
169
- end
170
92
  end
171
93
  end
172
94
  Card::Mod::Loader.load_chunks