Class: PolicyManager::UserTermsController

Inherits:
ApplicationController show all
Includes:
Concerns::UserTerms
Defined in:
app/controllers/policy_manager/user_terms_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin_user, #allow_admins, #current_user, #doc, #set_language, #user_authenticated?

Instance Method Details

#acceptObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/policy_manager/user_terms_controller.rb', line 49

def accept
  @user_term = accept_term(@term)

  respond_to do |format|
    format.html{ 
      if @user_term.errors.any?
        redirect_to root_url , notice: "hey there are some errors! #{@user_term.errors.full_messages.join()}"
      else
        redirect_to root_url 
      end
    }
    format.js
    format.json{
      render json: {
        status: @user_term ? @user_term.state : cookies["policy_rule_#{@term.rule.name}"]
      }
    }
  end
end

#accept_multiplesObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/policy_manager/user_terms_controller.rb', line 37

def accept_multiples
  rules = current_user.pending_policies.map{|o| "policy_rule_#{o.name}"}
  resource_params = params.require(:user).permit(rules)
  current_user.update_attributes(resource_params)
  @pending_policies = current_user.pending_policies
  
  respond_to do |format|
    format.html{ }
    format.json{ render json: @pending_policies }
  end
end

#blocking_termsObject

GET /blocking_terms



27
28
29
30
31
32
33
34
35
# File 'app/controllers/policy_manager/user_terms_controller.rb', line 27

def blocking_terms
  respond_to do |format|
    format.html{ }
    format.json{ render json: PolicyManager::Config.rules
                                                   .select{|p| p.blocking }
                                                   .map(&:name) 
    }
  end
end

#pendingObject

GET /pending



18
19
20
21
22
23
24
# File 'app/controllers/policy_manager/user_terms_controller.rb', line 18

def pending
  @pending_policies = current_user.pending_policies
  respond_to do |format|
    format.html{ }
    format.json{ render json: @pending_policies }
  end
end

#rejectObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/policy_manager/user_terms_controller.rb', line 69

def reject
  @user_term = reject_term(@term)

  respond_to do |format|
    format.html{ 
      if @user_term.errors.any?
        redirect_to root_url , notice: "hey there are some errors! #{@user_term.errors.full_messages.join()}"
      else
        redirect_to root_url 
      end
    }
    format.js
    format.json{
      if @user_term.present? && @user_term.errors.any?
        render json: { url: root_url , notice: "hey there are some errors! #{@user_term.errors.full_messages.join()}" }
      else
        render json: {
          state: @user_term ? @user_term.state : cookies["policy_rule_#{@term.rule.name}"]
        }
      end
    }
  end
end

#showObject

GET /user_terms/1



13
14
15
# File 'app/controllers/policy_manager/user_terms_controller.rb', line 13

def show
  @user_term = current_user.present? ? current_user.handle_policy_for(@term) : UserTerm.new(term: @term, user: nil, state: cookies["policy_rule_#{@term.rule.name}"])
end