Module: Card::Format::Permission

Included in:
Card::Format
Defined in:
lib/card/format/permission.rb

Instance Method Summary collapse

Instance Method Details

#approved_view(view, args = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/card/format/permission.rb', line 14

def approved_view view, args={}
  case
  when @depth >= Card.config.max_depth
    # prevent recursion. @depth tracks subformats
    :too_deep
  when Card::Format.perms[view] == :none
    # permission skipping specified in view definition
    view
  when args.delete(:skip_permissions)
    # permission skipping specified in args
    view
  when !card.known? && !tagged(view, :unknown_ok)
    # handle unknown cards (where view not exempt)
    view_for_unknown view, args
  else
    # run explicit permission checks
    permitted_view view, args
  end
end

#ok?(task) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/card/format/permission.rb', line 55

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, args = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/card/format/permission.rb', line 4

def ok_view view, args={}
  return view if args.delete :skip_permissions
  approved_view = approved_view view, args
  args[:denied_view] = view if approved_view != view
  if focal? && (error_code = Card::Format.error_code[approved_view])
    root.error_status = error_code
  end
  approved_view
end

#permitted_view(view, args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/card/format/permission.rb', line 34

def permitted_view view, args
  perms_required = Card::Format.perms[view] || :read
  args[:denied_task] =
    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

  if args[:denied_task]
    Card::Format.denial[view] || :denial
  else
    view
  end
end

#view_for_unknown(_view, _args) ⇒ Object



50
51
52
53
# File 'lib/card/format/permission.rb', line 50

def view_for_unknown _view, _args
  # note: overridden in HTML
  focal? ? :not_found : :missing
end