card 1.19.4 → 1.19.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/01_core_extensions/module.rb +4 -0
  4. data/lib/card.rb +2 -2
  5. data/lib/card/content/diff/lcs.rb +1 -1
  6. data/lib/card/model/save_helper.rb +100 -25
  7. data/lib/card/name.rb +8 -0
  8. data/lib/card/set/event.rb +22 -42
  9. data/lib/card/set/format.rb +1 -0
  10. data/lib/card/set/inheritance.rb +30 -5
  11. data/lib/card/set/loader.rb +24 -3
  12. data/mod/account/set/self/account_links.rb +45 -21
  13. data/mod/account/set/self/signin.rb +5 -9
  14. data/mod/account/set/type/signup.rb +22 -15
  15. data/mod/account/spec/set/all/account_spec.rb +3 -1
  16. data/mod/admin/set/self/admin.rb +4 -4
  17. data/mod/admin/set/self/admin_info.rb +3 -9
  18. data/mod/admin/set/self/trash.rb +21 -14
  19. data/mod/basic_formats/set/all/base.rb +6 -7
  20. data/mod/bootstrap/set/all/bootstrap/helper.rb +4 -5
  21. data/mod/bootstrap/set/all/bootstrap/tabs.rb +3 -4
  22. data/mod/bootstrap/spec/set/all/bootstrap/form_spec.rb +2 -0
  23. data/mod/carrierwave/set/abstract/attachment/storage_type.rb +3 -0
  24. data/mod/core/chunk/link.rb +3 -3
  25. data/mod/core/chunk/uri.rb +2 -2
  26. data/mod/core/set/all/actify.rb +11 -10
  27. data/mod/core/set/all/permissions.rb +6 -7
  28. data/mod/core/spec/set/all/actify_spec.rb +2 -0
  29. data/mod/developer/set/right/debug.rb +1 -1
  30. data/mod/email/set/all/follow.rb +2 -1
  31. data/mod/email/set/right/follow.rb +19 -22
  32. data/mod/email/set/type_plus_right/user/follow.rb +1 -1
  33. data/mod/email/spec/set/all/notify_spec.rb +17 -14
  34. data/mod/history/set/all/history.rb +35 -38
  35. data/mod/machines/spec/set/abstract/machine_spec.rb +2 -0
  36. data/mod/settings/set/abstract/permission.rb +6 -9
  37. data/mod/settings/set/type/setting.rb +4 -3
  38. data/mod/solid_cache/set/abstract/solid_cache.rb +41 -20
  39. data/mod/solid_cache/spec/set/abstract/solid_cache_spec.rb +3 -1
  40. data/mod/standard/set/all/error.rb +14 -19
  41. data/mod/standard/set/all/links.rb +149 -120
  42. data/mod/standard/set/all/rich_html/content.rb +9 -19
  43. data/mod/standard/set/all/rich_html/header.rb +3 -5
  44. data/mod/standard/set/all/rich_html/menu.rb +25 -23
  45. data/mod/standard/set/all/rich_html/modal.rb +11 -9
  46. data/mod/standard/set/all/rich_html/toolbar.rb +85 -84
  47. data/mod/standard/set/rstar/rules_editor.rb +96 -79
  48. data/mod/standard/set/type/cardtype.rb +2 -1
  49. data/mod/standard/set/type/search_type.rb +2 -1
  50. data/mod/standard/set/type/set.rb +15 -19
  51. data/mod/standard/set/type/uri.rb +2 -2
  52. data/mod/standard/spec/set/all/links_spec.rb +8 -5
  53. data/spec/config/initializers/core_extensions_spec.rb +2 -0
  54. data/spec/lib/card/format/nest_spec.rb +2 -0
  55. data/spec/lib/card/migration/import_spec.rb +2 -0
  56. data/spec/lib/card/set/trait_spec.rb +2 -0
  57. data/spec/lib/card/stage_director_spec.rb +2 -0
  58. data/spec/lib/card/view_cache_spec.rb +2 -0
  59. data/spec/spec_helper.rb +11 -139
  60. data/spec/support/card_spec_helper.rb +61 -0
  61. data/spec/support/card_spec_loader.rb +83 -0
  62. data/spec/support/helper/card_helper.rb +87 -0
  63. data/spec/support/helper/event_helper.rb +80 -0
  64. data/spec/support/helper/render_helper.rb +35 -0
  65. data/spec/support/helper/save_helper.rb +26 -0
  66. data/{config → spec/support}/simplecov_helper.rb +1 -1
  67. metadata +16 -5
  68. data/spec/card_spec_helper.rb +0 -137
