card 1.16.8 → 1.16.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/db/migrate_core_cards/{20150611203506_rails_inflection_updates.rb → 20120611203506_rails_inflection_updates.rb} +0 -0
  4. data/db/migrate_core_cards/20150326205655_bootswatch_themes.rb +0 -1
  5. data/db/migrate_core_cards/20150429090551_search_card_context.rb +1 -1
  6. data/db/migrate_core_cards/20150708224756_add_list_cards.rb +22 -0
  7. data/db/seed/new/card_actions.yml +789 -509
  8. data/db/seed/new/card_acts.yml +1 -1
  9. data/db/seed/new/card_changes.yml +2618 -1920
  10. data/db/seed/new/card_references.yml +1034 -901
  11. data/db/seed/new/cards.yml +2303 -1675
  12. data/db/seed/test/fixtures/card_actions.yml +1926 -1606
  13. data/db/seed/test/fixtures/card_acts.yml +354 -324
  14. data/db/seed/test/fixtures/card_changes.yml +5950 -5175
  15. data/db/seed/test/fixtures/card_references.yml +1861 -1630
  16. data/db/seed/test/fixtures/cards.yml +3768 -3048
  17. data/db/seed/test/seed.rb +121 -107
  18. data/lib/card.rb +2 -3
  19. data/lib/card/active_record_helper.rb +44 -0
  20. data/lib/card/auth.rb +51 -47
  21. data/lib/card/cache.rb +7 -3
  22. data/lib/card/codename.rb +7 -7
  23. data/lib/card/format.rb +2 -1
  24. data/lib/card/migration.rb +17 -16
  25. data/lib/card/name.rb +71 -20
  26. data/lib/card/set.rb +202 -166
  27. data/lib/card/simplecov_helper.rb +11 -7
  28. data/lib/card/subcards.rb +249 -0
  29. data/mod/01_core/set/all/collection.rb +1 -2
  30. data/mod/01_core/set/all/fetch.rb +167 -92
  31. data/mod/01_core/set/all/initialize.rb +8 -22
  32. data/mod/01_core/set/all/name.rb +128 -79
  33. data/mod/01_core/set/all/phases.rb +93 -95
  34. data/mod/01_core/set/all/subcards.rb +70 -0
  35. data/mod/01_core/set/all/tracked_attributes.rb +83 -59
  36. data/mod/01_core/set/all/trash.rb +14 -12
  37. data/mod/01_core/set/all/type.rb +3 -24
  38. data/mod/01_core/spec/set/all/initialize_spec.rb +44 -14
  39. data/mod/01_core/spec/set/all/permissions_spec.rb +206 -185
  40. data/mod/01_core/spec/set/all/tracked_attributes_spec.rb +0 -10
  41. data/mod/01_core/spec/set/all/trash_spec.rb +38 -13
  42. data/mod/01_core/spec/set/all/type_spec.rb +0 -19
  43. data/mod/01_history/set/all/content_history.rb +5 -3
  44. data/mod/01_history/set/all/history.rb +117 -82
  45. data/mod/02_basic_types/set/all/base.rb +50 -49
  46. data/mod/03_machines/lib/card/machine.rb +2 -1
  47. data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +55 -17
  48. data/mod/03_machines/spec/set/type/javascript_spec.rb +18 -12
  49. data/mod/05_email/set/right/followers.rb +5 -5
  50. data/mod/05_email/set/right/following.rb +1 -1
  51. data/mod/05_email/set/type_plus_right/user/follow.rb +1 -1
  52. data/mod/05_standard/lib/carrier_wave/cardmount.rb +19 -11
  53. data/mod/05_standard/lib/file_uploader.rb +1 -1
  54. data/mod/05_standard/set/abstract/attachment.rb +20 -8
  55. data/mod/05_standard/set/all/list_changes.rb +43 -0
  56. data/mod/05_standard/set/all/rich_html/form.rb +21 -11
  57. data/mod/05_standard/set/all/rich_html/menu.rb +1 -1
  58. data/mod/05_standard/set/right/account.rb +5 -5
  59. data/mod/05_standard/set/self/head.rb +0 -1
  60. data/mod/05_standard/set/self/signin.rb +43 -35
  61. data/mod/05_standard/set/type/file.rb +9 -2
  62. data/mod/05_standard/set/type/list.rb +134 -0
  63. data/mod/05_standard/set/type/listed_by.rb +94 -0
  64. data/mod/05_standard/set/type/search_type.rb +62 -61
  65. data/mod/05_standard/set/type/signup.rb +94 -63
  66. data/mod/05_standard/set/type/user.rb +48 -39
  67. data/mod/05_standard/spec/set/all/account_spec.rb +1 -1
  68. data/mod/05_standard/spec/set/all/rich_html/form_spec.rb +2 -2
  69. data/mod/05_standard/spec/set/self/signin_spec.rb +23 -27
  70. data/mod/05_standard/spec/set/type/email_template_spec.rb +0 -2
  71. data/mod/05_standard/spec/set/type/list_spec.rb +140 -0
  72. data/mod/05_standard/spec/set/type/listed_by_spec.rb +157 -0
  73. data/mod/05_standard/spec/set/type/signup_spec.rb +38 -32
  74. data/spec/lib/card/subcards_spec.rb +126 -0
  75. metadata +14 -3
