From 519b93c01b251850e9af2a5194954ea2b4cbbd61 Mon Sep 17 00:00:00 2001 From: patriciojofre Date: Wed, 9 May 2018 11:46:26 -0300 Subject: [PATCH 1/3] missing store_cookie method --- app/models/policy_manager/concerns/user_behavior.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/policy_manager/concerns/user_behavior.rb b/app/models/policy_manager/concerns/user_behavior.rb index c4c4bb8..f8f46f3 100644 --- a/app/models/policy_manager/concerns/user_behavior.rb +++ b/app/models/policy_manager/concerns/user_behavior.rb @@ -130,4 +130,12 @@ def can_request_portability? self.portability_requests.select{|p| p.pending? || p.progress?}.blank? end + def store_cookie(name) + term = PolicyManager::Config.rules.find{|o| o.name == name}.terms.published.last + if term.present? + user_term = self.handle_policy_for(term) + user_term.accept! unless user_term.accepted? + end + end + end \ No newline at end of file From f5f40e99f600c956ba3c829740309f30b8c4f6c6 Mon Sep 17 00:00:00 2001 From: patriciojofre Date: Wed, 9 May 2018 11:53:47 -0300 Subject: [PATCH 2/3] readme updated --- README.md | 2 +- lib/policy_manager/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bef32c0..4f04b6e 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ When the policies are configured will generate some helper methods on User model **Use this in your controller:** ```ruby -@user.store_policy_cookie if cookies["policy_rule_cookie"] == "accepted" +@user.store_cookie("your_cookie") if cookies["policy_rule_your_cookie"] == "accepted" ``` + **validates_on:** will require users validation, will automagically create virtual attributes for the policy you set, so, if you set `age` in your config you must supply in your forms a `policy_rule_age` checkbox in your form, if you don't supply those then the user validation will return errors on `policy_rule_age` . Don't forget to add the fields in your strong params in the controller which handles the request. + **if:** you can add conditions as a Proc in order skip validations: diff --git a/lib/policy_manager/version.rb b/lib/policy_manager/version.rb index 6c9b96e..67c7aea 100644 --- a/lib/policy_manager/version.rb +++ b/lib/policy_manager/version.rb @@ -1,3 +1,3 @@ module PolicyManager - VERSION = '0.2.2' + VERSION = '0.2.3' end From fb9bc1ccbef7a85c9dac1999d3ae19b5ad8027cc Mon Sep 17 00:00:00 2001 From: patriciojofre Date: Wed, 9 May 2018 13:10:31 -0300 Subject: [PATCH 3/3] change name store_cookie to accept_policy_from --- README.md | 2 +- app/models/policy_manager/concerns/user_behavior.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4f04b6e..5ca1f19 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ When the policies are configured will generate some helper methods on User model **Use this in your controller:** ```ruby -@user.store_cookie("your_cookie") if cookies["policy_rule_your_cookie"] == "accepted" +@user.accept_policy_from("your_cookie") if cookies["policy_rule_your_cookie"] == "accepted" ``` + **validates_on:** will require users validation, will automagically create virtual attributes for the policy you set, so, if you set `age` in your config you must supply in your forms a `policy_rule_age` checkbox in your form, if you don't supply those then the user validation will return errors on `policy_rule_age` . Don't forget to add the fields in your strong params in the controller which handles the request. + **if:** you can add conditions as a Proc in order skip validations: diff --git a/app/models/policy_manager/concerns/user_behavior.rb b/app/models/policy_manager/concerns/user_behavior.rb index f8f46f3..e6b8ea9 100644 --- a/app/models/policy_manager/concerns/user_behavior.rb +++ b/app/models/policy_manager/concerns/user_behavior.rb @@ -130,7 +130,7 @@ def can_request_portability? self.portability_requests.select{|p| p.pending? || p.progress?}.blank? end - def store_cookie(name) + def accept_policy_from(name) term = PolicyManager::Config.rules.find{|o| o.name == name}.terms.published.last if term.present? user_term = self.handle_policy_for(term)