fine_print 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +124 -0
  3. data/Rakefile +23 -0
  4. data/app/assets/javascripts/fine_print/agreements.js +19 -0
  5. data/app/assets/javascripts/fine_print/agreements.js~ +19 -0
  6. data/app/assets/javascripts/fine_print/application.js +4 -0
  7. data/app/assets/javascripts/fine_print/application.js~ +5 -0
  8. data/app/assets/javascripts/fine_print/dialog.js +2 -0
  9. data/app/assets/javascripts/fine_print/dialog.js~ +2 -0
  10. data/app/assets/javascripts/fine_print/user_agreements.js +20 -0
  11. data/app/assets/javascripts/fine_print/user_agreements.js~ +20 -0
  12. data/app/assets/stylesheets/fine_print/agreements.css +11 -0
  13. data/app/assets/stylesheets/fine_print/agreements.css~ +11 -0
  14. data/app/assets/stylesheets/fine_print/application.css +5 -0
  15. data/app/assets/stylesheets/fine_print/application.css~ +60 -0
  16. data/app/assets/stylesheets/fine_print/scaffold.css +56 -0
  17. data/app/assets/stylesheets/fine_print/user_agreements.css~ +3 -0
  18. data/app/assets/stylesheets/scaffold.css~ +56 -0
  19. data/app/controllers/fine_print/agreements_controller.rb +114 -0
  20. data/app/controllers/fine_print/agreements_controller.rb~ +113 -0
  21. data/app/controllers/fine_print/application_controller.rb +13 -0
  22. data/app/controllers/fine_print/application_controller.rb~ +13 -0
  23. data/app/controllers/fine_print/home_controller.rb +14 -0
  24. data/app/controllers/fine_print/home_controller.rb~ +15 -0
  25. data/app/controllers/fine_print/user_agreements_controller.rb +63 -0
  26. data/app/controllers/fine_print/user_agreements_controller.rb~ +63 -0
  27. data/app/models/fine_print/agreement.rb +50 -0
  28. data/app/models/fine_print/agreement.rb~ +50 -0
  29. data/app/models/fine_print/user_agreement.rb +19 -0
  30. data/app/models/fine_print/user_agreement.rb~ +21 -0
  31. data/app/views/fine_print/agreements/_agreement.html.erb +77 -0
  32. data/app/views/fine_print/agreements/_agreement.html.erb~ +77 -0
  33. data/app/views/fine_print/agreements/_dialog.html.erb +27 -0
  34. data/app/views/fine_print/agreements/_dialog.html.erb~ +27 -0
  35. data/app/views/fine_print/agreements/_form.html.erb +51 -0
  36. data/app/views/fine_print/agreements/_form.html.erb~ +51 -0
  37. data/app/views/fine_print/agreements/edit.html.erb +8 -0
  38. data/app/views/fine_print/agreements/edit.html.erb~ +8 -0
  39. data/app/views/fine_print/agreements/index.html.erb +32 -0
  40. data/app/views/fine_print/agreements/index.html.erb~ +32 -0
  41. data/app/views/fine_print/agreements/new.html.erb +7 -0
  42. data/app/views/fine_print/agreements/new.html.erb~ +7 -0
  43. data/app/views/fine_print/agreements/new_version.html.erb +7 -0
  44. data/app/views/fine_print/agreements/new_version.html.erb~ +7 -0
  45. data/app/views/fine_print/agreements/show.html.erb +15 -0
  46. data/app/views/fine_print/agreements/show.html.erb~ +14 -0
  47. data/app/views/fine_print/home/index.html.erb +7 -0
  48. data/app/views/fine_print/home/index.html.erb~ +7 -0
  49. data/app/views/fine_print/user_agreements/cancel.js.erb +1 -0
  50. data/app/views/fine_print/user_agreements/cancel.js.erb~ +2 -0
  51. data/app/views/fine_print/user_agreements/create.js.erb +2 -0
  52. data/app/views/fine_print/user_agreements/create.js.erb~ +2 -0
  53. data/app/views/fine_print/user_agreements/index.html.erb +25 -0
  54. data/app/views/fine_print/user_agreements/index.html.erb~ +25 -0
  55. data/app/views/layouts/fine_print/application.html.erb +14 -0
  56. data/config/initializers/fine_print.rb +53 -0
  57. data/config/initializers/fine_print.rb~ +53 -0
  58. data/config/routes.rb +7 -0
  59. data/config/routes.rb~ +7 -0
  60. data/db/migrate/0_create_fine_print_agreements.rb~ +22 -0
  61. data/db/migrate/0_install.rb +28 -0
  62. data/db/migrate/0_install.rb~ +28 -0
  63. data/lib/fine_print/agreements_helper.rb +13 -0
  64. data/lib/fine_print/agreements_helper.rb~ +11 -0
  65. data/lib/fine_print/engine.rb +5 -0
  66. data/lib/fine_print/fine_print_agreement.rb +26 -0
  67. data/lib/fine_print/fine_print_agreement.rb~ +26 -0
  68. data/lib/fine_print/require_agreement.rb~ +22 -0
  69. data/lib/fine_print/security_transgression.rb +4 -0
  70. data/lib/fine_print/security_transgression.rb~ +3 -0
  71. data/lib/fine_print/version.rb +3 -0
  72. data/lib/fine_print/version.rb~ +3 -0
  73. data/lib/fine_print.rb +69 -0
  74. data/lib/fine_print.rb~ +68 -0
  75. data/lib/tasks/fine_print_tasks.rake +42 -0
  76. data/lib/tasks/fine_print_tasks.rake~ +85 -0
  77. data/spec/dummy/README.md +3 -0
  78. data/spec/dummy/README.md~ +3 -0
  79. data/spec/dummy/Rakefile +7 -0
  80. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  81. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  82. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  83. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  84. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  85. data/spec/dummy/config/application.rb +59 -0
  86. data/spec/dummy/config/boot.rb +10 -0
  87. data/spec/dummy/config/database.yml +25 -0
  88. data/spec/dummy/config/environment.rb +5 -0
  89. data/spec/dummy/config/environments/development.rb +37 -0
  90. data/spec/dummy/config/environments/production.rb +67 -0
  91. data/spec/dummy/config/environments/test.rb +37 -0
  92. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  93. data/spec/dummy/config/initializers/inflections.rb +15 -0
  94. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  95. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  96. data/spec/dummy/config/initializers/session_store.rb +8 -0
  97. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  98. data/spec/dummy/config/locales/en.yml +5 -0
  99. data/spec/dummy/config/routes.rb +4 -0
  100. data/spec/dummy/config.ru +4 -0
  101. data/spec/dummy/db/development.sqlite3 +0 -0
  102. data/spec/dummy/db/schema.rb +36 -0
  103. data/spec/dummy/db/test.sqlite3 +0 -0
  104. data/spec/dummy/log/development.log +41 -0
  105. data/spec/dummy/log/test.log +3 -0
  106. data/spec/dummy/public/404.html +26 -0
  107. data/spec/dummy/public/422.html +26 -0
  108. data/spec/dummy/public/500.html +25 -0
  109. data/spec/dummy/public/favicon.ico +0 -0
  110. data/spec/dummy/script/rails +6 -0
  111. data/spec/fine_print_spec.rb +7 -0
  112. data/spec/fine_print_spec.rb~ +7 -0
  113. data/spec/minitest_helper.rb +12 -0
  114. metadata +277 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Rice University
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,124 @@
1
+ # FinePrint
2
+
3
+ FinePrint is a Rails gem that makes managing web site agreements (terms, privacy policy, etc) simple and easy.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```rb
10
+ gem 'fine_print'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself:
20
+
21
+ ```sh
22
+ $ gem install fine_print
23
+ ```
24
+
25
+ Then execute the following command to copy the necessary migration and the initializer to your application:
26
+
27
+ ```sh
28
+ $ rake fine_print:install
29
+ ```
30
+
31
+ And then migrate your database:
32
+
33
+ ```sh
34
+ $ rake db:migrate
35
+ ```
36
+
37
+ Also add FinePrint to your application's routes:
38
+
39
+ ```rb
40
+ mount FinePrint::Engine => "/fine_print"
41
+ ```
42
+
43
+ And provide a link on your site for administrators to access the fine_print engine to manage agreements.
44
+
45
+ ```erb
46
+ <%= link_to 'FinePrint', fine_print_path %>
47
+ ```
48
+
49
+ Finally, make sure your `application.js` requires jquery and jquery_ujs (it usually does by default):
50
+
51
+ ```js
52
+ //= require jquery
53
+ //= require jquery_ujs
54
+ ```
55
+
56
+ **Note:** FinePrint will **automatically** add the fine_print/dialog.js file to your asset precompilation list.
57
+
58
+ ## Configuration
59
+
60
+ After installation, the initializer for FinePrint will be located under `config/initializers/fine_print.rb`.
61
+ Make sure to configure it to suit your needs.
62
+ Pay particular attention to `user_admin_proc`, as you will be unable to manage your agreements unless you set up this proc to return true for your admins.
63
+
64
+ If you want to use FinePrint's modal dialogs, then make sure `application.js` also requires jquery-ui:
65
+
66
+ ```js
67
+ //= require jquery-ui
68
+ ```
69
+
70
+ ## Usage
71
+
72
+ FinePrint adds a new method to all controllers that behaves like a before_filter.
73
+ It can be accessed by calling `fine_print_agreement` from any controller.
74
+ This method takes an agreement name and an options hash.
75
+ Accepted options are (see initializer for more explanation):
76
+
77
+ - `only` and `except` just like a before_filter
78
+
79
+ - `agreement_notice` notice to be shown to the user above the agreement
80
+
81
+ - `accept_path` path to redirect users to when an agreement is accepted and no referer information is available
82
+ - `cancel_path` path to redirect users to when an agreement is not accepted and no referer information is available
83
+ - `use_referers` false if you want users to always be redirected to the above paths
84
+
85
+ - `use_modal_dialogs` true if you want to use FinePrint's modal dialogs
86
+
87
+ Example:
88
+
89
+ ```rb
90
+ fine_print_agreement 'terms of use', :except => :index, :use_modal_dialogs => true
91
+ ```
92
+
93
+ This gem also adds the `fine_print_dialog` helper method, which needs to be called (usually from your layout) if you want to use FinePrint's modal dialogs.
94
+ This method only takes an options hash. Accepted options are:
95
+
96
+ - `width`
97
+ - `height`
98
+
99
+ Example:
100
+
101
+ ```erb
102
+ <%= fine_print_dialog, :width => 800, :height => 600 %>
103
+ ```
104
+
105
+ ## Managing Agreements
106
+
107
+ Here are some important notes about managing your agreements with FinePrint:
108
+
109
+ - Agreements are referred to on your controller by the name you specified
110
+ - Creating another agreement with the same name will make it a new version of a previous agreement
111
+ - Agreements need to be marked as `ready` to be able to be accepted by users
112
+ - The latest version of each agreement that is marked as `ready` will always be used
113
+ - Agreements cannot be modified after at least one user has accepted them, but you can always create new versions
114
+ - When a new version is present, users will be asked to accept it the next time they visit a controller action that calls `fine_print_agreement`
115
+
116
+ ## Contributing
117
+
118
+ 1. Fork it
119
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
120
+ 3. Create specs for your feature
121
+ 4. Ensure that all specs pass
122
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
123
+ 6. Push to the branch (`git push origin my-new-feature`)
124
+ 7. Create new pull request
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
9
+ load 'rails/tasks/engine.rake'
10
+
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ require 'rake/testtask'
14
+
15
+ Rake::TestTask.new(:test => 'app:db:test:prepare') do |t|
16
+ t.libs << 'lib'
17
+ t.libs << 'spec'
18
+ t.pattern = 'spec/**/*_spec.rb'
19
+ t.verbose = false
20
+ end
21
+
22
+ task :default => :test
23
+
@@ -0,0 +1,19 @@
1
+ function fine_print_agreement_checkbox(index) {
2
+ var checkbox = $("#fine_print_confirmation_checkbox_" + index);
3
+ if (!checkbox) {
4
+ return;
5
+ }
6
+ checkbox.change(function() {
7
+ $("#fine_print_submit_ok_" + index).attr("disabled", !this.checked);
8
+ try {
9
+ if (this.checked) {
10
+ $("#fine_print_submit_ok_" + index).button("enable");
11
+ }
12
+ else {
13
+ $("#fine_print_submit_ok_" + index).button("disable");
14
+ }
15
+ }
16
+ catch(e) {}
17
+ });
18
+ $("#fine_print_submit_ok_" + index).attr("disabled", !checkbox.checked);
19
+ }
@@ -0,0 +1,19 @@
1
+ function fine_print_agreement_checkbox(index) {
2
+ var checkbox = $("#fine_print_confirmation_checkbox_" + index);
3
+ if (!checkbox) {
4
+ return;
5
+ }
6
+ checkbox.change(function() {
7
+ $("#fine_print_submit_ok_" + index).attr("disabled", !this.checked);
8
+ try {
9
+ if (this.checked) {
10
+ $("#fine_print_submit_ok_" + index).button("enable");
11
+ }
12
+ else {
13
+ $("#fine_print_submit_ok_" + index).button("disable");
14
+ }
15
+ }
16
+ catch (e) {}
17
+ });
18
+ $("#fine_print_submit_ok_" + index).attr("disabled", !checkbox.checked);
19
+ }
@@ -0,0 +1,4 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require fine_print/agreements
4
+ //= require fine_print/user_agreements
@@ -0,0 +1,5 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require jquery-ui
4
+ //= require fine_print/agreements
5
+ //= require fine_print/user_agreements
@@ -0,0 +1,2 @@
1
+ //= require fine_print/agreements
2
+ //= require fine_print/user_agreements
@@ -0,0 +1,2 @@
1
+ //= require agreements
2
+ //= require user_agreements
@@ -0,0 +1,20 @@
1
+ function fine_print_init_dialog(index, width, height) {
2
+ $("#fine_print_dialog_" + index).dialog({
3
+ autoOpen: false,
4
+ draggable: false,
5
+ modal: true,
6
+ resizable: false,
7
+ width: width,
8
+ height: height
9
+ }).on("dialogbeforeclose", function(event, ui) {
10
+ window.history.back();
11
+ return false;
12
+ });
13
+ }
14
+
15
+ $(function () {
16
+ try {
17
+ $("#fine_print_dialog_0").dialog("open");
18
+ }
19
+ catch(e) {}
20
+ });
@@ -0,0 +1,20 @@
1
+ function fine_print_init_dialog(index, width, height) {
2
+ $("#fine_print_dialog_" + index).dialog({
3
+ autoOpen: false,
4
+ draggable: false,
5
+ modal: true,
6
+ resizable: false,
7
+ width: 640,
8
+ height: 480
9
+ }).on("dialogbeforeclose", function(event, ui) {
10
+ window.history.back();
11
+ return false;
12
+ });
13
+ }
14
+
15
+ $(function () {
16
+ try {
17
+ $("#fine_print_dialog_0").dialog("open");
18
+ }
19
+ catch(e) {}
20
+ });
@@ -0,0 +1,11 @@
1
+ pre.fine_print.agreement.content {
2
+ background-color: white;
3
+ }
4
+
5
+ div.fine_print.agreement.dialog {
6
+ display: none;
7
+ }
8
+
9
+ input.fine_print.checkbox {
10
+ float: left;
11
+ }
@@ -0,0 +1,11 @@
1
+ pre.fine_print.agreement.content {
2
+ background-color: white;
3
+ }
4
+
5
+ pre.fine_print.agreement.dialog {
6
+ display: none;
7
+ }
8
+
9
+ input.fine_print.checkbox {
10
+ float: left;
11
+ }
@@ -0,0 +1,5 @@
1
+ /*
2
+ *= require_self
3
+ *= require_tree .
4
+ */
5
+
@@ -0,0 +1,60 @@
1
+ /*
2
+ *= require_self
3
+ *= require_tree .
4
+ */
5
+ body { background-color: #fff; color: #333; }
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 { color: #000; }
20
+ a:visited { color: #666; }
21
+ a:hover { color: #fff; background-color:#000; }
22
+
23
+ div.field, div.actions {
24
+ margin-bottom: 10px;
25
+ }
26
+
27
+ #notice {
28
+ color: green;
29
+ }
30
+
31
+ .field_with_errors {
32
+ padding: 2px;
33
+ background-color: red;
34
+ display: table;
35
+ }
36
+
37
+ #error_explanation {
38
+ width: 450px;
39
+ border: 2px solid red;
40
+ padding: 7px;
41
+ padding-bottom: 0;
42
+ margin-bottom: 20px;
43
+ background-color: #f0f0f0;
44
+ }
45
+
46
+ #error_explanation h2 {
47
+ text-align: left;
48
+ font-weight: bold;
49
+ padding: 5px 5px 5px 15px;
50
+ font-size: 12px;
51
+ margin: -7px;
52
+ margin-bottom: 0px;
53
+ background-color: #c00;
54
+ color: #fff;
55
+ }
56
+
57
+ #error_explanation ul li {
58
+ font-size: 12px;
59
+ list-style: square;
60
+ }
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,3 @@
1
+ input.fine_print .check_box {
2
+ float: left;
3
+ }
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,114 @@
1
+ require_dependency "fine_print/application_controller"
2
+
3
+ module FinePrint
4
+ class AgreementsController < ApplicationController
5
+ # GET /agreements
6
+ # GET /agreements.json
7
+ def index
8
+ raise SecurityTransgression unless Agreement.can_be_listed_by?(@user)
9
+ @agreements = Agreement.all
10
+
11
+ respond_to do |format|
12
+ format.html # index.html.erb
13
+ format.json { render json: @agreements }
14
+ end
15
+ end
16
+
17
+ # GET /agreements/1
18
+ # GET /agreements/1.json
19
+ def show
20
+ @agreement = Agreement.find(params[:id])
21
+ raise SecurityTransgression unless @agreement.can_be_read_by?(@user)
22
+ @user_agreement = UserAgreement.new(:agreement => @agreement) if @agreement.can_be_accepted_by?(@user)
23
+ @accept_path = session.delete(:fine_print_accept_path)
24
+ @cancel_path = session.delete(:fine_print_cancel_path)
25
+ @url = session.delete(:fine_print_request_url)
26
+ @ref = session.delete(:fine_print_request_ref)
27
+
28
+ respond_to do |format|
29
+ format.html # show.html.erb
30
+ format.json { render json: @agreement }
31
+ end
32
+ end
33
+
34
+ # GET /agreements/new
35
+ # GET /agreements/new.json
36
+ def new
37
+ @agreement = Agreement.new
38
+ raise SecurityTransgression unless @agreement.can_be_created_by?(@user)
39
+
40
+ respond_to do |format|
41
+ format.html # new.html.erb
42
+ format.json { render json: @agreement }
43
+ end
44
+ end
45
+
46
+ # GET /agreements/1/edit
47
+ def edit
48
+ @agreement = Agreement.find(params[:id])
49
+ raise SecurityTransgression unless @agreement.can_be_edited_by?(@user)
50
+ end
51
+
52
+ # GET /agreements/1/new_version
53
+ def new_version
54
+ @agreement = Agreement.find(params[:agreement_id]).dup
55
+ raise SecurityTransgression unless @agreement.can_be_created_by?(@user)
56
+
57
+ respond_to do |format|
58
+ format.html # new_version.html.erb
59
+ format.json { render json: @agreement }
60
+ end
61
+ end
62
+
63
+ # POST /agreements
64
+ # POST /agreements.json
65
+ def create
66
+ @agreement = Agreement.new(params[:agreement])
67
+ raise SecurityTransgression unless @agreement.can_be_created_by?(@user)
68
+ @agreement.version = Agreement.next_version(@agreement.name)
69
+
70
+ respond_to do |format|
71
+ if @agreement.save
72
+ format.html { redirect_to @agreement, notice: 'Agreement was successfully created.' }
73
+ format.json { render json: @agreement, status: :created, location: @agreement }
74
+ else
75
+ format.html { render action: "new" }
76
+ format.json { render json: @agreement.errors, status: :unprocessable_entity }
77
+ end
78
+ end
79
+ end
80
+
81
+ # PUT /agreements/1
82
+ # PUT /agreements/1.json
83
+ def update
84
+ @agreement = Agreement.find(params[:id])
85
+ raise SecurityTransgression unless @agreement.can_be_edited_by?(@user)
86
+ if params[:agreement][:name].try(:downcase) != @agreement.name.downcase
87
+ params[:agreement][:version] = Agreement.next_version(params[:agreement][:name])
88
+ end
89
+
90
+ respond_to do |format|
91
+ if @agreement.update_attributes(params[:agreement])
92
+ format.html { redirect_to @agreement, notice: 'Agreement was successfully updated.' }
93
+ format.json { head :no_content }
94
+ else
95
+ format.html { render action: "edit" }
96
+ format.json { render json: @agreement.errors, status: :unprocessable_entity }
97
+ end
98
+ end
99
+ end
100
+
101
+ # DELETE /agreements/1
102
+ # DELETE /agreements/1.json
103
+ def destroy
104
+ @agreement = Agreement.find(params[:id])
105
+ raise SecurityTransgression unless @agreement.can_be_destroyed_by?(@user)
106
+ @agreement.destroy
107
+
108
+ respond_to do |format|
109
+ format.html { redirect_to agreements_url }
110
+ format.json { head :no_content }
111
+ end
112
+ end
113
+ end
114
+ end