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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +270 -13
  3. data/app/assets/javascripts/policy_manager/application.js +4 -0
  4. data/app/assets/javascripts/policy_manager/portability_requests.js +2 -0
  5. data/app/assets/javascripts/policy_manager/user_portability_requests.js +2 -0
  6. data/app/assets/stylesheets/policy_manager/portability_requests.css +4 -0
  7. data/app/assets/stylesheets/policy_manager/user_portability_requests.css +4 -0
  8. data/app/controllers/policy_manager/application_controller.rb +22 -0
  9. data/app/controllers/policy_manager/categories_controller.rb +5 -47
  10. data/app/controllers/policy_manager/portability_requests_controller.rb +34 -0
  11. data/app/controllers/policy_manager/terms_controller.rb +16 -13
  12. data/app/controllers/policy_manager/user_portability_requests_controller.rb +41 -0
  13. data/app/controllers/policy_manager/user_terms_controller.rb +68 -28
  14. data/app/helpers/policy_manager/application_helper.rb +28 -0
  15. data/app/helpers/policy_manager/portability_requests_helper.rb +4 -0
  16. data/app/helpers/policy_manager/scripts_helper.rb +11 -0
  17. data/app/helpers/policy_manager/terms_helper.rb +1 -1
  18. data/app/helpers/policy_manager/user_portability_requests_helper.rb +4 -0
  19. data/app/jobs/policy_manager/exporter_job.rb +10 -0
  20. data/app/mailers/policy_manager/application_mailer.rb +20 -2
  21. data/app/mailers/policy_manager/portability_mailer.rb +34 -0
  22. data/app/models/policy_manager/concerns/user_behavior.rb +80 -22
  23. data/app/models/policy_manager/portability_request.rb +65 -0
  24. data/app/models/policy_manager/term.rb +18 -0
  25. data/app/models/policy_manager/user_term.rb +14 -7
  26. data/app/views/layouts/policy_manager/application.html.erb +41 -39
  27. data/app/views/layouts/policy_manager/mailer.html.erb +13 -0
  28. data/app/views/layouts/policy_manager/mailer.text.erb +1 -0
  29. data/app/views/policy_manager/categories/index.html.erb +6 -12
  30. data/app/views/policy_manager/categories/show.html.erb +13 -20
  31. data/app/views/policy_manager/portability_mailer/completed_notification.erb +7 -0
  32. data/app/views/policy_manager/portability_mailer/progress_notification.erb +3 -0
  33. data/app/views/policy_manager/portability_requests/index.html.erb +42 -0
  34. data/app/views/policy_manager/portability_requests/index.json.jbuilder +5 -0
  35. data/app/views/policy_manager/terms/_form.html.erb +12 -11
  36. data/app/views/policy_manager/terms/edit.html.erb +6 -4
  37. data/app/views/policy_manager/terms/index.html.erb +12 -13
  38. data/app/views/policy_manager/terms/new.html.erb +5 -3
  39. data/app/views/policy_manager/terms/show.html.erb +12 -10
  40. data/app/views/policy_manager/user_portability_requests/index.html.erb +42 -0
  41. data/app/views/policy_manager/user_portability_requests/index.json.jbuilder +5 -0
  42. data/app/views/policy_manager/user_terms/pending.html.erb +10 -6
  43. data/app/views/policy_manager/user_terms/show.html.erb +7 -8
  44. data/app/views/policy_manager/user_terms/show.json.jbuilder +15 -8
  45. data/config/locales/en.yml +122 -0
  46. data/config/locales/es.yml +122 -0
  47. data/config/routes.rb +15 -6
  48. data/db/migrate/20180326193825_create_policy_manager_terms.rb +1 -0
  49. data/db/migrate/20180410171354_create_policy_manager_portability_requests.rb +18 -0
  50. data/lib/policy_manager/anonimizer.rb +18 -0
  51. data/lib/policy_manager/config.rb +35 -1
  52. data/lib/policy_manager/exporter/handler.rb +110 -0
  53. data/lib/policy_manager/exporter/paginator_renderer.rb +74 -0
  54. data/lib/policy_manager/exporter/view.rb +108 -0
  55. data/lib/policy_manager/exporter/zip_generator.rb +60 -0
  56. data/lib/policy_manager/exporter.rb +75 -0
  57. data/lib/policy_manager/portability_rule.rb +15 -0
  58. data/lib/policy_manager/rule.rb +21 -4
  59. data/lib/policy_manager/script.rb +56 -0
  60. data/lib/policy_manager/templates/index.html.erb +1 -0
  61. data/lib/policy_manager/version.rb +1 -1
  62. data/lib/policy_manager.rb +10 -0
  63. metadata +160 -19
  64. data/app/controllers/policy_manager/dashboard_controller.rb +0 -6
  65. data/app/helpers/policy_manager/categories_helper.rb +0 -4
  66. data/app/helpers/policy_manager/dashboard_helper.rb +0 -4
  67. data/app/helpers/policy_manager/terms_categories_helper.rb +0 -4
  68. data/app/views/policy_manager/categories/_form.html.erb +0 -22
  69. data/app/views/policy_manager/categories/edit.html.erb +0 -6
  70. data/app/views/policy_manager/categories/new.html.erb +0 -5
  71. data/app/views/policy_manager/dashboard/index.erb +0 -33
  72. data/app/views/policy_manager/terms_categories/_form.html.erb +0 -17
  73. data/app/views/policy_manager/terms_categories/edit.html.erb +0 -6
  74. data/app/views/policy_manager/terms_categories/index.html.erb +0 -24
  75. data/app/views/policy_manager/terms_categories/new.html.erb +0 -5
  76. data/app/views/policy_manager/terms_categories/show.html.erb +0 -4
  77. data/app/views/policy_manager/user_terms/_form.html.erb +0 -17
  78. data/app/views/policy_manager/user_terms/edit.html.erb +0 -6
  79. data/app/views/policy_manager/user_terms/index.html.erb +0 -24
  80. data/app/views/policy_manager/user_terms/new.html.erb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b508168e6f7964e7ed9455719b8828f42c3f4bc
