Module: Card::Format::Permission
- Included in:
- Card::Format
- Defined in:
- lib/card/format/permission.rb
Instance Method Summary collapse
-
#assign_view_error_status(view) ⇒ Object
-
#check_view(view, skip_perms) ⇒ Object
-
#handle_view_denial(view, approved_view) ⇒ Object
-
#ok?(task) ⇒ Boolean
-
#ok_view(view, skip_perms = false) ⇒ Object
-
#permitted_view(view) ⇒ Object
-
#subformats_nested_too_deeply? ⇒ Boolean
-
#task_denied_for_view(view) ⇒ Object
-
#unknown_disqualifies_view?(view) ⇒ Boolean
-
#view_always_permitted?(view) ⇒ Boolean
-
#view_for_unknown(_view) ⇒ Object
Instance Method Details
#assign_view_error_status(view) ⇒ Object
18 19 20 21 22 |
# File 'lib/card/format/permission.rb', line 18 def assign_view_error_status view return unless focal? return unless (error_code = Card::Format.error_code[view]) root.error_status = error_code end |
#check_view(view, skip_perms) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/card/format/permission.rb', line 24 def check_view view, skip_perms case when skip_perms then view when view_always_permitted?(view) then view when unknown_disqualifies_view?(view) then view_for_unknown view else permitted_view view # run explicit permission checks end end |
#handle_view_denial(view, approved_view) ⇒ Object
13 14 15 16 |
# File 'lib/card/format/permission.rb', line 13 def handle_view_denial view, approved_view return if approved_view == view @denied_view = view end |
#ok?(task) ⇒ Boolean
70 71 72 73 74 75 |
# File 'lib/card/format/permission.rb', line 70 def ok? task task = :create if task == :update && card.new_card? @ok ||= {} @ok[task] = card.ok? task if @ok[task].nil? @ok[task] end |
#ok_view(view, skip_perms = false) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/card/format/permission.rb', line 4 def ok_view view, skip_perms=false return :too_deep if subformats_nested_too_deeply? approved_view = check_view view, skip_perms handle_view_denial view, approved_view assign_view_error_status approved_view approved_view end |
#permitted_view(view) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/card/format/permission.rb', line 48 def permitted_view view if (@denied_task = task_denied_for_view view) Card::Format.denial[view] || :denial else view end end |
#subformats_nested_too_deeply? ⇒ Boolean
39 40 41 42 |
# File 'lib/card/format/permission.rb', line 39 def subformats_nested_too_deeply? # prevent recursion depth >= Card.config.max_depth end |
#task_denied_for_view(view) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/card/format/permission.rb', line 56 def task_denied_for_view view perms_required = Card::Format.perms[view] || :read if perms_required.is_a? Proc :read unless perms_required.call(self) # read isn't quite right else [perms_required].flatten.find { |task| !ok? task } end end |
#unknown_disqualifies_view?(view) ⇒ Boolean
33 34 35 36 37 |
# File 'lib/card/format/permission.rb', line 33 def unknown_disqualifies_view? view # view can't handle unknown cards (and card is unknown) return if tagged view, :unknown_ok card.unknown? end |
#view_always_permitted?(view) ⇒ Boolean
44 45 46 |
# File 'lib/card/format/permission.rb', line 44 def view_always_permitted? view Card::Format.perms[view] == :none end |
#view_for_unknown(_view) ⇒ Object
65 66 67 68 |
# File 'lib/card/format/permission.rb', line 65 def view_for_unknown _view # note: overridden in HTML focal? ? :not_found : :missing end |