gdpr_rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +270 -13
- data/app/assets/javascripts/policy_manager/application.js +4 -0
- data/app/assets/javascripts/policy_manager/portability_requests.js +2 -0
- data/app/assets/javascripts/policy_manager/user_portability_requests.js +2 -0
- data/app/assets/stylesheets/policy_manager/portability_requests.css +4 -0
- data/app/assets/stylesheets/policy_manager/user_portability_requests.css +4 -0
- data/app/controllers/policy_manager/application_controller.rb +22 -0
- data/app/controllers/policy_manager/categories_controller.rb +5 -47
- data/app/controllers/policy_manager/portability_requests_controller.rb +34 -0
- data/app/controllers/policy_manager/terms_controller.rb +16 -13
- data/app/controllers/policy_manager/user_portability_requests_controller.rb +41 -0
- data/app/controllers/policy_manager/user_terms_controller.rb +68 -28
- data/app/helpers/policy_manager/application_helper.rb +28 -0
- data/app/helpers/policy_manager/portability_requests_helper.rb +4 -0
- data/app/helpers/policy_manager/scripts_helper.rb +11 -0
- data/app/helpers/policy_manager/terms_helper.rb +1 -1
- data/app/helpers/policy_manager/user_portability_requests_helper.rb +4 -0
- data/app/jobs/policy_manager/exporter_job.rb +10 -0
- data/app/mailers/policy_manager/application_mailer.rb +20 -2
- data/app/mailers/policy_manager/portability_mailer.rb +34 -0
- data/app/models/policy_manager/concerns/user_behavior.rb +80 -22
- data/app/models/policy_manager/portability_request.rb +65 -0
- data/app/models/policy_manager/term.rb +18 -0
- data/app/models/policy_manager/user_term.rb +14 -7
- data/app/views/layouts/policy_manager/application.html.erb +41 -39
- data/app/views/layouts/policy_manager/mailer.html.erb +13 -0
- data/app/views/layouts/policy_manager/mailer.text.erb +1 -0
- data/app/views/policy_manager/categories/index.html.erb +6 -12
- data/app/views/policy_manager/categories/show.html.erb +13 -20
- data/app/views/policy_manager/portability_mailer/completed_notification.erb +7 -0
- data/app/views/policy_manager/portability_mailer/progress_notification.erb +3 -0
- data/app/views/policy_manager/portability_requests/index.html.erb +42 -0
- data/app/views/policy_manager/portability_requests/index.json.jbuilder +5 -0
- data/app/views/policy_manager/terms/_form.html.erb +12 -11
- data/app/views/policy_manager/terms/edit.html.erb +6 -4
- data/app/views/policy_manager/terms/index.html.erb +12 -13
- data/app/views/policy_manager/terms/new.html.erb +5 -3
- data/app/views/policy_manager/terms/show.html.erb +12 -10
- data/app/views/policy_manager/user_portability_requests/index.html.erb +42 -0
- data/app/views/policy_manager/user_portability_requests/index.json.jbuilder +5 -0
- data/app/views/policy_manager/user_terms/pending.html.erb +10 -6
- data/app/views/policy_manager/user_terms/show.html.erb +7 -8
- data/app/views/policy_manager/user_terms/show.json.jbuilder +15 -8
- data/config/locales/en.yml +122 -0
- data/config/locales/es.yml +122 -0
- data/config/routes.rb +15 -6
- data/db/migrate/20180326193825_create_policy_manager_terms.rb +1 -0
- data/db/migrate/20180410171354_create_policy_manager_portability_requests.rb +18 -0
- data/lib/policy_manager/anonimizer.rb +18 -0
- data/lib/policy_manager/config.rb +35 -1
- data/lib/policy_manager/exporter/handler.rb +110 -0
- data/lib/policy_manager/exporter/paginator_renderer.rb +74 -0
- data/lib/policy_manager/exporter/view.rb +108 -0
- data/lib/policy_manager/exporter/zip_generator.rb +60 -0
- data/lib/policy_manager/exporter.rb +75 -0
- data/lib/policy_manager/portability_rule.rb +15 -0
- data/lib/policy_manager/rule.rb +21 -4
- data/lib/policy_manager/script.rb +56 -0
- data/lib/policy_manager/templates/index.html.erb +1 -0
- data/lib/policy_manager/version.rb +1 -1
- data/lib/policy_manager.rb +10 -0
- metadata +160 -19
- data/app/controllers/policy_manager/dashboard_controller.rb +0 -6
- data/app/helpers/policy_manager/categories_helper.rb +0 -4
- data/app/helpers/policy_manager/dashboard_helper.rb +0 -4
- data/app/helpers/policy_manager/terms_categories_helper.rb +0 -4
- data/app/views/policy_manager/categories/_form.html.erb +0 -22
- data/app/views/policy_manager/categories/edit.html.erb +0 -6
- data/app/views/policy_manager/categories/new.html.erb +0 -5
- data/app/views/policy_manager/dashboard/index.erb +0 -33
- data/app/views/policy_manager/terms_categories/_form.html.erb +0 -17
- data/app/views/policy_manager/terms_categories/edit.html.erb +0 -6
- data/app/views/policy_manager/terms_categories/index.html.erb +0 -24
- data/app/views/policy_manager/terms_categories/new.html.erb +0 -5
- data/app/views/policy_manager/terms_categories/show.html.erb +0 -4
- data/app/views/policy_manager/user_terms/_form.html.erb +0 -17
- data/app/views/policy_manager/user_terms/edit.html.erb +0 -6
- data/app/views/policy_manager/user_terms/index.html.erb +0 -24
- data/app/views/policy_manager/user_terms/new.html.erb +0 -5
@@ -0,0 +1,122 @@
|
|
1
|
+
es:
|
2
|
+
terms_app:
|
3
|
+
title: PolicyManager
|
4
|
+
sub_title: PolicyManager
|
5
|
+
sign_out: Salir
|
6
|
+
menu:
|
7
|
+
policies: Políticas
|
8
|
+
portability_requests: Solicitudes de portabilidad
|
9
|
+
user_portability_requests: Mis solicitudes de portabilidad
|
10
|
+
user_pending_policies: Mis políticas pendientes
|
11
|
+
misc:
|
12
|
+
back: Atras
|
13
|
+
edit: Editar
|
14
|
+
show: Ver
|
15
|
+
save: Guardar
|
16
|
+
download: Descargar
|
17
|
+
are_you_sure: ¿Estás seguro?
|
18
|
+
states:
|
19
|
+
draft: Borrador
|
20
|
+
published: Publicado
|
21
|
+
categories:
|
22
|
+
index:
|
23
|
+
title: Políticas
|
24
|
+
table:
|
25
|
+
name: Nombre
|
26
|
+
terms: Términos
|
27
|
+
show: Ver
|
28
|
+
show:
|
29
|
+
title: "Términos de política %{name}"
|
30
|
+
new: Nuevo término
|
31
|
+
table:
|
32
|
+
id: Id
|
33
|
+
content: Contenido
|
34
|
+
state: Estado
|
35
|
+
updated_at: Fecha de actualización
|
36
|
+
show: Ver
|
37
|
+
terms:
|
38
|
+
index:
|
39
|
+
title: Términos
|
40
|
+
button: Nuevo término
|
41
|
+
table:
|
42
|
+
description: Descripción
|
43
|
+
category: Politica
|
44
|
+
updated_at: Fecha de actualización
|
45
|
+
show: Ver
|
46
|
+
edit: Editar
|
47
|
+
destroy: Eliminar
|
48
|
+
new:
|
49
|
+
title: Nuevo término para %{name}
|
50
|
+
state: Estado
|
51
|
+
description: Descripción
|
52
|
+
button: Crear término
|
53
|
+
error: al guardar término
|
54
|
+
created: Término creado correctamente
|
55
|
+
updated: Término actualizado correctamente
|
56
|
+
destroyed: Término eliminado correctamente
|
57
|
+
edit:
|
58
|
+
title: Editar término %{name}
|
59
|
+
state: Estado
|
60
|
+
description: Descripción
|
61
|
+
error: al guardar término
|
62
|
+
show:
|
63
|
+
title: Término
|
64
|
+
last_update: Última actualización
|
65
|
+
table:
|
66
|
+
name: Nombre
|
67
|
+
terms: Términos
|
68
|
+
show: Ver
|
69
|
+
user_terms:
|
70
|
+
pending:
|
71
|
+
title: Mis politicas pendientes de aceptar
|
72
|
+
empty: No existen politicas por aceptar
|
73
|
+
show:
|
74
|
+
accepted:
|
75
|
+
message: Esta politica ya ha sido aceptada
|
76
|
+
question: ¿Deseas cambiar tu elección?
|
77
|
+
reject: Rechazar
|
78
|
+
not_now: No por ahora
|
79
|
+
pending:
|
80
|
+
message: por favor acepta esta politica
|
81
|
+
agree: Acepto
|
82
|
+
not_now: No por ahora
|
83
|
+
user_portability_requests:
|
84
|
+
index:
|
85
|
+
title: Mis solicitudes de portabilidad
|
86
|
+
empty: No existen solicitudes de portabilidad
|
87
|
+
table:
|
88
|
+
state: Estado
|
89
|
+
file: Archivo
|
90
|
+
created_at: Fecha de creación
|
91
|
+
destroy: Eliminar
|
92
|
+
button: Solicitar portabilidad
|
93
|
+
states:
|
94
|
+
pending: Pendiente
|
95
|
+
progress: En progreso
|
96
|
+
completed: Completado
|
97
|
+
has_pending: Tienes una solicitud de información pendiente, no puedes hacer otra aún
|
98
|
+
created: Petición de Datos Iniciada!
|
99
|
+
portability_requests:
|
100
|
+
index:
|
101
|
+
title: Solicitudes pendientes
|
102
|
+
destroyed: Solicitud eliminada exitosamente.
|
103
|
+
empty: No existen solicitudes por revisar
|
104
|
+
table:
|
105
|
+
user: Usuario
|
106
|
+
state: Estado
|
107
|
+
created_at: Fecha de creación
|
108
|
+
destroy: Eliminar
|
109
|
+
confirm: Confirmar
|
110
|
+
states:
|
111
|
+
pending: Pendiente
|
112
|
+
progress: En progreso
|
113
|
+
completed: Completado
|
114
|
+
mails:
|
115
|
+
progress:
|
116
|
+
subject: Tu información esta siendo descargada
|
117
|
+
completed:
|
118
|
+
subject: Tu información está disponible
|
119
|
+
will_paginate:
|
120
|
+
previous_label: "<"
|
121
|
+
next_label: ">"
|
122
|
+
page_gap: "…"
|
data/config/routes.rb
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
PolicyManager::Engine.routes.draw do
|
2
2
|
|
3
|
-
resources :
|
3
|
+
resources :user_portability_requests, only: [:index, :create, :destroy]
|
4
|
+
|
5
|
+
resources :portability_requests, only: [:index, :destroy] do
|
6
|
+
member do
|
7
|
+
get :confirm
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
resources :categories, only: [:show, :index] do
|
4
12
|
resources :terms
|
5
13
|
end
|
6
|
-
|
7
|
-
resources :user_terms do
|
14
|
+
|
15
|
+
resources :user_terms, only: [:show] do
|
8
16
|
collection do
|
9
17
|
get :pending
|
18
|
+
put :accept_multiples
|
19
|
+
get :blocking_terms
|
10
20
|
end
|
11
21
|
|
12
22
|
member do
|
@@ -14,7 +24,6 @@ PolicyManager::Engine.routes.draw do
|
|
14
24
|
put :reject
|
15
25
|
end
|
16
26
|
end
|
17
|
-
|
18
|
-
root '
|
19
|
-
|
27
|
+
|
28
|
+
root 'categories#index'
|
20
29
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreatePolicyManagerPortabilityRequests < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :policy_manager_portability_requests do |t|
|
4
|
+
#t.references :user, foreign_key: true
|
5
|
+
t.integer :user_id, index: true
|
6
|
+
t.string :state
|
7
|
+
t.string :attachment
|
8
|
+
t.string :attachment_file_name
|
9
|
+
t.string :attachment_file_size
|
10
|
+
t.datetime :attachment_content_type
|
11
|
+
t.string :attachment_file_content_type
|
12
|
+
|
13
|
+
t.datetime :expire_at
|
14
|
+
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
#c.anonimizer do |a|
|
3
|
+
# c.secret_key = "oeoeo123eoeo"
|
4
|
+
# c.encryptor = :sha512
|
5
|
+
# c.rule(on: User, fields: [:email])
|
6
|
+
#end
|
7
|
+
|
8
|
+
|
9
|
+
module PolicyManager
|
10
|
+
class Anonimizer
|
11
|
+
attr_accessor :secret_key, :encryptor, :rules
|
12
|
+
|
13
|
+
def initialize(opts={})
|
14
|
+
self.path = opts[:path]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -1,19 +1,53 @@
|
|
1
1
|
module PolicyManager
|
2
2
|
class Config
|
3
3
|
|
4
|
+
mattr_accessor :exporter,
|
5
|
+
:from_email,
|
6
|
+
:is_admin_method,
|
7
|
+
:logout_url,
|
8
|
+
:user_language_method,
|
9
|
+
:scripts
|
10
|
+
|
4
11
|
def self.setup
|
5
12
|
@@rules = []
|
13
|
+
@@portability_rules = []
|
14
|
+
@@portability_templates = []
|
15
|
+
@@scripts = []
|
6
16
|
yield self
|
7
17
|
self
|
8
18
|
end
|
9
19
|
|
20
|
+
def self.exporter=(opts)
|
21
|
+
@@exporter = Exporter.new(opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.is_admin?(user)
|
25
|
+
@@is_admin_method.call(user)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.user_language(user)
|
29
|
+
@@user_language_method.call(user) rescue :en
|
30
|
+
end
|
31
|
+
|
10
32
|
def self.rules
|
11
|
-
@@rules
|
33
|
+
@@rules ||= []
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.portability_rules
|
37
|
+
@@portability_rules ||= []
|
12
38
|
end
|
13
39
|
|
14
40
|
def self.add_rule(opts={}, &block)
|
15
41
|
@@rules << PolicyManager::Rule.new(opts, &block)
|
16
42
|
end
|
17
43
|
|
44
|
+
def self.add_portability_rule(opts={}, &block)
|
45
|
+
@@portability_rules << PolicyManager::PortabilityRule.new(opts, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.add_script(opts={}, &block)
|
49
|
+
@@scripts << PolicyManager::Script.new(opts, &block)
|
50
|
+
end
|
51
|
+
|
18
52
|
end
|
19
53
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require 'zip'
|
3
|
+
|
4
|
+
module PolicyManager
|
5
|
+
class ExporterHandler
|
6
|
+
attr_accessor :resource, :path, :after_zip
|
7
|
+
|
8
|
+
def initialize(opts={})
|
9
|
+
self.path = opts[:path]
|
10
|
+
self.resource = opts[:resource]
|
11
|
+
self.after_zip = opts[:after_zip] if opts[:after_zip]
|
12
|
+
end
|
13
|
+
|
14
|
+
def base_path
|
15
|
+
self.path.join resource.id.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def zip_path
|
19
|
+
"#{base_path}-out.zip"
|
20
|
+
end
|
21
|
+
|
22
|
+
def perform
|
23
|
+
FileUtils.mkdir_p(base_path)
|
24
|
+
create_sections
|
25
|
+
generate_zip
|
26
|
+
handle_zip_upload
|
27
|
+
after_zip.call(zip_path, resource)
|
28
|
+
clear!
|
29
|
+
end
|
30
|
+
|
31
|
+
def handle_zip_upload
|
32
|
+
resource
|
33
|
+
.portability_requests
|
34
|
+
.find_by(state: "progress")
|
35
|
+
.update_attributes(file_remote_url: zip_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def clear!
|
39
|
+
FileUtils.rm_rf(base_path)
|
40
|
+
FileUtils.rm_rf(zip_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_sections
|
44
|
+
PolicyManager::Config.portability_rules.each do |rule|
|
45
|
+
handle_render_for(rule)
|
46
|
+
end
|
47
|
+
|
48
|
+
render_index
|
49
|
+
puts "FOLDER CREATED AT #{base_path}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def handle_render_for(rule)
|
53
|
+
if rule.member
|
54
|
+
render_member(rule)
|
55
|
+
end
|
56
|
+
|
57
|
+
if rule.collection
|
58
|
+
render_collection(rule)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def base_dir
|
63
|
+
end
|
64
|
+
|
65
|
+
def render_member(rule)
|
66
|
+
return unless resource.respond_to?(:portability_member_for)
|
67
|
+
o = resource.portability_member_for(rule)
|
68
|
+
base_dir = self.base_path.join(rule.name)
|
69
|
+
resource_path = base_dir.join("index.html")
|
70
|
+
FileUtils.mkdir_p(base_dir)
|
71
|
+
view = ExporterView.new({member: o}, {build_path: self.base_path, base_path: resource_path, template: rule.template, rule: rule})
|
72
|
+
puts "saving at #{self.path.join rule.name}"
|
73
|
+
view.save(resource_path )
|
74
|
+
end
|
75
|
+
|
76
|
+
def render_collection(rule)
|
77
|
+
return unless resource.respond_to?(:portability_collection_for)
|
78
|
+
o = resource.portability_collection_for(rule ,1)
|
79
|
+
|
80
|
+
(1..o.total_pages).to_a.each do |i|
|
81
|
+
o = resource.portability_collection_for(rule,i)
|
82
|
+
page_name = i #== 1 ? "index" : i
|
83
|
+
base_dir = self.base_path.join(rule.name)
|
84
|
+
base_dir = base_dir.join(page_name.to_s) unless page_name == 1
|
85
|
+
FileUtils.mkdir_p(base_dir)
|
86
|
+
resource_path = base_dir.join("index.html")
|
87
|
+
view = ExporterView.new({collection: o}, {build_path: self.base_path, base_path: resource_path, template: rule.template, rule: rule})
|
88
|
+
puts "saving at #{self.path.join rule.name}"
|
89
|
+
view.save( resource_path )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def render_index
|
94
|
+
resource_path = self.base_path.join("index.html")
|
95
|
+
template = PolicyManager::Config.exporter.index_template
|
96
|
+
view = ExporterView.new({collection: PolicyManager::Config.portability_rules},
|
97
|
+
{build_path: self.base_path, base_path: resource_path, template: template})
|
98
|
+
puts "saving at #{resource_path}"
|
99
|
+
view.save( resource_path )
|
100
|
+
end
|
101
|
+
|
102
|
+
def generate_zip
|
103
|
+
directory_to_zip = base_path.to_s
|
104
|
+
output_file = zip_path.to_s
|
105
|
+
zf = ZipGenerator.new(directory_to_zip, output_file)
|
106
|
+
zf.write()
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "will_paginate"
|
2
|
+
require 'will_paginate/view_helpers/action_view'
|
3
|
+
|
4
|
+
module PolicyManager
|
5
|
+
class PaginatorRenderer < WillPaginate::ActionView::LinkRenderer
|
6
|
+
ELLIPSIS = '…'
|
7
|
+
|
8
|
+
def to_html
|
9
|
+
list_items = pagination.map do |item|
|
10
|
+
case item
|
11
|
+
when (1.class == Integer ? Integer : Fixnum)
|
12
|
+
page_number(item)
|
13
|
+
else
|
14
|
+
send(item)
|
15
|
+
end
|
16
|
+
end.join(@options[:link_separator])
|
17
|
+
|
18
|
+
list_wrapper = tag :nav, list_items, class: "pagination button-group"
|
19
|
+
tag :nav, list_wrapper
|
20
|
+
end
|
21
|
+
|
22
|
+
def container_attributes
|
23
|
+
super.except(*[:link_options])
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def page_number(page)
|
29
|
+
link_options = @options[:link_options] || {}
|
30
|
+
|
31
|
+
if page == current_page
|
32
|
+
tag(:a, page, class: 'btn page-item active', href: '')
|
33
|
+
else
|
34
|
+
tag(:a, page, href: page_path(page), class: 'page-link btn', rel: rel_value(page))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def page_path(page)
|
39
|
+
return "../index.html" if page == 1
|
40
|
+
if @collection.current_page == 1
|
41
|
+
return "./#{page}/index.html" if @collection.current_page < page
|
42
|
+
return "../#{page}/index.html" if @collection.current_page > page
|
43
|
+
else
|
44
|
+
return "../#{page}/index.html"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def previous_or_next_page(page, text, classname)
|
49
|
+
link_options = @options[:link_options] || {}
|
50
|
+
if page
|
51
|
+
link_wrapper = tag(:a, text || page, href: page_path(page), class: "page-link btn" + classname.to_s)
|
52
|
+
# link_wrapper, class: 'page-item '
|
53
|
+
else
|
54
|
+
tag(:a, text, href:'', class: 'page-link btn')
|
55
|
+
# span_wrapper, class: 'page-item disabled'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def gap
|
60
|
+
tag :p, tag(:i, ELLIPSIS, class: 'page-link'), class: 'page-item disabled btn'
|
61
|
+
end
|
62
|
+
|
63
|
+
def previous_page
|
64
|
+
num = @collection.current_page > 1 && @collection.current_page - 1
|
65
|
+
previous_or_next_page num, @options[:previous_label], 'previous btn'
|
66
|
+
end
|
67
|
+
|
68
|
+
def next_page
|
69
|
+
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
|
70
|
+
previous_or_next_page num, @options[:next_label], 'next btn'
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "erb"
|
2
|
+
require 'open-uri'
|
3
|
+
require "tilt"
|
4
|
+
require "will_paginate"
|
5
|
+
require 'will_paginate/view_helpers'
|
6
|
+
require 'will_paginate/view_helpers/action_view'
|
7
|
+
|
8
|
+
|
9
|
+
module PolicyManager
|
10
|
+
class ExporterView
|
11
|
+
|
12
|
+
include ERB::Util
|
13
|
+
include ActionView::Helpers
|
14
|
+
include WillPaginate::ViewHelpers #if defined?(WillPaginate)
|
15
|
+
include WillPaginate::ActionView #if defined?(WillPaginate)
|
16
|
+
|
17
|
+
attr_accessor :template, :base_path
|
18
|
+
|
19
|
+
def self.template
|
20
|
+
"Welcome, <%= @name %>"
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(vars={}, options={}, date=Time.now)
|
24
|
+
# collection or member, or wathever!?
|
25
|
+
vars.each{|k, v| self.instance_variable_set("@#{k}", v)}
|
26
|
+
@base_path = options[:base_path]
|
27
|
+
@build_path = options[:build_path]
|
28
|
+
|
29
|
+
index_path
|
30
|
+
|
31
|
+
@template = options.fetch(:template, self.class.template)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def index_path
|
36
|
+
path = @base_path.to_s.gsub(@build_path.to_s, "")
|
37
|
+
len = path.split("/").size
|
38
|
+
case len
|
39
|
+
when 2
|
40
|
+
@index_path = "./"
|
41
|
+
when 3
|
42
|
+
@index_path = "../"
|
43
|
+
when 4
|
44
|
+
@index_path = "../../"
|
45
|
+
else
|
46
|
+
@index_path = "../../"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def image_tag(remote_image, opts={})
|
51
|
+
begin
|
52
|
+
basename = File.basename(remote_image)
|
53
|
+
id = opts[:id] || SecureRandom.hex(10)
|
54
|
+
composed_name = [id, basename].compact.join("-")
|
55
|
+
path = "#{File.dirname(base_path)}/#{composed_name}"
|
56
|
+
self.save_image(remote_image, path)
|
57
|
+
tag(:img, {src: "./#{id}-#{File.basename(URI(remote_image).path)}" }.merge(opts))
|
58
|
+
rescue => e
|
59
|
+
Bugsnag.notify(e)
|
60
|
+
content_tag(:p, "broken image")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def save_image(remote_image, path)
|
65
|
+
open(URI(path).path, 'wb') do |file|
|
66
|
+
file << open(remote_image).read
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def render()
|
71
|
+
#template_layout = Tilt::ERBTemplate.new {PolicyManager::Config.exporter.layout}
|
72
|
+
context = self
|
73
|
+
#template_layout.render {
|
74
|
+
# view = Tilt::ERBTemplate.new{handled_template}
|
75
|
+
# view.render(context)
|
76
|
+
#}
|
77
|
+
|
78
|
+
render_with_layout()
|
79
|
+
end
|
80
|
+
|
81
|
+
def render_with_layout(context = self)
|
82
|
+
render_layout do
|
83
|
+
ERB.new(handled_template).result(binding)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def render_layout
|
88
|
+
layout = PolicyManager::Config.exporter.layout #File.read('views/layouts/app.html.erb')
|
89
|
+
ERB.new(layout).result(binding)
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def save(file)
|
94
|
+
File.open(file, "w+") do |f|
|
95
|
+
f.write(render)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def handled_template
|
100
|
+
if @template.is_a?(String)
|
101
|
+
@template
|
102
|
+
elsif @template.is_a?(Pathname)
|
103
|
+
File.open(@template).read
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
# This is a simple example which uses rubyzip to
|
4
|
+
# recursively generate a zip file from the contents of
|
5
|
+
# a specified directory. The directory itself is not
|
6
|
+
# included in the archive, rather just its contents.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
# directory_to_zip = "/tmp/input"
|
10
|
+
# output_file = "/tmp/out.zip"
|
11
|
+
# zf = ZipFileGenerator.new(directory_to_zip, output_file)
|
12
|
+
# zf.write()
|
13
|
+
|
14
|
+
module PolicyManager
|
15
|
+
class ZipGenerator
|
16
|
+
# Initialize with the directory to zip and the location of the output archive.
|
17
|
+
def initialize(input_dir, output_file)
|
18
|
+
@input_dir = input_dir
|
19
|
+
@output_file = output_file
|
20
|
+
end
|
21
|
+
|
22
|
+
# Zip the input directory.
|
23
|
+
def write
|
24
|
+
entries = Dir.entries(@input_dir) - %w(. ..)
|
25
|
+
|
26
|
+
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |zipfile|
|
27
|
+
write_entries entries, '', zipfile
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# A helper method to make the recursion work.
|
34
|
+
def write_entries(entries, path, zipfile)
|
35
|
+
entries.each do |e|
|
36
|
+
zipfile_path = path == '' ? e : File.join(path, e)
|
37
|
+
disk_file_path = File.join(@input_dir, zipfile_path)
|
38
|
+
puts "Deflating #{disk_file_path}"
|
39
|
+
|
40
|
+
if File.directory? disk_file_path
|
41
|
+
recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
|
42
|
+
else
|
43
|
+
put_into_archive(disk_file_path, zipfile, zipfile_path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
|
49
|
+
zipfile.mkdir zipfile_path
|
50
|
+
subdir = Dir.entries(disk_file_path) - %w(. ..)
|
51
|
+
write_entries subdir, zipfile_path, zipfile
|
52
|
+
end
|
53
|
+
|
54
|
+
def put_into_archive(disk_file_path, zipfile, zipfile_path)
|
55
|
+
zipfile.get_output_stream(zipfile_path) do |f|
|
56
|
+
f.write(File.open(disk_file_path, 'rb').read)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module PolicyManager
|
4
|
+
class Exporter
|
5
|
+
attr_accessor :path,
|
6
|
+
:resource,
|
7
|
+
:index_template,
|
8
|
+
:layout,
|
9
|
+
:after_zip,
|
10
|
+
:mail_helpers,
|
11
|
+
:attachment_path,
|
12
|
+
:attachment_storage,
|
13
|
+
:expiration_link,
|
14
|
+
:mailer_templates,
|
15
|
+
:mailer
|
16
|
+
|
17
|
+
def initialize(opts={})
|
18
|
+
self.path = opts[:path]
|
19
|
+
self.resource = opts[:resource] #.call if opts[:resource].is_a?(Proc)
|
20
|
+
self.index_template = opts[:index_template]
|
21
|
+
self.layout = opts[:layout]
|
22
|
+
self.after_zip = opts[:after_zip]
|
23
|
+
self.mail_helpers = opts[:mail_helpers]
|
24
|
+
self.attachment_path = opts[:attachment_path]
|
25
|
+
self.attachment_storage = opts[:attachment_storage]
|
26
|
+
self.expiration_link = opts[:expiration_link]
|
27
|
+
self.mailer_templates = opts[:mailer_templates]
|
28
|
+
end
|
29
|
+
|
30
|
+
def perform(resource)
|
31
|
+
e = ExporterHandler.new(resource: resource, path: path, after_zip: after_zip)
|
32
|
+
e.perform
|
33
|
+
end
|
34
|
+
|
35
|
+
def clear!(resource)
|
36
|
+
e = ExporterHandler.new(resource: resource, path: path)
|
37
|
+
e.clear!
|
38
|
+
end
|
39
|
+
|
40
|
+
def index_template
|
41
|
+
handled_template(@index_template) || default_index_template
|
42
|
+
end
|
43
|
+
|
44
|
+
def layout
|
45
|
+
handled_template(@layout) || '<body> eeeee <%= yield %> eeee</body>'
|
46
|
+
end
|
47
|
+
|
48
|
+
def mail_helpers
|
49
|
+
@mail_helpers ||= []
|
50
|
+
end
|
51
|
+
|
52
|
+
def expiration_link
|
53
|
+
@expiration_link ||= 60
|
54
|
+
end
|
55
|
+
|
56
|
+
def handled_template(template)
|
57
|
+
return if template.blank?
|
58
|
+
if template.is_a?(String)
|
59
|
+
template
|
60
|
+
elsif template.is_a?(Pathname)
|
61
|
+
File.open(template).read
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def default_index_template
|
66
|
+
'<h1>links</h1>
|
67
|
+
<ul>
|
68
|
+
<% @collection.each do |rule| %>
|
69
|
+
<li><%= link_to rule.name, "./#{rule.name}" %></li>
|
70
|
+
<% end %>
|
71
|
+
</ul>'
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PolicyManager
|
2
|
+
class PortabilityRule
|
3
|
+
attr_accessor :name, :methods, :formats, :per, :collection, :member, :template
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
self.collection = opts[:collection]
|
7
|
+
self.member = opts[:member]
|
8
|
+
self.per = opts[:per]
|
9
|
+
self.name = opts[:name]
|
10
|
+
self.formats = opts[:formats]
|
11
|
+
self.template = opts[:template]
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|