@@ -30,15 +30,11 @@ format :html do
30
30
  # i18n-tasks-use t(:reset_password,
31
31
  # scope: 'mod.standard.set.self.signin')
32
32
  args[:buttons] = button_tag sign_in, situation: "primary"
33
- if Card.new(type_id: Card::SignupID).ok? :create
34
- args[:buttons] += link_to(or_sign_up, card_path("account/signup"))
35
- end
36
- args[:buttons] += raw(
37
- "<div style='float:right'>" \
38
- "#{view_link reset_password, :edit,
39
- path_opts: { slot: { hide: :toolbar } }}" \
40
- "</div>"
41
- ) # FIXME: hardcoded styling
33
+ subformat(Card[:account_links]).render :sign_up, title: or_sign_up
34
+ reset_link = link_to_view :edit, reset_password,
35
+ path: { slot: { hide: :toolbar } }
36
+ args[:buttons] += raw("<div style='float:right'>#{reset_link}</div>")
37
+ # FIXME: hardcoded styling
42
38
  args
43
39
  end
44
40
 
@@ -77,21 +77,28 @@ format :html do
77
77
  end
78
78
 
79
79
  def verification_links account, token_action
80
- links = []
81
- if account.confirm_ok?
82
- links << link_to(
83
- "#{token_action} verification email",
84
- card_path("update/~#{card.id}?approve_with_token=true")
85
- )
86
- links << link_to(
87
- "Approve without verification",
88
- card_path("update/~#{card.id}?approve_without_token=true")
89
- )
90
- end
91
- if card.ok? :delete
92
- links << link_to("Deny and delete", card_path("delete/~#{card.id}"))
93
- end
94
- links
80
+ [
81
+ approve_with_token_link(account, token_action),
82
+ approve_without_token_link(account),
83
+ deny_link
84
+ ].compact
85
+ end
86
+
87
+ def approve_with_token_link account, token_action
88
+ return unless account.confirm_ok?
89
+ link_to_card card, "#{token_action} verification email",
90
+ path: { action: :update, approve_with_token: true }
91
+ end
92
+
93
+ def approve_without_token_link account
94
+ return unless account.confirm_ok?
95
+ link_to_card card, "Approve without verification",
96
+ path: { action: :update, approve_without_token: true }
97
+ end
98
+
99
+ def deny_link
100
+ return unless card.ok? :delete
101
+ link_to_card card, "Deny and delete", path: { action: :delete }
95
102
  end
96
103
  end
97
104
 
@@ -113,7 +113,9 @@ describe Card::Set::All::Account do
113
113
  it "should not allow a user to block or unblock himself" do
114
114
  expect do
115
115
  @card.account.status_card.update_attributes! content: "blocked"
116
- end.to raise_error
116
+ end.to raise_error(ActiveRecord::RecordInvalid,
117
+ "Validation failed: Permission denied You don't have "\
118
+ "permission to change the status of your own account")
117
119
  expect(@card.account.blocked?).to be_falsey
118
120
  end
119
121
  end
@@ -83,8 +83,8 @@ format :html do
83
83
  res = [(args[:title] || "")]
84
84
  res << "#{count(args[:count])}#{args[:unit]}"
85
85
  return res unless args[:task]
86
- path = card_path("update/:admin?task=#{args[:task]}")
87
- res << link_to(args[:link_text] || args[:task], path)
86
+ res << link_to_card(:admin, (args[:link_text] || args[:task]),
87
+ path: { action: :update, task: args[:task] })
88
88
  res
89
89
  end
90
90
 
@@ -102,8 +102,8 @@ format :html do
102
102
  end
103
103
 
104
104
  def delete_sessions_link months
105
- link_to months,
106
- card_path("update/:admin?task=delete_old_sessions&months=#{months}")
105
+ link_to_card :admin, months, path: { action: :update, months: months,
106
+ task: "delete_old_sessions" }
107
107
  end
108
108
  end
109
109
 
@@ -70,31 +70,25 @@ format :html do
70
70
 
71
71
  def howto_add_new_recaptcha_keys