data/db/seed/test/seed.rb CHANGED
@@ -4,8 +4,8 @@ require 'timecop'
4
4
  class SharedData
5
5
  #attr_accessor :users
6
6
  USERS = [
7
- 'Joe User', 'Joe Admin', 'Joe Camel', 'Sample User', 'No count',
8
- 'u1', 'u2', 'u3',
7
+ 'Joe User', 'Joe Admin', 'Joe Camel', 'Sample User', 'No count',
8
+ 'u1', 'u2', 'u3',
9
9
  'Big Brother', 'Optic fan', 'Sunglasses fan', 'Narcissist'
10
10
  ]
11
11
 
@@ -14,188 +14,202 @@ class SharedData
14
14
  end
15
15
 
16
16
  def self.add_test_data
17
-
17
+
18
18
  Card::Cache.reset_global
19
19
  Card::Env.reset
20
20
  Card::Auth.as_bot
21
21
 
22
- Card.create! :name=>"Joe User", :type_code=>'user', :content=>"I'm number two", :subcards=>account_args( '+*email'=>'joe@user.com' )
23
- Card.create! :name=>"Joe Admin", :type_code=>'user', :content=>"I'm number one", :subcards=>account_args( '+*email'=>'joe@admin.com' )
24
- Card.create! :name=>"Joe Camel", :type_code=>'user', :content=>"Mr. Buttz", :subcards=>account_args( '+*email'=>'joe@camel.com' )
25
-
26
- Card['Joe Admin'].fetch(:trait=>:roles, :new=>{:type_code=>'pointer'}).items = [ Card::AdministratorID ]
22
+ Card::Auth.instant_account_activation do
23
+ Card.create! name: "Joe User", type_code: 'user',
24
+ content: "I'm number two",
25
+ subcards: account_args( '+*email'=>'joe@user.com' )
26
+ Card.create! name: "Joe Admin", type_code: 'user',
27
+ content: "I'm number one",
28
+ subcards: account_args( '+*email'=>'joe@admin.com' )
29
+ Card.create! name: "Joe Camel", type_code: 'user',
30
+ content: "Mr. Buttz",
31
+ subcards: account_args( '+*email'=>'joe@camel.com' )
32
+
33
+ # data for testing users and account requests
34
+ Card.create! type_code: 'user', name: "No Count",
35
+ content: "I got no account"
36
+ Card.create! name: "Sample User", type_code: 'user',
37
+ subcards: account_args(
38
+ '+*email'=>'sample@user.com', '+*password'=>'sample_pass'
39
+ )
40
+ end
27
41
 
28
- Card.create! :name=>'signup alert email+*to', :content=>'signups@wagn.org'
42
+ Card['Joe Admin'].fetch(trait: :roles, new: {type_code: 'pointer'})
43
+ .items = [ Card::AdministratorID ]
44
+ Card.create! name: 'signup alert email+*to', content: 'signups@wagn.org'
29
45
 
30
46
  # generic, shared attribute card
31
- color = Card.create! :name=>"color"
32
- basic = Card.create! :name=>"Basic Card"
33
-
34
- # data for testing users and account requests
35
-
36
- Card.create! :type_code=>'user', :name=>"No Count", :content=>"I got no account"
37
-
38
-
39
- Card.create! :name=>"Sample User", :type_code=>'user', :subcards=>account_args('+*email'=>'sample@user.com', '+*password'=>'sample_pass')
47
+ color = Card.create! name: 'color'
48
+ basic = Card.create! name: "Basic Card"
40
49
 
41
50
  # CREATE A CARD OF EACH TYPE
42
-
43
- Card.create! :type_id=>Card::SignupID, :name=>"Sample Signup" #, :email=>"invitation@request.com"
51
+ Card.create! type_id: Card::SignupID, name: "Sample Signup" #, email: "invitation@request.com"
44
52
  #above still necessary? try commenting out above and 'Sign up' below
45
53
  Card::Auth.current_id = Card::WagnBotID # need to reset after creating sign up, which changes current_id for extend phase
46
54
 
47
55
  Card::Auth.createable_types.each do |type|