4
- data.tar.gz: 0fd77a485f155609c0e7a7b5fb6f7d92b24e8cf6
3
+ metadata.gz: 6e1522cfa4e643a2187c28f8dda396e10bff4df2
4
+ data.tar.gz: 2ba6c8e17738855fcd61e9d476a78412c678d77c
5
5
  SHA512:
6
- metadata.gz: 97d1ae4542cf9462b2c5ea35771e7c9c6c5cfa558b6dcf729a3e0938668ee4615391af7e14794bbf0e1049646f034937c9dd7e1a70c4317ead000ab3a7399705
7
- data.tar.gz: 5ebdb33e81e72cc8605dafef381ab14b20130d095f06f2d4b6842536a94d32e8444336d645f42cbac17c98b7af4caa830dc56590ee8894cb6cebe71a16369d26
6
+ metadata.gz: 45a4ef9b1af643d4730bade46b7c589aace9c9cec2d67518c38d9b56d7ab64ebb07e513ba87ab63f14cd407ba215f95c953ba830cd0b2228f928e3b2aff21912
7
+ data.tar.gz: 1a2974662d4eaa3e44c10a99e69f99d4dd633ff93a7a40932dea50878358f15b74e184f29d450915e3130e087e5c22d636f42458a5bbd4a190ecb05c59084b1d
data/README.md CHANGED
@@ -1,28 +1,285 @@
1
- # Terms
2
- Short description and motivation.
3
1
 
