From 0370e0aa4089e5dd7432f64fbf62f8e64fd5f2ac Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:09:13 -0400 Subject: [PATCH 01/11] add custom controller for rendering adds image_tag helper --- .../policy_manager/exporter_controller.rb | 7 +++++ app/helpers/policy_manager/exporter_helper.rb | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 app/controllers/policy_manager/exporter_controller.rb create mode 100644 app/helpers/policy_manager/exporter_helper.rb diff --git a/app/controllers/policy_manager/exporter_controller.rb b/app/controllers/policy_manager/exporter_controller.rb new file mode 100644 index 0000000..55328b7 --- /dev/null +++ b/app/controllers/policy_manager/exporter_controller.rb @@ -0,0 +1,7 @@ +module PolicyManager + class ExporterController < ActionController::Base + + include ExporterHelper + + end +end \ No newline at end of file diff --git a/app/helpers/policy_manager/exporter_helper.rb b/app/helpers/policy_manager/exporter_helper.rb new file mode 100644 index 0000000..4d6b4f8 --- /dev/null +++ b/app/helpers/policy_manager/exporter_helper.rb @@ -0,0 +1,29 @@ +module PolicyManager + module ExporterHelper + + def image_tag(remote_image, opts={}) + begin + basename = File.basename(remote_image) + id = opts[:id] || SecureRandom.hex(10) + composed_name = [id, basename].compact.join("-") + path = "#{File.dirname(@base_path)}/#{composed_name}" + save_image(remote_image, path) + tag(:img, {src: "./#{id}-#{File.basename(URI(remote_image).path)}" }.merge(opts)) + rescue => e + Config.error_notifier_method(e) + content_tag(:p, "broken image") + end + end + + private + + def save_image(remote_image, path) + open(URI(path).path, 'wb') do |file| + file << open(remote_image).read + end + end + + end +end + + From 0a9289547cec00cfeda253eb8e6c07a27d5bcb97 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:10:31 -0400 Subject: [PATCH 02/11] handle error notifier presence --- lib/policy_manager/config.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/policy_manager/config.rb b/lib/policy_manager/config.rb index 7bb3d01..fb69d30 100644 --- a/lib/policy_manager/config.rb +++ b/lib/policy_manager/config.rb @@ -28,7 +28,8 @@ def self.setup end def self.error_notifier_method(error) - @@error_notifier.call(error) + puts error + @@error_notifier.call(error) unless @@error_notifier.blank? end def self.admin_email(user) From a62381ef03de7f81eed14bd2840d7b88627afb1e Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:11:23 -0400 Subject: [PATCH 03/11] json view --- lib/policy_manager.rb | 2 + lib/policy_manager/exporter/json_link.rb | 19 ++++++++++ lib/policy_manager/exporter/json_view.rb | 47 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/policy_manager/exporter/json_link.rb create mode 100644 lib/policy_manager/exporter/json_view.rb diff --git a/lib/policy_manager.rb b/lib/policy_manager.rb index b96a8b3..36b8f08 100644 --- a/lib/policy_manager.rb +++ b/lib/policy_manager.rb @@ -8,8 +8,10 @@ require "policy_manager/exporter" require "policy_manager/exporter/handler.rb" require "policy_manager/exporter/view.rb" +require "policy_manager/exporter/json_view.rb" require "policy_manager/exporter/zip_generator.rb" require "policy_manager/exporter/paginator_renderer.rb" +require "policy_manager/exporter/json_link.rb" require "policy_manager/config" diff --git a/lib/policy_manager/exporter/json_link.rb b/lib/policy_manager/exporter/json_link.rb new file mode 100644 index 0000000..1ee90cc --- /dev/null +++ b/lib/policy_manager/exporter/json_link.rb @@ -0,0 +1,19 @@ +module PolicyManager + class JsonLink + + def self.render(collection = nil) + ActionController::Base.helpers.content_tag(:a, "Open as JSON", href: link(collection), target: '_blank') + end + + private + + def self.link(collection) + if collection.nil? || collection.current_page == 1 + return "./data.json" + else + return "./../data.json" + end + end + + end +end \ No newline at end of file diff --git a/lib/policy_manager/exporter/json_view.rb b/lib/policy_manager/exporter/json_view.rb new file mode 100644 index 0000000..ea68ce9 --- /dev/null +++ b/lib/policy_manager/exporter/json_view.rb @@ -0,0 +1,47 @@ +require "fileutils" + +module PolicyManager + class JsonExporterView + attr_accessor :template, :folder, :assigns + + def initialize(vars={}, options) + self.folder = options[:folder] + self.assigns = options[:assigns] + @template = options.fetch(:template) #, self.class.template) + return self + end + + def save + render_json + end + + def save_json(file, data) + File.open(file, "w") do |f| + f.write(data) + end + end + + def render_json + ac = ActionController::Base.new() + options = handled_template.merge!({assigns: self.assigns }) + content = ac.render_to_string(options) + save_json("#{folder}/data.json", content) + end + + def handled_template + begin + if URI.parse(@template) + return {template: @template} + end + rescue URI::InvalidURIError + end + + if @template.is_a?(String) + return {inline: @template} + elsif @template.is_a?(Pathname) + return {file: @template } + end + end + + end +end \ No newline at end of file From 421f066b9d4873e55b4da25ad7420ede83a319bd Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:11:35 -0400 Subject: [PATCH 04/11] handler exports html & json --- lib/policy_manager/exporter/handler.rb | 67 ++++++++++++++++++++------ 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/lib/policy_manager/exporter/handler.rb b/lib/policy_manager/exporter/handler.rb index 50de2de..a429202 100644 --- a/lib/policy_manager/exporter/handler.rb +++ b/lib/policy_manager/exporter/handler.rb @@ -66,37 +66,72 @@ def render_member(rule) return unless resource.respond_to?(:portability_member_for) o = resource.portability_member_for(rule) base_dir = self.base_path.join(rule.name) - resource_path = base_dir.join("index.html") FileUtils.mkdir_p(base_dir) - view = ExporterView.new({member: o}, {build_path: self.base_path, base_path: resource_path, template: rule.template, rule: rule}) + resource_path = base_dir.join("index.html") + + view = ExporterView.new({ + assigns: {member: o}, + build_path: self.base_path, + base_path: resource_path, + template: rule.template, + rule: rule + }).save(resource_path) + puts "saving at #{self.path.join rule.name}" - view.save(resource_path ) + + json = JsonExporterView.new({ + assigns: {member: o}, + template: rule.json_template, + folder: base_dir + }).save if rule.json_template.present? end def render_collection(rule) return unless resource.respond_to?(:portability_collection_for) - o = resource.portability_collection_for(rule ,1) - + o = resource.portability_collection_for(rule, 1) + + base_dir = self.base_path.join(rule.name) + FileUtils.mkdir_p(base_dir) + (1..o.total_pages).to_a.each do |i| - o = resource.portability_collection_for(rule,i) - page_name = i #== 1 ? "index" : i - base_dir = self.base_path.join(rule.name) - base_dir = base_dir.join(page_name.to_s) unless page_name == 1 - FileUtils.mkdir_p(base_dir) - resource_path = base_dir.join("index.html") - view = ExporterView.new({collection: o}, {build_path: self.base_path, base_path: resource_path, template: rule.template, rule: rule}) + o = resource.portability_collection_for(rule, i) + + page_name = i + folder_dir = page_name == 1 ? base_dir : base_dir.join(page_name.to_s) + FileUtils.mkdir_p(folder_dir) + resource_path = folder_dir.join("index.html") + + view = ExporterView.new({ + assigns: {collection: o} , + build_path: self.base_path, + base_path: resource_path, + template: rule.template, + rule: rule + }).save(resource_path) + + + json = JsonExporterView.new({ + assigns: {collection: o}, + template: rule.json_template, + folder: folder_dir + }).save if rule.json_template.present? + puts "saving at #{self.path.join rule.name}" - view.save( resource_path ) end end def render_index resource_path = self.base_path.join("index.html") template = PolicyManager::Config.exporter.index_template - view = ExporterView.new({collection: PolicyManager::Config.portability_rules}, - {build_path: self.base_path, base_path: resource_path, template: template}) + view = ExporterView.new({ + assigns: { + collection: PolicyManager::Config.portability_rules + }, + build_path: self.base_path, + base_path: resource_path, + template: template + }).save( resource_path ) puts "saving at #{resource_path}" - view.save( resource_path ) end def generate_zip From b8f80c06f243bf142963e0aef06989c59ded1a39 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:11:46 -0400 Subject: [PATCH 05/11] will paginate array support --- lib/policy_manager/exporter/paginator_renderer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/policy_manager/exporter/paginator_renderer.rb b/lib/policy_manager/exporter/paginator_renderer.rb index 4177a97..20905f1 100644 --- a/lib/policy_manager/exporter/paginator_renderer.rb +++ b/lib/policy_manager/exporter/paginator_renderer.rb @@ -1,5 +1,6 @@ require "will_paginate" require 'will_paginate/view_helpers/action_view' +require 'will_paginate/array' module PolicyManager class PaginatorRenderer < WillPaginate::ActionView::LinkRenderer From f5b7b9cace48a79f4b9c8fe143664cb7c915ec14 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:12:13 -0400 Subject: [PATCH 06/11] exporter view refactor, action view rendering --- lib/policy_manager/exporter/view.rb | 72 ++++++++++------------------- 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/lib/policy_manager/exporter/view.rb b/lib/policy_manager/exporter/view.rb index 5efb911..e1aa574 100644 --- a/lib/policy_manager/exporter/view.rb +++ b/lib/policy_manager/exporter/view.rb @@ -14,22 +14,19 @@ class ExporterView include WillPaginate::ViewHelpers #if defined?(WillPaginate) include WillPaginate::ActionView #if defined?(WillPaginate) - attr_accessor :template, :base_path + attr_accessor :template, :base_path, :assigns def self.template "Welcome, <%= @name %>" end - def initialize(vars={}, options={}, date=Time.now) - # collection or member, or wathever!? - vars.each{|k, v| self.instance_variable_set("@#{k}", v)} + def initialize(options={}, date=Time.now) @base_path = options[:base_path] @build_path = options[:build_path] - + self.assigns = options[:assigns] index_path - @template = options.fetch(:template, self.class.template) - + return self end def index_path @@ -47,60 +44,39 @@ def index_path end end - def image_tag(remote_image, opts={}) - begin - basename = File.basename(remote_image) - id = opts[:id] || SecureRandom.hex(10) - composed_name = [id, basename].compact.join("-") - path = "#{File.dirname(base_path)}/#{composed_name}" - self.save_image(remote_image, path) - tag(:img, {src: "./#{id}-#{File.basename(URI(remote_image).path)}" }.merge(opts)) - rescue => e - Config.error_notifier_method(e) - content_tag(:p, "broken image") - end - end - - def save_image(remote_image, path) - open(URI(path).path, 'wb') do |file| - file << open(remote_image).read - end - end - def render() - #template_layout = Tilt::ERBTemplate.new {PolicyManager::Config.exporter.layout} context = self - #template_layout.render { - # view = Tilt::ERBTemplate.new{handled_template} - # view.render(context) - #} - - render_with_layout() - end - - def render_with_layout(context = self) - render_layout do - ERB.new(handled_template).result(binding) - end - end - - def render_layout - layout = PolicyManager::Config.exporter.layout #File.read('views/layouts/app.html.erb') - ERB.new(layout).result(binding) + ac = PolicyManager::ExporterController.new() + options = handled_template.merge!({ + assigns: self.assigns.merge!({ + base_path: base_path, + build_path: @build_path, + index_path: index_path + }), + layout: PolicyManager::Config.exporter.layout + }) + ac.render_to_string(options) end - def save(file) File.open(file, "w+") do |f| f.write(render) end end + # TODO: method duplicated from json def handled_template + begin + if URI.parse(@template) + return {template: @template} + end + rescue URI::InvalidURIError + end + if @template.is_a?(String) - @template + return {inline: @template} elsif @template.is_a?(Pathname) - File.open(@template).read + return {file: @template } end end From 7532ef052b90482781e34e507e32f6038b23ba76 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:12:33 -0400 Subject: [PATCH 07/11] json template config on portability rule --- lib/policy_manager/portability_rule.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/policy_manager/portability_rule.rb b/lib/policy_manager/portability_rule.rb index ac9d0ac..bd3aafc 100644 --- a/lib/policy_manager/portability_rule.rb +++ b/lib/policy_manager/portability_rule.rb @@ -1,6 +1,13 @@ module PolicyManager class PortabilityRule - attr_accessor :name, :methods, :formats, :per, :collection, :member, :template + attr_accessor :name, + :methods, + :formats, + :per, + :collection, + :member, + :template, + :json_template def initialize(opts={}) self.collection = opts[:collection] @@ -9,6 +16,7 @@ def initialize(opts={}) self.name = opts[:name] self.formats = opts[:formats] self.template = opts[:template] + self.json_template = opts[:json_template] end end From 640c078c2695eac2ba6a5c09733ab23ee4d48fb6 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:13:15 -0400 Subject: [PATCH 08/11] test templates --- test/dummy/app/views/collection.json.jbuilder | 11 +++++++++++ test/dummy/app/views/layouts/portability.erb | 15 +++++++++++++++ .../app/views/layouts/portability_requests.erb | 14 ++++++++++++++ test/dummy/app/views/template.haml | 1 + test/dummy/app/views/template.json.jbuilder | 16 ++++++++++++++++ test/dummy/app/views/test.erb | 2 ++ 6 files changed, 59 insertions(+) create mode 100644 test/dummy/app/views/collection.json.jbuilder create mode 100644 test/dummy/app/views/layouts/portability.erb create mode 100644 test/dummy/app/views/layouts/portability_requests.erb create mode 100644 test/dummy/app/views/template.haml create mode 100644 test/dummy/app/views/template.json.jbuilder create mode 100644 test/dummy/app/views/test.erb diff --git a/test/dummy/app/views/collection.json.jbuilder b/test/dummy/app/views/collection.json.jbuilder new file mode 100644 index 0000000..1b834f9 --- /dev/null +++ b/test/dummy/app/views/collection.json.jbuilder @@ -0,0 +1,11 @@ +json.collection @collection do |j| + json.id j.id +end + +json.meta do + json.current_page( @collection.current_page ) + json.next_page( @collection.next_page ) + json.prev_page( @collection.previous_page ) + json.total_pages( @collection.total_pages) + json.total_count( @collection.total_entries) +end \ No newline at end of file diff --git a/test/dummy/app/views/layouts/portability.erb b/test/dummy/app/views/layouts/portability.erb new file mode 100644 index 0000000..f86a7ac --- /dev/null +++ b/test/dummy/app/views/layouts/portability.erb @@ -0,0 +1,15 @@ + + + + + +

