fine_print 1.3.0 → 1.4.1

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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +56 -44
  3. data/app/controllers/fine_print/application_controller.rb +0 -3
  4. data/app/models/fine_print/contract.rb +9 -8
  5. data/app/models/fine_print/signature.rb +1 -1
  6. data/config/initializers/fine_print.rb +20 -16
  7. data/db/migrate/0_install_fine_print.rb +4 -3
  8. data/lib/fine_print/controller_includes.rb +114 -0
  9. data/lib/fine_print/version.rb +1 -1
  10. data/lib/fine_print.rb +20 -24
  11. data/spec/controllers/contracts_controller_spec.rb +38 -36
  12. data/spec/controllers/home_controller_spec.rb +4 -4
  13. data/spec/controllers/signatures_controller_spec.rb +8 -8
  14. data/spec/dummy/Rakefile +0 -1
  15. data/spec/dummy/app/assets/javascripts/application.js +3 -5
  16. data/spec/dummy/app/views/layouts/application.html.erb +2 -2
  17. data/spec/dummy/bin/bundle +3 -0
  18. data/spec/dummy/bin/rails +4 -0
  19. data/spec/dummy/bin/rake +4 -0
  20. data/spec/dummy/config/application.rb +3 -37
  21. data/spec/dummy/config/boot.rb +4 -9
  22. data/spec/dummy/config/environment.rb +2 -2
  23. data/spec/dummy/config/environments/development.rb +11 -19
  24. data/spec/dummy/config/environments/production.rb +40 -27
  25. data/spec/dummy/config/environments/test.rb +13 -14
  26. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  27. data/spec/dummy/config/initializers/fine_print.rb +1 -34
  28. data/spec/dummy/config/initializers/inflections.rb +6 -5
  29. data/spec/dummy/config/initializers/secret_token.rb +7 -2
  30. data/spec/dummy/config/initializers/session_store.rb +1 -6
  31. data/spec/dummy/config/initializers/wrap_parameters.rb +6 -6
  32. data/spec/dummy/config/locales/en.yml +20 -2
  33. data/spec/dummy/config/routes.rb +2 -1
  34. data/spec/dummy/config.ru +1 -1
  35. data/spec/dummy/db/development.sqlite3 +0 -0
  36. data/spec/dummy/db/schema.rb +21 -21
  37. data/spec/dummy/db/test.sqlite3 +0 -0
  38. data/spec/dummy/log/development.log +15 -1849
  39. data/spec/dummy/log/test.log +10536 -53785
  40. data/spec/dummy/public/404.html +43 -11
  41. data/spec/dummy/public/422.html +43 -11
  42. data/spec/dummy/public/500.html +43 -11
  43. data/spec/factories/contract.rb +2 -2
  44. data/spec/lib/fine_print/{controller_additions_spec.rb → controller_includes_spec.rb} +16 -6
  45. metadata +104 -166
  46. data/app/assets/javascripts/application.js~ +0 -16
  47. data/app/controllers/fine_print/application_controller.rb~ +0 -15
  48. data/app/controllers/fine_print/contracts_controller.rb~ +0 -79
  49. data/app/controllers/fine_print/home_controller.rb~ +0 -6
  50. data/app/controllers/fine_print/signatures_controller.rb~ +0 -14
  51. data/app/helpers/fine_print/application_helper.rb~ +0 -7
  52. data/app/helpers/fine_print/contracts_helper.rb~ +0 -7
  53. data/app/models/fine_print/contract.rb~ +0 -100
  54. data/app/models/fine_print/signature.rb~ +0 -25
  55. data/app/views/fine_print/contracts/_form.html.erb~ +0 -35
  56. data/app/views/fine_print/contracts/index.html.erb~ +0 -43
  57. data/app/views/fine_print/contracts/show.html.erb~ +0 -35
  58. data/app/views/fine_print/home/index.html.erb~ +0 -15
  59. data/app/views/fine_print/signatures/index.html.erb~ +0 -32
  60. data/app/views/layouts/fine_print/application.html.erb~ +0 -20
  61. data/config/initializers/fine_print.rb~ +0 -36
  62. data/config/routes.rb~ +0 -12
  63. data/db/migrate/0_install_fine_print.rb~ +0 -26
  64. data/lib/fine_print/controller_additions.rb +0 -80
  65. data/lib/fine_print/controller_additions.rb~ +0 -86
  66. data/lib/fine_print/utilities.rb~ +0 -26
  67. data/lib/fine_print/version.rb~ +0 -3
  68. data/lib/fine_print.rb~ +0 -120
  69. data/spec/controllers/contracts_controller_spec.rb~ +0 -224
  70. data/spec/controllers/home_controller_spec.rb~ +0 -25
  71. data/spec/controllers/signatures_controller_spec.rb~ +0 -46
  72. data/spec/dummy/app/controllers/dummy_models_controller.rb~ +0 -29
  73. data/spec/dummy/app/models/dummy_user.rb~ +0 -4
  74. data/spec/dummy/app/models/user.rb~ +0 -78
  75. data/spec/dummy/config/application.rb~ +0 -60
  76. data/spec/dummy/config/initializers/fine_print.rb~ +0 -36
  77. data/spec/dummy/config/initializers/session_store.rb~ +0 -8
  78. data/spec/dummy/config/initializers/wrap_parameters.rb~ +0 -14
  79. data/spec/dummy/config/routes.rb~ +0 -4
  80. data/spec/dummy/db/migrate/1_create_dummy_users.rb~ +0 -8
  81. data/spec/dummy/script/rails +0 -6
  82. data/spec/factories/contract.rb~ +0 -26
  83. data/spec/factories/dummy_user.rb~ +0 -6
  84. data/spec/factories/signature.rb~ +0 -8
  85. data/spec/factories/user.rb~ +0 -6
  86. data/spec/fine_print_spec.rb~ +0 -18
  87. data/spec/lib/fine_print/controller_additions_spec.rb~ +0 -20
  88. data/spec/lib/fine_print_spec.rb~ +0 -47
  89. data/spec/models/contract_spec.rb~ +0 -80
  90. data/spec/models/signature_spec.rb~ +0 -28
  91. data/spec/spec_helper.rb~ +0 -32
  92. data/spec/test_helper.rb~ +0 -15