48
- next if ['User', 'Sign up', 'Set', 'Number'].include? type
49
- Card.create! :type=>type, :name=>"Sample #{type}"
56
+ next if ['User', 'Sign up', 'Set', 'Number', 'List', 'Listed by'].include? type
57
+ Card.create! type: type, name: "Sample #{type}"
50
58
  end
51
59
 
52
60
 
53
61
 
54
62
  # data for role_test.rb
55
63
 
56
- Card.create! :name=>"u1", :type_code=>'user', :subcards=>account_args('+*email'=>'u1@user.com', '+*password'=>'u1_pass')
57
- Card.create! :name=>"u2", :type_code=>'user', :subcards=>account_args('+*email'=>'u2@user.com', '+*password'=>'u2_pass')
58
- Card.create! :name=>"u3", :type_code=>'user', :subcards=>account_args('+*email'=>'u3@user.com', '+*password'=>'u3_pass')
64
+ Card.create! name: 'u1', type_code: 'user', subcards: account_args('+*email'=>'u1@user.com', '+*password'=>'u1_pass')
65
+ Card.create! name: 'u2', type_code: 'user', subcards: account_args('+*email'=>'u2@user.com', '+*password'=>'u2_pass')
66
+ Card.create! name: 'u3', type_code: 'user', subcards: account_args('+*email'=>'u3@user.com', '+*password'=>'u3_pass')
59
67
 
60
- r1 = Card.create!( :type_code=>'role', :name=>'r1' )
61
- r2 = Card.create!( :type_code=>'role', :name=>'r2' )
62
- r3 = Card.create!( :type_code=>'role', :name=>'r3' )
63
- r4 = Card.create!( :type_code=>'role', :name=>'r4' )
68
+ r1 = Card.create!( type_code: 'role', name: 'r1' )
69
+ r2 = Card.create!( type_code: 'role', name: 'r2' )
70
+ r3 = Card.create!( type_code: 'role', name: 'r3' )
71
+ r4 = Card.create!( type_code: 'role', name: 'r4' )
64
72
 
65
- Card['u1'].fetch( :trait=>:roles, :new=>{} ).items = [ r1, r2, r3 ]
66
- Card['u2'].fetch( :trait=>:roles, :new=>{} ).items = [ r1, r2, r4 ]
67
- Card['u3'].fetch( :trait=>:roles, :new=>{} ).items = [ r1, r4, Card::AdministratorID ]
73
+ Card['u1'].fetch( trait: :roles, new: {} ).items = [ r1, r2, r3 ]
74
+ Card['u2'].fetch( trait: :roles, new: {} ).items = [ r1, r2, r4 ]
75
+ Card['u3'].fetch( trait: :roles, new: {} ).items = [ r1, r4, Card::AdministratorID ]
68
76
 
69
- c1 = Card.create! :name=>'c1'
70
- c2 = Card.create! :name=>'c2'
71
- c3 = Card.create! :name=>'c3'
77
+ c1 = Card.create! name: 'c1'
78
+ c2 = Card.create! name: 'c2'
79
+ c3 = Card.create! name: 'c3'
72
80
 
73
81
  # cards for rename_test
74
82
  # FIXME: could probably refactor these..
75
- z = Card.create! :name=>"Z", :content=>"I'm here to be referenced to"
76
- a = Card.create! :name=>"A", :content=>"Alpha [[Z]]"
77
- b = Card.create! :name=>"B", :content=>"Beta {{Z}}"
78
- t = Card.create! :name=>"T", :content=>"Theta"
79
- x = Card.create! :name=>"X", :content=>"[[A]] [[A+B]] [[T]]"
80
- y = Card.create! :name=>"Y", :content=>"{{B}} {{A+B}} {{A}} {{T}}"
81
- ab = Card.create! :name => "A+B", :content => "AlphaBeta"
83
+ z = Card.create! name: 'Z', content: "I'm here to be referenced to"
84
+ a = Card.create! name: 'A', content: "Alpha [[Z]]"
85
+ b = Card.create! name: 'B', content: "Beta {{Z}}"
86
+ t = Card.create! name: 'T', content: 'Theta'
87
+ x = Card.create! name: 'X', content: "[[A]] [[A+B]] [[T]]"
88
+ y = Card.create! name: 'Y', content: "{{B}} {{A+B}} {{A}} {{T}}"
89
+ ab = Card.create! name: "A+B", content: 'AlphaBeta'
82
90
 
83
- Card.create! :name=>"One+Two+Three"
84
- Card.create! :name=>"Four+One+Five"
91
+ Card.create! name: "One+Two+Three"
92
+ Card.create! name: "Four+One+Five"
85
93
 
86
94
  # for wql & permissions