layout header

+
+ <%= yield %> +
+
layout footer
+ + + + + \ No newline at end of file diff --git a/test/dummy/app/views/layouts/portability_requests.erb b/test/dummy/app/views/layouts/portability_requests.erb new file mode 100644 index 0000000..8147646 --- /dev/null +++ b/test/dummy/app/views/layouts/portability_requests.erb @@ -0,0 +1,14 @@ + +<%= @build_path %> +
+<%= @base_path %> +
+<%= @index_path %> +
+<% PolicyManager::Config.portability_rules.each do |rule| %> +
  • <%= link_to rule.name, "#{@index_path}#{rule.name}/index.html" %>
  • +<% end %> +

    layout header

    +<%= yield %> +
    layout footer
    + \ No newline at end of file diff --git a/test/dummy/app/views/template.haml b/test/dummy/app/views/template.haml new file mode 100644 index 0000000..4e9b278 --- /dev/null +++ b/test/dummy/app/views/template.haml @@ -0,0 +1 @@ += @collection.to_json diff --git a/test/dummy/app/views/template.json.jbuilder b/test/dummy/app/views/template.json.jbuilder new file mode 100644 index 0000000..1c585b7 --- /dev/null +++ b/test/dummy/app/views/template.json.jbuilder @@ -0,0 +1,16 @@ + +json.collection @collection do |j| + json.id j.id + json.name j.name + json.info j.info + json.info2 j.info2 + json.created_at j.created_at + end + + json.meta do + json.current_page( @collection.current_page ) + json.next_page( @collection.next_page ) + json.prev_page( @collection.prev_page ) + json.total_pages( @collection.total_pages) + json.total_count( @collection.total_count) + end \ No newline at end of file diff --git a/test/dummy/app/views/test.erb b/test/dummy/app/views/test.erb new file mode 100644 index 0000000..bf117e0 --- /dev/null +++ b/test/dummy/app/views/test.erb @@ -0,0 +1,2 @@ +<% binding.pry %> +<%= @collection.to_json %> From e09bdd1a487a2699475f6b30d6c74af4c9abf8a3 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 19:21:09 -0400 Subject: [PATCH 09/11] readme notes & exporter tests --- Gemfile | 2 ++ README.md | 10 ++++++---- .../policy_manager/concerns/user_behavior.rb | 8 +++----- test/models/policy_manager/exporter_test.rb | 17 ++--------------- .../policy_manager/portability_request_test.rb | 15 +-------------- test/models/policy_manager/user_test.rb | 6 +----- 6 files changed, 15 insertions(+), 43 deletions(-) diff --git a/Gemfile b/Gemfile index 08f0319..0071077 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,8 @@ gem 'mysql2' # To use a debugger gem 'pry-byebug', group: [:development, :test] gem 'puma' +gem 'haml' +gem 'jbuilder' # Added at 2018-04-02 12:15:56 -0300 by michelson: gem "capybara", "~> 2.18" diff --git a/README.md b/README.md index 5ca1f19..1cd9637 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ PolicyManager (Aka GDPR RAILS) was created with flexibility in mind to comply wi + JSON endpoints to handle pending policies and portability logic in order to be implemented in *client only* interfaces, ie: frontend apps like React, Vue, Backbone, you name it. #### Portability -Portability module lets you define export options, that will generate a navigable static site with all the data you've defined in the **portability rules** +Portability module lets you define export options, that will generate a navigable static HTML site with all the data you've defined in the **portability rules** with json support too. + Seamless data export with configurable templates + Configurable Mailer templates for progress & download completion + Downloads images to the local filesystem in order to comply with GDPR requirements on data accessibility. @@ -134,7 +134,7 @@ When the policies are configured will generate some helper methods on User model **Use this in your controller:** ```ruby -@user.accept_policy_from("your_cookie") if cookies["policy_rule_your_cookie"] == "accepted" +@user.store_policy_cookie if cookies["policy_rule_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: @@ -210,8 +210,8 @@ Export option & Portability rules will allow you to set up how and which data yo #### Exporter: + **path**: where the folder will be generated, usually can be set on /tmp, this will need a pathname, like `Rails.root.join("tmp/export")` + **resource**: which model , ie: `User` -+ **index_template**: The first page. defaults to a simple ul li list of links tied to your rules, this expects a Pathname or a String with yout template -+ **layout**: A layout template to wrap the static site, this expects a Pathname or a String with your template ++ **index_template**: The first page. defaults to a simple ul li list of links tied to your rules, this expects a Pathname or a String with your template ++ **layout**: A layout template this expects a layout name which has to be available on your app. + **after_zip**: a callback to handle the zip file on the resource, something like: ```ruby after_zip: ->(zip_path, resource){ @@ -245,6 +245,8 @@ PolicyManager::Config.setup do |c| name: "exportable_data", collection: :articles, template: "hello, a collection will be rendered here use @collection.to_json", + json_template: "collection.json.jbuilder", # or Rails.root.join("app/views/collection.json.jbuilder") + per: 10 }) diff --git a/app/models/policy_manager/concerns/user_behavior.rb b/app/models/policy_manager/concerns/user_behavior.rb index fb8f1d3..44905e1 100644 --- a/app/models/policy_manager/concerns/user_behavior.rb +++ b/app/models/policy_manager/concerns/user_behavior.rb @@ -65,11 +65,9 @@ def portability_member_for(rule) self.send(rule.member) end - def portability_collection_for(rule, page) - # if kaminari - # self.send(rule.collection).page(1) - # if will paginate - self.send(rule.collection).paginate(page: page, per_page: rule.per) + def portability_collection_for(rule, page = nil) + collection = self.send(rule.collection) + .paginate(page: page, per_page: rule.per) end def pending_policies diff --git a/test/models/policy_manager/exporter_test.rb b/test/models/policy_manager/exporter_test.rb index e3df8d3..897a00b 100644 --- a/test/models/policy_manager/exporter_test.rb +++ b/test/models/policy_manager/exporter_test.rb @@ -19,21 +19,7 @@ def setup
  • <%= link_to rule.name, "./#{rule.name}/index.html" %>
  • <% end %> ', - layout: ' - - - - -

    layout header

    -
    - <%= yield %> -
    -
    layout footer
    - - - - - ', + layout: 'portability', after_zip: ->(o, r){ puts "THIS IS GREAT #{o} was zipped, now what ??" } } @@ -48,6 +34,7 @@ def setup <% end %> <%= will_paginate(@collection, renderer: PolicyManager::PaginatorRenderer) %>", + json_template: Rails.root.join("app/views/collection.json.jbuilder"), per: 10 }) diff --git a/test/models/policy_manager/portability_request_test.rb b/test/models/policy_manager/portability_request_test.rb index e83a29e..e1dae03 100644 --- a/test/models/policy_manager/portability_request_test.rb +++ b/test/models/policy_manager/portability_request_test.rb @@ -21,20 +21,7 @@ def setup
  • <%= link_to rule.name, "./#{rule.name}/index.html" %>
  • <% end %> ', - layout: ' - <%= @build_path %> -
    - <%= @base_path %> -
    - <%= @index_path %> -
    - <% PolicyManager::Config.portability_rules.each do |rule| %> -
  • <%= link_to rule.name, "#{@index_path}#{rule.name}/index.html" %>
  • - <% end %> -

    layout header

    - <%= yield %> -
    layout footer
    - ', + layout: 'portability_requests', after_zip: ->(zip_path, resource){ puts "THIS IS GREAT #{zip_path} was zipped, now what ??" } diff --git a/test/models/policy_manager/user_test.rb b/test/models/policy_manager/user_test.rb index eb703ef..13626d6 100644 --- a/test/models/policy_manager/user_test.rb +++ b/test/models/policy_manager/user_test.rb @@ -18,11 +18,7 @@ def setup
  • <%= link_to rule.name, "./#{rule.name}/index.html" %>
  • <% end %> ', - layout: " -

    layout header

    - <%= yield %> -
    layout footer
    - ", + layout: "portability", after_zip: ->(zip_path, resource){ puts "THIS IS GREAT #{zip_path} was zipped, now what ??" } From e7e6495fa0cbc76763f5a8a31199804985a68dc5 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 20:42:24 -0400 Subject: [PATCH 10/11] user concern method format + readme notes --- README.md | 2 +- app/models/policy_manager/concerns/user_behavior.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1cd9637..2eac875 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.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 44905e1..c74a990 100644 --- a/app/models/policy_manager/concerns/user_behavior.rb +++ b/app/models/policy_manager/concerns/user_behavior.rb @@ -66,8 +66,7 @@ def portability_member_for(rule) end def portability_collection_for(rule, page = nil) - collection = self.send(rule.collection) - .paginate(page: page, per_page: rule.per) + self.send(rule.collection).paginate(page: page, per_page: rule.per) end def pending_policies From bbc9a86fd64d8d6bf18014497cda89db61eb8974 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Date: Mon, 14 May 2018 20:46:18 -0400 Subject: [PATCH 11/11] use PolicyManager::ExporterController on exporter json view --- lib/policy_manager/exporter/json_view.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/policy_manager/exporter/json_view.rb b/lib/policy_manager/exporter/json_view.rb index ea68ce9..8681adb 100644 --- a/lib/policy_manager/exporter/json_view.rb +++ b/lib/policy_manager/exporter/json_view.rb @@ -22,7 +22,7 @@ def save_json(file, data) end def render_json - ac = ActionController::Base.new() + ac = PolicyManager::ExporterController.new() options = handled_template.merge!({assigns: self.assigns }) content = ac.render_to_string(options) save_json("#{folder}/data.json", content)