72
72
  instructions(
73
- # 'How to add new recaptcha keys:'
74
73
  I18n.t(:howto_add_keys, scope: "mod.admin.set.self.admin_info"),
75
74
  [
76
- # "1. Register your domain at #{web_link 'http://google.com/recaptcha'}"
77
75
  I18n.t(:howto_register,
78
76
  scope: "mod.admin.set.self.admin_info",
79
- recaptcha_link: web_link("http://google.com/recaptcha")),
80
- # "2. Add your keys to #{card_link :recaptcha_settings}"
77
+ recaptcha_link: link_to_resource("http://google.com/recaptcha")),
81
78
  I18n.t(:howto_add,
82
79
  scope: "mod.admin.set.self.admin_info",
83
- recaptcha_settings: card_link(:recaptcha_settings))
80
+ recaptcha_settings: link_to_card(:recaptcha_settings))
84
81
  ]
85
82
  )
86
83
  end
87
84
 
88
85
  def howto_turn_captcha_off
89
86
  instructions(
90
- # 'How to turn captcha off:'
91
87
  I18n.t(:howto_turn_off, scope: "mod.admin.set.self.admin_info"),
92
88
  [
93
- # "1. Go to #{card_link :captcha}"
94
89
  I18n.t(:howto_go,
95
90
  scope: "mod.admin.set.self.admin_info",
96
- captcha_card: card_link(:captcha)),
97
- # '2. Update all *captcha rules to "no".'
91
+ captcha_card: link_to_card(:captcha)),
98
92
  I18n.t(:howto_update,
99
93
  scope: "mod.admin.set.self.admin_info")
100
94
  ]
@@ -30,27 +30,34 @@ format :html do
30
30
  end
31
31
 
32
32
  def empty_trash_link
33
- button =
34
- button_link "empty trash",
35
- { card: :admin, action: :update,
36
- task: :empty_trash, success: { id: "~#{card.id}" } },
33
+ content_tag(
34
+ :p,
35
+ button_link("empty trash",
37
36
  btn_type: :default,
38
- "data-confirm" => "Are you sure you want to delete all "\
39
- "cards in the trash"
40
- content_tag :p, button
37
+ path: { card: :admin, action: :update, task: :empty_trash,
38
+ success: { id: "~#{card.id}" } },
39
+ "data-confirm" => "Are you sure you want to delete "\
40
+ "all cards in the trash?")
41
+ )
41
42
  end
42
43
 
43
44
  def history_link trashed_card
44
- card_link trashed_card, path_opts: { view: :history, look_in_trash: true },
45
- text: "history"
45
+ link_to_card trashed_card, "history",
46
+ path: { view: :history, look_in_trash: true }
46
47
  end
47
48
 
48
49
  def restore_link trashed_card
49
50
  before_delete = trashed_card.actions[-2]
50
- link_path = path id: trashed_card.id, look_in_trash: true, action: :update,
51
- view: :open, restore: trashed_card.id,
52
- action_ids: [before_delete], success: { id: "~#{card.id}" }
53
- link_to "restore", link_path, method: :post, rel: "nofollow",
54
- remote: true, class: "slotter"
51
+ link_to "restore", method: :post,
52
+ rel: "nofollow",
53
+ remote: true,
54
+ class: "slotter",
55
+ path: { id: trashed_card.id,
56
+ view: :open,
57
+ look_in_trash: true,
58
+ action: :update,
59
+ restore: trashed_card.id,
60
+ action_ids: [before_delete],
61
+ success: { id: "~#{card.id}" } }
55
62
  end
56
63
  end
@@ -38,16 +38,15 @@ format do
38
38
  end
39
39
 
40
40
  view :url_link, closed: true, perms: :none do
41
- web_link card_url(_render_linkname)
41
+ link_to_resource card_url(_render_linkname)
42
42
  end
43
43
 
44
44
  view :link, closed: true, perms: :none do |args|
45
- card_link(
46
- card.name,
47
- text: showname(args[:title]),
48
- known: card.known?,
49
- path_opts: { type: args[:type] }
50
- )
45
+ title = showname args[:title]
46
+ known = card.known?
47
+ path_opts = {}
48
+ path_opts[:type] = args[:type] if !known && Card.known?(args[:type])
49
+ link_to_card card.name, title, known: known, path: path_opts
51
50
  end
52
51
 
53
52
  view(:codename, closed: true) { card.codename.to_s }
@@ -7,11 +7,10 @@ format :html do
7
7
  )