87
- %w{ A+C A+D A+E C+A D+A F+A A+B+C }.each do |name| Card.create!(:name=>name) end
88
- Card.create! :type_code=>'cardtype', :name=>"Cardtype A", :codename=>"cardtype_a"
89
- Card.create! :type_code=>'cardtype', :name=>"Cardtype B", :codename=>"cardtype_b"
90
- Card.create! :type_code=>'cardtype', :name=>"Cardtype C", :codename=>"cardtype_c"
91
- Card.create! :type_code=>'cardtype', :name=>"Cardtype D", :codename=>"cardtype_d"
92
- Card.create! :type_code=>'cardtype', :name=>"Cardtype E", :codename=>"cardtype_e"
93
- Card.create! :type_code=>'cardtype', :name=>"Cardtype F", :codename=>"cardtype_f"
94
-
95
- Card.create! :name=>'basicname', :content=>'basiccontent'
96
- Card.create! :type_code=>'cardtype_a', :name=>"type-a-card", :content=>"type_a_content"
97
- Card.create! :type_code=>'cardtype_b', :name=>"type-b-card", :content=>"type_b_content"
98
- Card.create! :type_code=>'cardtype_c', :name=>"type-c-card", :content=>"type_c_content"
99
- Card.create! :type_code=>'cardtype_d', :name=>"type-d-card", :content=>"type_d_content"
100
- Card.create! :type_code=>'cardtype_e', :name=>"type-e-card", :content=>"type_e_content"
101
- Card.create! :type_code=>'cardtype_f', :name=>"type-f-card", :content=>"type_f_content"
95
+ %w{ A+C A+D A+E C+A D+A F+A A+B+C }.each do |name| Card.create!(name: name) end
96
+ Card.create! type_code: 'cardtype', name: "Cardtype A", codename: 'cardtype_a'
97
+ Card.create! type_code: 'cardtype', name: "Cardtype B", codename: 'cardtype_b'
98
+ Card.create! type_code: 'cardtype', name: "Cardtype C", codename: 'cardtype_c'
99
+ Card.create! type_code: 'cardtype', name: "Cardtype D", codename: 'cardtype_d'
100
+ Card.create! type_code: 'cardtype', name: "Cardtype E", codename: 'cardtype_e'
101
+ Card.create! type_code: 'cardtype', name: "Cardtype F", codename: 'cardtype_f'
102
+
103
+ Card.create! name: 'basicname', content: 'basiccontent'
104
+ Card.create! type_code: 'cardtype_a', name: "type-a-card", content: 'type_a_content'
105
+ Card.create! type_code: 'cardtype_b', name: "type-b-card", content: 'type_b_content'
106
+ Card.create! type_code: 'cardtype_c', name: "type-c-card", content: 'type_c_content'
107
+ Card.create! type_code: 'cardtype_d', name: "type-d-card", content: 'type_d_content'
108
+ Card.create! type_code: 'cardtype_e', name: "type-e-card", content: 'type_e_content'
109
+ Card.create! type_code: 'cardtype_f', name: "type-f-card", content: 'type_f_content'
102
110
 
103
111
  #warn "current user #{User.session_user.inspect}. always ok? #{Card::Auth.always_ok?}"
104
- c = Card.create! :name=>'revtest', :content=>'first'
105
- c.update_attributes! :content=>'second'
106
- c.update_attributes! :content=>'third'
107
- #Card.create! :type_code=>'cardtype', :name=>'*priority'
112
+ c = Card.create! name: 'revtest', content: 'first'
113
+ c.update_attributes! content: 'second'
114
+ c.update_attributes! content: 'third'
115
+ #Card.create! type_code: 'cardtype', name: '*priority'
108
116
 
109
117
  # for template stuff
110
- Card.create! :type_id=>Card::CardtypeID, :name=> "UserForm"
111
- Card.create! :name=>"UserForm+*type+*structure", :content=>"{{+name}} {{+age}} {{+description}}"
118
+ Card.create! type_id: Card::CardtypeID, name: 'UserForm'
119
+ Card.create! name: "UserForm+*type+*structure", content: "{{+name}} {{+age}} {{+description}}"
112
120
 
113
121
  Card::Auth.current_id = Card['joe_user'].id
114
- Card.create!( :name=>"JoeLater", :content=>"test")
115
- Card.create!( :name=>"JoeNow", :content=>"test")
122
+ Card.create!( name: 'JoeLater', content: 'test')
123
+ Card.create!( name: 'JoeNow', content: 'test')
116
124
 
117
125
  Card::Auth.current_id = Card::WagnBotID
118
- Card.create!(:name=>"AdminNow", :content=>"test")
126
+ Card.create!(name: 'AdminNow', content: 'test')
127
+
128
+ Card.create name: 'Cardtype B+*type+*create', type: 'Pointer', content: '[[r1]]'
119
129
 
