agreement_engine 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +17 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +36 -0
- data/README.md +278 -17
- data/app/controllers/agreement_engine/admin/documents_controller.rb +6 -32
- data/app/controllers/agreement_engine/admin/issues_controller.rb +50 -0
- data/app/controllers/agreement_engine/agreements_controller.rb +5 -5
- data/app/controllers/agreement_engine/consents_controller.rb +47 -0
- data/app/controllers/agreement_engine/documents_controller.rb +4 -7
- data/app/controllers/agreement_engine/receipts_controller.rb +31 -0
- data/app/controllers/agreement_engine/record_documents_controller.rb +47 -0
- data/app/controllers/agreement_engine/signatures_controller.rb +89 -0
- data/app/controllers/agreement_engine/verifications_controller.rb +18 -0
- data/app/mailers/agreement_engine/receipt_mailer.rb +18 -0
- data/app/models/agreement_engine/acceptance.rb +84 -0
- data/app/models/agreement_engine/consent_withdrawal.rb +13 -0
- data/app/models/agreement_engine/document.rb +81 -3
- data/app/views/agreement_engine/admin/documents/index.html.erb +1 -2
- data/app/views/agreement_engine/admin/documents/show.html.erb +52 -2
- data/app/views/agreement_engine/admin/issues/new.html.erb +51 -0
- data/app/views/agreement_engine/agreements/show.html.erb +4 -1
- data/app/views/agreement_engine/consents/show.html.erb +19 -0
- data/app/views/agreement_engine/documents/_issued_version.html.erb +5 -0
- data/app/views/agreement_engine/documents/{terms.html.erb → show.html.erb} +4 -4
- data/app/views/agreement_engine/receipt_mailer/copy.text.erb +5 -0
- data/app/views/agreement_engine/signatures/show.html.erb +37 -0
- data/app/views/agreement_engine/verifications/show.html.erb +22 -0
- data/config/locales/en.yml +44 -0
- data/config/routes.rb +12 -3
- data/db/migrate/20261120011146_add_issued_versions_to_agreement_engine_documents.rb +8 -0
- data/db/migrate/20261120022247_create_agreement_engine_acceptances.rb +22 -0
- data/db/migrate/20261120023407_create_agreement_engine_consent_withdrawals.rb +12 -0
- data/db/migrate/20261120024007_add_signature_fields_to_agreement_engine_acceptances.rb +7 -0
- data/db/migrate/20261120030101_add_subject_to_agreement_engine_documents.rb +9 -0
- data/db/migrate/20261120041730_add_carry_over_to_agreement_engine_acceptances.rb +8 -0
- data/db/migrate/20261120141925_add_period_to_agreement_engine_acceptances.rb +6 -0
- data/db/migrate/20261120143946_add_database_guards_to_agreement_engine.rb +9 -0
- data/db/migrate/20261120145611_add_one_signature_index_to_agreement_engine_acceptances.rb +5 -0
- data/docs/byte-form/examples/blank-standing/bytes.json +1 -0
- data/docs/byte-form/examples/blank-standing/input.json +15 -0
- data/docs/byte-form/examples/blank-standing/sha256 +1 -0
- data/docs/byte-form/examples/with-values/bytes.json +1 -0
- data/docs/byte-form/examples/with-values/input.json +15 -0
- data/docs/byte-form/examples/with-values/sha256 +1 -0
- data/docs/byte-form.md +44 -0
- data/exe/agreement_engine-verify +14 -0
- data/lib/agreement_engine/acceptance_event.rb +22 -0
- data/lib/agreement_engine/byte_form.rb +28 -0
- data/lib/agreement_engine/configuration.rb +35 -2
- data/lib/agreement_engine/consent.rb +26 -0
- data/lib/agreement_engine/database_guards.rb +46 -0
- data/lib/agreement_engine/document_type.rb +23 -0
- data/lib/agreement_engine/enforceable.rb +6 -7
- data/lib/agreement_engine/engine.rb +7 -0
- data/lib/agreement_engine/html_to_page.rb +63 -0
- data/lib/agreement_engine/integrity.rb +23 -0
- data/lib/agreement_engine/pages_elements.rb +29 -0
- data/lib/agreement_engine/period.rb +23 -0
- data/lib/agreement_engine/receipt.rb +43 -0
- data/lib/agreement_engine/seed.rb +37 -0
- data/lib/agreement_engine/signable.rb +25 -9
- data/lib/agreement_engine/upgrade.rb +75 -0
- data/lib/agreement_engine/verification.rb +13 -0
- data/lib/agreement_engine/version.rb +1 -1
- data/lib/agreement_engine.rb +43 -1
- data/lib/generators/agreement_engine/templates/initializer.rb +5 -4
- data/lib/tasks/agreement_engine.rake +18 -15
- metadata +64 -9
- data/app/views/agreement_engine/admin/documents/_form.html.erb +0 -44
- data/app/views/agreement_engine/admin/documents/edit.html.erb +0 -5
- data/app/views/agreement_engine/admin/documents/new.html.erb +0 -5
- data/app/views/agreement_engine/documents/privacy.html.erb +0 -16
- data/lib/agreement_engine/agreement.rb +0 -23
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AgreementEngine
|
|
4
|
+
class RecordDocumentsController < SignaturesController
|
|
5
|
+
def update
|
|
6
|
+
return super if @type.signature?
|
|
7
|
+
|
|
8
|
+
AgreementEngine::Acceptance.record!(
|
|
9
|
+
signer: signer,
|
|
10
|
+
document: @version,
|
|
11
|
+
request: request,
|
|
12
|
+
statement: t("agreement_engine.record_documents.show.statement", document: @type.title),
|
|
13
|
+
button_text: t("agreement_engine.record_documents.show.accept"),
|
|
14
|
+
evidence: AgreementEngine.config.evidence(self, signer)
|
|
15
|
+
)
|
|
16
|
+
redirect_to after_signing_path, status: :see_other, notice: t("agreement_engine.record_documents.update.accepted", document: @type.title)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def require_consent
|
|
22
|
+
super if @type.signature?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def set_type_and_version
|
|
26
|
+
@version = AgreementEngine::Document.where.not(subject_id: nil).find_by(code: params[:code])
|
|
27
|
+
@type = @version && AgreementEngine.document_type(@version.document_type)
|
|
28
|
+
head :not_found unless @type && AgreementEngine.config.may_sign?(self, signer, @version)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def current_version
|
|
32
|
+
AgreementEngine.current_for(@type.key, @version.subject)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def form_url
|
|
36
|
+
agreement_engine.record_document_path(@version, return_to: return_path)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def after_signing_path
|
|
40
|
+
return_path || super
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def return_path
|
|
44
|
+
AgreementEngine.config.allowed_return_path(params[:return_to])
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AgreementEngine
|
|
4
|
+
class SignaturesController < ::ApplicationController
|
|
5
|
+
skip_before_action :require_accepted_agreements!, raise: false
|
|
6
|
+
before_action :require_signed_in
|
|
7
|
+
before_action :set_type_and_version
|
|
8
|
+
before_action :require_consent
|
|
9
|
+
|
|
10
|
+
layout "agreement_engine/minimal"
|
|
11
|
+
|
|
12
|
+
def show
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def update
|
|
16
|
+
if stale?
|
|
17
|
+
@error = t("agreement_engine.signatures.update.stale")
|
|
18
|
+
@version = current_version
|
|
19
|
+
render :show, status: :conflict
|
|
20
|
+
elsif already_signed?
|
|
21
|
+
redirect_to after_signing_path, status: :see_other, notice: t("agreement_engine.signatures.update.signed", document: @type.title)
|
|
22
|
+
elsif typed_name.blank?
|
|
23
|
+
@error = t("agreement_engine.signatures.update.blank")
|
|
24
|
+
render :show, status: :unprocessable_entity
|
|
25
|
+
else
|
|
26
|
+
AgreementEngine::Acceptance.record!(
|
|
27
|
+
signer: signer,
|
|
28
|
+
document: @version,
|
|
29
|
+
request: request,
|
|
30
|
+
statement: t("agreement_engine.signatures.show.statement", document: @type.title),
|
|
31
|
+
button_text: t("agreement_engine.signatures.show.sign"),
|
|
32
|
+
evidence: AgreementEngine.config.evidence(self, signer),
|
|
33
|
+
signature: {strength: "signature", typed_name: typed_name, consent: signer.held_consent}
|
|
34
|
+
)
|
|
35
|
+
redirect_to after_signing_path, status: :see_other, notice: t("agreement_engine.signatures.update.signed", document: @type.title)
|
|
36
|
+
end
|
|
37
|
+
rescue ActiveRecord::RecordNotUnique
|
|
38
|
+
redirect_to after_signing_path, status: :see_other, notice: t("agreement_engine.signatures.update.signed", document: @type.title)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def already_signed?
|
|
44
|
+
@version.acceptances.exists?(signer: signer, strength: "signature")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def stale?
|
|
48
|
+
params.dig(:signature, :content_hash).to_s != @version.content_hash.to_s || current_version != @version
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def current_version
|
|
52
|
+
AgreementEngine::Document.current(@type.key)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def typed_name
|
|
56
|
+
params.dig(:signature, :typed_name).to_s.strip
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def signer
|
|
60
|
+
AgreementEngine.config.current_user(self)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def require_signed_in
|
|
64
|
+
redirect_to main_app.root_path unless AgreementEngine.config.signed_in?(self)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def require_consent
|
|
68
|
+
return if signer.holds_consent?
|
|
69
|
+
|
|
70
|
+
session[:agreement_engine_after_consent] = form_url
|
|
71
|
+
redirect_to agreement_engine.consent_path
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def form_url
|
|
75
|
+
agreement_engine.signature_path(@type.key)
|
|
76
|
+
end
|
|
77
|
+
helper_method :form_url
|
|
78
|
+
|
|
79
|
+
def after_signing_path
|
|
80
|
+
main_app.root_path
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def set_type_and_version
|
|
84
|
+
@type = AgreementEngine.document_type(params[:document_type])
|
|
85
|
+
@version = @type&.signature? && AgreementEngine::Document.current(@type.key)
|
|
86
|
+
redirect_to main_app.root_path unless @version
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AgreementEngine
|
|
4
|
+
class VerificationsController < ::ApplicationController
|
|
5
|
+
skip_before_action :require_accepted_agreements!, raise: false
|
|
6
|
+
|
|
7
|
+
layout "agreement_engine/minimal"
|
|
8
|
+
|
|
9
|
+
def show
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create
|
|
13
|
+
file = params.dig(:verification, :file)
|
|
14
|
+
@matched = file.present? && AgreementEngine::Verification.matches?(file.read, params.dig(:verification, :hash_value))
|
|
15
|
+
render :show
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AgreementEngine
|
|
4
|
+
class ReceiptMailer < ActionMailer::Base
|
|
5
|
+
rescue_from StandardError do |error|
|
|
6
|
+
Rails.error.report(error, handled: true, source: "agreement_engine")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def copy(acceptance)
|
|
10
|
+
@acceptance = acceptance
|
|
11
|
+
@type = AgreementEngine.document_type(acceptance.document.document_type)
|
|
12
|
+
name = "#{acceptance.document.document_type}-#{acceptance.document.version}"
|
|
13
|
+
attachments["#{name}.pdf"] = {mime_type: "application/pdf", content: AgreementEngine::Receipt.pdf(acceptance)}
|
|
14
|
+
attachments["#{name}.json"] = {mime_type: "application/json", content: AgreementEngine::Receipt.byte_form(acceptance)}
|
|
15
|
+
mail(to: acceptance.person["email"], from: AgreementEngine.config.mailer_from || "no-reply@example.com", subject: t(".subject", document: @type&.title || acceptance.document.document_type.titleize))
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AgreementEngine
|
|
4
|
+
class Acceptance < ActiveRecord::Base
|
|
5
|
+
self.table_name = "agreement_engine_acceptances"
|
|
6
|
+
|
|
7
|
+
belongs_to :signer, polymorphic: true
|
|
8
|
+
|
|
9
|
+
before_create :set_period
|
|
10
|
+
after_create_commit :tell_host
|
|
11
|
+
after_create_commit :email_copy
|
|
12
|
+
|
|
13
|
+
def readonly?
|
|
14
|
+
persisted?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
belongs_to :document, class_name: "AgreementEngine::Document"
|
|
18
|
+
has_one :consent_withdrawal, class_name: "AgreementEngine::ConsentWithdrawal"
|
|
19
|
+
belongs_to :consent, class_name: "AgreementEngine::Acceptance", optional: true
|
|
20
|
+
|
|
21
|
+
def self.record!(signer:, document:, request:, statement:, button_text:, evidence: {}, signature: {})
|
|
22
|
+
create!(
|
|
23
|
+
signer: signer,
|
|
24
|
+
person: person_snapshot(signer).merge(evidence[:person].to_h.stringify_keys),
|
|
25
|
+
account: evidence[:account],
|
|
26
|
+
sign_in: evidence[:sign_in],
|
|
27
|
+
document: document,
|
|
28
|
+
content_hash: document.content_hash,
|
|
29
|
+
byte_form_version: document.byte_form_version,
|
|
30
|
+
accepted_at: Time.current,
|
|
31
|
+
engine_version: AgreementEngine::VERSION,
|
|
32
|
+
pages_version: KeystoneUi::Pages::VERSION,
|
|
33
|
+
ip_address: request.remote_ip,
|
|
34
|
+
user_agent: request.user_agent,
|
|
35
|
+
statement: statement,
|
|
36
|
+
button_text: button_text,
|
|
37
|
+
**signature
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def in_force_on?(day)
|
|
42
|
+
return false if accepted_at && accepted_at.to_date > day
|
|
43
|
+
return false if period_starts_on && period_starts_on > day
|
|
44
|
+
return false if period_ends_on && period_ends_on < day
|
|
45
|
+
|
|
46
|
+
true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def set_period
|
|
50
|
+
period = document.frozen_copy.to_h["period"]
|
|
51
|
+
return if period.blank?
|
|
52
|
+
|
|
53
|
+
if period["duration"]
|
|
54
|
+
return unless accepted_at
|
|
55
|
+
|
|
56
|
+
self.period_starts_on = accepted_at.to_date
|
|
57
|
+
self.period_ends_on = period_starts_on + ActiveSupport::Duration.parse(period["duration"])
|
|
58
|
+
else
|
|
59
|
+
self.period_starts_on = period["starts_on"]&.to_date
|
|
60
|
+
self.period_ends_on = period["ends_on"]&.to_date
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def email_copy
|
|
65
|
+
return unless AgreementEngine.config.copy_email_types.map(&:to_s).include?(document.document_type)
|
|
66
|
+
return if person.to_h["email"].blank?
|
|
67
|
+
|
|
68
|
+
AgreementEngine::ReceiptMailer.copy(self).deliver_later
|
|
69
|
+
rescue => error
|
|
70
|
+
Rails.error.report(error, handled: true, source: "agreement_engine")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def tell_host
|
|
74
|
+
handler = AgreementEngine.config.acceptance_handler
|
|
75
|
+
handler&.call(AcceptanceEvent.for(self))
|
|
76
|
+
rescue => error
|
|
77
|
+
Rails.error.report(error, handled: true, source: "agreement_engine")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def self.person_snapshot(signer)
|
|
81
|
+
{"id" => signer.id, "name" => signer.try(:name), "email" => signer.try(:email)}
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AgreementEngine
|
|
4
|
+
class ConsentWithdrawal < ActiveRecord::Base
|
|
5
|
+
self.table_name = "agreement_engine_consent_withdrawals"
|
|
6
|
+
|
|
7
|
+
belongs_to :acceptance, class_name: "AgreementEngine::Acceptance"
|
|
8
|
+
|
|
9
|
+
def readonly?
|
|
10
|
+
persisted?
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -7,21 +7,99 @@ module AgreementEngine
|
|
|
7
7
|
has_rich_text :content
|
|
8
8
|
|
|
9
9
|
validates :document_type, presence: true
|
|
10
|
-
validates :version, presence: true, uniqueness: {scope: :document_type}
|
|
11
|
-
validates :content, presence: true
|
|
10
|
+
validates :version, presence: true, uniqueness: {scope: [:document_type, :subject_type, :subject_id]}
|
|
11
|
+
validates :content, presence: true, unless: :content_hash
|
|
12
12
|
|
|
13
13
|
scope :published, -> { where("effective_at <= ?", Time.current) }
|
|
14
14
|
scope :draft, -> { where(effective_at: nil) }
|
|
15
15
|
|
|
16
|
+
FROZEN = "Issued versions are frozen and cannot be changed or deleted."
|
|
17
|
+
|
|
18
|
+
before_destroy :refuse_when_issued
|
|
19
|
+
validate :unchanged_once_issued, on: :update
|
|
20
|
+
validate :drawable_as_pdf, on: :create
|
|
21
|
+
|
|
22
|
+
has_many :acceptances, -> { order(:accepted_at, :id) }, class_name: "AgreementEngine::Acceptance"
|
|
23
|
+
|
|
24
|
+
belongs_to :page_version, class_name: "KeystoneUi::Pages::Version", optional: true
|
|
25
|
+
belongs_to :subject, polymorphic: true, optional: true
|
|
26
|
+
|
|
27
|
+
before_create { self.code ||= SecureRandom.alphanumeric(20) }
|
|
28
|
+
|
|
29
|
+
def to_param = code
|
|
30
|
+
|
|
31
|
+
def self.issue!(type:, page_version:, version:, effective_at:, subject: nil, values: {}, period: nil)
|
|
32
|
+
frozen_copy = {"slug" => page_version.page.slug, "number" => page_version.number, "document" => page_version.document, "values" => values, "period" => period.presence}
|
|
33
|
+
create!(
|
|
34
|
+
subject: subject,
|
|
35
|
+
document_type: type.to_s,
|
|
36
|
+
version: version,
|
|
37
|
+
effective_at: effective_at,
|
|
38
|
+
page_version: page_version,
|
|
39
|
+
frozen_copy: frozen_copy,
|
|
40
|
+
byte_form_version: ByteForm::VERSION,
|
|
41
|
+
content_hash: ByteForm.digest(slug: frozen_copy["slug"], number: frozen_copy["number"], document: frozen_copy["document"], values: values, period: frozen_copy["period"])
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def issue_in_place!(page_version)
|
|
46
|
+
copy = {"slug" => page_version.page.slug, "number" => page_version.number, "document" => page_version.document, "values" => {}}
|
|
47
|
+
update!(
|
|
48
|
+
page_version: page_version,
|
|
49
|
+
frozen_copy: copy,
|
|
50
|
+
byte_form_version: ByteForm::VERSION,
|
|
51
|
+
content_hash: ByteForm.digest(slug: copy["slug"], number: copy["number"], document: copy["document"])
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
16
55
|
def self.current(document_type)
|
|
17
|
-
where(document_type: document_type)
|
|
56
|
+
where(document_type: document_type, subject_id: nil)
|
|
18
57
|
.published
|
|
19
58
|
.order(effective_at: :desc)
|
|
20
59
|
.first
|
|
21
60
|
end
|
|
22
61
|
|
|
62
|
+
def issued?
|
|
63
|
+
content_hash.present?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def hash_intact?
|
|
67
|
+
return true unless issued?
|
|
68
|
+
|
|
69
|
+
copy = frozen_copy
|
|
70
|
+
ByteForm.digest(slug: copy["slug"], number: copy["number"], document: copy["document"], values: copy["values"] || {}, period: copy["period"]) == content_hash
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def source_moved?
|
|
74
|
+
return false unless issued?
|
|
75
|
+
|
|
76
|
+
source = KeystoneUi::Pages::Version.find_by(id: page_version_id)
|
|
77
|
+
source.nil? || source.document != frozen_copy["document"]
|
|
78
|
+
end
|
|
79
|
+
|
|
23
80
|
def published?
|
|
24
81
|
effective_at.present? && effective_at <= Time.current
|
|
25
82
|
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
def unchanged_once_issued
|
|
87
|
+
errors.add(:base, FROZEN) if content_hash_was.present? && changed?
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def drawable_as_pdf
|
|
91
|
+
return unless frozen_copy
|
|
92
|
+
|
|
93
|
+
KeystoneUi::Pages::Operations.elements(frozen_copy["document"]).map { |element| KeystoneUi::Pages.catalog.find(element["key"]) }.uniq.each do |definition|
|
|
94
|
+
errors.add(:base, "The #{definition.name} element cannot be drawn as a PDF, so this page cannot be issued") if definition && !definition.pdf
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def refuse_when_issued
|
|
99
|
+
return unless issued?
|
|
100
|
+
|
|
101
|
+
errors.add(:base, FROZEN)
|
|
102
|
+
throw :abort
|
|
103
|
+
end
|
|
26
104
|
end
|
|
27
105
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div class="mx-auto max-w-6xl px-4 py-8">
|
|
2
2
|
<div class="flex items-center justify-between mb-6">
|
|
3
3
|
<h1 class="text-2xl font-bold">Legal Documents</h1>
|
|
4
|
-
<%= link_to "
|
|
4
|
+
<%= link_to "Issue a version", agreement_engine.new_admin_issue_path, class: "btn btn-primary" %>
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
7
|
<div class="mb-4 flex gap-2">
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
<td class="px-4 py-2"><%= document.effective_at&.strftime("%B %d, %Y") || "—" %></td>
|
|
30
30
|
<td class="px-4 py-2 flex gap-2">
|
|
31
31
|
<%= link_to "View", agreement_engine.admin_document_path(document) %>
|
|
32
|
-
<%= link_to "Edit", agreement_engine.edit_admin_document_path(document) %>
|
|
33
32
|
</td>
|
|
34
33
|
</tr>
|
|
35
34
|
<% end %>
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
<div class="flex items-center justify-between mb-6">
|
|
3
3
|
<h1 class="text-2xl font-bold"><%= @document.document_type.titleize %> v<%= @document.version %></h1>
|
|
4
4
|
<div class="flex gap-2">
|
|
5
|
-
<%= link_to "Edit", agreement_engine.edit_admin_document_path(@document), class: "btn btn-secondary" %>
|
|
6
5
|
<%= link_to "Back", agreement_engine.admin_documents_path, class: "btn btn-secondary" %>
|
|
7
6
|
</div>
|
|
8
7
|
</div>
|
|
@@ -16,6 +15,16 @@
|
|
|
16
15
|
<dt class="text-sm font-medium text-gray-500">Effective Date</dt>
|
|
17
16
|
<dd><%= @document.effective_at&.strftime("%B %d, %Y") || "Not set" %></dd>
|
|
18
17
|
</div>
|
|
18
|
+
<% if @document.content_hash %>
|
|
19
|
+
<div class="col-span-2">
|
|
20
|
+
<dt class="text-sm font-medium text-gray-500">Issued from page</dt>
|
|
21
|
+
<dd><%= @document.frozen_copy["slug"] %>, version <%= @document.frozen_copy["number"] %></dd>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="col-span-2">
|
|
24
|
+
<dt class="text-sm font-medium text-gray-500">SHA-256</dt>
|
|
25
|
+
<dd class="font-mono break-all"><%= @document.content_hash %></dd>
|
|
26
|
+
</div>
|
|
27
|
+
<% end %>
|
|
19
28
|
<% if @document.summary.present? %>
|
|
20
29
|
<div class="col-span-2">
|
|
21
30
|
<dt class="text-sm font-medium text-gray-500">Summary</dt>
|
|
@@ -24,7 +33,48 @@
|
|
|
24
33
|
<% end %>
|
|
25
34
|
</dl>
|
|
26
35
|
|
|
36
|
+
<% unless @document.hash_intact? %>
|
|
37
|
+
<p class="mb-4 rounded border border-red-300 bg-red-50 p-3 text-red-800">The frozen copy no longer produces this hash.</p>
|
|
38
|
+
<% end %>
|
|
39
|
+
<% if @document.source_moved? %>
|
|
40
|
+
<p class="mb-4 rounded border border-amber-300 bg-amber-50 p-3 text-amber-800">The page version this was issued from has changed or been deleted since. The text below is the frozen copy.</p>
|
|
41
|
+
<% end %>
|
|
42
|
+
|
|
27
43
|
<article class="prose prose-gray dark:prose-invert max-w-none">
|
|
28
|
-
<%= @document
|
|
44
|
+
<%= render "agreement_engine/documents/issued_version", document: @document %>
|
|
29
45
|
</article>
|
|
46
|
+
|
|
47
|
+
<h2 class="text-xl font-bold mt-10 mb-4">Acceptances</h2>
|
|
48
|
+
<% if @document.acceptances.any? %>
|
|
49
|
+
<div class="overflow-x-auto">
|
|
50
|
+
<table class="min-w-full divide-y divide-gray-200 text-sm">
|
|
51
|
+
<thead>
|
|
52
|
+
<tr>
|
|
53
|
+
<th class="px-3 py-2 text-left font-medium text-gray-500">Accepted</th>
|
|
54
|
+
<th class="px-3 py-2 text-left font-medium text-gray-500">Person</th>
|
|
55
|
+
<th class="px-3 py-2 text-left font-medium text-gray-500">Account</th>
|
|
56
|
+
<th class="px-3 py-2 text-left font-medium text-gray-500">IP address</th>
|
|
57
|
+
<th class="px-3 py-2 text-left font-medium text-gray-500">Browser</th>
|
|
58
|
+
<th class="px-3 py-2 text-left font-medium text-gray-500">Signed in with</th>
|
|
59
|
+
<th class="px-3 py-2 text-left font-medium text-gray-500">Hash</th>
|
|
60
|
+
</tr>
|
|
61
|
+
</thead>
|
|
62
|
+
<tbody class="divide-y divide-gray-200">
|
|
63
|
+
<% @document.acceptances.each do |acceptance| %>
|
|
64
|
+
<tr>
|
|
65
|
+
<td class="px-3 py-2"><%= acceptance.accepted_at&.strftime("%B %d, %Y %H:%M %Z") %></td>
|
|
66
|
+
<td class="px-3 py-2"><%= acceptance.person.to_h.values_at("name", "email").compact.join(", ") %></td>
|
|
67
|
+
<td class="px-3 py-2"><%= acceptance.account.to_h["name"] %></td>
|
|
68
|
+
<td class="px-3 py-2"><%= acceptance.ip_address %></td>
|
|
69
|
+
<td class="px-3 py-2"><%= acceptance.user_agent %></td>
|
|
70
|
+
<td class="px-3 py-2"><%= Array(acceptance.sign_in.to_h["methods"]).join(", ") %></td>
|
|
71
|
+
<td class="px-3 py-2 font-mono break-all"><%= acceptance.content_hash %></td>
|
|
72
|
+
</tr>
|
|
73
|
+
<% end %>
|
|
74
|
+
</tbody>
|
|
75
|
+
</table>
|
|
76
|
+
</div>
|
|
77
|
+
<% else %>
|
|
78
|
+
<p class="text-gray-500">No one has accepted this version yet.</p>
|
|
79
|
+
<% end %>
|
|
30
80
|
</div>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<div class="mx-auto max-w-4xl px-4 py-8">
|
|
2
|
+
<h1 class="text-2xl font-bold mb-6">Issue a version</h1>
|
|
3
|
+
|
|
4
|
+
<%= form_with(scope: :issue, url: agreement_engine.admin_issues_path, class: "space-y-4") do |form| %>
|
|
5
|
+
<% if @error %>
|
|
6
|
+
<div class="bg-red-50 border border-red-200 rounded p-4 text-red-700"><%= @error %></div>
|
|
7
|
+
<% end %>
|
|
8
|
+
|
|
9
|
+
<div>
|
|
10
|
+
<%= form.label :document_type, "Document type", class: "block text-sm font-medium text-gray-700" %>
|
|
11
|
+
<%= form.select :document_type, AgreementEngine.config.registered_document_types.map { |type| [type.title, type.key] }, {}, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm" %>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div>
|
|
15
|
+
<%= form.label :page_version_id, "Published page", class: "block text-sm font-medium text-gray-700" %>
|
|
16
|
+
<%= form.select :page_version_id, @page_versions.map { |version| ["#{version.page.name}, version #{version.number}", version.id] }, {}, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm" %>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div>
|
|
20
|
+
<%= form.label :version, "Version label", class: "block text-sm font-medium text-gray-700" %>
|
|
21
|
+
<%= form.text_field :version, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm" %>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<div>
|
|
25
|
+
<%= form.label :effective_at, "Effective date", class: "block text-sm font-medium text-gray-700" %>
|
|
26
|
+
<%= form.datetime_local_field :effective_at, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm" %>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<fieldset class="space-y-2">
|
|
30
|
+
<legend class="text-sm font-medium text-gray-700">Period, if the document covers one</legend>
|
|
31
|
+
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
|
32
|
+
<div>
|
|
33
|
+
<%= form.label :period_starts_on, "Starts", class: "block text-sm text-gray-700" %>
|
|
34
|
+
<%= form.date_field :period_starts_on, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm" %>
|
|
35
|
+
</div>
|
|
36
|
+
<div>
|
|
37
|
+
<%= form.label :period_ends_on, "Ends", class: "block text-sm text-gray-700" %>
|
|
38
|
+
<%= form.date_field :period_ends_on, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm" %>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
<div>
|
|
42
|
+
<%= form.label :period_duration, "Or a duration from acceptance", class: "block text-sm text-gray-700" %>
|
|
43
|
+
<%= form.select :period_duration, [["None", ""], ["1 month", "P1M"], ["3 months", "P3M"], ["6 months", "P6M"], ["1 year", "P1Y"], ["2 years", "P2Y"], ["3 years", "P3Y"]], {}, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm" %>
|
|
44
|
+
</div>
|
|
45
|
+
</fieldset>
|
|
46
|
+
|
|
47
|
+
<div>
|
|
48
|
+
<%= form.submit "Issue", class: "btn btn-primary" %>
|
|
49
|
+
</div>
|
|
50
|
+
<% end %>
|
|
51
|
+
</div>
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
<% if @version %>
|
|
5
5
|
<%= tag.p t(".last_updated", date: l(@version.effective_at.to_date, format: :long)), class: "mb-4 text-gray-700 leading-normal italic" %>
|
|
6
6
|
|
|
7
|
+
<% if (period = AgreementEngine::Period.describe(@version.frozen_copy.to_h["period"])) %>
|
|
8
|
+
<p class="mb-4 font-medium">Period: <%= period %></p>
|
|
9
|
+
<% end %>
|
|
7
10
|
<article class="prose prose-gray dark:prose-invert max-w-none">
|
|
8
|
-
<%= @version
|
|
11
|
+
<%= render "agreement_engine/documents/issued_version", document: @version %>
|
|
9
12
|
</article>
|
|
10
13
|
<% else %>
|
|
11
14
|
<p class="text-gray-500">No version has been published yet.</p>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<div class="max-w-4xl mx-auto p-4 my-8 lg:my-24">
|
|
2
|
+
<article class="prose prose-gray dark:prose-invert max-w-none">
|
|
3
|
+
<%= render "agreement_engine/documents/issued_version", document: @version %>
|
|
4
|
+
</article>
|
|
5
|
+
|
|
6
|
+
<div class="mt-8 sm:mt-16 text-center">
|
|
7
|
+
<% if AgreementEngine.config.current_user(controller).held_consent %>
|
|
8
|
+
<p><%= t(".held") %></p>
|
|
9
|
+
<div class="mt-4 flex items-center justify-center gap-2">
|
|
10
|
+
<%= button_to t(".withdraw"), agreement_engine.consent_path, method: :delete, class: "btn btn-secondary btn-large" %>
|
|
11
|
+
</div>
|
|
12
|
+
<% else %>
|
|
13
|
+
<p><%= t(".statement") %></p>
|
|
14
|
+
<div class="mt-4 flex items-center justify-center gap-2">
|
|
15
|
+
<%= button_to t(".consent"), agreement_engine.consent_path, method: :post, class: "btn btn-primary btn-large" %>
|
|
16
|
+
</div>
|
|
17
|
+
<% end %>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<% content_for :title,
|
|
1
|
+
<% content_for :title, @type.title %>
|
|
2
2
|
|
|
3
3
|
<div class="mx-auto max-w-4xl px-4 py-12 sm:px-6 lg:px-8">
|
|
4
4
|
<article class="prose prose-gray dark:prose-invert max-w-none">
|
|
5
|
-
<h1
|
|
5
|
+
<h1><%= @type.title %></h1>
|
|
6
6
|
|
|
7
7
|
<% if @version %>
|
|
8
8
|
<p class="text-sm text-gray-500 dark:text-gray-400">
|
|
9
9
|
Version <%= @version.version %> - Effective <%= @version.effective_at.strftime("%B %d, %Y") %>
|
|
10
10
|
</p>
|
|
11
|
-
<%= @version
|
|
11
|
+
<%= render "agreement_engine/documents/issued_version", document: @version %>
|
|
12
12
|
<% else %>
|
|
13
|
-
<p class="text-gray-500"
|
|
13
|
+
<p class="text-gray-500"><%= t(".none.#{@type.key}", default: t(".none.default")) %></p>
|
|
14
14
|
<% end %>
|
|
15
15
|
</article>
|
|
16
16
|
</div>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<div class="max-w-4xl mx-auto p-4 my-8 lg:my-24">
|
|
2
|
+
<h1 class="mb-4"><%= @type.title %></h1>
|
|
3
|
+
|
|
4
|
+
<% if (period = AgreementEngine::Period.describe(@version.frozen_copy.to_h["period"])) %>
|
|
5
|
+
<p class="mb-4 font-medium">Period: <%= period %></p>
|
|
6
|
+
<% end %>
|
|
7
|
+
<article class="prose prose-gray dark:prose-invert max-w-none">
|
|
8
|
+
<%= render "agreement_engine/documents/issued_version", document: @version %>
|
|
9
|
+
</article>
|
|
10
|
+
|
|
11
|
+
<%= form_with(scope: :signature, url: form_url, method: :patch, class: "mt-8 sm:mt-16 space-y-4") do |form| %>
|
|
12
|
+
<%= form.hidden_field :content_hash, value: @version.content_hash %>
|
|
13
|
+
|
|
14
|
+
<% if @error %>
|
|
15
|
+
<div class="bg-red-50 border border-red-200 rounded p-4 text-red-700"><%= @error %></div>
|
|
16
|
+
<% end %>
|
|
17
|
+
|
|
18
|
+
<% if @type.signature? %>
|
|
19
|
+
<p><%= t("agreement_engine.signatures.show.statement", document: @type.title) %></p>
|
|
20
|
+
|
|
21
|
+
<div>
|
|
22
|
+
<%= form.label :typed_name, t("agreement_engine.signatures.show.typed_name"), class: "block text-sm font-medium text-gray-700" %>
|
|
23
|
+
<%= form.text_field :typed_name, autocomplete: "name", class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm" %>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div>
|
|
27
|
+
<%= form.submit t("agreement_engine.signatures.show.sign"), class: "btn btn-primary btn-large" %>
|
|
28
|
+
</div>
|
|
29
|
+
<% else %>
|
|
30
|
+
<p><%= t("agreement_engine.record_documents.show.statement", document: @type.title) %></p>
|
|
31
|
+
|
|
32
|
+
<div>
|
|
33
|
+
<%= form.submit t("agreement_engine.record_documents.show.accept"), class: "btn btn-primary btn-large" %>
|
|
34
|
+
</div>
|
|
35
|
+
<% end %>
|
|
36
|
+
<% end %>
|
|
37
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<div class="max-w-2xl mx-auto p-4 my-8 lg:my-24">
|
|
2
|
+
<h1 class="mb-4"><%= t(".title") %></h1>
|
|
3
|
+
<p class="mb-6"><%= t(".description") %></p>
|
|
4
|
+
|
|
5
|
+
<% unless @matched.nil? %>
|
|
6
|
+
<p class="mb-6 font-medium"><%= @matched ? t(".matched") : t(".not_matched") %></p>
|
|
7
|
+
<% end %>
|
|
8
|
+
|
|
9
|
+
<%= form_with(scope: :verification, url: agreement_engine.verification_path, multipart: true, class: "space-y-4") do |form| %>
|
|
10
|
+
<div>
|
|
11
|
+
<%= form.label :file, t(".file"), class: "block text-sm font-medium text-gray-700" %>
|
|
12
|
+
<%= form.file_field :file, class: "mt-1 block w-full" %>
|
|
13
|
+
</div>
|
|
14
|
+
<div>
|
|
15
|
+
<%= form.label :hash_value, t(".hash"), class: "block text-sm font-medium text-gray-700" %>
|
|
16
|
+
<%= form.text_field :hash_value, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm font-mono" %>
|
|
17
|
+
</div>
|
|
18
|
+
<div>
|
|
19
|
+
<%= form.submit t(".check"), class: "btn btn-primary" %>
|
|
20
|
+
</div>
|
|
21
|
+
<% end %>
|
|
22
|
+
</div>
|