fine_print 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -2
  3. data/Rakefile +0 -1
  4. data/app/assets/javascripts/fine_print/application.js +0 -1
  5. data/app/assets/stylesheets/fine_print/application.css +0 -1
  6. data/app/controllers/fine_print/application_controller.rb +9 -4
  7. data/app/controllers/fine_print/contracts_controller.rb +16 -12
  8. data/app/controllers/fine_print/home_controller.rb +5 -0
  9. data/app/controllers/fine_print/signatures_controller.rb +44 -2
  10. data/app/models/fine_print/contract.rb +17 -45
  11. data/app/models/fine_print/signature.rb +4 -3
  12. data/app/views/fine_print/contracts/_show.html.erb +11 -0
  13. data/app/views/fine_print/contracts/edit.html.erb +1 -1
  14. data/app/views/fine_print/contracts/index.html.erb +12 -14
  15. data/app/views/fine_print/contracts/new_version.html.erb +1 -1
  16. data/app/views/fine_print/contracts/show.html.erb +18 -29
  17. data/app/views/fine_print/signatures/_form.html.erb +21 -0
  18. data/app/views/fine_print/signatures/index.html.erb +3 -7
  19. data/app/views/fine_print/signatures/new.html.erb +13 -0
  20. data/config/initializers/fine_print.rb +36 -33
  21. data/config/routes.rb +5 -5
  22. data/db/migrate/0_install_fine_print.rb +2 -3
  23. data/lib/fine_print/controller_includes.rb +41 -67
  24. data/lib/fine_print/engine.rb +3 -0
  25. data/lib/fine_print/version.rb +1 -1
  26. data/lib/fine_print.rb +48 -57
  27. data/spec/controllers/contracts_controller_spec.rb +98 -98
  28. data/spec/controllers/home_controller_spec.rb +7 -5
  29. data/spec/controllers/signatures_controller_spec.rb +48 -19
  30. data/spec/dummy/app/models/dummy_user.rb +0 -1
  31. data/spec/dummy/config/initializers/fine_print.rb +2 -1
  32. data/spec/dummy/db/development.sqlite3 +0 -0
  33. data/spec/dummy/db/test.sqlite3 +0 -0
  34. data/spec/dummy/log/development.log +31970 -0
  35. data/spec/dummy/log/test.log +71587 -0
  36. data/spec/lib/fine_print/controller_includes_spec.rb +9 -14
  37. data/spec/lib/fine_print_spec.rb +15 -9
  38. data/spec/models/contract_spec.rb +17 -25
  39. data/spec/models/signature_spec.rb +4 -14
  40. data/spec/spec_helper.rb +1 -2
  41. metadata +33 -4
  42. data/app/views/fine_print/home/index.html.erb +0 -16
  43. data/lib/fine_print/security_transgression.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ae19efef1a93bef86de360020973d0c72e58e74
4
- data.tar.gz: fd9d302b91cebd30ad20e4aaac6530c0d9d29e95
3
+ metadata.gz: 229ff9376133bf2ec88be816ca6c0616cc3870c5
4
+ data.tar.gz: ba35f289d9cbf3f3405fa02eba2b87d6ec1f552d
5
5
  SHA512:
6
- metadata.gz: eb8a60a9956d17a72e7b8b59725d6ca269a7103ddd1219ad9318b68662b34ec4384ee3529294aae6d1706835e4ade31e5f53a97dfe6fd30434d2bdff95ad4661
7
- data.tar.gz: 212e0c1badbd251eba90272f370ef6e77d96755ade8e067ef3c2cd780c618f2b53b064e5ea0b354e0ceb3d0eb6666bef6bbb0557dddd1a2bbd583c56fa2977dd
6
+ metadata.gz: 9a56e58821c884748ccd333fe9c9f87e7d16d393da9646069c39b02f1f81afbc883b74a4ab3ad3e919b4913f68feccd189089549ac00a0e7c998f1f9f18b4886
7
+ data.tar.gz: cd1acacfbf520bc35018053891830c15017a71517f0cbd7cac4cdceb251f7261173e4a1af59accb9779190bc4382c21aab63d0787e77fa6e0b08dc4065d24e8f
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # FinePrint
2
2
 
