gdpr_rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,75 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module PolicyManager::Concerns::UserBehavior
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :user_terms, class_name: "PolicyManager::UserTerm"
7
+ has_many :terms, through: :user_terms
8
+ end
9
+
10
+ def pending_policies
11
+ # TODO: this seems to be a litle inefficient,
12
+ # hint: try to do this in one query
13
+ PolicyManager::Config.rules.select do |c|
14
+ self.needs_policy_confirmation_for?(c.name)
15
+ end
16
+ end
17
+
18
+ def confirm_all_policies!
19
+ peding_policies.each do |c|
20
+ term = c.terms.last
21
+ current_user.handle_policy_for(term).accept!
22
+ end
23
+ end
24
+
25
+ def reject_all_policies!
26
+ peding_policies.each do |c|
27
+ term = c.terms.last
28
+ current_user.handle_policy_for(term).reject!
29
+ end
30
+ end
31
+
32
+ def needs_policy_confirmation_for?(rule)
33
+ term = policy_term_on(rule)
34
+ user_term = policy_user_term_on(rule)
35
+ return false if term.blank?
36
+ return true if user_term.blank?
37
+ term.created_at > user_term.created_at
38
+ end
39
+
40
+ def is_confirmed?
41
+ end
42
+
43
+ def block_feature?
44
+ end
45
+
46
+ def policy_term_on(rule)
47
+ category = PolicyManager::Config.rules.find{|o| o.name == rule}
48
+ term = category.terms.last
49
+ return if term.blank?
50
+ term
51
+ end
52
+
53
+ def policy_user_term_on(rule)
54
+ term = policy_term_on(rule)
55
+ return if term.blank?
56
+ self.user_terms.where(term_id: term.id).first
57
+ end
58
+
59
+ def handle_policy_for(term)
60
+ self.user_terms.where(term_id: term).first_or_initialize do |member|
61
+ member.term_id = term.id
62
+ end
63
+ end
64
+
65
+
66
+ #######
67
+ ## DATA PORTABILITY
68
+ #######
69
+
70
+
71
+ #######
72
+ ## DATA FOGOTTABILITY
73
+ #######
74
+
75
+ end
@@ -0,0 +1,20 @@
1
+ require "redcarpet"
2
+
3
+ module PolicyManager
4
+ class Term < ApplicationRecord
5
+
6
+ validates_presence_of :rule
7
+
8
+ def self.renderer
9
+ @markdown = markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
10
+ end
11
+
12
+ def to_html
13
+ self.class.renderer.render(self.description)
14
+ end
15
+
16
+ def rule
17
+ PolicyManager::Config.rules.find{|o| o.name == self[:rule]}
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module PolicyManager
2
+ class UserTerm < ApplicationRecord
3
+ belongs_to :user
4
+ belongs_to :term
5
+
6
+ validates_uniqueness_of :term_id, :scope => :user_id
7
+
8
+ def accept!
9
+ self.state = "accepted"
10
+ self.save
11
+ end
12
+
13
+ def reject!
14
+ self.state = "rejected"
15
+ self.save
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,92 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Terms</title>
5
+
6
+ <%= csrf_meta_tags %>
7
+
8
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
9
+ <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
10
+
11
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
12
+
13
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
14
+
15
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
16
+ <script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
17
+
18
+ <%= stylesheet_link_tag "terms/application", media: "all" %>
19
+ <%= javascript_include_tag "terms/application" %>
20
+
21
+ </head>
22
+ <body>
23
+
24
+ <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
25
+ <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">PREYPROJECT</a>
26
+ <input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
27
+ <ul class="navbar-nav px-3">
28
+ <li class="nav-item text-nowrap">
29
+ <a class="nav-link" href="#">Sign out</a>
30
+ </li>
31
+ </ul>
32
+ </nav>
33
+
34
+ <div class="container-fluid">
35
+
36
+
37
+ <div class="row">
38
+ <nav class="col-md-2 d-none d-md-block bg-light sidebar">
39
+ <div class="sidebar-sticky">
40
+ <ul class="nav flex-column">
41
+ <li class="nav-item">
42
+ <a class="nav-link active" href="<%= root_url %>">
43
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg>
44
+ Dashboard <span class="sr-only">(current)</span>
45
+ </a>
46
+ </li>
47
+ <li class="nav-item">
48
+ <a class="nav-link" href="<%= categories_path %>">
49
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file"><path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline></svg>
50
+ Categories
51
+ </a>
52
+ </li>
53
+
54
+
55
+ <li class="nav-item">
56
+ <a class="nav-link" href="<%= pending_user_terms_path %>">
57
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file"><path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline></svg>
58
+ user's pending policies
59
+ </a>
60
+ </li>
61
+ </ul>
62
+
63
+ </div>
64
+ </nav>
65
+
66
+ <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
67
+
68
+ <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
69
+ <h1 class="h2">Policies</h1>
70
+ <div class="btn-toolbar mb-2 mb-md-0">
71
+ <div class="btn-group mr-2">
72
+ <button class="btn btn-sm btn-outline-secondary">Share</button>
73
+ <button class="btn btn-sm btn-outline-secondary">Export</button>
74
+ </div>
75
+ </div>
76
+ </div>
77
+
78
+ <p id="notice">
79
+ <%= notice %>
80
+ </p>
81
+
82
+ <%= yield %>
83
+ </main>
84
+ </div>
85
+
86
+
87
+
88
+
89
+ </div>
90
+
91
+ </body>
92
+ </html>
@@ -0,0 +1,22 @@
1
+ <%= form_with(model: category, local: true) do |form| %>
2
+ <% if category.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:</h2>
5
+
6
+ <ul>
7
+ <% category.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="form-group">
15
+ <%= form.label :name %>
16
+ <%= form.text_field :name, id: :category_name, class: "form-control" %>
17
+ </div>
18
+
19
+ <div class="actions">
20
+ <%= form.submit class: "btn btn-primary" %>
21
+ </div>
22
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Category</h1>
2
+
3
+ <%= render 'form', category: @category %>
4
+
5
+ <%= link_to 'Show', @category %> |
6
+ <%= link_to 'Back', categories_path %>
@@ -0,0 +1,32 @@
1
+
2
+ <h1>Categories</h1>
3
+
4
+
5
+ <div class="table-responsive">
6
+ <table class="table table-striped table-sm">
7
+ <thead>
8
+ <tr>
9
+ <th>Name</th>
10
+ <th>Articles</th>
11
+ <th colspan="3"></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @categories.each do |category| %>
17
+ <tr>
18
+ <td><%= category.name %></td>
19
+ <td><%= category.terms.size %></td>
20
+ <td><%= link_to 'Show', category %></td>
21
+ <td><%= link_to 'Edit', edit_category_path(category) %></td>
22
+ <td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
23
+ </tr>
24
+ <% end %>
25
+ </tbody>
26
+ </table>
27
+
28
+ </div>
29
+
30
+ <br>
31
+
32
+ <%= link_to 'New Category', new_category_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New Category</h1>
2
+
3
+ <%= render 'form', category: @category %>
4
+
5
+ <%= link_to 'Back', categories_path %>
@@ -0,0 +1,39 @@
1
+
2
+ <p>
3
+ <strong>Name:</strong>
4
+ <%= @category.name %>
5
+ </p>
6
+
7
+
8
+ <%= link_to 'New Article', new_category_term_path(@category), class: " btn btn-success float-right" %>
9
+
10
+ <%= link_to 'Edit', edit_category_path(@category), class: "btn btn-default" %> |
11
+ <%= link_to 'Back', categories_path , class: "btn btn-default"%>
12
+
13
+
14
+
15
+ <div class="table-responsive">
16
+ <table class="table table-striped table-sm">
17
+ <thead>
18
+ <tr>
19
+ <th>ID</th>
20
+ <th>content</th>
21
+ <th>updated at</th>
22
+ <th colspan="3"></th>
23
+ </tr>
24
+ </thead>
25
+
26
+ <tbody>
27
+ <% @category.terms.each do |term| %>
28
+ <tr>
29
+ <td><%= term.id %></td>
30
+ <td><%= truncate(term.description, length: 17, separator: " ", omission: '... (more)') %></td>
31
+ <td><%= term.updated_at %></td>
32
+ <td><%= link_to 'Show', category_term_path(@category, term) %></td>
33
+ <td><%= link_to 'Edit', edit_category_term_path(@category, term) %></td>
34
+ <td><%= link_to 'Destroy', category_term_path(@category, term), method: :delete, data: { confirm: 'Are you sure?' } %></td>
35
+ </tr>
36
+ <% end %>
37
+ </tbody>
38
+ </table>
39
+ </div>
@@ -0,0 +1,33 @@
1
+
2
+ <h3>Categories</h3>
3
+
4
+ <div>
5
+ <% PolicyManager::UserTerm.group("year(created_at)").group("month(created_at)").count.each do |ut| %>
6
+ <%= ut.first %> | <%= ut.last %>
7
+ <% end %>
8
+ </div>
9
+
10
+ <div class="table-responsive">
11
+ <table class="table table-striped table-sm">
12
+ <thead>
13
+ <tr>
14
+ <th>Name</th>
15
+ <th>Articles</th>
16
+ <th colspan="3"></th>
17
+ </tr>
18
+ </thead>
19
+
20
+ <tbody>
21
+ <% PolicyManager::Category.all.each do |category| %>
22
+ <tr>
23
+ <td><%= category.name %></td>
24
+ <td><%= category.terms.size %></td>
25
+ <td><%= link_to 'Show', category %></td>
26
+ <td><%= link_to 'Edit', edit_category_path(category) %></td>
27
+ <td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
28
+ </tr>
29
+ <% end %>
30
+ </tbody>
31
+ </table>
32
+
33
+
@@ -0,0 +1,32 @@
1
+
2
+ <% path = @term.persisted? ? category_term_path(params[:category_id], @term) : category_terms_path(params[:category_id]) %>
3
+
4
+ <%= form_with(model: term, local: true, url: path ) do |form| %>
5
+ <% if term.errors.any? %>
6
+ <div id="error_explanation">
7
+ <h2><%= pluralize(term.errors.count, "error") %> prohibited this term from being saved:</h2>
8
+
9
+ <ul>
10
+ <% term.errors.full_messages.each do |message| %>
11
+ <li><%= message %></li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
15
+ <% end %>
16
+
17
+ <div class="form-group">
18
+ <%= form.select :category_id, PolicyManager::Category.all.map{|o| [o.name, o.id]}, :selected => params[:category_id] %>
19
+ <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
20
+ </div>
21
+ <div class="form-group">
22
+ <%= form.label :description %>
23
+ <%= form.text_area :description, id: :term_description, class: "form-control" %>
24
+ </div>
25
+
26
+ <%= form.submit class: "btn btn-primary" %>
27
+
28
+ <% end %>
29
+
30
+ <script>
31
+ var simplemde = new SimpleMDE({ element: $("#term_description")[0] });
32
+ </script>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Term</h1>
2
+
3
+ <%= render 'form', term: @term %>
4
+
5
+ <%= link_to 'Show', category_term_path(@term.category, @term) %> |
6
+ <%= link_to 'Back', category_terms_path %>
@@ -0,0 +1,33 @@
1
+
2
+ <h2>Terms</h2>
3
+
4
+ <div class="table-responsive">
5
+ <table class="table table-striped table-sm">
6
+ <thead>
7
+ <tr>
8
+ <th>Description</th>
9
+ <th>Category</th>
10
+ <th>updated at</th>
11
+ <th colspan="3"></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @terms.each do |term| %>
17
+ <tr>
18
+ <td><%= truncate(term.description, length: 170, separator: " ", omission: '... (more)') %></td>
19
+ <td><%= term.category.name %></td>
20
+ <td><%= term.updated_at %></td>
21
+ <td><%= link_to 'Show', category_term_path(term.category,term) %></td>
22
+ <td><%= link_to 'Edit', edit_category_term_path(term.category,term) %></td>
23
+ <td><%= link_to 'Destroy', category_term_path(term.category, term), method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ </div>
30
+
31
+ <br>
32
+
33
+ <%= link_to 'New Term', new_category_term_path(params[:category_id]) %>
@@ -0,0 +1,5 @@
1
+ <h1>New Term</h1>
2
+
3
+ <%= render 'form', term: @term %>
4
+
5
+ <%= link_to 'Back', category_terms_path(params[:category_id]) %>
@@ -0,0 +1,16 @@
1
+
2
+ <div class="float-right">
3
+ published in
4
+ <span class="badge badge-pill badge-primary">
5
+ <%= @term.category.name %>
6
+ </span>
7
+ <br/>
8
+ <span class="text-muted">
9
+ last updated on <%= @term.updated_at %>
10
+ </span>
11
+ </div>
12
+
13
+ <%= raw @term.to_html %>
14
+
15
+ <%= link_to 'Edit', edit_category_term_path(@term.category, @term) %> |
16
+ <%= link_to 'Back', category_terms_path(@term.category) %>
@@ -0,0 +1,17 @@
1
+ <%= form_with(model: terms_category, local: true) do |form| %>
2
+ <% if terms_category.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(terms_category.errors.count, "error") %> prohibited this terms_category from being saved:</h2>
5
+
6
+ <ul>
7
+ <% terms_category.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="actions">
15
+ <%= form.submit %>
16
+ </div>
17
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Terms Category</h1>
2
+
3
+ <%= render 'form', terms_category: @terms_category %>
4
+
5
+ <%= link_to 'Show', @terms_category %> |
6
+ <%= link_to 'Back', terms_categories_path %>
@@ -0,0 +1,24 @@
1
+
2
+ <h1>Terms Categories</h1>
3
+
4
+ <table>
5
+ <thead>
6
+ <tr>
7
+ <th colspan="3"></th>
8
+ </tr>
9
+ </thead>
10
+
11
+ <tbody>
12
+ <% @terms_categories.each do |terms_category| %>
13
+ <tr>
14
+ <td><%= link_to 'Show', terms_category %></td>
15
+ <td><%= link_to 'Edit', edit_terms_category_path(terms_category) %></td>
16
+ <td><%= link_to 'Destroy', terms_category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
17
+ </tr>
18
+ <% end %>
19
+ </tbody>
20
+ </table>
21
+
22
+ <br>
23
+
24
+ <%= link_to 'New Terms Category', new_terms_category_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New Terms Category</h1>
2
+
3
+ <%= render 'form', terms_category: @terms_category %>
4
+
5
+ <%= link_to 'Back', terms_categories_path %>
@@ -0,0 +1,4 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <%= link_to 'Edit', edit_terms_category_path(@terms_category) %> |
4
+ <%= link_to 'Back', terms_categories_path %>
@@ -0,0 +1,17 @@
1
+ <%= form_with(model: user_term, local: true) do |form| %>
2
+ <% if user_term.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(user_term.errors.count, "error") %> prohibited this user_term from being saved:</h2>
5
+
6
+ <ul>
7
+ <% user_term.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="actions">
15
+ <%= form.submit %>
16
+ </div>
17
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing User Term</h1>
2
+
3
+ <%= render 'form', user_term: @user_term %>
4
+
5
+ <%= link_to 'Show', @user_term %> |
6
+ <%= link_to 'Back', user_terms_path %>
@@ -0,0 +1,24 @@
1
+
2
+ <h1>User Terms</h1>
3
+
4
+ <table>
5
+ <thead>
6
+ <tr>
7
+ <th colspan="3"></th>
8
+ </tr>
9
+ </thead>
10
+
11
+ <tbody>
12
+ <% @user_terms.each do |user_term| %>
13
+ <tr>
14
+ <td><%= link_to 'Show', user_term %></td>
15
+ <td><%= link_to 'Edit', edit_user_term_path(user_term) %></td>
16
+ <td><%= link_to 'Destroy', user_term, method: :delete, data: { confirm: 'Are you sure?' } %></td>
17
+ </tr>
18
+ <% end %>
19
+ </tbody>
20
+ </table>
21
+
22
+ <br>
23
+
24
+ <%= link_to 'New User Term', new_user_term_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New User Term</h1>
2
+
3
+ <%= render 'form', user_term: @user_term %>
4
+
5
+ <%= link_to 'Back', user_terms_path %>
@@ -0,0 +1,7 @@
1
+ <h2>Pending Policies </h2>
2
+
3
+ <ul>
4
+ <% @pending_policies.each do |category| %>
5
+ <li><%= link_to category.name, user_term_path(category.id) %></li>
6
+ <% end %>
7
+ </ul>
@@ -0,0 +1,32 @@
1
+
2
+ <%= raw @term.to_html %>
3
+
4
+ <hr/>
5
+
6
+ <% if @user_term.persisted? && @user_term.state == "accepted" %>
7
+
8
+ <div>
9
+ <strong>THIS POLICY HAS ALREADY BEEN ACCEPTED</strong>
10
+ <br/> change your mind ??
11
+
12
+ <%= form_with model: @user_term, url: reject_user_term_path(params[:id]), method: :put, local: true do |f| %>
13
+ <%= f.submit "reject", class: "btn btn-danger" %>
14
+ <a href="" class="btn btn-secondary">not now</a>
15
+ <% end %>
16
+
17
+ </div>
18
+
19
+ <% else %>
20
+ <strong>
21
+ <%= current_user.email %>
22
+ </strong> please accept terms
23
+
24
+ <hr/>
25
+
26
+ <%= form_with model: @user_term, url: accept_user_term_path(params[:id]), method: :put, local: true do |f| %>
27
+ <%= f.submit "accept", class: "btn btn-success" %>
28
+ <a href="" class="btn btn-secondary">not now</a>
29
+ <% end %>
30
+
31
+ <hr/>
32
+ <% end %>
@@ -0,0 +1,11 @@
1
+ json.body raw( @term.to_html)
2
+
3
+ if @user_term.persisted? && @user_term.state == "accepted"
4
+ json.message "THIS POLICY HAS ALREADY BEEN ACCEPTED"
5
+ json.url reject_user_term_path(params[:id])
6
+ json.method :put
7
+ else
8
+ json.message "#{current_user.email} please accept terms"
9
+ json.url accept_user_term_path(params[:id])
10
+ json.method :put
11
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,20 @@
1
+ PolicyManager::Engine.routes.draw do
2
+
3
+ resources :categories do
4
+ resources :terms
5
+ end
6
+ resources :terms_categories
7
+ resources :user_terms do
8
+ collection do
9
+ get :pending
10
+ end
11
+
12
+ member do
13
+ put :accept
14
+ put :reject
15
+ end
16
+ end
17
+ #resources :terms
18
+ root 'dashboard#index'
19
+
20
+ end
@@ -0,0 +1,11 @@
1
+ class CreatePolicyManagerTerms < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :policy_manager_terms do |t|
4
+ t.text :description
5
+ t.string :rule
6
+ t.datetime :accepted_at
7
+ t.datetime :rejected_at
8
+ t.timestamps
9
+ end
10
+ end
11
+ end