8
8
  end
9
9
 
10
- def button_link link_text, target, html_args={}
11
- html_args[:class] ||= ""
12
- btn_type = html_args[:btn_type] || "primary"
13
- html_args[:class] += " btn btn-#{btn_type}"
14
- smart_link link_text, target, html_args.merge(type: "button")
10
+ def button_link link_text, opts={}
11
+ btn_type = opts.delete(:btn_type) || "primary"
12
+ opts[:class] = [opts[:class], "btn btn-#{btn_type}"].compact.join " "
13
+ smart_link_to link_text, opts.merge(type: "button")
15
14
  end
16
15
 
17
16
  def dropdown_button name, opts={}
@@ -61,10 +61,9 @@ format :html do
61
61
  end
62
62
 
63
63
  def tab_button target, text, active=false, link_attr={}
64
- link = link_to(
65
- fancy_title(text),
66
- target,
67
- link_attr.merge("role" => "tab", "data-toggle" => "tab"))
64
+ link = link_to fancy_title(text), link_attr.merge(
65
+ path: target, role: "tab", "data-toggle" => "tab"
66
+ )
68
67
  li_args = { role: :presentation }
69
68
  li_args[:class] = "active" if active
70
69
  content_tag :li, link, li_args
@@ -1,3 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+
1
3
  describe Card::Set::All::Bootstrap::Form do
2
4
  describe "input" do
3
5
  it "has form-group css class" do
@@ -170,6 +170,9 @@ def ensure_bucket_config
170
170
  unless config.present?
171
171
  raise Card::Error, "couldn't find configuration for bucket #{bucket}"
172
172
  end
173
+ unless config[:credentials]
174
+ raise Card::Error, "couldn't find credentials for bucket #{bucket}"
175
+ end
173
176
  config
174
177
  end
175
178
 
@@ -59,10 +59,10 @@ module Card::Content::Chunk
59
59
 
60
60
  if @explicit_link
61
61
  @explicit_link = render_obj @explicit_link
62
- format.web_link @explicit_link, text: @link_text
62
+ format.link_to_resource @explicit_link, @link_text
63
63
  elsif @name
64
- format.card_link referee_name, text: @link_text,
65
- known: referee_card.send_if(:known?)
64
+ known = referee_card.send_if :known?
65
+ format.link_to_card referee_name, @link_text, known: known
66
66
  end
67
67
  end
68
68
 
@@ -80,8 +80,8 @@ module Card::Content::Chunk
80
80
  end
81
81
 
82
82
  def process_uri_chunk
83
- link_opts = { text: process_text }
84
- "#{format.web_link(@link_text, link_opts)}#{@trailing_punctuation}"
83
+ link = format.link_to_resource @link_text, process_text
84
+ "#{link}#{@trailing_punctuation}"
85
85
  end
86
86
  end
87
87
 
@@ -19,17 +19,12 @@ def abort status, msg="action canceled"
19
19
  raise Card::Error::Abort.new(status, msg)
20
20
  end
21
21
 
22
- def act opts={}
22
+ def act opts={}, &block
23
23
  if ActManager.act_card
24
- add_to_act opts
25
- main_act_block = false
24
+ add_to_act opts, &block
26
25
  else
27
- start_new_act opts
28
- main_act_block = true
26
+ start_new_act opts, &block
29
27
  end
30
- yield
31
- ensure
32
- ActManager.clear if main_act_block
33
28
  end
34
29
 
35
30
  def start_new_act opts
@@ -39,11 +34,16 @@ def start_new_act opts
39
34
  if opts && opts[:success]
40
35
  Env[:success] = Env::Success.new(cardname, Env.params[:success])
41
36
  end
37
+ run_callbacks :act do
38
+ yield
39
+ end
40
+ ensure
41
+ ActManager.clear
42
42
  end
43
43
 
44
44
  def add_to_act opts
45
- # if only_storage_phase is true the card is already part of the act
46
- return if ActManager.act_card == self || only_storage_phase
45
+ # if only_storage_phase is true then the card is already part of the act
46
+ return yield if ActManager.act_card == self || only_storage_phase
47
47
  director.reset_stage
48
48
  if opts && opts[:trash]
49
49
  @action = :delete
@@ -52,6 +52,7 @@ def add_to_act opts
52
52
  end
53
53
  director.update_card self
54
54
  self.only_storage_phase = true
55
+ yield
55
56
  end