@@ -1,100 +0,0 @@
1
- module FinePrint
2
- class Contract < ActiveRecord::Base
3
- has_many :signatures, :inverse_of => :contract
4
-
5
- has_many :same_name, :class_name => 'Contract', :primary_key => :name, :foreign_key => :name
6
-
7
- before_validation :downcase_name
8
- before_update :no_signatures
9
- before_destroy :no_signatures
10
-
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
14
-
15
- default_scope order(:name, 'version DESC')
16
-
17
- scope :published, where(arel_table[:version].not_eq(nil))
18
- scope :latest, published
19
- .joins(:same_name)
20
- .group(:id)
21
- .having(:version => arel_table.alias(:same_names_fine_print_contracts)[:version]
22
- .maximum.tap{|mvq| mvq.alias = nil})
23
-
24
- def is_published?
25
- !version.nil?
26
- end
27
-
28
- def is_latest?
29
- is_published? && version == same_name.maximum(:version)
30
- end
31
-
32
- def sign(user)
33
- FinePrint.sign_contract(self, user)
34
- end
35
-
36
- def signed_by?(user)
37
- FinePrint.signed_contract?(self, user)
38
- end
39
-
40
- def publish
41
- no_signatures
42
- errors.add(:base, 'Contract is already published') if is_published?
43
- return false unless errors.empty?
44
-
45
- self.version = (same_name.published.first.try(:version) || 0) + 1
46
- save
47
- end
48
-
49
- def unpublish
50
- no_signatures
51
- errors.add(:base, 'Contract is not the latest published version') unless is_latest?
52
- return false unless errors.empty?
53
-
54
- self.version = nil
55
- save
56
- end
57
-
58
- def draft_copy
59
- Contract.where(:name => name, :version => nil).first || dup.tap{|contract| contract.version = nil}
60
- end
61
-
62
- ##################
63
- # Access Control #
64
- ##################
65
-
66
- def can_be_updated?
67
- signatures.empty?
68
- end
69
-
70
- def can_be_published?
71
- signatures.empty? && !is_published?
72
- end
73
-
74
- def can_be_unpublished?
75
- signatures.empty? && is_latest?
76
- end
77
-
78
- def can_be_new_versioned?
79
- is_published?
80
- end
81
-
82
- alias_method :can_be_destroyed?, :can_be_updated?
83
-
84
- ##############
85
- # Validation #
86
- ##############
87
-
88
- def no_signatures
89
- return if signatures.empty?
90
- errors.add(:base, 'Contract cannot be modified because users have signed it')
91
- false
92
- end
93
-
94
- protected
95
-
96
- def downcase_name
97
- self.name = name.downcase
98
- end
99
- end
100
- end
@@ -1,25 +0,0 @@
1
- module FinePrint
2
- class Signature < ActiveRecord::Base
3
- belongs_to :contract, :inverse_of => :signatures
4
- belongs_to :user, :polymorphic => true
5
-
6
- before_save :contract_published
7
-
8
- validates_presence_of :contract, :user_type, :user_id
9
- validates_uniqueness_of :contract_id, :scope => [:user_type, :user_id]
10
-
11
- default_scope order(:contract_id, :user_type, :user_id)
12
-
13
- protected
14
-
15
- ##############
16
- # Validation #
17
- ##############
18
-
19
- def contract_published
20
- return if contract.is_published?
21
- errors.add(:contract, 'needs to be published before it can be signed')
22
- false
23
- end
24
- end
25
- end
@@ -1,35 +0,0 @@
1
- <%= form_for(@contract, :html => {class: 'fine_print'}) do |f| %>
2
- <% if @contract.errors.any? %>
3
- <div id='error_explanation' class='fine_print errors'>
4
- <h2 class='fine_print heading'><%= pluralize(@contract.errors.count, 'error') %> prohibited this contract from being saved:</h2>
5
-
6
- <ul>
7
- <% @contract.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 :name, :class => 'fine_print' %>
16
- <%= f.text_field :name, :size => 40, :class => 'fine_print text_field' %>
17
- <div class='fine_print field_help'>
18
- used internally by your code, only letters, numbers, underscores; changing this will start a new contract with new version counts
19
- </div>
20
- </div>
21
- <div class='field'>
22
- <%= f.label :title, :class => 'fine_print' %>
23
- <%= f.text_field :title, :size => 40, :class => 'fine_print text_field' %>
24
- <div class='fine_print field_help'>
25
- e.g., 'Terms of Use'
26
- </div>
27
- </div>
28
- <div class='field'>
29
- <%= f.label :content, :class => 'fine_print' %>
30
- <%= f.text_area :content, :cols => 56, :class => 'fine_print text_area' %>
31
- </div>
32
- <div class='actions'>
33
- <%= f.submit nil, :class => 'fine_print submit' %>
34
- </div>
35
- <% end %>
@@ -1,43 +0,0 @@
1
- <h1 class='fine_print heading'>FinePrint Contracts</h1>
2
-
3
- <div class='fine_print contract_index'>
4
-
5
- <% @contracts.group_by(&:name).each do |name, contracts| %>
6
-
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} %>
9
-
10
- <ul class='fine_print'>
11
- <li><%= name %></li>
12
-
13
- <ul class='fine_print'>
14
- <% contracts.each do |contract| %>
15
- <li><%= link_to contract.title, contract %>
16
- (<%= contract.version.nil? ? 'draft' : "v.#{contract.version.to_s}" %>)
17
- <% if contract.can_be_updated? %>
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? %>
28
- [<%= link_to 'Delete', contract, :method => :delete, :data => {:confirm => 'Are you sure you wish to delete this contract?'}, :class => 'fine_print link' %>]
29
- <% end %>
30
- </li>
31
- <% end %>
32
- </ul>
33
-
34
- </ul>
35
-
36
- <% end %>
37
-
38
- <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' %>
41
- </div>
42
-
43
- </div>
@@ -1,35 +0,0 @@
1
- <h1 class='fine_print heading'>Contract Details</h1>
2
-
3
- <div class='fine_print show_contract'>
4
-
5
- <table class='fine_print left_heading'>
6
- <tr>
7
- <th>Name</th>
8
- <td><%= @contract.name %></td>
9
- </tr>
10
- <tr>
11
- <th>Title</th>
12
- <td><%= @contract.title %></td>
13
- </tr>
14
- <tr>
15
- <th>Version</th>
16
- <td><%= @contract.version.nil? ? 'Draft' : @contract.version %></td>
17
- </tr>
18
- <tr>
19
- <th>Updated at</th>
20
- <td><%= @contract.updated_at %></td>
21
- </tr>
22
- <tr>
23
- <th>Content</th>
24
- <td><%= @contract.content.html_safe %></td>
25
- </tr>
26
- </table>
27
-
28
- <div class='fine_print links'>
29
- <% if @contract.can_be_updated? %>
30
- <%= link_to 'Edit', edit_contract_path(@contract), :class => 'fine_print link' %> |
31
- <% end %>
32
- <%= link_to 'List', contracts_path, :class => 'fine_print link' %>
33
- </div>
34
-
35
- </div>
@@ -1,15 +0,0 @@
1
- <h1 class='fine_print heading'>FinePrint</h1>
2
-
3
- <ul class='fine_print'>
4
- <li>
5
- <%= link_to 'Manage contracts',
6
- contracts_path,
7
- :class => 'fine_print link' %>
8
- </li>
9
- <li>
10
- <%= link_to 'View signatures',
11
- signatures_path,
12
- :class => 'fine_print link' %>
13
- </li>
14
- </ul>
15
-
@@ -1,32 +0,0 @@
1
- <h1 class='fine_print heading'>Contract Signatures</h1>
2
-
3
- <table class='fine_print index'>
4
- <tr class='fine_print heading-row'>
5
- <th>User ID</th>
6
- <th>Contract name</th>
7
- <th>Contract version</th>
8
- <th>Date accepted</th>
9
- <th></th>
10
- </tr>
11
-
12
- <% @signatures.each do |signature| %>
13
- <tr class='fine_print data-row <%= cycle('even', 'odd') %>'>
14
- <td><%= signature.user.id %></td>
15
- <td><%= signature.contract.name %></td>
16
- <td><%= signature.contract.version %></td>
17
- <td><%= signature.created_at %></td>
18
- <td><%= link_to 'Terminate',
19
- signature,
20
- method: :delete,
21
- data: {
22
- confirm: 'User will be asked to accept the contract again. Are you sure?'
23
- },
24
- :class => 'fine_print link' %>
25
- </td>
26
- </tr>
27
- <% end %>
28
- </table>
29
-
30
- <br />
31
-
32
- <%= link_to 'Overview', root_path, :class => 'fine_print link' %>
@@ -1,20 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>FinePrint</title>
5
- <%= stylesheet_link_tag "fine_print/application", :media => "all" %>
6
- <%= javascript_include_tag "fine_print/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <% if flash[:notice] %>
12
- <div class="notice"><%= flash[:notice] %></div>
13
- <% elsif flash[:notice] %>
14
- <div class="notice"><%= flash[:notice] %></div>
15
- <% end %>
16
-
17
- <%= yield %>
18
-
19
- </body>
20
- </html>
@@ -1,36 +0,0 @@
1
- # Change the settings below to suit your needs
2
- # All settings are initially set to their default values
3
- FinePrint.configure do |config|
4
- # Engine Configuration
5
-
6
- # Proc called with controller as argument that returns the current user.
7
- # Default: lambda { |controller| controller.current_user }
8
- config.current_user_proc = lambda { |controller| controller.current_user }
9
-
10
- # Proc called with user as argument that returns true iif the user is an admin.
11
- # Admins can create and edit agreements and terminate accepted agreements.
12
- # Default: lambda { |user| false } (no admins)
13
- config.user_admin_proc = lambda { |user| false }
14
-
15
- # Proc called with user as argument that returns true iif the argument is a user
16
- # who can sign a contract. In many systems, a non-logged-in user is represented by nil.
17
- # However, some systems use something like an AnonymousUser class to represent this state.
18
- # This proc is mostly used to help the developer realize that they should only be asking
19
- # signed in users to sign contracts; without this, developers would get a cryptic SQL error.
20
- # Default: lambda { |user| user }
21
- config.can_sign_contracts_proc = lambda { |user| user }
22
-
23
- # Path to redirect users to when an error occurs (e.g. permission denied on admin pages).
24
- # Default: '/'
25
- config.redirect_path = '/'
26
-
27
- # Signature (fine_print_get_signatures) Configuration
28
-
29
- # Path to redirect users to when they need to agree to contract(s).
30
- # A list of contract names that must be agreed to will be available in the 'contracts' parameter.
31
- # Your code doesn't have to deal with all of them at once, e.g. you can get
32
- # the user to agree to the first one and then they'll just eventually be
33
- # redirected back to this page with the remaining contract names.
34
- # Default: '/'
35
- config.pose_contracts_path = '/'
36
- end
data/config/routes.rb~ DELETED
@@ -1,12 +0,0 @@
1
- FinePrint::Engine.routes.draw do
2
- resources :contracts do
3
- member do
4
- get :new_version, :on => :member
5
- put :publish, :on => :member
6
- put :unpublish, :on => :member
7
- end
8
-
9
- resources :signatures, :only => [:index, :destroy]
10
-
11
- root :to => 'home#index'
12
- end
@@ -1,26 +0,0 @@
1
- class InstallFinePrint < ActiveRecord::Migration
2
- def change
3
- create_table :fine_print_contracts do |t|
4
- t.string :name, :null => false
5
- t.integer :version
6
- t.string :title, :null => false, :default => ''
7
- t.text :content, :null => false, :default => ''
8
-
9
- t.timestamps
10
- end
11
-
12
- add_index :fine_print_contracts, [:name, :version], :unique => true
13
-
14
- create_table :fine_print_signatures do |t|
15
- t.belongs_to :contract, :null => false
16
- t.belongs_to :user, :polymorphic => true, :null => false
17
-
18
- t.timestamps
19
- end
20
-
21
- add_index :fine_print_signatures, :contract_id
22
- add_index :fine_print_signatures, [:user_id, :user_type, :contract_id],
23
- :name => 'index_fine_print_s_on_u_id_and_u_type_and_c_id',
24
- :unique => true
25
- end
26
- end
@@ -1,80 +0,0 @@
1
- module FinePrint
2
- module ControllerAdditions
3
- #
4
- # Internally these methods think of contract names as strings, not symbols.
5
- # Any names passed in as symbols are converted to strings.
6
- #
7
- def self.included(base)
8
- base.extend(ClassMethods)
9
- end
10
-
11
- def fine_print_skipped_contract_names
12
- @fine_print_skipped_contract_names ||= []
13
- end
14
-
15
- # See the README
16
- def fine_print_return
17
- redirect_to session.delete(:fine_print_return_to) || root_path
18
- end
19
-
20
- module ClassMethods
21
- # See the README
22
- def fine_print_get_signatures(*args)
23
- options = args.last.is_a?(Hash) ? args.pop : {}
24
-
25
- filter_options = options.except(*FinePrint::SIGNATURE_OPTIONS)
26
- fine_print_options = options.slice(*FinePrint::SIGNATURE_OPTIONS)
27
-
28
- # Convert all names to string
29
- names = args.flatten.collect{|n| n.to_s}
30
-
31
- class_eval do
32
- before_filter(filter_options) do |controller|
33
- # If the user isn't signed in, they can't sign a contract. Since there
34
- # may be some pages that logged in and non-logged in users can visit,
35
- # just return quietly instead of raising an exception.
36
- user = FinePrint.current_user_proc.call(self)
37
- return true unless FinePrint.can_sign?(user)
38
-
39
- contract_names = names - fine_print_skipped_contract_names
40
-
41
- # Bail if nothing to do
42
- return true if contract_names.blank?
43
-
44
- unsigned_contract_names =
45
- FinePrint.get_unsigned_contract_names(user, contract_names)
46
-
47
- # Ignore contracts that don't yet exist or aren't yet published (happens
48
- # when adding code that requires a new contract but before that contract
49
- # has been added and published)
50
- unsigned_contract_names.reject!{|name| FinePrint.get_contract(name).blank?}
51
-
52
- return true if unsigned_contract_names.empty?
53
-
54
- # http://stackoverflow.com/a/2165727/1664216
55
- session[:fine_print_return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
56
- # http://stackoverflow.com/a/6561953
57
- path = fine_print_options[:pose_contracts_path] || FinePrint.pose_contracts_path
58
- redirect_to path + (path.include?('?') ? '&' : '?') + {:terms => unsigned_contract_names}.to_query
59
- end
60
- end
61
- end
62
-
63
- # See the README
64
- def fine_print_skip_signatures(*args)
65
- options = args.last.is_a?(Hash) ? args.pop : {}
66
-
67
- # Convert all names to string
68
- names = args.flatten.collect{|n| n.to_s}
69
-
70
- class_eval do
71
- prepend_before_filter(options) do |controller|
72
- fine_print_skipped_contract_names.push(*names)
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
79
-
80
- ActionController::Base.send :include, FinePrint::ControllerAdditions
@@ -1,86 +0,0 @@
1
- module FinePrint
2
- module ControllerAdditions
3
- #
4
- # Internally these methods think of contract names as strings, not symbols.
5
- # Any names passed in as symbols are converted to strings.
6
- #
7
- def self.included(base)
8
- base.extend(ClassMethods)
9
- end
10
-
11
- def fine_print_skipped_contract_names
12
- @fine_print_skipped_contract_names ||= []
13
- end
14
-
15
- # See the README
16
- def fine_print_return
17
- redirect_to session.delete(:fine_print_return_to) || root_path
18
- end
19
-
20
- module ClassMethods
21
- # See the README
22
- def fine_print_get_signatures(*args)
23
- options = args.last.is_a?(Hash) ? args.pop : {}
24
-
25
- filter_options = options.except(*FinePrint::SIGNATURE_OPTIONS)
26
- fine_print_options = options.slice(*FinePrint::SIGNATURE_OPTIONS)
27
-
28
- # Convert all names to string
29
- names = args.flatten.collect{|n| n.to_s}
30
-
31
- class_eval do
32
- before_filter(filter_options) do |controller|
33
- # If the user isn't signed in, they can't sign a contract. Since there
34
- # may be some pages that logged in and non-logged in users can visit,
35
- # just return quietly instead of raising an exception.
36
- user = FinePrint.current_user_proc.call(self)
37
- return true unless FinePrint.can_sign?(user)
38
-
39
- contract_names = names - fine_print_skipped_contract_names
40
-
41
- # Bail if nothing to do
42
- return true if contract_names.blank?
43
-
44
- <<<<<<< HEAD
45
- =======
46
- user = FinePrint.current_user_proc.call(self)
47
- FinePrint.raise_unless_can_sign(user)
48
-
49
- >>>>>>> a0cf8254c527fa9f44b9dae47c2a157221aa14ab
50
- unsigned_contract_names =
51
- FinePrint.get_unsigned_contract_names(user, contract_names)
52
-
53
- # Ignore contracts that don't yet exist or aren't yet published (happens
54
- # when adding code that requires a new contract but before that contract
55
- # has been added and published)
56
- unsigned_contract_names.reject!{|name| FinePrint.get_contract(name).blank?}
57
-
58
- return true if unsigned_contract_names.empty?
59
-
60
- # http://stackoverflow.com/a/2165727/1664216
61
- session[:fine_print_return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
62
- # http://stackoverflow.com/a/6561953
63
- path = fine_print_options[:pose_contracts_path] || FinePrint.pose_contracts_path
64
- redirect_to path + (path.include?('?') ? '&' : '?') + {:terms => unsigned_contract_names}.to_query
65
- end
66
- end
67
- end
68
-
69
- # See the README
70
- def fine_print_skip_signatures(*args)
71
- options = args.last.is_a?(Hash) ? args.pop : {}
72
-
73
- # Convert all names to string
74
- names = args.flatten.collect{|n| n.to_s}
75
-
76
- class_eval do
77
- prepend_before_filter(options) do |controller|
78
- fine_print_skipped_contract_names.push(*names)
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
85
-
86
- ActionController::Base.send :include, FinePrint::ControllerAdditions
@@ -1,26 +0,0 @@
1
- module FinePrint
2
- module Utilities
3
- # Returns true iff the given user has signed any version of the given contract.
4
- # contract -- can be a Contract object, its ID, or its name as a String or Symbol
5
- def self.any_signed_contract_version?(contract, user)
6
- contract = FinePrint::get_contract(contract)
7
- !user.nil? &&
8
- !Signature.joins(:contract)
9
- .where(:contract => {:name => contract.name},
10
- :user_type => user.class.name,
11
- :user_id => user.id).first.nil?
12
- end
13
-
14
- # Returns the latest version of the named contract (since contracts don't have
15
- # versions until they are published this only returns published contracts).
16
- # If no such contract exists, returns nil.
17
- # name -- can be a String or a Symbol
18
- def self.latest_contract_named(name)
19
- name = name.to_s
20
- contract = Contract.where(:name => name).published.first
21
- raise IllegalState, "Published version of #{name} not found" \
22
- if contract.nil?
23
- contract
24
- end
25
- end
26
- end
@@ -1,3 +0,0 @@
1
- module FinePrint
2
- VERSION = '1.2.0'
3
- end