gdpr_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +36 -0
  5. data/app/assets/config/policy_manager_manifest.js +2 -0
  6. data/app/assets/javascripts/policy_manager/application.js +13 -0
  7. data/app/assets/stylesheets/policy_manager/application.css +15 -0
  8. data/app/assets/stylesheets/policy_manager/dashboard.css +99 -0
  9. data/app/assets/stylesheets/scaffold.css +80 -0
  10. data/app/controllers/policy_manager/application_controller.rb +5 -0
  11. data/app/controllers/policy_manager/categories_controller.rb +62 -0
  12. data/app/controllers/policy_manager/dashboard_controller.rb +6 -0
  13. data/app/controllers/policy_manager/terms_controller.rb +62 -0
  14. data/app/controllers/policy_manager/user_terms_controller.rb +119 -0
  15. data/app/helpers/policy_manager/application_helper.rb +4 -0
  16. data/app/helpers/policy_manager/categories_helper.rb +4 -0
  17. data/app/helpers/policy_manager/dashboard_helper.rb +4 -0
  18. data/app/helpers/policy_manager/terms_categories_helper.rb +4 -0
  19. data/app/helpers/policy_manager/terms_helper.rb +4 -0
  20. data/app/helpers/policy_manager/user_terms_helper.rb +4 -0
  21. data/app/jobs/policy_manager/application_job.rb +4 -0
  22. data/app/mailers/policy_manager/application_mailer.rb +6 -0
  23. data/app/models/policy_manager/application_record.rb +5 -0
  24. data/app/models/policy_manager/concerns/user_behavior.rb +75 -0
  25. data/app/models/policy_manager/term.rb +20 -0
  26. data/app/models/policy_manager/user_term.rb +19 -0
  27. data/app/views/layouts/policy_manager/application.html.erb +92 -0
  28. data/app/views/policy_manager/categories/_form.html.erb +22 -0
  29. data/app/views/policy_manager/categories/edit.html.erb +6 -0
  30. data/app/views/policy_manager/categories/index.html.erb +32 -0
  31. data/app/views/policy_manager/categories/new.html.erb +5 -0
  32. data/app/views/policy_manager/categories/show.html.erb +39 -0
  33. data/app/views/policy_manager/dashboard/index.erb +33 -0
  34. data/app/views/policy_manager/terms/_form.html.erb +32 -0
  35. data/app/views/policy_manager/terms/edit.html.erb +6 -0
  36. data/app/views/policy_manager/terms/index.html.erb +33 -0
  37. data/app/views/policy_manager/terms/new.html.erb +5 -0
  38. data/app/views/policy_manager/terms/show.html.erb +16 -0
  39. data/app/views/policy_manager/terms_categories/_form.html.erb +17 -0
  40. data/app/views/policy_manager/terms_categories/edit.html.erb +6 -0
  41. data/app/views/policy_manager/terms_categories/index.html.erb +24 -0
  42. data/app/views/policy_manager/terms_categories/new.html.erb +5 -0
  43. data/app/views/policy_manager/terms_categories/show.html.erb +4 -0
  44. data/app/views/policy_manager/user_terms/_form.html.erb +17 -0
  45. data/app/views/policy_manager/user_terms/edit.html.erb +6 -0
  46. data/app/views/policy_manager/user_terms/index.html.erb +24 -0
  47. data/app/views/policy_manager/user_terms/new.html.erb +5 -0
  48. data/app/views/policy_manager/user_terms/pending.html.erb +7 -0
  49. data/app/views/policy_manager/user_terms/show.html.erb +32 -0
  50. data/app/views/policy_manager/user_terms/show.json.jbuilder +11 -0
  51. data/config/routes.rb +20 -0
  52. data/db/migrate/20180326193825_create_policy_manager_terms.rb +11 -0
  53. data/db/migrate/20180326193827_create_policy_manager_user_terms.rb +12 -0
  54. data/lib/policy_manager/config.rb +19 -0
  55. data/lib/policy_manager/engine.rb +5 -0
  56. data/lib/policy_manager/rule.rb +20 -0
  57. data/lib/policy_manager/version.rb +3 -0
  58. data/lib/policy_manager.rb +8 -0
  59. data/lib/tasks/terms_tasks.rake +4 -0
  60. metadata +145 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b508168e6f7964e7ed9455719b8828f42c3f4bc