3
- FinePrint is a Rails gem (engine) that makes managing web site agreements (terms, privacy policy, etc) simple and easy.
3
+ [![Gem Version](https://badge.fury.io/rb/fine_print.svg)](http://badge.fury.io/rb/fine_print)
4
+ [![Build Status](https://travis-ci.org/lml/fine_print.svg?branch=master)](https://travis-ci.org/lml/fine_print)
5
+ [![Code Climate](https://codeclimate.com/github/lml/fine_print/badges/gpa.svg)](https://codeclimate.com/github/lml/fine_print)
6
+
7
+ FinePrint is a Rails engine in gem form that makes managing web site agreements (terms of use, privacy policy, etc) simple and easy.
4
8
 
5
9
  As the meaning of 'agreement' can be somewhat ambiguous (meaning either the thing someone agrees to or the record of the agreement between that thing and the user), we call a set of terms a 'contract' and a user's agreement to that contract a 'signature'.
6
10
 
@@ -64,13 +68,16 @@ You can choose to check if users signed contracts either as a before_filter or i
64
68
 
65
69
  ### Option 1 - As a before_filter
66
70
 
67
- If you choose to have FinePrint work like a before_filter, you can user the following 2 class methods, which are automatically added to all of your controllers:
71
+ If you choose to have FinePrint work like a before_filter, you can user the following 3 class methods, which are automatically added to all of your controllers:
68
72
 
69
73
  ```rb
70
74
  fine_print_get_signatures(contract_names..., options_hash)
75
+ fine_print_require_signatures(contract_names..., options_hash)
71
76
  fine_print_skip_signatures(contract_names..., options_hash)
72
77
  ```
73
78
 
79
+ They work as follows:
80
+ - `fine_print_get_signatures` will redirect the user
74
81
  To require that your users sign the most recent version of a contract, call
75
82
  `fine_print_get_signatures` in your controller classes. It works just like a `before_filter` (in fact, it will add a `before_filter` for you).
76
83
 
data/Rakefile CHANGED
@@ -20,4 +20,3 @@ desc 'Run all specs in spec directory (excluding plugin specs)'
20
20
  RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
21
21
 
22
22
  task :default => :spec
23
-
@@ -7,4 +7,3 @@
7
7
  //= require jquery
8
8
  //= require jquery_ujs
9
9
  //= require_tree .
10
-
@@ -2,4 +2,3 @@
2
2
  *= require_self
3
3
  *= require_tree .
4
4
  */
5
-
@@ -1,12 +1,17 @@
1
1
  module FinePrint
2
2
  class ApplicationController < ActionController::Base
3
- before_filter :verify_admin
3
+ respond_to :html
4
+
5
+ before_filter :get_user, :can_manage
4
6
 
5
7
  protected
6
8
 
7
- def verify_admin
8
- user = FinePrint.current_user_proc.call(self)
9
- FinePrint.raise_unless_admin(user)
9
+ def get_user
10
+ @user = instance_exec &FinePrint.current_user_proc
11
+ end
12
+
13
+ def can_manage
14
+ with_interceptor { instance_exec @user, &FinePrint.can_manage_proc }
10
15
  end
11
16
  end
12
17
  end
@@ -1,22 +1,17 @@
1
1
  module FinePrint
2
2
  class ContractsController < FinePrint::ApplicationController
3
3
  include FinePrint::ApplicationHelper
4
+
4
5
  before_filter :get_contract, :except => [:index, :new, :create]
5
6
 
6
7
  def index
7
- @contracts = Contract.all
8
- end
9
-
10
- def show
8
+ @contracts = Contract.includes(:signatures).all.to_a.group_by(&:name)
11
9
  end
12
10
 
13
11
  def new
14
12
  @contract = Contract.new
15
13
  end
16
-
17
- def edit
18
- end
19
-
14
+
20
15
  def create
21
16
  @contract = Contract.new
22
17
  @contract.name = params[:contract][:name]
@@ -26,10 +21,19 @@ module FinePrint
26
21
  if @contract.save
27
22
  redirect_to @contract, :notice => 'Contract was successfully created.'
28
23
  else
29
- render :action => 'new'
24
+ render :action => 'new', :alert => merge_errors_for(@contract)
30
25
  end
31
26
  end
32
-
27
+
28
+ def show
29
+ end
30
+
31
+ def edit
32
+ @contract.no_signatures
33
+ redirect_to contracts_path, :alert => merge_errors_for(@contract) \
34
+ unless @contract.errors.empty?
35
+ end
36
+
33
37
  def update
34
38
  @contract.name = params[:contract][:name]
35
39
  @contract.title = params[:contract][:title]
@@ -38,7 +42,7 @@ module FinePrint
38
42
  if @contract.save
39
43
  redirect_to @contract, :notice => 'Contract was successfully updated.'
40
44
  else
41
- render :action => 'edit'
45
+ render :action => 'edit', :alert => merge_errors_for(@contract)
42
46
  end
43
47
  end
44
48
 
@@ -67,7 +71,7 @@ module FinePrint
67
71
  end
68
72
 
69
73
  def new_version
70
- @contract = @contract.draft_copy
74
+ @contract = @contract.new_version
71
75
  end
72
76
 
73
77
  protected
@@ -1,4 +1,9 @@
1
1
  module FinePrint
2
2
  class HomeController < FinePrint::ApplicationController
3
+
4
+ def index
5
+ redirect_to contracts_path
6
+ end
7
+
3
8
  end
4
9
  end
@@ -1,14 +1,56 @@
1
1
  module FinePrint
2
2
  class SignaturesController < FinePrint::ApplicationController
3
+ include FinePrint::ApplicationHelper
4
+
5
+ acts_as_interceptor :override_url_options => true
6
+
7
+ skip_before_filter :can_manage, :only => [:new, :create]
8
+ before_filter :can_sign, :only => [:new, :create]
9
+ before_filter :get_contract, :only => [:index, :new, :create]
10
+
3
11
  def index
4
- @signatures = Signature.all
12
+ @signatures = @contract.signatures
13
+ end
14
+
15
+ def new
16
+ @signature = Signature.new
17
+ end
18
+
19
+ def create
20
+ @signature = Signature.new
21
+
22
+ unless params[:signature_accept]
23
+ @signature.errors.add(:contract, 'must be accepted to proceed')
24
+ render :action => 'new'
25
+ return
26
+ end
27
+
28
+ @signature.user = @user
29
+ @signature.contract = @contract
30
+
31
+ if @signature.save
32
+ redirect_back
33
+ else
34
+ render :action => 'new', :alert => merge_errors_for(@signature)
35
+ end
5
36
  end
6
37
 
7
38
  def destroy
8
39
  @signature = Signature.find(params[:id])
9
40
 
10
41
  @signature.destroy
11
- redirect_to signatures_path
42
+ redirect_to contract_signatures_path(@signature.contract),
43
+ :notice => 'Signature was successfully deleted.'
44
+ end
45
+
46
+ protected
47
+
48
+ def can_sign
49
+ with_interceptor { instance_exec @user, &FinePrint.can_sign_proc }
50
+ end
51
+
52
+ def get_contract
53
+ @contract = Contract.find(params[:contract_id])
12
54
  end
13
55
  end
14
56
  end
@@ -1,45 +1,35 @@
1
1
  module FinePrint
2
2
  class Contract < ActiveRecord::Base
3
- has_many :signatures, :inverse_of => :contract
3
+ has_many :signatures, :dependent => :destroy, :inverse_of => :contract
4
4
 
5
- has_many :same_name, :class_name => 'Contract', :primary_key => :name, :foreign_key => :name
5
+ has_many :same_name, :class_name => 'Contract',
6
+ :primary_key => :name, :foreign_key => :name
6
7
 
7
8
  before_validation :downcase_name
8
9
  before_update :no_signatures
9
10
  before_destroy :no_signatures
10
11
 
11
- validates_presence_of :name, :title, :content
12
- validates_format_of :name, :with => /\A\w+\z/
13
- validates_uniqueness_of :version, :scope => :name, :case_sensitive => false
12
+ validates :name, :presence => true, :format => /\A[\w-]+\z/
13
+ validates :title, :presence => true
14
+ validates :content, :presence => true
15
+ validates :version, :uniqueness => {:scope => :name, :case_sensitive => false},
16
+ :allow_nil => true
14
17
 
15
- default_scope { order(:name, 'version DESC') }
18
+ default_scope lambda { order{[name.asc, version.desc]} }
16
19
 
17
- scope :published, lambda { where(arel_table[:version].not_eq(nil)) }
18
- scope :latest, lambda {
19
- published.joins(:same_name)
20
- .group('fine_print_contracts.id')
21
- .having(:version =>
22
- arel_table.alias(:same_names_fine_print_contracts)[:version].maximum.tap{|mvq| mvq.alias = nil})
23
- }
20
+ scope :published, lambda { where{version != nil} }
21
+ scope :latest, lambda { joins(:same_name).group{id}
22
+ .having{version == max(same_name.version)} }
24
23
 
25
24
  def is_published?
26
25
  !version.nil?
27
26
  end
28
27
 
29
28
  def is_latest?
30
- is_published? && version == same_name.maximum(:version)
31
- end
32
-
33
- def sign(user)
34
- FinePrint.sign_contract(self, user)
35
- end
36
-
37
- def signed_by?(user)
38
- FinePrint.signed_contract?(self, user)
29
+ is_published? && self == same_name.published.first
39
30
  end
40
31
 
41
32
  def publish
42
- no_signatures
43
33
  errors.add(:base, 'Contract is already published') if is_published?
44
34
  return false unless errors.empty?
45
35
 
@@ -48,7 +38,6 @@ module FinePrint
48
38
  end
49
39
 
50
40
  def unpublish
51
- no_signatures
52
41
  errors.add(:base, 'Contract is not the latest published version') unless is_latest?
53
42
  return false unless errors.empty?
54
43
 
@@ -56,28 +45,11 @@ module FinePrint
56
45
  save
57
46
  end
58
47
 
59
- def draft_copy
60
- Contract.where(:name => name, :version => nil).first || dup.tap{|contract| contract.version = nil}
61
- end
62
-
63
- ##################
64
- # Access Control #
65
- ##################
66
-
67
- def can_be_updated?
68
- signatures.empty?
69
- end
70
-
71
- def can_be_published?
72
- signatures.empty? && !is_published?
48
+ def new_version
49
+ Contract.where(:name => name, :version => nil).first || \
50
+ dup.tap{|contract| contract.version = nil}
73
51
  end
74
52
 
75
- def can_be_unpublished?
76
- signatures.empty? && is_latest?
77
- end
78
-
79
- alias_method :can_be_destroyed?, :can_be_updated?
80
-
81
53
  ##############
82
54
  # Validation #
83
55
  ##############
@@ -91,7 +63,7 @@ module FinePrint
91
63
  protected
92
64
 
93
65
  def downcase_name
94
- self.name = name.downcase
66
+ self.name = name.try(:downcase)
95
67
  end
96
68
  end
97
69
  end
@@ -3,10 +3,11 @@ module FinePrint
3
3
  belongs_to :contract, :inverse_of => :signatures
4
4
  belongs_to :user, :polymorphic => true
5
5
 
6
- before_create :contract_published
6
+ validate :contract_published, :on => :create
7
7
 
8
- validates_presence_of :contract, :user_type, :user_id
9
- validates_uniqueness_of :contract_id, :scope => [:user_type, :user_id]
8
+ validates :contract, :presence => true,
9
+ :uniqueness => {:scope => [:user_type, :user_id]}
10
+ validates :user, :presence => true
10
11
 
11
12
  default_scope { order(:contract_id, :user_type, :user_id) }
12
13
 
@@ -0,0 +1,11 @@
1
+ <%# Clients of this partial must provide the following variable:
2
+ contract %>
3
+
4
+ <h2 class='fine_print heading'><%= contract.title %> <%= @contract.version ? \
5
+ "(v.#{@contract.version})" : 'Draft' %></h2>
6
+
7
+ <h4 class='fine_print heading'>Last updated: <%= contract.updated_at %></h4>
8
+
9
+ <div class='fine_print contract'>
10
+ <pre><%= @contract.content.html_safe %></pre>
11
+ </div>
@@ -7,4 +7,4 @@
7
7
  <%= link_to 'Show', @contract, :class => 'fine_print link' %> |
8
8
  <%= link_to 'List', contracts_path, :class => 'fine_print link' %>
9
9
  </div>
10
- </div>
10
+ </div>
@@ -2,10 +2,10 @@
2
2
 
3
3
  <div class='fine_print contract_index'>
4
4
 
5
- <% @contracts.group_by(&:name).each do |name, contracts| %>
5
+ <% @contracts.each do |name, contracts| %>
6
6
 
7
7
  <%# Sort contracts by version number; unpublished contracts go at end by creation date %>
8
- <% contracts = contracts.sort_by {|cc| cc.version || cc.created_at.to_i} %>
8
+ <% #contracts = contracts.sort_by {|cc| cc.version || cc.created_at.to_i} %>
9
9
 
10
10
  <ul class='fine_print'>
11
11
  <li><%= name %></li>
@@ -14,18 +14,17 @@
14
14
  <% contracts.each do |contract| %>
15
15
  <li><%= link_to contract.title, contract %>
16
16
  (<%= contract.version.nil? ? 'draft' : "v.#{contract.version.to_s}" %>)
17
- <% if contract.can_be_updated? %>
17
+ <% if contract.signatures.empty? %>
18
18
  [<%= link_to 'Edit', edit_contract_path(contract), :class => 'fine_print link' %>]
19
- <% else %>
20
- [<%= link_to 'New version', new_version_contract_path(contract), :class => 'fine_print link' %>]
21
- <% end %>
22
- <% if contract.can_be_published? %>
23
- [<%= link_to 'Publish', publish_contract_path(contract), :method => :put, :data => {:confirm => 'Are you sure you want to publish this contract?'} %>]
24
- <% elsif contract.can_be_unpublished? %>
25
- [<%= link_to 'Unpublish', unpublish_contract_path(contract), :method => :put, :data => {:confirm => 'Are you sure you want to unpublish this contract?'} %>]
26
- <% end %>
27
- <% if contract.can_be_destroyed? %>
19
+ <% if contract.is_published? %>
20
+ [<%= link_to 'Unpublish', unpublish_contract_path(contract), :method => :put, :data => {:confirm => 'Are you sure you want to unpublish this contract?'} %>]
21
+ <% else %>
22
+ [<%= link_to 'Publish', publish_contract_path(contract), :method => :put, :data => {:confirm => 'Are you sure you want to publish this contract?'} %>]
23
+ <% end %>
28
24
  [<%= link_to 'Delete', contract, :method => :delete, :data => {:confirm => 'Are you sure you wish to delete this contract?'}, :class => 'fine_print link' %>]
25
+ <% else %>
26
+ [<%= link_to 'New version', new_version_contract_path(contract), :method => :post %>]
27
+ [<%= link_to 'Signatures', contract_signatures_path(contract) %>]
29
28
  <% end %>
30
29
  </li>
31
30
  <% end %>
@@ -36,8 +35,7 @@
36
35
  <% end %>
37
36
 
38
37
  <div class='fine_print links'>
39
- <%= link_to 'New Contract', new_contract_path, :class => 'fine_print link' %> |
40
- <%= link_to 'Overview', root_path, :class => 'fine_print link' %>
38
+ <%= link_to 'New Contract', new_contract_path, :class => 'fine_print link' %>
41
39
  </div>
42
40
 
43
41
  </div>
@@ -6,4 +6,4 @@
6
6
  <div class='fine_print links'>
7
7
  <%= link_to 'List', contracts_path, :class => 'fine_print link' %>
8
8
  </div>
9
- </div>
9
+ </div>
@@ -1,33 +1,22 @@
1
1
  <h1 class='fine_print heading'>Contract Details</h1>
2
2
 
3
- <div class='fine_print show_contract'>
4
- <table class='fine_print left_heading'>
5
- <tr>
6
- <th>Name</th>
7
- <td><%= @contract.name %></td>
8
- </tr>
9
- <tr>
10
- <th>Title</th>
11
- <td><%= @contract.title %></td>
12
- </tr>
13
- <tr>
14
- <th>Version</th>
15
- <td><%= @contract.version.nil? ? 'Draft' : @contract.version %></td>
16
- </tr>
17
- <tr>
18
- <th>Updated at</th>
19
- <td><%= @contract.updated_at %></td>
20
- </tr>
21
- <tr>
22
- <th>Content</th>
23
- <td><%= @contract.content.html_safe %></td>
24
- </tr>
25
- </table>
3
+ <h4 class='fine_print heading'>Name: <%= @contract.name %></h4>
26
4
 
27
- <div class='fine_print links'>
28
- <% if @contract.can_be_updated? %>
29
- <%= link_to 'Edit', edit_contract_path(@contract), :class => 'fine_print link' %> |
30
- <% end %>
31
- <%= link_to 'List', contracts_path, :class => 'fine_print link' %>
32
- </div>
5
+ <%= render :partial => 'show', :locals => {:contract => @contract} %>
6
+
7
+ <div class='fine_print links'>
8
+ <% if @contract.signatures.empty? %>
9
+ <%= link_to 'Edit', edit_contract_path(@contract), :class => 'fine_print link' %> |
10
+ <% if @contract.is_published? %>
11
+ <%= link_to 'Unpublish', unpublish_contract_path(@contract), :method => :put, :data => {:confirm => 'Are you sure you want to unpublish this contract?'} %>
12
+ <% else %>
13
+ <%= link_to 'Publish', publish_contract_path(@contract), :method => :put, :data => {:confirm => 'Are you sure you want to publish this contract?'} %> |
14
+ <% end %>
15
+ <%= link_to 'Delete', @contract, :method => :delete, :data => {:confirm => 'Are you sure you wish to delete this contract?'}, :class => 'fine_print link' %>
16
+ <% else %>
17
+ <%= link_to 'New version', new_version_contract_path(@contract), :method => :post %> |
18
+ <%= link_to 'Signatures', contract_signatures_path(@contract),
19
+ :class => 'fine_print link' %>
20
+ <% end %>
21
+ | <%= link_to 'List', contracts_path, :class => 'fine_print link' %>
33
22
  </div>
@@ -0,0 +1,21 @@
1
+ <%= form_for([@contract, @signature], :html => {:class => 'fine_print'}) do |f| %>
2
+ <% if @signature.errors.any? %>
3
+ <div id='error_explanation' class='fine_print errors'>
4
+ <h4 class='fine_print heading'>Error:</h4>
5
+
6
+ <ul>
7
+ <% @signature.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class='field'>
15
+ <%= f.label :accept, 'I have read and accept the terms above.', :class => 'fine_print' %>
16
+ <%= check_box_tag :signature_accept, :class => 'fine_print check_box' %>
17
+ </div>
18
+ <div class='actions'>
19
+ <%= f.submit 'I agree', :class => 'fine_print submit' %>
20
+ </div>
21
+ <% end %>
@@ -1,12 +1,10 @@
1
- <h1 class='fine_print heading'>Contract Signatures</h1>
1
+ <h1 class='fine_print heading'>Signatures for <%= link_to "#{@contract.title} (v.#{@contract.version})", @contract %></h1>
2
2
 
3
3
  <div class='fine_print signature_index'>
4
4
 
5
5
  <table class='fine_print top_heading index'>
6
6
  <tr class='fine_print heading-row'>
7
7
  <th>User ID</th>
8
- <th>Contract name</th>
9
- <th>Contract version</th>
10
8
  <th>Date accepted</th>
11
9
  <th></th>
12
10
  </tr>
@@ -14,8 +12,6 @@
14
12
  <% @signatures.each do |signature| %>
15
13
  <tr class='fine_print data-row <%= cycle('even', 'odd') %>'>
16
14
  <td><%= signature.user.id %></td>
17
- <td><%= signature.contract.name %></td>
18
- <td><%= signature.contract.version %></td>
19
15
  <td><%= signature.created_at %></td>
20
16
  <td><%= link_to 'Terminate',
21
17
  signature,
@@ -30,7 +26,7 @@
30
26
  </table>
31
27
 
32
28
  <div class='fine_print links'>
33
- <%= link_to 'Overview', root_path, :class => 'fine_print link' %>
29
+ <%= link_to 'List', contracts_path, :class => 'fine_print link' %>
34
30
  </div>
35
31
 
36
- </div>
32
+ </div>
@@ -0,0 +1,13 @@
1
+ <div class='fine_print contract'>
2
+ <%= render :partial => 'fine_print/contracts/show',
3
+ :locals => {:contract => @contract} %>
4
+ </div>
5
+
6
+ <div class='fine_print new_signature'>
7
+ <%= render 'form' %>
8
+
9
+ <div class='fine_print links'>
10
+ <%= without_interceptor { link_to 'I do not agree',
11
+ main_app.root_url, :class => 'fine_print link' } %>
12
+ </div>
13
+ </div>
@@ -1,41 +1,44 @@
1
1
  # Change the settings below to suit your needs
2
2
  # All options are initially set to their default values
3
3
  FinePrint.configure do |config|
4
+
4
5
  # Engine Configuration
5
6
 
6
- # Proc called with a controller as argument.
7
+ # Proc called with a controller as self.
7
8
  # Returns the current user.
8
- # Default: lambda { |controller| controller.current_user }
9
- config.current_user_proc = lambda { |controller| controller.current_user }
10
-
11
- # Proc called with a user as argument.
12
- # Returns true iif the user is an admin.
13
- # Admins can create and edit agreements and terminate accepted agreements.
14
- # Default: lambda { |user| false } (no admins)
15
- config.user_admin_proc = lambda { |user| false }
16
-
17
- # Proc called with a user as argument
18
- # Returns true iif the argument the user is allowed to sign a contract.
19
- # In many systems, a non-logged-in user is represented by nil.
20
- # However, some systems use something like an AnonymousUser class to represent this state.
21
- # If this proc returns false, FinePrint will not ask for signatures and will not redirect the user, so it's up to the developer to make sure that unsigned users can't access pages that should require a signed contract to use.
22
- # Default: lambda { |user| !!user }
23
- config.user_can_sign_proc = lambda { |user| !!user }
24
-
25
-
26
-
27
- # Contract Configuration
28
-
29
- # What to call the contract names param, passed when the user is redirected
30
- # This is visible to the user in the Url
31
- # Default: 'contracts'
32
- config.contract_param_name = 'contracts'
9
+ # Default: lambda { current_user }
10
+ config.current_user_proc = lambda { current_user }
11
+
12
+ # Proc called with a user as argument and a controller as self.
13
+ # This proc is called when a user tries to access FinePrint's controllers.
14
+ # Should raise and exception, render or redirect unless the user can manage contracts.
15
+ # Contract managers can create and edit agreements and terminate accepted agreements.
16
+ # The default does not allow anyone to manage contracts.
17
+ # Note: Proc must account for nil users, if current_user_proc returns nil.
18
+ # Default: lambda { |user| false || raise(ActionController::RoutingError, 'Not Found') }
19
+ config.can_manage_proc = lambda { |user| false || \
20
+ raise(ActionController::RoutingError, 'Not Found') }
21
+
22
+ # Proc called with a user as argument and a controller as self.
23
+ # This proc is called to check that the given user is allowed to sign contracts.
24
+ # Should raise and exception, render or redirect unless the user can sign contracts.
25
+ # You might want to redirect users to a login page if they are not signed in.
26
+ # The default renders 401 Unauthorized for nil users.
27
+ # Default: lambda { |user| !user.nil? || head(:unauthorized) }
28
+ config.can_sign_proc = lambda { |user| !user.nil? || head(:unauthorized) }
29
+
30
+ # Controller Configuration
31
+
32
+ # Proc called with a user and an array of contract ids as arguments and a controller as self.
33
+ # This proc is called when a user tries to access a resource protected by FinePrint,
34
+ # but has not signed all the required contracts.
35
+ # Should raise and exception, render or redirect the user.
36
+ # The `contract_ids` variable contains the contract ids that need to be signed.
37
+ # The default redirects users to FinePrint's contract signing views.
38
+ # The `fine_print_return` method can be used to return from a redirect made here.
39
+ # Default: lambda { |user, contract_ids| with_interceptor { redirect_to(
40
+ # fine_print.new_contract_signature_path(:contract_id => contract_ids.first)) } }
41
+ config.must_sign_proc = lambda { |user, contract_ids| redirect_to(
42
+ fine_print.new_contract_signature_path(:contract_id => contract_ids.first)) }
33
43
 
34
- # Path to redirect users to when they need to agree to contract(s).
35
- # A list of contract names that must be agreed to will be available in the `contract_param_name` parameter.
36
- # Your code doesn't have to deal with all of them at once, e.g. you can get
37
- # the user to agree to the first one and then they'll just eventually be
38
- # redirected back to this page with the remaining contract names.
39
- # Default: '/'
40
- config.contract_redirect_path = '/'
41
44
  end
data/config/routes.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  FinePrint::Engine.routes.draw do
2
+ root :to => 'home#index'
3
+
2
4
  resources :contracts do
5
+ resources :signatures, :only => [:index, :new, :create, :destroy], :shallow => true
6
+
3
7
  member do
4
- get :new_version
8
+ post :new_version
5
9
  put :publish
6
10
  put :unpublish
7
11
  end
8
12
  end
9
-
10
- resources :signatures, :only => [:index, :destroy]
11
-
12
- root :to => 'home#index'
13
13
  end