card 1.16.15 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/config/initializers/recaptcha.rb +21 -4
- data/db/migrate_core_cards/20130823192433_add_style_cards.rb +1 -1
- data/db/migrate_core_cards/20140512155840_add_script_cards.rb +1 -1
- data/db/migrate_core_cards/20140629222005_add_email_cards.rb +2 -2
- data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
- data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +1 -1
- data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +63 -0
- data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
- data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +1 -1
- data/db/schema.rb +1 -1
- data/db/seed/new/card_actions.yml +602 -394
- data/db/seed/new/card_acts.yml +595 -1
- data/db/seed/new/card_changes.yml +26282 -10262
- data/db/seed/new/card_references.yml +1252 -1084
- data/db/seed/new/cards.yml +1899 -1423
- data/db/seed/test/fixtures/card_actions.yml +1653 -1413
- data/db/seed/test/fixtures/card_acts.yml +1063 -445
- data/db/seed/test/fixtures/card_changes.yml +29674 -13637
- data/db/seed/test/fixtures/card_references.yml +1976 -1815
- data/db/seed/test/fixtures/cards.yml +3194 -2719
- data/lib/card.rb +14 -13
- data/lib/card/auth.rb +10 -6
- data/lib/card/cache.rb +58 -120
- data/lib/card/cache/persistent.rb +50 -0
- data/lib/card/cache/temporary.rb +38 -0
- data/lib/card/chunk.rb +34 -25
- data/lib/card/content.rb +3 -3
- data/lib/card/env.rb +3 -0
- data/lib/card/format.rb +56 -53
- data/lib/card/migration.rb +6 -2
- data/lib/card/name.rb +9 -1
- data/lib/card/query.rb +1 -1
- data/lib/card/reference.rb +17 -11
- data/lib/card/set.rb +1 -1
- data/lib/card/subcards.rb +6 -6
- data/lib/card/view_cache.rb +45 -28
- data/lib/generators/card/migration/templates/card_migration.erb +1 -2
- data/mod/01_core/chunk/include.rb +71 -48
- data/mod/01_core/chunk/link.rb +6 -3
- data/mod/01_core/chunk/query_reference.rb +38 -29
- data/mod/01_core/chunk/reference.rb +23 -24
- data/mod/01_core/set/all/collection.rb +1 -1
- data/mod/01_core/set/all/fetch.rb +39 -12
- data/mod/01_core/set/all/permissions.rb +2 -4
- data/mod/01_core/set/all/references.rb +50 -75
- data/mod/01_core/set/all/rules.rb +19 -18
- data/mod/01_core/set/all/subcards.rb +1 -1
- data/mod/01_core/set/all/templating.rb +31 -88
- data/mod/01_core/set/all/tracked_attributes.rb +7 -14
- data/mod/01_core/set/all/utils.rb +77 -66
- data/mod/01_core/set_pattern/07_type_plus_right.rb +6 -3
- data/mod/01_core/spec/set/all/fetch_spec.rb +148 -96
- data/mod/01_core/spec/set/all/templating_spec.rb +49 -40
- data/mod/01_core/spec/set/all/trash_spec.rb +1 -1
- data/mod/01_history/set/all/actions.rb +1 -1
- data/mod/02_basic_types/set/all/base.rb +13 -7
- data/mod/02_basic_types/set/all/rss.rb +17 -22
- data/mod/02_basic_types/set/type/plain_text.rb +5 -2
- data/mod/02_basic_types/spec/set/all/base_spec.rb +1 -0
- data/mod/02_basic_types/spec/set/all/rss_spec.rb +7 -6
- data/mod/03_machines/lib/javascript/wagn.js.coffee +22 -9
- data/mod/03_machines/set/right/machine_output.rb +1 -1
- data/mod/04_settings/lib/card/setting.rb +45 -31
- data/mod/04_settings/set/right/structure.rb +47 -1
- data/mod/04_settings/set/self/default_html_view.rb +2 -0
- data/mod/04_settings/set/self/follow_fields.rb +2 -0
- data/mod/04_settings/set/self/recent_settings.rb +1 -1
- data/mod/05_standard/file/favicon/image-icon.png +0 -0
- data/mod/05_standard/file/favicon/image-large.png +0 -0
- data/mod/05_standard/file/favicon/image-medium.png +0 -0
- data/mod/05_standard/file/favicon/image-original.png +0 -0
- data/mod/05_standard/file/favicon/image-small.png +0 -0
- data/mod/05_standard/set/all/links.rb +27 -26
- data/mod/05_standard/set/all/rich_html/editing.rb +1 -1
- data/mod/05_standard/set/all/rich_html/toolbar.rb +1 -1
- data/mod/05_standard/set/rstar/rules.rb +20 -325
- data/mod/05_standard/set/rstar/rules_editor.rb +362 -0
- data/mod/05_standard/set/self/admin_info.rb +82 -0
- data/mod/05_standard/set/self/all.rb +16 -10
- data/mod/05_standard/set/self/head.rb +20 -19
- data/mod/05_standard/set/type/signup.rb +0 -1
- data/mod/05_standard/spec/set/all/account_spec.rb +44 -43
- data/mod/05_standard/spec/set/right/account_spec.rb +4 -2
- data/mod/05_standard/spec/set/type/search_type_spec.rb +8 -0
- data/mod/05_standard/spec/set/type/signup_spec.rb +24 -17
- data/mod/06_bootstrap/set/all/bootstrap/helper.rb +1 -1
- data/spec/lib/card/cache_spec.rb +64 -70
- data/spec/lib/card/content_spec.rb +236 -150
- data/spec/lib/card/reference_spec.rb +22 -38
- data/spec/lib/card/subcards_spec.rb +38 -0
- data/spec/lib/card/view_cache_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- data/tmpsets/set/mod001-01_core/all/collection.rb +77 -74
- data/tmpsets/set/mod001-01_core/all/content.rb +14 -16
- data/tmpsets/set/mod001-01_core/all/fetch.rb +137 -110
- data/tmpsets/set/mod001-01_core/all/name.rb +58 -40
- data/tmpsets/set/mod001-01_core/all/pattern.rb +12 -11
- data/tmpsets/set/mod001-01_core/all/permissions.rb +125 -117
- data/tmpsets/set/mod001-01_core/all/phases.rb +2 -1
- data/tmpsets/set/mod001-01_core/all/references.rb +52 -77
- data/tmpsets/set/mod001-01_core/all/rules.rb +47 -53
- data/tmpsets/set/mod001-01_core/all/templating.rb +31 -87
- data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +12 -21
- data/tmpsets/set/mod001-01_core/all/trash.rb +4 -1
- data/tmpsets/set/mod001-01_core/all/type.rb +23 -21
- data/tmpsets/set/mod001-01_core/all/utils.rb +80 -64
- data/tmpsets/set/mod002-01_history/all/actions.rb +20 -16
- data/tmpsets/set/mod002-01_history/all/history.rb +18 -13
- data/tmpsets/set/mod003-02_basic_types/all/base.rb +37 -10
- data/tmpsets/set/mod003-02_basic_types/all/rss.rb +17 -22
- data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +5 -2
- data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +51 -39
- data/tmpsets/set/mod004-03_machines/right/machine_output.rb +10 -6
- data/tmpsets/set/mod005-04_settings/abstract/permission.rb +10 -5
- data/tmpsets/set/mod005-04_settings/right/structure.rb +47 -1
- data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +1 -0
- data/tmpsets/set/mod005-04_settings/type/setting.rb +4 -1
- data/tmpsets/set/mod006-05_email/all/follow.rb +45 -54
- data/tmpsets/set/mod006-05_email/all/notify.rb +88 -73
- data/tmpsets/set/mod006-05_email/right/followers.rb +17 -14
- data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +22 -18
- data/tmpsets/set/mod006-05_email/type/email_template.rb +1 -1
- data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +94 -67
- data/tmpsets/set/mod007-05_standard/all/account.rb +18 -20
- data/tmpsets/set/mod007-05_standard/all/comment.rb +51 -29
- data/tmpsets/set/mod007-05_standard/all/error.rb +129 -99
- data/tmpsets/set/mod007-05_standard/all/links.rb +27 -26
- data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +115 -103
- data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +112 -78
- data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +123 -81
- data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +15 -58
- data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -2
- data/tmpsets/set/mod007-05_standard/right/account.rb +71 -75
- data/tmpsets/set/mod007-05_standard/right/email.rb +16 -13
- data/tmpsets/set/mod007-05_standard/right/password.rb +20 -12
- data/tmpsets/set/mod007-05_standard/right/status.rb +2 -2
- data/tmpsets/set/mod007-05_standard/right/token.rb +49 -2
- data/tmpsets/set/mod007-05_standard/rstar/rules.rb +20 -325
- data/tmpsets/set/mod007-05_standard/self/all.rb +16 -10
- data/tmpsets/set/mod007-05_standard/self/head.rb +76 -62
- data/tmpsets/set/mod007-05_standard/self/search.rb +45 -22
- data/tmpsets/set/mod007-05_standard/self/signin.rb +14 -12
- data/tmpsets/set/mod007-05_standard/type/cardtype.rb +13 -11
- data/tmpsets/set/mod007-05_standard/type/file.rb +1 -1
- data/tmpsets/set/mod007-05_standard/type/search_type.rb +3 -2
- data/tmpsets/set/mod007-05_standard/type/set.rb +20 -16
- data/tmpsets/set/mod007-05_standard/type/signup.rb +19 -25
- data/tmpsets/set/mod007-05_standard/type/user.rb +1 -1
- data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +1 -1
- data/tmpsets/set_pattern/106-type_plus_right.rb +6 -3
- metadata +11 -2
@@ -4,18 +4,20 @@ class Card; module Set; module All; module Name; extend Card::Set
|
|
4
4
|
require 'uuid'
|
5
5
|
|
6
6
|
module ClassMethods
|
7
|
-
def uniquify_name name, rename
|
8
|
-
return name unless Card
|
7
|
+
def uniquify_name name, rename=:new
|
8
|
+
return name unless Card.exists?(name)
|
9
9
|
uniq_name = "#{name} 1"
|
10
|
-
while Card
|
10
|
+
while Card.exists?(uniq_name)
|
11
11
|
uniq_name.next!
|
12
12
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
if rename == :old
|
14
|
+
# name conflict resolved; original name can be used
|
15
|
+
Card[name].update_attributes! name: uniq_name,
|
16
|
+
update_referencers: true
|
17
|
+
name
|
18
|
+
else
|
19
|
+
uniq_name
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -122,24 +124,42 @@ def left_or_new args={}
|
|
122
124
|
left(args) || Card.new(args.merge(name: cardname.left))
|
123
125
|
end
|
124
126
|
|
127
|
+
def fields
|
128
|
+
field_names.map { |name| Card[name] }
|
129
|
+
end
|
130
|
+
|
131
|
+
def field_names parent_name=nil
|
132
|
+
child_names parent_name, :left
|
133
|
+
end
|
134
|
+
|
125
135
|
def children
|
126
|
-
|
136
|
+
child_names.map { |name| Card[name] }
|
127
137
|
end
|
128
138
|
|
129
|
-
def
|
130
|
-
|
139
|
+
def child_names parent_name=nil, side=nil
|
140
|
+
# eg, A+B is a child of A and B
|
141
|
+
parent_name ||= name
|
142
|
+
side ||= parent_name.to_name.simple? ? :part : :left
|
143
|
+
Card.search({ side => parent_name, return: :name },
|
144
|
+
"(#{side}) children of #{parent_name}")
|
145
|
+
end
|
131
146
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
# Rails.logger.warn "dependents[#{inspect}] #{@dependents.inspect}"
|
147
|
+
def descendant_names parent_name=nil
|
148
|
+
return [] if new_card?
|
149
|
+
parent_name ||= name
|
150
|
+
Auth.as_bot do
|
151
|
+
deps = child_names parent_name
|
152
|
+
deps.inject(deps) do |array, childname|
|
153
|
+
array + descendant_names(childname)
|
154
|
+
end
|
141
155
|
end
|
142
|
-
|
156
|
+
end
|
157
|
+
|
158
|
+
def descendants
|
159
|
+
# children and children's children
|
160
|
+
# NOTE - set modules are not loaded
|
161
|
+
# -- should only be used for name manipulations
|
162
|
+
@descendants ||= descendant_names.map { |name| Card.quick_fetch name }
|
143
163
|
end
|
144
164
|
|
145
165
|
def repair_key
|
@@ -157,7 +177,7 @@ def repair_key
|
|
157
177
|
saved ||= (self.cardname = current_key) && self.save!
|
158
178
|
|
159
179
|
if saved
|
160
|
-
|
180
|
+
descendants.each(&:repair_key)
|
161
181
|
else
|
162
182
|
Rails.logger.debug "FAILED TO REPAIR BROKEN KEY: #{key}"
|
163
183
|
self.name = "BROKEN KEY: #{name}"
|
@@ -215,8 +235,9 @@ end
|
|
215
235
|
event :set_autoname, before: :validate_name, on: :create do
|
216
236
|
if name.blank? && (autoname_card = rule_card(:autoname))
|
217
237
|
self.name = autoname autoname_card.content
|
218
|
-
# FIXME: should give placeholder
|
219
|
-
|
238
|
+
# FIXME: should give placeholder in approve phase
|
239
|
+
# and finalize/commit change in store phase
|
240
|
+
autoname_card.refresh.update_column :db_content, name
|
220
241
|
end
|
221
242
|
end
|
222
243
|
|
@@ -278,28 +299,25 @@ event :cascade_name_changes, after: :store, on: :update, changed: :name do
|
|
278
299
|
self.update_referencers = false if update_referencers == 'false'
|
279
300
|
Card::Reference.update_on_rename self, name, self.update_referencers
|
280
301
|
|
281
|
-
|
282
|
-
|
283
|
-
# " #{deps.map(&:name)*', '} -----------------------"
|
284
|
-
|
285
|
-
@dependents = nil # reset
|
302
|
+
des = descendants
|
303
|
+
@descendants = nil # reset
|
286
304
|
|
287
|
-
|
305
|
+
des.each do |de|
|
288
306
|
# here we specifically want NOT to invoke recursive cascades on these
|
289
307
|
# cards, have to go this low level to avoid callbacks.
|
290
|
-
Rails.logger.info "cascading name: #{
|
291
|
-
Card.expire
|
292
|
-
newname =
|
293
|
-
Card.where(id:
|
294
|
-
Card::Reference.update_on_rename
|
308
|
+
Rails.logger.info "cascading name: #{de.name}"
|
309
|
+
Card.expire de.name # old name
|
310
|
+
newname = de.cardname.replace_part name_was, name
|
311
|
+
Card.where(id: de.id).update_all name: newname.to_s, key: newname.key
|
312
|
+
Card::Reference.update_on_rename de, newname, update_referencers
|
295
313
|
Card.expire newname
|
296
314
|
end
|
297
|
-
execute_referencers_update(
|
315
|
+
execute_referencers_update(des) if update_referencers
|
298
316
|
end
|
299
317
|
|
300
|
-
def execute_referencers_update
|
318
|
+
def execute_referencers_update descendants
|
301
319
|
Auth.as_bot do
|
302
|
-
[name_referencers(name_was) +
|
320
|
+
[name_referencers(name_was) + descendants.map(&:referencers)]
|
303
321
|
.flatten.uniq.each do |card|
|
304
322
|
# FIXME: using 'name_referencers' instead of plain 'referencers' for self
|
305
323
|
# because there are cases where trunk and tag
|
@@ -310,7 +328,7 @@ def execute_referencers_update dependents
|
|
310
328
|
# so at this time X is still including Y, which does not exist.
|
311
329
|
# therefore #referencers doesn't find it, but name_referencers(old_name)
|
312
330
|
# does.
|
313
|
-
# some even more complicated scenario probably breaks on the
|
331
|
+
# some even more complicated scenario probably breaks on the descendants,
|
314
332
|
# so this probably needs a more thoughtful refactor
|
315
333
|
# aligning the dependent saving with the name cascading
|
316
334
|
|
@@ -22,26 +22,28 @@ def reset_patterns_if_rule saving=false
|
|
22
22
|
set.reset_patterns
|
23
23
|
set.include_set_modules
|
24
24
|
|
25
|
-
#
|
26
|
-
if saving
|
27
|
-
self.add_to_read_rule_update_queue(
|
25
|
+
# FIXME: should be in right/read.rb
|
26
|
+
if saving && right.id == Card::ReadID
|
27
|
+
self.add_to_read_rule_update_queue(set.item_cards limit: 0)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def safe_set_keys
|
33
|
-
patterns.map(
|
33
|
+
patterns.map(&:safe_key).reverse * " "
|
34
34
|
end
|
35
35
|
|
36
36
|
def set_modules
|
37
|
-
@set_modules ||=
|
37
|
+
@set_modules ||=
|
38
|
+
patterns_without_new[0..-2].reverse.map(&:module_list).flatten.compact
|
38
39
|
end
|
39
40
|
|
40
41
|
def set_format_modules klass
|
41
42
|
@set_format_modules ||= {}
|
42
|
-
@set_format_modules[klass] =
|
43
|
-
|
44
|
-
|
43
|
+
@set_format_modules[klass] =
|
44
|
+
patterns_without_new[0..-2].reverse.map do |pattern|
|
45
|
+
pattern.format_module_list klass
|
46
|
+
end.flatten.compact
|
45
47
|
end
|
46
48
|
|
47
49
|
def set_names
|
@@ -53,11 +55,10 @@ def set_names
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def rule_set_keys
|
56
|
-
set_names #this triggers set_members cache. need better solution!
|
57
|
-
@rule_set_keys ||= patterns.map(
|
58
|
+
set_names # this triggers set_members cache. need better solution!
|
59
|
+
@rule_set_keys ||= patterns.map(&:rule_set_key).compact
|
58
60
|
end
|
59
61
|
|
60
62
|
|
61
|
-
|
62
63
|
# ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/pattern.rb ~~~~~~~~~~~
|
63
64
|
end;end;end;end;
|
@@ -2,17 +2,17 @@
|
|
2
2
|
class Card; module Set; module All; module Permissions; extend Card::Set
|
3
3
|
# ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/permissions.rb ~~~~~~~~~~~
|
4
4
|
|
5
|
-
Card.error_codes.merge! permission_denied: [:denial, 403],
|
6
|
-
|
5
|
+
Card.error_codes.merge! permission_denied: [:denial, 403],
|
6
|
+
captcha: [:errors, 449]
|
7
7
|
|
8
8
|
# ok? and ok! are public facing methods to approve one action at a time
|
9
9
|
#
|
10
10
|
# fetching: if the optional :trait parameter is supplied, it is passed
|
11
11
|
# to fetch and the test is perfomed on the fetched card, therefore:
|
12
12
|
#
|
13
|
-
# trait: :account
|
14
|
-
# trait: :roles, new: {} would initialize a new card with default ({})
|
15
|
-
|
13
|
+
# trait: :account would fetch this card plus a tag codenamed :account
|
14
|
+
# trait: :roles, new: {} would initialize a new card with default ({})
|
15
|
+
# options.
|
16
16
|
|
17
17
|
def ok? action
|
18
18
|
@action_ok = true
|
@@ -24,39 +24,50 @@ def ok_with_fetch? action, opts={}
|
|
24
24
|
card = opts[:trait].nil? ? self : fetch(opts)
|
25
25
|
card && card.ok_without_fetch?(action)
|
26
26
|
end
|
27
|
-
alias_method_chain :ok?, :fetch # note: method is chained so that we can return the instance variable @action_ok
|
28
27
|
|
28
|
+
# note: method is chained so that we can return the instance variable @action_ok
|
29
|
+
alias_method_chain :ok?, :fetch
|
29
30
|
|
30
31
|
def ok! action, opts={}
|
31
32
|
raise Card::PermissionDenied.new self unless ok? action, opts
|
32
33
|
end
|
33
34
|
|
34
35
|
def who_can action
|
35
|
-
#warn "who_can[#{name}] #{(prc=permission_rule_card(action)).inspect},
|
36
|
-
|
36
|
+
# warn "who_can[#{name}] #{(prc=permission_rule_card(action)).inspect},
|
37
|
+
# #{prc.first.item_cards.map(&:id)}" if action == :update
|
38
|
+
permission_rule_card(action).item_cards.map &:id
|
37
39
|
end
|
38
40
|
|
41
|
+
def permission_rule_id_and_class action
|
42
|
+
direct_rule_id = rule_card_id action
|
43
|
+
require_permission_rule! direct_rule_id, action
|
44
|
+
direct_rule = Card.fetch direct_rule_id, skip_modules: true
|
45
|
+
[applicable_permission_rule_id(direct_rule, action),
|
46
|
+
direct_rule.rule_class_name]
|
47
|
+
end
|
39
48
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
raise Card::PermissionDenied.new(self)
|
46
|
-
end
|
47
|
-
|
48
|
-
rcard = Auth.as_bot do
|
49
|
-
if ['_left','[[_left]]'].member?(opcard.db_content) && self.junction? # compound cards can inherit permissions from left parent
|
50
|
-
lcard = left_or_new( skip_virtual: true, skip_modules: true )
|
51
|
-
if action==:create && lcard.real? && !lcard.action==:create
|
52
|
-
action = :update
|
53
|
-
end
|
54
|
-
lcard.permission_rule_card(action).first
|
55
|
-
else
|
56
|
-
opcard
|
49
|
+
def applicable_permission_rule_id direct_rule, action
|
50
|
+
if junction? && direct_rule.db_content =~ /^\[?\[?_left\]?\]?$/
|
51
|
+
lcard = left_or_new(skip_virtual: true, skip_modules: true)
|
52
|
+
if action == :create && lcard.real? && !lcard.action == :create
|
53
|
+
action = :update
|
57
54
|
end
|
55
|
+
lcard.permission_rule_id_and_class(action).first
|
56
|
+
else
|
57
|
+
direct_rule.id
|
58
58
|
end
|
59
|
-
|
59
|
+
end
|
60
|
+
|
61
|
+
def permission_rule_card action
|
62
|
+
Card.fetch permission_rule_id_and_class(action).first
|
63
|
+
end
|
64
|
+
|
65
|
+
def require_permission_rule! rule_id, action
|
66
|
+
return if rule_id
|
67
|
+
# RULE missing. should not be possible.
|
68
|
+
# generalize this to handling of all required rules
|
69
|
+
errors.add :permission_denied, "No #{action} rule for #{name}"
|
70
|
+
raise Card::PermissionDenied.new(self)
|
60
71
|
end
|
61
72
|
|
62
73
|
def rule_class_name
|
@@ -67,67 +78,61 @@ def you_cant what
|
|
67
78
|
"You don't have permission to #{what}"
|
68
79
|
end
|
69
80
|
|
70
|
-
|
71
81
|
def deny_because why
|
72
82
|
@permission_errors << why if @permission_errors
|
73
83
|
@action_ok = false
|
74
84
|
end
|
75
85
|
|
76
86
|
def permitted? action
|
87
|
+
return if Card.config.read_only
|
88
|
+
return true if action != :comment and Auth.always_ok?
|
77
89
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
permitted_ids
|
82
|
-
|
83
|
-
|
84
|
-
!permitted_ids.empty?
|
85
|
-
else
|
86
|
-
Auth.among? permitted_ids
|
87
|
-
end
|
90
|
+
permitted_ids = who_can action
|
91
|
+
if action == :comment && Auth.always_ok?
|
92
|
+
# admin can comment if anyone can
|
93
|
+
!permitted_ids.empty?
|
94
|
+
else
|
95
|
+
Auth.among? permitted_ids
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|
91
99
|
def permit action, verb=nil
|
92
|
-
|
93
100
|
if Card.config.read_only # not called by ok_to_read
|
94
|
-
deny_because
|
101
|
+
deny_because 'Currently in read-only mode'
|
95
102
|
end
|
96
103
|
|
104
|
+
return if permitted? action
|
97
105
|
verb ||= action.to_s
|
98
|
-
|
99
|
-
deny_because you_cant("#{verb} #{name.present? ? name : 'this'}")
|
100
|
-
end
|
106
|
+
deny_because you_cant("#{verb} #{name.present? ? name : 'this'}")
|
101
107
|
end
|
102
108
|
|
103
109
|
def ok_to_create
|
104
110
|
permit :create
|
105
|
-
if
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
111
|
+
return if !@action_ok || !junction?
|
112
|
+
|
113
|
+
[:left, :right].each do |side|
|
114
|
+
# left is supercard; create permissions will get checked there.
|
115
|
+
next if side == :left && @superleft
|
116
|
+
part_card = send side, new: {}
|
117
|
+
if part_card && part_card.new_card? # if no card, there must be other errors
|
118
|
+
unless part_card.ok? :create
|
119
|
+
deny_because you_cant("create #{part_card.name}")
|
113
120
|
end
|
114
121
|
end
|
115
122
|
end
|
116
123
|
end
|
117
124
|
|
118
125
|
def ok_to_read
|
119
|
-
if
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
124
|
-
end
|
126
|
+
return if Auth.always_ok?
|
127
|
+
@read_rule_id ||= permission_rule_id_and_class(:read).first
|
128
|
+
return if Auth.as_card.read_rules.member? @read_rule_id
|
129
|
+
deny_because you_cant 'read this'
|
125
130
|
end
|
126
131
|
|
127
132
|
def ok_to_update
|
128
133
|
permit :update
|
129
|
-
if @action_ok
|
130
|
-
deny_because you_cant(
|
134
|
+
if @action_ok && type_id_changed? && !permitted?(:create)
|
135
|
+
deny_because you_cant('change to this type (need create permission)')
|
131
136
|
end
|
132
137
|
ok_to_read if @action_ok
|
133
138
|
end
|
@@ -138,51 +143,51 @@ end
|
|
138
143
|
|
139
144
|
def ok_to_comment
|
140
145
|
permit :comment, 'comment on'
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
146
|
+
return unless @action_ok
|
147
|
+
deny_because 'No comments allowed on templates' if is_template?
|
148
|
+
deny_because 'No comments allowed on structured content' if structure
|
145
149
|
end
|
146
150
|
|
151
|
+
event :clear_read_rule, before: :store, on: :delete do
|
152
|
+
self.read_rule_id = self.read_rule_class = nil
|
153
|
+
end
|
147
154
|
|
148
|
-
event :set_read_rule, before: :store do
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
155
|
+
event :set_read_rule, before: :store, on: :save do
|
156
|
+
# avoid doing this on simple content saves?
|
157
|
+
read_rule_id, read_rule_class = permission_rule_id_and_class(:read)
|
158
|
+
self.read_rule_id = read_rule_id
|
159
|
+
self.read_rule_class = read_rule_class
|
160
|
+
end
|
161
|
+
|
162
|
+
event :set_field_read_rules,
|
163
|
+
after: :set_read_rule, on: :update, changed: :type_id do
|
164
|
+
# find all cards with me as trunk and update their read_rule
|
165
|
+
# (because of *type plus right)
|
166
|
+
# skip if name is updated because will already be resaved
|
167
|
+
|
168
|
+
Auth.as_bot do
|
169
|
+
fields.each do |field|
|
170
|
+
field.refresh.update_read_rule
|
165
171
|
end
|
166
172
|
end
|
167
173
|
end
|
168
174
|
|
169
175
|
def update_read_rule
|
170
176
|
Card.record_timestamps = false
|
171
|
-
|
172
177
|
reset_patterns # why is this needed?
|
173
178
|
rcard, rclass = permission_rule_card :read
|
174
|
-
|
175
|
-
|
176
|
-
|
179
|
+
# these two are just to make sure vals are correct on current object
|
180
|
+
self.read_rule_id = rcard.id
|
177
181
|
self.read_rule_class = rclass
|
178
|
-
Card.where(id:
|
179
|
-
|
182
|
+
Card.where(id: id).update_all read_rule_id: rcard.id, read_rule_class: rclass
|
183
|
+
expire_hard
|
180
184
|
|
181
|
-
# currently doing a brute force search for every card that may be impacted.
|
185
|
+
# currently doing a brute force search for every card that may be impacted.
|
186
|
+
# may want to optimize(?)
|
182
187
|
Auth.as_bot do
|
183
|
-
|
184
|
-
if
|
185
|
-
|
188
|
+
fields.each do |field|
|
189
|
+
if field.rule(:read) == '_left'
|
190
|
+
field.update_read_rule
|
186
191
|
end
|
187
192
|
end
|
188
193
|
end
|
@@ -191,17 +196,18 @@ ensure
|
|
191
196
|
Card.record_timestamps = true
|
192
197
|
end
|
193
198
|
|
199
|
+
|
194
200
|
def add_to_read_rule_update_queue updates
|
195
201
|
@read_rule_update_queue = Array.wrap(@read_rule_update_queue).concat updates
|
196
202
|
end
|
197
203
|
|
198
|
-
|
199
204
|
event :check_permissions, after: :approve do
|
200
|
-
task =
|
201
|
-
:comment
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
+
task =
|
206
|
+
if @action != :delete && comment # will be obviated by new comment handling
|
207
|
+
:comment
|
208
|
+
else
|
209
|
+
@action
|
210
|
+
end
|
205
211
|
track_permission_errors do
|
206
212
|
ok? task
|
207
213
|
end
|
@@ -219,19 +225,22 @@ def track_permission_errors
|
|
219
225
|
result
|
220
226
|
end
|
221
227
|
|
222
|
-
|
223
228
|
def recaptcha_on?
|
224
229
|
have_recaptcha_keys? &&
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
+
Env[:controller] &&
|
231
|
+
!Auth.signed_in? &&
|
232
|
+
!Auth.needs_setup? &&
|
233
|
+
!Auth.always_ok? &&
|
234
|
+
Card.toggle(rule :captcha)
|
230
235
|
end
|
231
236
|
|
232
237
|
def have_recaptcha_keys?
|
233
|
-
@@have_recaptcha_keys =
|
234
|
-
|
238
|
+
@@have_recaptcha_keys =
|
239
|
+
if defined?(@@have_recaptcha_keys)
|
240
|
+
@@have_recaptcha_keys
|
241
|
+
else
|
242
|
+
!!(Card.config.recaptcha_public_key && Card.config.recaptcha_private_key)
|
243
|
+
end
|
235
244
|
end
|
236
245
|
|
237
246
|
event :recaptcha, before: :approve do
|
@@ -242,21 +251,23 @@ event :recaptcha, before: :approve do
|
|
242
251
|
end
|
243
252
|
|
244
253
|
module Accounts
|
245
|
-
# This is a short-term hack that is used in account-related cards to allow a
|
246
|
-
# permissions are restricted to the owner of the
|
247
|
-
#
|
248
|
-
#
|
254
|
+
# This is a short-term hack that is used in account-related cards to allow a
|
255
|
+
# permissions pattern where permissions are restricted to the owner of the
|
256
|
+
# account (and, by default, Admin)
|
257
|
+
# That pattern should be permitted by our card representation
|
258
|
+
# (without creating separate rules for each account holder) but is not yet.
|
249
259
|
|
250
260
|
def permit action, verb=nil
|
251
261
|
case
|
252
|
-
when action
|
253
|
-
when action
|
254
|
-
#restricts account creation to subcard handling on permitted card
|
255
|
-
|
256
|
-
|
262
|
+
when action == :comment then @action_ok = false
|
263
|
+
when action == :create then @superleft ? true : super(action, verb)
|
264
|
+
# restricts account creation to subcard handling on permitted card
|
265
|
+
# (unless explicitly permitted)
|
266
|
+
when own_account? then true
|
267
|
+
else
|
268
|
+
super action, verb
|
257
269
|
end
|
258
270
|
end
|
259
|
-
|
260
271
|
end
|
261
272
|
|
262
273
|
module Follow
|
@@ -274,17 +285,14 @@ module Follow
|
|
274
285
|
|
275
286
|
def permit action, verb=nil
|
276
287
|
if [:create, :delete, :update].include?(action) && Auth.signed_in? &&
|
277
|
-
|
288
|
+
(user = rule_user) && Auth.current_id == user.id
|
278
289
|
return true
|
279
290
|
else
|
280
291
|
super action, verb
|
281
292
|
end
|
282
293
|
end
|
283
|
-
|
284
294
|
end
|
285
295
|
|
286
296
|
|
287
|
-
|
288
|
-
|
289
297
|
# ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/permissions.rb ~~~~~~~~~~~
|
290
298
|
end;end;end;end;
|