120
- Card.create :name=>'Cardtype B+*type+*create', :type=>'Pointer', :content=>'[[r1]]'
130
+ Card.create! type: 'Cardtype', name: 'Book'
131
+ Card.create! name: "Book+*type+*structure", content: "by {{+author}}, design by {{+illustrator}}"
132
+ Card.create! name: 'Iliad', type: 'Book'
121
133
 
122
- Card.create! :type=>"Cardtype", :name=>"Book"
123
- Card.create! :name=>"Book+*type+*structure", :content=>"by {{+author}}, design by {{+illustrator}}"
124
- Card.create! :name => "Iliad", :type=>"Book"
134
+ Card.create! type: 'Cardtype', name: 'Author'
135
+ Card.create! type: 'Author', name: 'Darles Chickens'
136
+ Card.create! type: 'Author', name: 'Stam Broker'
137
+ Card.create! name: 'Parry Hotter', type: 'Book'
138
+ Card.create! name: '50 grades of shy' , type: 'Book'
125
139
 
126
140
 
127
141
  ### -------- Notification data ------------
128
142
  Timecop.freeze(Cardio.future_stamp - 1.day) do
129
143
  # fwiw Timecop is apparently limited by ruby Time object, which goes only to 2037 and back to 1900 or so.
130
144
  # whereas DateTime can represent all dates.
131
-
132
-
145
+
146
+
133
147
  followers = {
134
148
  'John' => ['John Following', 'All Eyes On Me'],
135
- 'Sara' => ['Sara Following', 'All Eyes On Me', 'Optic+*type', 'Google Glass'],
149
+ 'Sara' => ['Sara Following', 'All Eyes On Me', 'Optic+*type', 'Google Glass'],
136
150
  'Big Brother' => ['All Eyes on Me', 'Look at me+*self', 'Optic+*type', 'lens+*right', 'Optic+tint+*type plus right', ['*all','*created'], ['*all','*edited']],
137
151
  'Optic fan' => ['Optic+*type'],
138
152
  'Sunglasses fan' => ['Sunglasses'],
139
153
  'Narcissist' => [['*all','*created'], ['*all','*edited']]
140
154
  }
141
-
155
+
142
156
  followers.each do |name, follow|
143
- user = Card.create! :name=>name, :type_code=>'user', :subcards=>account_args('+*email'=>"#{name.parameterize}@user.com", '+*password'=>"#{name.parameterize}_pass")
157
+ user = Card.create! name: name, type_code: 'user', subcards: account_args('+*email'=>"#{name.parameterize}@user.com", '+*password'=>"#{name.parameterize}_pass")
144
158
  end
145
-
146
- Card.create! :name => "All Eyes On Me"
147
- Card.create! :name => "No One Sees Me"
148
- Card.create! :name => "Look At Me"
149
- Card.create! :name => "Optic", :type => "Cardtype"
150
- Card.create! :name => "Sara Following"
151
- Card.create! :name => "John Following", :content => "{{+her}}"
152
- Card.create! :name => "John Following+her"
153
- magnifier = Card.create! :name => "Magnifier+lens"
159
+
160
+ Card.create! name: "All Eyes On Me"
161
+ Card.create! name: "No One Sees Me"
162
+ Card.create! name: "Look At Me"
163
+ Card.create! name: 'Optic', type: 'Cardtype'
164
+ Card.create! name: "Sara Following"
165
+ Card.create! name: "John Following", content: "{{+her}}"
166
+ Card.create! name: "John Following+her"
167
+ magnifier = Card.create! name: "Magnifier+lens"
154
168
 
155
169
  Card::Auth.current_id = Card['Narcissist'].id
156
- magnifier.update_attributes! :content=>"zoom in"
157
- Card.create! :name => "Sunglasses", :type=>"Optic", :content=>"{{+tint}}{{+lens}}"
158
-
170
+ magnifier.update_attributes! content: "zoom in"
171
+ Card.create! name: 'Sunglasses', type: 'Optic', content: "{{+tint}}{{+lens}}"
172
+
159
173
  Card::Auth.current_id = Card['Optic fan'].id
160
- Card.create! :name => "Google glass", :type=>"Optic", :content=>"{{+price}}"
161
-
174
+ Card.create! name: "Google glass", type: 'Optic', content: "{{+price}}"
175
+
162
176
  Card::Auth.current_id = Card::WagnBotID
