Module: Erbac::AuthManage::ClassMethods

Defined in:
lib/erbac/auth_manage.rb

Constant Summary collapse

AUTH_TYPES =
["operation", "task", "role"]

Instance Method Summary collapse

Instance Method Details

#add_item_child(parent, child) ⇒ Object



24
25
26
# File 'lib/erbac/auth_manage.rb', line 24

def add_item_child(parent, child)
    parent.add_child child
end

#assign(item, user, bizrule = nil, data = nil) ⇒ Object



36
37
38
# File 'lib/erbac/auth_manage.rb', line 36

def assign(item, user, bizrule=nil, data=nil)
	item.assign user, bizrule, data
end

#check_access?(*args) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
# File 'lib/erbac/auth_manage.rb', line 74

def check_access?(*args)
  unless (args.first.is_a? Erbac.auth_item_class.constantize)
    raise TypeError, "Should pass in #{Erbac.auth_item_class} instance as the first parameter. Got #{args.first.to_s}", caller
  end

  user = (args[1].is_a? Erbac.user_class.constantize) ? args[1] : Erbac.user_class.constantize.anonymous
  user.check_access? args.first, args.extract_options!
end

#clear_allObject



52
53
54
# File 'lib/erbac/auth_manage.rb', line 52

def clear_all
	Erbac.auth_item_class.constantize.delete_all
end

#clear_auth_assignments(*args) ⇒ Object



56
57
58
# File 'lib/erbac/auth_manage.rb', line 56

def clear_auth_assignments(*args)
	Erbac.auth_assignment_class.constantize.delete_all args
end

#execute_biz_rule?(*args) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/erbac/auth_manage.rb', line 60

def execute_biz_rule?(*args)
  item = args.first
  params = args.extract_options!
  unless (item.is_a? Erbac.auth_item_class.constantize or item.is_a? Erbac.auth_assignment_class.constantize)
    raise TypeError, "Argument type not supported, should pass in #{Erbac.auth_item_class} or #{Erbac.auth_assignment_class} instance as the first parameter. Got #{item.class.to_s}", caller
  end

  if (args[1].is_a? Erbac.user_class.constantize)
    args[1].execute_biz_rule? item, params
  else
    bizrule_sandbox(item.bizrule, params, item.data)
  end
end

#get_auth_assignment(item, user) ⇒ Object



48
49
50
# File 'lib/erbac/auth_manage.rb', line 48

def get_auth_assignment(item, user)
	item.get_auth_assignment user
end

#has_item_child?(parent, child) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/erbac/auth_manage.rb', line 32

def has_item_child?(parent, child)
	parent.has_child? child
end

#is_assigned?(item, user) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/erbac/auth_manage.rb', line 44

def is_assigned?(item, user)
	item.is_assigned? user
end

#remove_item_child(parent, child) ⇒ Object



28
29
30
# File 'lib/erbac/auth_manage.rb', line 28

def remove_item_child(parent, child)
	parent.remove_child child
end

#revoke(item, user) ⇒ Object



40
41
42
# File 'lib/erbac/auth_manage.rb', line 40

def revoke(item, user)
	item.revoke user
end