4
- ## Usage
5
- How to use my plugin.
2
+
3
+ # GDPR RAILS
4
+
5
+ ### Rails Engine for the GDPR compliance
6
+ ![RB](https://media.giphy.com/media/L74KIFFW4kUkE/giphy.gif)
7
+ > The world needs some privacy, please
8
+
9
+
10
+ [![Build Status](https://travis-ci.org/prey/gdpr_rails.svg?branch=master&aa=123)](https://travis-ci.org/prey/gdpr_rails)
11
+ [![Maintainability](https://api.codeclimate.com/v1/badges/4908e74f90a34ba473df/maintainability)](https://codeclimate.com/github/prey/gdpr_rails/maintainability)
12
+ [![Coverage Status](https://coveralls.io/repos/github/prey/gdpr_rails/badge.svg?branch=master)](https://coveralls.io/github/prey/gdpr_rails?branch=master)
13
+
14
+ ## About this project
15
+
16
+ PolicyManager (Aka GDPR RAILS) was created with flexibility in mind to comply with the requirements of the GDPR ([General Data Protection Regulation](https://www.eugdpr.org/)). It's currently being developed at preyproject and will be battle-tested on [preyproject.com](https://preyproject.com) from May 25th.
17
+
18
+ ### Main Features:
19
+
20
+ #### Policy Rules
21
+ + Configurable policy rules, supports activerecord validations for new or existing users
22
+ + Supports session-less consent policies which will become persistent once the user signs in or signs up
23
+ + Versioning system for new policies
24
+ + 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.
25
+
26
+ #### Portability
27
+ 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**
28
+ + Seamless data export with configurable templates
29
+ + Configurable Mailer templates for progress & download completion
30
+ + Downloads images to the local filesystem in order to comply with GDPR requirements on data accessibility.
31
+ + Zips all the information and delivers it with a expirable download link
32
+ + ActiveJob to handle the process
33
+ + Behind the scenes uses the paperclip gem in which you can set up storages, like S3, Google
34
+
35
+ #### Scripts & Cookies
36
+ Configurable *scripts* which will bind cookie names in order to handle the script rendering and the cookie clean up.
37
+
38
+ #### Forgotability
39
+ + TBD, for now we simply delete all the data when a user closes the account. This could be handled in the future with encryption like in emails or other kind of sensible fields on a database.
40
+
41
+ ### Admin Panel
42
+ ![admin panel](./panel.jpg)
6
43
 
7
44
  ## Installation
8
- Add this line to your application's Gemfile:
45
+ Add this line to your application's Gemfile:
46
+
47
+ as `gem 'gdpr_rails'`
48
+
49
+ Then in your application.rb require the policy_manager lib with
50
+
51
+ `require "policy_manager"`
52
+
53
+ Install & run the migrations
54
+
55
+ `rake policy_manager:install:migrations`
56
+
57
+ ## Usage examples
58
+
59
+ ### Basic config
60
+ ```ruby
61
+ config = PolicyManager::Config.setup do |c|
62
+ c.logout_url = "logout"
63
+ c.from_email = "admin@acme.com"
64
+ # is_admin method in order for engine to know
65
+ # how to authorize admin only areas
66
+ c.is_admin_method = ->(o){
67
+ o.is_god? || o.is_admin? || o.is_me? || o.watheva
68
+ }
69
+ ```
70
+
71
+ In order for this engine to work you must supply some rules according to your needs, in order to be in comply with the GDPR you will need 3 rules at least. A cookie consent, a Privacy& TOS and an Age confirmation (+16).
72
+ So, let's start by doing that:
73
+
74
+ ## Term rules
75
+
76
+ In your app router add the following:
77
+
78
+ ```ruby
79
+ mount PolicyManager::Engine => "/policies"
80
+ ```
81
+
82
+ Then add an initializer, `config/initializers/gdpr.rb` and inside it set your policy rules.
9
83
 
10
84
  ```ruby
11
- gem 'terms'
85
+ PolicyManager::Config.setup do |c|
86
+ c.add_rule({name: "cookie", sessionless: true } )
87
+ c.add_rule({name: "age", validates_on: [:create, :update], blocking: true })
88
+ c.add_rule({name: "privacy_terms", validates_on: [:create, :update], blocking: true })
89
+ end
90
+
91
+ # If you are using devise, you must extend engines's controller with devise helpers in order to get current_user
92
+ PolicyManager::UserTermsController.send(:include, Devise::Controllers::Helpers)
12
93
  ```
13
94
 
14
- And then execute:
15
- ```bash
16
- $ bundle
95
+ > Note that you will need to go to the policy panel and add the policy
96
+ > content for each term at `http://localhost:3000/policies/categories` otherwise you will see errors like `no term for #{rule} policy`
97
+
98
+ ### ActiveRecord Methods
99
+
100
+ When the policies are configured will generate some helper methods on User model. For example, with the example above you will get the following methods for free:
101
+
102
+ + `@user.has_consented_cookie?`
103
+ + `@user.has_consented_age?`
104
+ + `@user.has_consented_privacy_terms?`
105
+ #### also you get:
106
+ + `@user.pending_policies`
107
+ + `@user.pending_blocking_policies`
108
+ + `@user.confirm_all_policies!`
109
+ + `@user.reject_all_policies!`
110
+ + `@user.needs_policy_confirmation_for?(rule)`
111
+ + `@user.policy_term_on(rule)`
112
+ + `@user.policy_user_term_on(term)`
113
+ + `@user.handle_policy_for(term)`
114
+ + `@user.can_request_portability?`
115
+
116
+ ## Policy rules:
117
+
118
+ + **sessionless:** will allow rules to be available for non logged users, if accepted a cookie `cookies["policy_rule_cookie"]` will be generated. If then the user sign in or signs up you could get this cookie it will persist in database.
119
+
120
+ **Use this in your controller:**
121
+ ```ruby
122
+ @user.store_policy_cookie if cookies["policy_rule_cookie"] == "accepted"
123
+ ```
124
+ + **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.
125
+ + **if:** you can add conditions as a Proc in order skip validations:
126
+ ```ruby
127
+ c.add_rule({name: "age", validates_on: [:create, :update],
128
+ if: ->(o){ o.enabled_for_validation } })
17
129
  ```
130
+ + **on_reject**: Proc which will be triggered when user rejects a policy (has an argument that contains the controller context)
131
+ + **on_accept**: Proc which will be triggered when user accepts a policy (has an argument that contains the controller context)
18
132
 
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install terms
133
+ #### Example
134
+ > This is an example for a `cookie` rule. The expected behavior would be when the user rejects cookies iterate over our scripts and delete cookies:
135
+
136
+ ```ruby
137
+ c.add_rule({name: "cookie", sessionless: true, on_reject: ->(context){
138
+ PolicyManager::Script.cookies
139
+ .select{|o| !o.permanent }
140
+ .each{|o|
141
+ o.cookies.each{|c|
142
+ context.send(:cookies).delete(c, domain: o.domain)
143
+ }
144
+ }
145
+ }
146
+ })
22
147
  ```
23
148
 
149
+ #### Policy handling:
150
+
151
+ There are some endpoints that will handle json in order to interact with client applications, like react interfaces, $.ajax etc.
152
+ you can also use the html web panel directly from the engine.
153
+ So, if the Engine was mounted on `/policies` then your routes will be:
154
+
155
+ pending_user_terms GET /user_terms/pending(.:format) policy_manager/user_terms#pending
156
+ accept_multiples_user_terms PUT /user_terms/accept_multiples(.:format) policy_manager/user_terms#accept_multiples
157
+ blocking_terms_user_terms GET /user_terms/blocking_terms(.:format) policy_manager/user_terms#blocking_terms
158
+ accept_user_term PUT /user_terms/:id/accept(.:format) policy_manager/user_terms#accept
159
+ reject_user_term PUT /user_terms/:id/reject(.:format) policy_manager/user_terms#reject
160
+ user_terms GET /user_terms(.:format) policy_manager/user_terms#index
161
+ user_term GET /user_terms/:id(.:format) policy_manager/user_terms#show
162
+
163
+ ## Scripts & Cookies
164
+
165
+ This is supposed to in mix with your declared cookie term. So, this configuration let's you declare your external scripts that are related with tracking, ie: Google Analytics, Kissmetrics, Google Tag manager, etc... This configuration expects that you declare scripts that will be rendered over certain contexts (environments) and have the names (and domains) of the cookies that those scripts generates.
166
+
167
+ #### example:
168
+ ```ruby
169
+ c.add_script(
170
+ name: "google analytics",
171
+ script: 'shared/analytics/universal',
172
+ environments: [:production],
173
+ description: ->{I18n.t("cookies.list.google_analytics")},
174
+ cookies: ["_ga", "_gid", "_gat_XXX-XXX"],
175
+ domain: ".panel.preyproject.com"
176
+ )
177
+ ```
178
+
179
+ > **Importance of declaring the cookie domain**: When you clean up the cookies (like in the example above for `on_reject`) is important to set the domain that this cookies belongs. In some cases this external scripts could add the cookie on your subdomain or your base domain. In out case we found that some cookies are generated on panel.preyproject.com or .panel.preyproject or just preyproject.com. Try to get that information on chrome console -> application -> cookies.
180
+
181
+ ### Example in your layout:
182
+ This is an example on how you would render your scripts only if the user has accepted the cookie
183
+ ```ruby
184
+ <% if current_user.has_consented_cookie? %>
185
+ <!-- # this cames from portability/helpers/scripts_helpers -->
186
+ <%= render_scripts %>
187
+ <% end %>
188
+ ```
189
+ `render_scripts` will iterate over your configured scripts and render the templates defined on `PolicyManager::Script`
190
+
191
+ ## Portability Rules
192
+
193
+ Export option & Portability rules will allow you to set up how and which data you will give to a requester user.
194
+
195
+ #### Exporter:
196
+ + **path**: where the folder will be generated, usually can be set on /tmp, this will need a pathname, like `Rails.root.join("tmp/export")`
197
+ + **resource**: which model , ie: `User`
198
+ + **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
199
+ + **layout**: A layout template to wrap the static site, this expects a Pathname or a String with your template
200
+ + **after_zip**: a callback to handle the zip file on the resource, something like:
201
+ ```ruby
202
+ after_zip: ->(zip_path, resource){
203
+ puts "THIS IS GREAT #{zip_path} was zipped, now what ??"
204
+ }
205
+ ```
206
+
207
+ + **mail_helpers**: If you have some helpers you want to add to the mailers, then you can pass an Array of helpers, `[MailHelper, OtherMailHelper]`,
208
+ + **attachment_path**: Paperclip upload path , defaults to "portability/:id/build.zip",
209
+ + **attachment_storage**: Paperclip storage, defaults to filesystem , you can set `s3` or `google` or whatever paperclip supports
210
+ + **expiration_link**: integer, defaults to 60 (1 minute),
211
+
212
+ #### Portability Rules:
213
+
214
+ Portability rules collection render. This will call a @user.articles
215
+ and will auto paginate records
216
+
217
+ ```ruby
218
+ PolicyManager::Config.setup do |c|
219
+
220
+ # minimal exporter setup
221
+ c.exporter = {
222
+ path: Rails.root + "tmp/export",
223
+ resource: User
224
+ }
225
+
226
+ # portability rules, collection render. This will call a @user.articles
227
+ # and will auto paginate records
228
+ # template expects a string or path
229
+ c.add_portability_rule({
230
+ name: "exportable_data",
231
+ collection: :articles,
232
+ template: "hello, a collection will be rendered here use @collection.to_json",
233
+ per: 10
234
+ })
235
+
236
+ # portability rules, member render. This will call a @user.account_data
237
+ # template expects a string or path
238
+ c.add_portability_rule({
239
+ name: "my_account",
240
+ member: :account_data,
241
+ template: "hellow , here a resource will be rendered <%= @member.to_json %> "
242
+ })
243
+
244
+ end
245
+ ```
246
+ **Important:**
247
+ > If the content that will be delivered has images use the `image_tag`
248
+ > in your template. This helper was reimplemented in order for the remote image to be downloaded automatically.
249
+ > And will be served locally in order to comply with the
250
+ > Portability data requirements.
251
+
252
+ ### Web Endpoints and methods for user:
253
+
254
+ ```
255
+ user_portability_requests GET /user_portability_requests(.:format) policy_manager/user_portability_requests#index
256
+ POST /user_portability_requests(.:format) policy_manager/user_portability_requests#create
257
+ user_portability_request DELETE /user_portability_requests/:id(.:format) policy_manager/user_portability_requests#destroy
258
+
259
+ ```
260
+ ### Web Endpoints and methods for admin :
261
+ this routes are accessible from engine's admin panel
262
+ ```
263
+
264
+ confirm_portability_request GET /portability_requests/:id/confirm(.:format) policy_manager/portability_requests#confirm
265
+ portability_requests GET /portability_requests(.:format) policy_manager/portability_requests#index
266
+ portability_request DELETE /portability_requests/:id(.:format) policy_manager/portability_requests#destroy
267
+ ```
268
+
269
+
270
+ # TO DO
271
+ + anonimyzer
272
+
273
+ #### Acknowledgments
274
+ + [Prey Team](https://github.com/orgs/prey/people)
275
+ + Special thanks to our legal GDPR advisor: Paul Lagniel <paul@preyhq.com>
276
+
277
+ #### Main maintainers
278
+ + Miguel Michelson - miguel@preyhq.com
279
+ + Patricio Jofré - pato@preyhq.com
280
+
24
281
  ## Contributing
25
- Contribution directions go here.
282
+ just fork the repo and send us a Pull Request, with some tests please :)
26
283
 
27
284
  ## License
28
285
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -11,3 +11,7 @@
11
11
  // about supported directives.
12
12
  //
13
13
  //= require_tree .
14
+
15
+ //= require rails-ujs
16
+
17
+ //= require chartkick
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -1,5 +1,27 @@
1
1
  module PolicyManager
2
2
  class ApplicationController < ActionController::Base
3
+
4
+ if defined? Doorman
5
+ include Doorman::Controller
6
+ end
7
+
8
+ before_action :user_authenticated?
9
+ before_action :set_language
10
+
11
+ def allow_admins
12
+ return redirect_to root_path unless Config.is_admin?(current_user)
13
+ end
14
+
15
+ def user_authenticated?
16
+ if current_user.blank?
17
+ render :file => "public/401.html", :layout => false, :status => :unauthorized
18
+ end
19
+ end
20
+
21
+ def set_language
22
+ I18n.locale = Config.user_language(current_user)
23
+ end
24
+
3
25
  protect_from_forgery with: :exception
4
26
  end
5
27
  end
@@ -1,62 +1,20 @@
1
- require_dependency "terms/application_controller"
1
+ require_dependency "policy_manager/application_controller"
2
2
 
3
3
  module PolicyManager
4
4
  class CategoriesController < ApplicationController
5
- before_action :set_category, only: [:show, :edit, :update, :destroy]
5
+
6
+ before_action :allow_admins
6
7
 
7
8
  # GET /categories
8
9
  def index
9
- @categories = Category.all
10
+ @categories = PolicyManager::Config.rules
10
11
  end
11
12
 
12
13
  # GET /categories/1
13
14
  def show
14
- end
15
-
16
- # GET /categories/new
17
- def new
18
- @category = Category.new
19
- end
20
-
21
- # GET /categories/1/edit
22
- def edit
23
- end
24
-
25
- # POST /categories
26
- def create
27
- @category = Category.new(category_params)
28
-
29
- if @category.save
30
- redirect_to @category, notice: 'Category was successfully created.'
31
- else
32
- render :new
33
- end
34
- end
35
-
36
- # PATCH/PUT /categories/1
37
- def update
38
- if @category.update(category_params)
39
- redirect_to @category, notice: 'Category was successfully updated.'
40
- else
41
- render :edit
42
- end
43
- end
44
-
45
- # DELETE /categories/1
46
- def destroy
47
- @category.destroy
48
- redirect_to categories_url, notice: 'Category was successfully destroyed.'
15
+ @category = PolicyManager::Config.rules.find{|o| o.name == params[:id]}
49
16
  end
50
17
 
51
18
  private
52
- # Use callbacks to share common setup or constraints between actions.
53
- def set_category
54
- @category = Category.find(params[:id])
55
- end
56
-
57
- # Only allow a trusted parameter "white list" through.
58
- def category_params
59
- params.require(:category).permit(:name)
60
- end
61
19
  end
62
20
  end
@@ -0,0 +1,34 @@
1
+ require_dependency "policy_manager/application_controller"
2
+ module PolicyManager
3
+ class PortabilityRequestsController < ApplicationController
4
+
5
+ before_action :set_portability_request, only: :destroy
6
+ before_action :allow_admins
7
+
8
+ # GET /portability_requests
9
+ def index
10
+ @portability_requests = PortabilityRequest.order(created_at: :desc).paginate(:page => params[:page], :per_page => 10)
11
+ end
12
+
13
+ def confirm
14
+ @portability_request = PortabilityRequest.find(params[:id])
15
+ if @portability_request.confirm!
16
+ redirect_to portability_requests_path
17
+ end
18
+ end
19
+
20
+ # DELETE /portability_requests/1
21
+ def destroy
22
+ @portability_request.destroy
23
+ redirect_to portability_requests_url, notice: I18n.t("terms_app.portability_requests.index.destroyed")
24
+ end
25
+
26
+ private
27
+
28
+ # Use callbacks to share common setup or constraints between actions.
29
+ def set_portability_request
30
+ @portability_request = PortabilityRequest.find(params[:id])
31
+ end
32
+
33
+ end
34
+ end
@@ -1,9 +1,10 @@
1
- require_dependency "terms/application_controller"
1
+ require_dependency "policy_manager/application_controller"
2
2
 
3
3
  module PolicyManager
4
4
  class TermsController < ApplicationController
5
5
  before_action :set_term, only: [:show, :edit, :update, :destroy]
6
-
6
+ before_action :allow_admins
7
+
7
8
  # GET /terms
8
9
  def index
9
10
  @terms = Term.all
@@ -27,7 +28,7 @@ module PolicyManager
27
28
  @term = Term.new(term_params)
28
29
 
29
30
  if @term.save
30
- redirect_to category_term_path(@term.category, @term), notice: 'Term was successfully created.'
31
+ redirect_to category_term_path(@term.rule.name, @term), notice: I18n.t("terms_app.terms.new.created")
31
32
  else
32
33
  render :new
33
34
  end
@@ -36,7 +37,7 @@ module PolicyManager
36
37
  # PATCH/PUT /terms/1
37
38
  def update
38
39
  if @term.update(term_params)
39
- redirect_to category_term_path(@term.category, @term), notice: 'Term was successfully updated.'
40
+ redirect_to category_term_path(@term.rule.name, @term), notice: I18n.t("terms_app.terms.new.updated")
40
41
  else
41
42
  render :edit
42
43
  end
@@ -45,18 +46,20 @@ module PolicyManager
45
46
  # DELETE /terms/1
46
47
  def destroy
47
48
  @term.destroy
48
- redirect_to category_terms_path(@term.category), notice: 'Term was successfully destroyed.'
49
+ redirect_to category_terms_path(@term.rule.name), notice: I18n.t("terms_app.terms.new.destroyed")
49
50
  end
50
51
 
51
52
  private
52
- # Use callbacks to share common setup or constraints between actions.
53
- def set_term
54
- @term = Term.find(params[:id])
55
- end
56
53
 
57
- # Only allow a trusted parameter "white list" through.
58
- def term_params
59
- params.require(:term).permit(:description, :category_id)
60
- end
54
+ # Use callbacks to share common setup or constraints between actions.
55
+ def set_term
56
+ @term = Term.find(params[:id])
57
+ end
58
+
59
+ # Only allow a trusted parameter "white list" through.
60
+ def term_params
61
+ params.require(:term).permit(:description, :rule, :state)
62
+ end
63
+
61
64
  end
62
65
  end
@@ -0,0 +1,41 @@
1
+ require_dependency "policy_manager/application_controller"
2
+
3
+ module PolicyManager
4
+ class UserPortabilityRequestsController < ApplicationController
5
+
6
+ def index
7
+ @user_portability_requests = current_user.portability_requests.order(created_at: :desc).paginate(:page => params[:page], :per_page => 10)
8
+ end
9
+
10
+ def create
11
+ respond_to do |format|
12
+ format.html{
13
+ if current_user.can_request_portability?
14
+ if current_user.portability_requests.create
15
+ redirect_to user_portability_requests_path, notice: I18n.t("terms_app.user_portability_requests.index.created")
16
+ end
17
+ else
18
+ redirect_to user_portability_requests_path, notice: I18n.t("terms_app.user_portability_requests.index.has_pending")
19
+ end
20
+ }
21
+ format.json{
22
+ if current_user.can_request_portability?
23
+ if current_user.portability_requests.create
24
+ render json: {notice: I18n.t("terms_app.user_portability_requests.index.created")}
25
+ end
26
+ else
27
+ render json: {notice: I18n.t("terms_app.user_portability_requests.index.has_pending")}, status: 422
28
+ end
29
+ }
30
+ end
31
+ end
32
+
33
+ def destroy
34
+ PortabilityRequest.find(params[:id]).destroy
35
+ redirect_to user_portability_requests_url, notice: I18n.t("terms_app.portability_requests.index.destroyed")
36
+ end
37
+
38
+ private
39
+
40
+ end
41
+ end