163
- Card.create! :name=>'Google glass+*self+*follow_fields', :content=>''
164
- Card.create! :name=>'Sunglasses+*self+*follow_fields', :content=>"[[#{Card[:includes].name}]]\n[[_self+price]]\n[[_self+producer]]"
165
- Card.create! :name => "Sunglasses+tint"
166
- Card.create! :name => "Sunglasses+price"
177
+ Card.create! name: 'Google glass+*self+*follow_fields', content: ''
178
+ Card.create! name: 'Sunglasses+*self+*follow_fields', content: "[[#{Card[:includes].name}]]\n[[_self+price]]\n[[_self+producer]]"
179
+ Card.create! name: "Sunglasses+tint"
180
+ Card.create! name: "Sunglasses+price"
167
181
 
168
182
  followers.each do |name, follow|
169
183
  user = Card[name]
170
184
  follow.each do |f|
171
185
  user.follow *f
172
186
  end
173
- end
187
+ end
174
188
  end
175
189
 
176
190
 
177
191
  ## --------- create templated permissions -------------
178
- ctt = Card.create! :name=> 'Cardtype E+*type+*default'
192
+ ctt = Card.create! name: 'Cardtype E+*type+*default'
179
193
 
180
194
 
181
195
  ## --------- Fruit: creatable by anon but not readable ---
182
- f = Card.create! :type=>"Cardtype", :name=>"Fruit"
183
- Card.create! :name=>'Fruit+*type+*create', :type=>'Pointer', :content=>'[[Anyone]]'
184
- Card.create! :name=>'Fruit+*type+*read', :type=>'Pointer', :content=>'[[Administrator]]'
196
+ f = Card.create! type: 'Cardtype', name: 'Fruit'
197
+ Card.create! name: 'Fruit+*type+*create', type: 'Pointer', content: '[[Anyone]]'
198
+ Card.create! name: 'Fruit+*type+*read', type: 'Pointer', content: '[[Administrator]]'
185
199
 
186
200
  # codenames for card_accessor tests
187
- Card.create! :name=>'*write', :codename=>:write
201
+ Card.create! name: '*write', codename: :write
188
202
 
189
203
  # -------- For toc testing: ------------
190
204
 
191
- Card.create! :name=>"OnneHeading", :content => "<h1>This is one heading</h1>\r\n<p>and some text</p>"
192
- Card.create! :name=>'TwwoHeading', :content => "<h1>One Heading</h1>\r\n<p>and some text</p>\r\n<h2>And a Subheading</h2>\r\n<p>and more text</p>"
193
- Card.create! :name=>'ThreeHeading', :content =>"<h1>A Heading</h1>\r\n<p>and text</p>\r\n<h2>And Subhead</h2>\r\n<p>text</p>\r\n<h1>And another top Heading</h1>"
205
+ Card.create! name: 'OnneHeading', content: "<h1>This is one heading</h1>\r\n<p>and some text</p>"
206
+ Card.create! name: 'TwwoHeading', content: "<h1>One Heading</h1>\r\n<p>and some text</p>\r\n<h2>And a Subheading</h2>\r\n<p>and more text</p>"
207
+ Card.create! name: 'ThreeHeading', content: "<h1>A Heading</h1>\r\n<p>and text</p>\r\n<h2>And Subhead</h2>\r\n<p>text</p>\r\n<h1>And another top Heading</h1>"
194
208
 
195
209
  # -------- For history testing: -----------
196
- first = Card.create! :name=>"First", :content => 'egg'
197
- first.update_attributes! :content=> 'chicken'
198
- first.update_attributes! :content=> 'chick'
210
+ first = Card.create! name: 'First', content: 'egg'
211
+ first.update_attributes! content: 'chicken'
212
+ first.update_attributes! content: 'chick'
199
213
 
200
214
  end
201
215
  end
data/lib/card.rb CHANGED
@@ -18,8 +18,6 @@ class Card < ActiveRecord::Base
18
18
  attr_accessor *args
19
19
  end
20
20
 
21
-
22
-
23
21
  require_dependency 'card/active_record_ext'
24
22
  require_dependency 'card/codename'
25
23
  require_dependency 'card/query'
@@ -32,6 +30,7 @@ class Card < ActiveRecord::Base
32
30
  require_dependency 'card/act'
33
31
  require_dependency 'card/change'
34
32
  require_dependency 'card/reference'
33
+ require_dependency 'card/subcards'
35
34
  require_dependency 'card/view_cache'
36
35
 
37
36
  has_many :references_from, class_name: :Reference, foreign_key: :referee_id
@@ -43,7 +42,7 @@ class Card < ActiveRecord::Base
43
42
  cattr_accessor :set_patterns, :error_codes, :serializable_attributes, :set_specific_attributes
44
43
  @@set_patterns, @@error_codes = [], {}
45
44
 
46
- serializable_attr_accessor :action, :supercard, :current_act, :current_action,
45
+ serializable_attr_accessor :action, :supercard, :superleft, :current_act, :current_action,
47
46
  :comment, :comment_author, # obviated soon
