card 1.16.10 → 1.16.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -117,7 +117,6 @@ class Card
117
117
  host_class.event(
118
118
  "reset_machine_output_#{ event_suffix }".to_sym,
119
119
  after: :expire_related, on: :save
120
- #after: :store_subcards, on: :save
121
120
  ) do
122
121
  reset_machine_output!
123
122
  end
@@ -2,31 +2,35 @@ format :html do
2
2
  ###---( TOP_LEVEL (used by menu) NEW / EDIT VIEWS )
3
3
 
4
4
  view :new, perms: :create, tags: :unknown_ok do |args|
5
- frame_and_form :create, args, 'main-success'=>'REDIRECT' do
5
+ frame_and_form :create, args, 'main-success' => 'REDIRECT' do
6
6
  [
7
- _optional_render( :name_formgroup, args ),
8
- _optional_render( :type_formgroup, args ),
9
- _optional_render( :content_formgroup, args ),
10
- _optional_render( :button_formgroup, args )
7
+ _optional_render(:name_formgroup, args),
8
+ _optional_render(:type_formgroup, args),
9
+ _optional_render(:content_formgroup, args),
10
+ _optional_render(:button_formgroup, args)
11
11
  ]
12
12
  end
13
13
  end
14
14
 
15
-
16
15
  def default_new_args args
17
16
  hidden = args[:hidden] ||= {}
18
17
  hidden[:success] ||= card.rule(:thanks) || '_self'
19
- hidden[:card ] ||={}
18
+ hidden[:card] ||= {}
20
19
 
21
20
  args[:optional_help] ||= :show
22
21
 
23
22
  # name field / title
24
- if !params[:name_prompt] and !card.cardname.blank?
23
+ if !params[:name_prompt] && !card.cardname.blank?
25
24
  # name is ready and will show up in title
26
25
  hidden[:card][:name] ||= card.name
27
26
  else
28
27
  # name is not ready; need generic title
29
- args[:title] ||= "New #{ card.type_name unless card.type_id == Card.default_type_id }" #fixme - overrides nest args
28
+ args[:title] ||= if card.type_id == Card.default_type_id
29
+ 'New'
30
+ else
31
+ "New #{card.type_name}"
32
+ end
33
+ # FIXME: - overrides nest args
30
34
  unless card.rule_card :autoname
31
35
  # prompt for name
32
36
  hidden[:name_prompt] = true unless hidden.has_key? :name_prompt
@@ -35,39 +39,43 @@ format :html do
35
39
  end
36
40
  args[:optional_name_formgroup] ||= :hide
37
41
 
38
-
39
42
  # type field
40
- if ( !params[:type] and !args[:type] and
41
- ( main? || card.simple? || card.is_template? ) and
42
- Card.new( type_id: card.type_id ).ok? :create #otherwise current type won't be on menu
43
- )
43
+ if !params[:type] &&
44
+ !args[:type] &&
45
+ (main? || card.simple? || card.is_template?) &&
46
+ Card.new(type_id: card.type_id).ok?(:create)
47
+ # otherwise current type won't be on menu
48
+
44
49
  args[:optional_type_formgroup] = :show
45
50
  else
46
51
  hidden[:card][:type_id] ||= card.type_id
47
52
  args[:optional_type_formgroup] = :hide
48
53
  end
49
54
 
50
-
51
- cancel = if main?
52
- { class: 'redirecter', href: Card.path_setting('/*previous') }
53
- else
54
- { class: 'slotter', href: path( view: :missing ) }
55
- end
55
+ cancel =
56
+ if main?
57
+ { class: 'redirecter', href: Card.path_setting('/*previous') }
58
+ else
59
+ { class: 'slotter', href: path(view: :missing) }
60
+ end
56
61
 
