Module: PolicyManager::Concerns::UserTerms

Extended by:
ActiveSupport::Concern
Included in:
UserTermsController
Defined in:
app/controllers/policy_manager/concerns/user_terms.rb

Instance Method Summary collapse

Instance Method Details

#accept_term(term) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/policy_manager/concerns/user_terms.rb', line 5

def accept_term(term)
  if current_user
    user_term = current_user.handle_policy_for(term)
    return if user_term.accepted?
    if user_term.accept!
      term.rule.on_accept.call(self) if term.rule.on_accept.is_a?(Proc)
    end
  end

  cookies["policy_rule_#{term.rule.name}"] = {
      :value => "accepted",
      :expires => 1.year.from_now
  }

  user_term
end

#policy_term_on(name) ⇒ Object

Use callbacks to share common setup or constraints between actions.



37
38
39
40
# File 'app/controllers/policy_manager/concerns/user_terms.rb', line 37

def policy_term_on(name)
  category = PolicyManager::Config.rules.find{|o| o.name == name}
  category.terms.last
end

#reject_term(term) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/policy_manager/concerns/user_terms.rb', line 22

def reject_term(term)
  if current_user
    user_term = current_user.handle_policy_for(term)
    return if user_term.rejected?
    if user_term.reject!
      term.rule.on_reject.call(self) if term.rule.on_reject.is_a?(Proc)
    end
  end

  cookies.delete("policy_rule_#{term.rule.name}")

  user_term
end