4
+ data.tar.gz: 0fd77a485f155609c0e7a7b5fb6f7d92b24e8cf6
5
+ SHA512:
6
+ metadata.gz: 97d1ae4542cf9462b2c5ea35771e7c9c6c5cfa558b6dcf729a3e0938668ee4615391af7e14794bbf0e1049646f034937c9dd7e1a70c4317ead000ab3a7399705
7
+ data.tar.gz: 5ebdb33e81e72cc8605dafef381ab14b20130d095f06f2d4b6842536a94d32e8444336d645f42cbac17c98b7af4caa830dc56590ee8894cb6cebe71a16369d26
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Miguel Michelson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Terms
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'terms'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install terms
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Terms'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/terms .js
2
+ //= link_directory ../stylesheets/terms .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,99 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+
7
+ body {
8
+ font-size: .875rem;
9
+ }
10
+
11
+ .feather {
12
+ width: 16px;
13
+ height: 16px;
14
+ vertical-align: text-bottom;
15
+ }
16
+
17
+ /*
18
+ * Sidebar
19
+ */
20
+
21
+ .sidebar {
22
+ position: fixed;
23
+ top: 0;
24
+ bottom: 0;
25
+ left: 0;
26
+ z-index: 100; /* Behind the navbar */
27
+ padding: 0;
28
+ box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
29
+ }
30
+
31
+ .sidebar-sticky {
32
+ position: -webkit-sticky;
33
+ position: sticky;
34
+ top: 48px; /* Height of navbar */
35
+ height: calc(100vh - 48px);
36
+ padding-top: .5rem;
37
+ overflow-x: hidden;
38
+ overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
39
+ }
40
+
41
+ .sidebar .nav-link {
42
+ font-weight: 500;
43
+ color: #333;
44
+ }
45
+
46
+ .sidebar .nav-link .feather {
47
+ margin-right: 4px;
48
+ color: #999;
49
+ }
50
+
51
+ .sidebar .nav-link.active {
52
+ color: #007bff;
53
+ }
54
+
55
+ .sidebar .nav-link:hover .feather,
56
+ .sidebar .nav-link.active .feather {
57
+ color: inherit;
58
+ }
59
+
60
+ .sidebar-heading {
61
+ font-size: .75rem;
62
+ text-transform: uppercase;
63
+ }
64
+
65
+ /*
66
+ * Navbar
67
+ */
68
+
69
+ .navbar-brand {
70
+ padding-top: .75rem;
71
+ padding-bottom: .75rem;
72
+ font-size: 1rem;
73
+ background-color: rgba(0, 0, 0, .25);
74
+ box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
75
+ }
76
+
77
+ .navbar .form-control {
78
+ padding: .75rem 1rem;
79
+ border-width: 0;
80
+ border-radius: 0;
81
+ }
82
+
83
+ .form-control-dark {
84
+ color: #fff;
85
+ background-color: rgba(255, 255, 255, .1);
86
+ border-color: rgba(255, 255, 255, .1);
87
+ }
88
+
89
+ .form-control-dark:focus {
90
+ border-color: transparent;
91
+ box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
92
+ }
93
+
94
+ /*
95
+ * Utilities
96
+ */
97
+
98
+ .border-top { border-top: 1px solid #e5e5e5; }
99
+ .border-bottom { border-bottom: 1px solid #e5e5e5; }
@@ -0,0 +1,80 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ margin: 33px;
5
+ }
6
+
7
+ body, p, ol, ul, td {
8
+ font-family: verdana, arial, helvetica, sans-serif;
9
+ font-size: 13px;
10
+ line-height: 18px;
11
+ }
12
+
13
+ pre {
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ font-size: 11px;
17
+ }
18
+
19
+ a {
20
+ color: #000;
21
+ }
22
+
23
+ a:visited {
24
+ color: #666;
25
+ }
26
+
27
+ a:hover {
28
+ color: #fff;
29
+ background-color: #000;
30
+ }
31
+
32
+ th {
33
+ padding-bottom: 5px;
34
+ }
35
+
36
+ td {
37
+ padding: 0 5px 7px;
38
+ }
39
+
40
+ div.field,
41
+ div.actions {
42
+ margin-bottom: 10px;
43
+ }
44
+
45
+ #notice {
46
+ color: green;
47
+ }
48
+
49
+ .field_with_errors {
50
+ padding: 2px;
51
+ background-color: red;
52
+ display: table;
53
+ }
54
+
55
+ #error_explanation {
56
+ width: 450px;
57
+ border: 2px solid red;
58
+ padding: 7px 7px 0;
59
+ margin-bottom: 20px;
60
+ background-color: #f0f0f0;
61
+ }
62
+
63
+ #error_explanation h2 {
64
+ text-align: left;
65
+ font-weight: bold;
66
+ padding: 5px 5px 5px 15px;
67
+ font-size: 12px;
68
+ margin: -7px -7px 0;
69
+ background-color: #c00;
70
+ color: #fff;
71
+ }
72
+
73
+ #error_explanation ul li {
74
+ font-size: 12px;
75
+ list-style: square;
76
+ }
77
+
78
+ label {
79
+ display: block;
80
+ }
@@ -0,0 +1,5 @@
1
+ module PolicyManager
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "terms/application_controller"
2
+
3
+ module PolicyManager
4
+ class CategoriesController < ApplicationController
5
+ before_action :set_category, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /categories
8
+ def index
9
+ @categories = Category.all
10
+ end
11
+
12
+ # GET /categories/1
13
+ 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.'
49
+ end
50
+
51
+ 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
+ end
62
+ end
@@ -0,0 +1,6 @@
1
+ require_dependency "terms/application_controller"
2
+
3
+ module PolicyManager
4
+ class DashboardController < ApplicationController
5
+ end
6
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "terms/application_controller"
2
+
3
+ module PolicyManager
4
+ class TermsController < ApplicationController
5
+ before_action :set_term, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /terms
8
+ def index
9
+ @terms = Term.all
10
+ end
11
+
12
+ # GET /terms/1
13
+ def show
14
+ end
15
+
16
+ # GET /terms/new
17
+ def new
18
+ @term = Term.new
19
+ end
20
+
21
+ # GET /terms/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /terms
26
+ def create
27
+ @term = Term.new(term_params)
28
+
29
+ if @term.save
30
+ redirect_to category_term_path(@term.category, @term), notice: 'Term was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /terms/1
37
+ def update
38
+ if @term.update(term_params)
39
+ redirect_to category_term_path(@term.category, @term), notice: 'Term was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /terms/1
46
+ def destroy
47
+ @term.destroy
48
+ redirect_to category_terms_path(@term.category), notice: 'Term was successfully destroyed.'
49
+ end
50
+
51
+ 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
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def term_params
59
+ params.require(:term).permit(:description, :category_id)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,119 @@
1
+ require_dependency "terms/application_controller"
2
+
3
+ require "request_store"
4
+
5
+ module PolicyManager
6
+ class UserTermsController < ApplicationController
7
+ before_action :set_user_term, only: [:accept, :reject, :show, :edit, :update, :destroy]
8
+
9
+ if defined? Doorman
10
+ include Doorman::Controller
11
+ end
12
+
13
+ # GET /user_terms
14
+ def index
15
+ @user_terms = UserTerm.all
16
+ end
17
+
18
+ # GET /user_terms/1
19
+ def show
20
+ @user_term = current_user.handle_policy_for(@term)
21
+ end
22
+
23
+ def pending
24
+ @pending_policies = current_user.pending_policies
25
+ respond_to do |format|
26
+ format.html{ }
27
+ format.json{ render json: @pending_policies }
28
+ end
29
+ end
30
+
31
+ def accept
32
+ @user_term = current_user.handle_policy_for(@term)
33
+ @user_term.accept!
34
+ respond_to do |format|
35
+ format.html{
36
+ if @user_term.errors.any?
37
+ redirect_to root_url , notice: "hey there are some errors! #{@user_term.errors.full_messages.join()}"
38
+ else
39
+ redirect_to root_url
40
+ end
41
+ }
42
+ format.js
43
+ format.json
44
+ end
45
+ end
46
+
47
+ def reject
48
+ @user_term = current_user.handle_policy_for(term: @term)
49
+ @user_term.reject!
50
+ respond_to do |format|
51
+ format.html{
52
+ if @user_term.errors.any?
53
+ redirect_to root_url , notice: "hey there are some errors! #{@user_term.errors.full_messages.join()}"
54
+ else
55
+ redirect_to root_url
56
+ end
57
+ }
58
+ format.js
59
+ format.json{
60
+
61
+ if @user_term.errors.any?
62
+ render :json, url: root_url , notice: "hey there are some errors! #{@user_term.errors.full_messages.join()}"
63
+ else
64
+ render :json, url: root_url
65
+ end
66
+
67
+ }
68
+ end
69
+ end
70
+
71
+ # GET /user_terms/new
72
+ def new
73
+ @user_term = UserTerm.new
74
+ end
75
+
76
+ # GET /user_terms/1/edit
77
+ def edit
78
+ end
79
+
80
+ # POST /user_terms
81
+ def create
82
+ @user_term = UserTerm.new(user_term_params)
83
+
84
+ if @user_term.save
85
+ redirect_to @user_term, notice: 'User term was successfully created.'
86
+ else
87
+ render :new
88
+ end
89
+ end
90
+
91
+ # PATCH/PUT /user_terms/1
92
+ def update
93
+ if @user_term.update(user_term_params)
94
+ redirect_to @user_term, notice: 'User term was successfully updated.'
95
+ else
96
+ render :edit
97
+ end
98
+ end
99
+
100
+ # DELETE /user_terms/1
101
+ def destroy
102
+ @user_term.destroy
103
+ redirect_to user_terms_url, notice: 'User term was successfully destroyed.'
104
+ end
105
+
106
+ private
107
+ # Use callbacks to share common setup or constraints between actions.
108
+ def set_user_term
109
+ @category = Category.find(params[:id])
110
+ @term = @category.terms.last
111
+ #@term = Term.find(params[:id])
112
+ end
113
+
114
+ # Only allow a trusted parameter "white list" through.
115
+ def user_term_params
116
+ params.fetch(:user_term, {})
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,4 @@
1
+ module PolicyManager
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PolicyManager
2
+ module CategoriesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PolicyManager
2
+ module DashboardHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PolicyManager
2
+ module PolicyManagerCategoriesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PolicyManager
2
+ module PolicyManagerHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PolicyManager
2
+ module UserTermsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PolicyManager
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module PolicyManager
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module PolicyManager
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end