48
47
  :update_referencers, # wrong mechanism for this
49
48
  :update_all_users, # if the above is wrong then this one too
@@ -0,0 +1,44 @@
1
+ module Card::ActiveRecordHelper
2
+ def create_card args
3
+ resolve_name_conflict args
4
+ Card.create! args
5
+ end
6
+
7
+ def create_card! args
8
+ create_card args.merge(rename_if_conflict: :other)
9
+ end
10
+
11
+ def update_card name, args
12
+ resolve_name_conflict args
13
+ Card[name].update_attributes! args
14
+ end
15
+
16
+ def update_card! args
17
+ update_card args.merge(resolve_name_conflict: :other)
18
+ end
19
+
20
+ def create_or_update name_or_args, args=nil
21
+ name = args ? name_or_args : name_or_args[:name]
22
+ args ||= name_or_args
23
+ if Card[name]
24
+ update_card name, args
25
+ else
26
+ create_card args.merge(:name=>name)
27
+ end
28
+ end
29
+
30
+ def create_or_update! name_or_args, args=nil
31
+ if args
32
+ args[:resolve_name_conflict] = :other
33
+ else
34
+ name_or_args[:resolve_name_conflict] = :other
35
+ end
36
+ create_or_update name_or_args, args
37
+ end
38
+
39
+ def resolve_name_conflict args
40
+ if (rename = args.delete :rename_if_conflict)
41
+ args[:name] = Card.uniquify_name args[:name], rename == :other
42
+ end
43
+ end
44
+ end
data/lib/card/auth.rb CHANGED
@@ -2,30 +2,30 @@
2
2
 
3
3
  class Card
4
4
  module Auth
5
- @@as_card = @@as_id = @@current_id = @@current = @@simulating_setup_need = nil
5
+ @@as_card = @@as_id = @@current_id = @@current = nil
6
+ @@simulating_setup_need = nil
6
7
 
7
8
  NON_CREATEABLE_TYPES = %w{ signup setting set } # NEED API
8
- NEED_SETUP_KEY = 'NEED_SETUP'
9
+ SETUP_COMPLETED_KEY = 'SETUP_COMPLETED'
9
10
 
10
- #after_save :reset_instance_cache
11
+ # after_save :reset_instance_cache
11
12
 
12
13
  class << self
13
-
14
14
  # Authenticates a user by their login name and unencrypted password.
15
15
  def authenticate email, password
16
- accounted = Auth[ email ]
17
- if accounted and account = accounted.account and account.active?
18
- if Card.config.no_authentication or password_authenticated?( account, password.strip )
19
- accounted.id
20
- end
16
+ accounted = Auth[email]
17
+ return unless accounted && (account = accounted.account) &&
18
+ account.active?
19
+ if Card.config.no_authentication ||
20
+ password_authenticated?(account, password.strip)
21
+ accounted.id
21
22
  end
22
23
  end
23
24
 
24
25
  def password_authenticated? account, password
25
- account.password == encrypt( password, account.salt )
26
+ account.password == encrypt(password, account.salt)
26
27
  end
27
28
 
28
-
29
29
  # Encrypts some data with the salt.
30
30
  def encrypt password, salt
31
31
  Digest::SHA1.hexdigest "#{salt}--#{password}--"
@@ -34,9 +34,11 @@ class Card
34
34
  # find accounted by email
35
35
  def [] email
36
36
  Auth.as_bot do
