Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store cookie method #13

Merged
merged 3 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions app/models/policy_manager/concerns/user_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,12 @@ def can_request_portability?
self.portability_requests.select{|p| p.pending? || p.progress?}.blank?
end

def store_cookie(name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patriciojofre why call it store_cookie if it can apply to any rule ?
We could have a store_policy_RULE_NAME for every rule initialized in the user concern for example
What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the method naming, however I think we could avoid creating multiple methods and just just add the store_policy_from(name).
This is just a method that wraps the "current_user.handle_policy_for(@term)" with an extra logic were validates the presence of a published term.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the method accepts a term, we should name it as accept_policy_from

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 @michelson, create multiples methods for this little wrapper is not necessary.
I'll change the name to accept_policy_from 😄

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
2 changes: 1 addition & 1 deletion lib/policy_manager/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PolicyManager
VERSION = '0.2.2'
VERSION = '0.2.3'
end