57
62
  args[:buttons] ||= %{
58
- #{ button_tag 'Submit', class: 'create-submit-button', disable_with: 'Submitting', situation: 'primary' }
59
- #{ button_tag 'Cancel', type: 'button', class: "create-cancel-button #{cancel[:class]}", href: cancel[:href] }
63
+ #{button_tag 'Submit',
64
+ class: 'create-submit-button',
65
+ disable_with: 'Submitting',
66
+ situation: 'primary'}
67
+ #{button_tag 'Cancel',
68
+ type: 'button',
69
+ class: "create-cancel-button #{cancel[:class]}",
70
+ href: cancel[:href]}
60
71
  }
61
-
62
72
  end
63
73
 
64
-
65
-
66
74
  view :edit, perms: :update, tags: :unknown_ok do |args|
67
75
  frame_and_form :update, args.merge(optional_toolbar: :show) do
68
76
  [
69
- _optional_render( :content_formgroup, args ),
70
- _optional_render( :button_formgroup, args )
77
+ _optional_render(:content_formgroup, args),
78
+ _optional_render(:button_formgroup, args)
71
79
  ]
72
80
  end
73
81
  end
@@ -98,13 +106,13 @@ format :html do
98
106
 
99
107
  view :confirm_rename do |args|
100
108
  referers = args[:referers]
101
- dependents = card.dependents
109
+ descendants = card.descendants
102
110
  alert 'warning' do