37
- Card.search( right_plus: [
38
- {id: Card::AccountID},
39
- {right_plus: [{id: Card::EmailID},{ content: email.strip.downcase }]}
37
+ Card.search(right_plus: [
38
+ { id: Card::AccountID },
39
+ { right_plus: [
40
+ { id: Card::EmailID }, { content: email.strip.downcase }
41
+ ] }
40
42
  ]).first
41
43
  end
42
44
  end
@@ -53,7 +55,7 @@ class Card
53
55
  def set_current_from_session
54
56
  self.current_id =
55
57
  if session
56
- if card_id=session[:user] and Card.exists? card_id
58
+ if (card_id = session[:user]) && Card.exists?(card_id)
57
59
  card_id
58
60
  else
59
61
  session[:user] = nil
@@ -81,28 +83,23 @@ class Card
81
83
 
82
84
  def get_user_id user
83
85
  case user
84
- when NilClass; nil
85
- when Card ; user.id
86
- when Integer ; user
87
- else
88
- user = user.to_s
89
- Card::Codename[user] or (cd=Card[user] and cd.id)
86
+ when NilClass then nil
87
+ when Card then user.id
88
+ else Card.fetch_id(user)
90
89
  end
91
90
  end
92
91
 
93
92
  def as given_user
94
93
  tmp_id, tmp_card = @@as_id, @@as_card
95
- @@as_id, @@as_card = get_user_id( given_user ), nil # we could go ahead and set as_card if given a card...
94
+ # we could go ahead and set as_card if given a card...
95
+ @@as_id, @@as_card = get_user_id(given_user), nil
96
96
 
97
97
  @@current_id = @@as_id if @@current_id.nil?
98
98
 
99
- if block_given?
100
- value = yield
101
- @@as_id, @@as_card = tmp_id, tmp_card
102
- return value
103
- else
104
- #fail "BLOCK REQUIRED with Card#as"
105
- end
99
+ return unless block_given?
100
+ value = yield
101
+ @@as_id, @@as_card = tmp_id, tmp_card
102
+ value
106
103
  end
107
104
 
108
105
  def as_bot &block
@@ -118,7 +115,7 @@ class Card
118
115
  end
119
116
 
120
117
  def as_card
121
- if @@as_card and @@as_card.id == as_id
118
+ if @@as_card && @@as_card.id == as_id
122
119
  @@as_card
123
120
  else
124
121
  @@as_card = Card[as_id]
@@ -130,43 +127,51 @@ class Card
130
127
  end
131
128
 
132
129
  def needs_setup?
133
- test = Card.cache.read NEED_SETUP_KEY
134
- !test.nil? ? test : begin
135
- @@simulating_setup_need or Card.cache.write( NEED_SETUP_KEY, (account_count < 3) ) # 3, because
136
- end
130
+ @@simulating_setup_need || (
131
+ !Card.cache.read(SETUP_COMPLETED_KEY) &&
132
+ !Card.cache.write(SETUP_COMPLETED_KEY, account_count > 2)
133
+ )
134
+ # every deck starts with WagnBot and Anonymous account
137
135
  end
138
136
 
139
137
  def simulate_setup_need! mode=true
140
138
  @@simulating_setup_need = mode
141
- Card.cache.write NEED_SETUP_KEY, nil
142
139
  end
143
140
 
141
+ def instant_account_activation
142
+ simulate_setup_need!
143
+ yield
144
+ ensure
145
+ simulate_setup_need! false
146
+ end
144
147
 
145
148
  def always_ok?
146
- #warn Rails.logger.warn("aok? #{as_id}, #{as_id&&Card[as_id].id}")
147
- return false unless usr_id = as_id
148
- return true if usr_id == Card::WagnBotID #cannot disable
149
+ # warn Rails.logger.warn("aok? #{as_id}, #{as_id&&Card[as_id].id}")
150
+ return false unless (usr_id = as_id)
151
+ return true if usr_id == Card::WagnBotID # cannot disable
149
152
 
150
153
  always = Card.cache.read('ALWAYS') || {}
151
- #warn(Rails.logger.warn "Auth.always_ok? #{usr_id}")
154
+ # warn(Rails.logger.warn "Auth.always_ok? #{usr_id}")
152
155
  if always[usr_id].nil?
153
156
  always = always.dup if always.frozen?
154
- always[usr_id] = !!Card[usr_id].all_roles.detect{|r|r==Card::AdministratorID}
155
- #warn(Rails.logger.warn "update always hash #{always[usr_id]}, #{always.inspect}")
157
+ always[usr_id] =
158
+ !!Card[usr_id].all_roles.find { |r| r == Card::AdministratorID }
159
+ # warn(Rails.logger.warn "update always hash #{always[usr_id]},
160
+ # #{always.inspect}")
156
161
  Card.cache.write 'ALWAYS', always
157
162
  end
158
- #warn Rails.logger.warn("aok? #{usr_id}, #{always[usr_id]}")
163
+ # warn Rails.logger.warn("aok? #{usr_id}, #{always[usr_id]}")
159
164
  always[usr_id]
160
165
  end
161
166
  # PERMISSIONS
162
167
 
163
-
164
168
  def createable_types
165
169
  type_names = Auth.as_bot do
166
- Card.search type: Card::CardtypeID, return: :name, not: { codename: ['in'] + NON_CREATEABLE_TYPES }
170
+ Card.search type: Card::CardtypeID, return: :name,
171
+ not: { codename: ['in'] + NON_CREATEABLE_TYPES }
167
172
  end
168
- type_names.reject do |name|
169
- !Card.new( type: name ).ok? :create
173
+ type_names.select do |name|
174
+ Card.new(type: name).ok? :create
170
175
  end.sort
171
176
  end
172
177
 
@@ -175,7 +180,6 @@ class Card
175
180
  def account_count
176
181
  as_bot { Card.count_by_wql right: Card[:account].name }
177
182
  end
178
-
179
183
  end
180
184
  end
181
185
  end