56
57
 
57
58
  module ClassMethods
@@ -277,13 +277,12 @@ module Accounts
277
277
  # (without creating separate rules for each account holder) but is not yet.
278
278
 
279
279
  def permit action, verb=nil
280
- if action == :comment then @action_ok = false
281
- elsif action == :create then @superleft ? true : super(action, verb)
282
- # restricts account creation to subcard handling on permitted card
283
- # (unless explicitly permitted)
284
- elsif own_account? then true
285
- else
286
- super action, verb
280
+ case action
281
+ when :comment then @action_ok = false
282
+ when :create then @superleft ? true : super(action, verb)
283
+ # restricts account creation to subcard handling on permitted card
284
+ # (unless explicitly permitted)
285
+ else own_account? ? true : super(action, verb)
287
286
  end
288
287
  end
289
288
  end
@@ -1,3 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+
1
3
  describe "act API" do
2
4
  let(:create_card) { Card.create!(name: "main card") }
3
5
  let(:create_card_with_subcards) do
@@ -33,7 +33,7 @@ format :html do
33
33
  end
34
34
 
35
35
  def set_patterns_breadcrumb subject
36
- links = subject.patterns.reverse.map { |pattern| card_link pattern.to_s }
36
+ links = subject.patterns.reverse.map { |pattern| link_to_card pattern.to_s }
37
37
  breadcrumb(links)
38
38
  end
39
39
  # rubocop:enable AccessorMethodName
@@ -70,7 +70,8 @@ format :html do
70
70
  "data-target" => "#modal-#{card.cardname.safe_key}"
71
71
  )
72
72
  opts[:class] = "follow-link #{opts[:class]}"
73
- link_to text, hash[:path], opts
73
+ opts[:path] = hash[:path]
74
+ link_to text, opts
74
75
  end
75
76
  end
76
77
 
@@ -43,7 +43,7 @@ format :html do
43
43
  ) do
44
44
  output [
45
45
  _optional_render(button_view, args),
46
- card_link(link_target, text: text)
46
+ link_to_card(link_target, text)
47
47
  ]
48
48
  end
49
49
  end
@@ -54,29 +54,26 @@ format :html do
54
54
  end
55
55
 
56
56
  view :follow_status do |args|
57
- delete_options =
58
- wrap_with(:ul, class: "delete-list list-group") do
59
- card.item_names.map do |option|
60
- content_tag :li, class: "list-group-item" do
61
- condition = option == "*never" ? "*always" : option
62
- subformat(card).render_follow_item condition: condition
63
- end
64
- end.join "\n"
65
- end
66
-
67
- follow_link =
68
- card_link args[:card_key],
69
- text: "more options",
70
- path_opts: {
71
- view: :related,
72
- related: { name: card.name, view: :edit_single_rule }
73
- },
74
- class: "btn update-follow-link",
75
- "data-card_key" => args[:card_key]
57
+ ["<h4>Get notified about changes</h4>",
58
+ render(:follow_status_delete_options),
59
+ follow_status_link(card.name, args[:card_key])].join "\n\n"
60
+ end
76
61
 
77
- header = "<h4>Get notified about changes</h4>"
62
+ def follow_status_link name, key
63
+ link_to_related key, "more options",
64
+ path: { related: { name: name, view: :edit_single_rule } },
65
+ class: "btn update-follow-link", "data-card_key" => key
66
+ end
78
67
 
79
- [header, delete_options, follow_link].join "\n\n"
68
+ view :follow_status_delete_options do
69
+ wrap_with(:ul, class: "delete-list list-group") do
70
+ card.item_names.map do |option|
71
+ content_tag :li, class: "list-group-item" do
72
+ condition = option == "*never" ? "*always" : option
73
+ subformat(card).render_follow_item condition: condition
74
+ end
75
+ end.join "\n"
76
+ end
80
77
  end
81
78
 
82
79
  view :delete_follow_rule_button do |_args|
@@ -161,7 +161,7 @@ format :html do
161
161
  title = "Problems with #{card.name}"
162
162
  frame args.merge(panel_class: "panel panel-warning",
163
163
  title: title, hide: "menu") do
164
- "Please #{link_to 'sign in', card_url(':signin')}" # " #{to_task}"
164
+ "Please #{link_to_card :signin, 'sign in'}" # " #{to_task}"
165
165
  end
166
166
  else
167
167
  super(args)