103
111
  %{
104
112
  <h5>Are you sure you want to rename <em>#{card.name}</em>?</h5>
105
- #{ %{ <h6>This change will...</h6> } if referers.any? || dependents.any? }
113
+ #{ %{ <h6>This change will...</h6> } if referers.any? || descendants.any? }
106
114
  <ul>
107
- #{ %{<li>automatically alter #{ dependents.size } related name(s). </li>} if dependents.any? }
115
+ #{ %{<li>automatically alter #{ descendants.size } related name(s). </li>} if descendants.any? }
108
116
  #{ %{<li>affect at least #{referers.size} reference(s) to "#{card.name}".</li>} if referers.any? }
109
117
  </ul>
110
118
  #{ %{<p>You may choose to <em>update or ignore</em> the references.</p>} if referers.any? }
@@ -7,47 +7,66 @@ card_accessor :salt
7
7
  card_accessor :status
8
8
  card_accessor :token
9
9
 
10
- def active? ; status=='active' end
11
- def blocked? ; status=='blocked' end
12
- def built_in? ; status=='system' end
13
- def pending? ; status=='pending' end
14
-
10
+ def active?; status == 'active' end
11
+ def blocked?; status == 'blocked' end
12
+ def built_in?; status == 'system' end
13
+ def pending?; status == 'pending' end
15
14
 
16
15
  def authenticate_by_token val
17
- tcard = token_card or return :token_not_found
18
- token == val or return :incorrect_token
19
- tcard.updated_at > Card.config.token_expiry.ago or return :token_expired # > means "after"
20
- left and left.accountable? or return :illegal_account #(overkill?)
21
- Auth.as_bot { tcard.delete! }
22
- left.id
16
+ tcard = token_card
17
+ error = token_error(tcard, val)
18
+ if error == :none
19
+ Auth.as_bot { tcard.delete! }
20
+ left.id
21
+ else
22
+ error
23
+ end
23
24
  end
24
25
 
26
+ def token_error tcard, val
27
+ case
28
+ when !tcard
29
+ :token_not_found
30
+ when token != val
31
+ :incorrect_token
32
+ when tcard.updated_at <= Card.config.token_expiry.ago
33
+ # < means "before"
34
+ :token_expired
35
+ when !left || !left.accountable?
36
+ :illegal_account
37
+ else
38
+ :none
39
+ end
40
+ end
25
41
 
26
42
  format do
27
- view :verify_url do |args|
43
+ view :verify_url do
28
44
  card_url "update/#{card.cardname.left_name.url_key}?token=#{card.token}"
29
45
  end
30
46
 
31
- view :verify_days do |args|
32
- ( Card.config.token_expiry / 1.day ).to_s
47
+ view :verify_days do
48
+ (Card.config.token_expiry / 1.day).to_s
33
49
  end
34
50
 
35
- view :reset_password_url do |args|
36
- card_url "update/#{card.cardname.url_key}?reset_token=#{card.token_card.refresh(true).content}"
51
+ view :reset_password_url do
52
+ card_url "update/#{card.cardname.url_key}?" \
53
+ "reset_token=#{card.token_card.refresh(true).content}"
37
54
  end
38
55
 
39
- view :reset_password_days do |args|
40
- ( Card.config.token_expiry / 1.day ).to_s
56
+ view :reset_password_days do
57
+ (Card.config.token_expiry / 1.day).to_s
41
58
  end
42
59
  end
43
60
 
44
-
45
61
  format :html do
46
-
47
62
  view :raw do |args|
48
63
  content = []
49
- content << "{{+#{Card[:email ].name}|titled;title:email}}" unless args[:no_email]
50
- content << "{{+#{Card[:password].name}|titled;title:password}}" unless args[:no_password]
64
+ unless args[:no_email]
65
+ content << "{{+#{Card[:email].name}|titled;title:email}}"
66
+ end
67
+ unless args[:no_password]
68
+ content << "{{+#{Card[:password].name}|titled;title:password}}"
69
+ end
51
70
  content * ' '
52
71
  end
53
72
 
@@ -83,47 +83,31 @@ describe Card, "created without permission" do
83
83
  end
84
84
  end
85
85
 
86
-
87
- describe Card, "Normal card with dependents" do
86
+ describe Card, 'Normal card with descendants' do
88
87
  before do
89
88
  @a = Card['A']
90
89
  end
91
- it "should confirm that it has dependents" do
92
- expect(@a.dependents.length).to be > 0
90
+
91
+ it 'should confirm that it has descendants' do
92
+ expect(@a.descendants.length).to be > 0
93
93
  end
94
- it "should successfully have its type changed" do
94
+
95
+ it 'should successfully have its type changed' do
95
96
  Card::Auth.as_bot do
96
- @a.type_id = Card::PhraseID;
97
+ @a.type_id = Card::PhraseID
97
98
  @a.save!
98
99
  expect(Card['A'].type_code).to eq(:phrase)
99
100
  end
100
101
  end
101
- it "should still have its dependents after changing type" do
102
+ it 'should still have its descendants after changing type' do
102
103
  Card::Auth.as_bot do
103
104
  assert type_id = Card.fetch_id('cardtype_e')
104
- @a.type_id = type_id; @a.save!
105
- expect(Card['A'].dependents.length).to be > 0
106
- end
107
- end
108
- end
109
-
110
-
111
- =begin No extension any more, is there a modified version of this we need?
112
- describe Card, "Recreated Card" do
113
- before do
114
- Card::Auth.as_bot do
115
- @ct = Card.create! name: 'Species', type: 'Cardtype'
116
- @ct.delete!
117
- @ct = Card.create! name: 'Species', type: 'Cardtype'
105
+ @a.type_id = type_id
106
+ @a.save!
107
+ expect(Card['A'].descendants.length).to be > 0
118
108
  end
119
109
  end
120
-
121
- it "should have a cardtype extension" do
122
- @ct.extension.should_not be_nil
123
- end
124
-
125
110
  end
126
- =end
127
111
 
128
112
  describe Card, "New Cardtype" do
129
113
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.10
4
+ version: 1.16.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-11-04 00:00:00.000000000 Z
14
+ date: 2015-11-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: smartname
@@ -262,6 +262,7 @@ files:
262
262
  - db/migrate/20141208132159_remove_present_from_reference_table.rb
263
263
  - db/migrate/20141216053032_better_index_names.rb
264
264
  - db/migrate/20150724210803_add_comment_to_actions.rb
265
+ - db/migrate/20151105225559_more_space_for_db_content.rb
265
266
  - db/migrate_core_cards/20120611203506_rails_inflection_updates.rb
266
267
  - db/migrate_core_cards/20130411191151_renaming_for_menu.rb
267
268
  - db/migrate_core_cards/20130411211600_delete_old_related_tab_cards.rb