agreement_engine 0.2.2 → 0.3.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/CHANGELOG.md +22 -0
- data/README.md +16 -0
- data/app/controllers/agreement_engine/agreements_controller.rb +21 -2
- data/app/controllers/agreement_engine/consents_controller.rb +1 -1
- data/app/controllers/agreement_engine/documents_controller.rb +8 -0
- data/app/controllers/agreement_engine/record_documents_controller.rb +7 -1
- data/app/controllers/agreement_engine/signatures_controller.rb +14 -2
- data/app/controllers/agreement_engine/verifications_controller.rb +1 -1
- data/app/models/agreement_engine/acceptance.rb +2 -1
- data/app/views/agreement_engine/agreements/show.html.erb +20 -12
- data/app/views/agreement_engine/consents/show.html.erb +8 -4
- data/app/views/agreement_engine/signatures/show.html.erb +25 -24
- data/config/locales/en.yml +9 -0
- data/db/migrate/20261123171528_add_reading_to_agreement_engine_acceptances.rb +5 -0
- data/lib/agreement_engine/acceptance_event.rb +1 -0
- data/lib/agreement_engine/configuration.rb +2 -0
- data/lib/agreement_engine/document_type.rb +26 -2
- data/lib/agreement_engine/enforceable.rb +8 -0
- data/lib/agreement_engine/reading_check.rb +63 -0
- data/lib/agreement_engine/receipt.rb +25 -0
- data/lib/agreement_engine/signable.rb +5 -2
- data/lib/agreement_engine/version.rb +1 -1
- data/lib/agreement_engine.rb +1 -0
- metadata +17 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f90c43809e52a4d6ec4705391b849d8a1b37e7e4576da25e1e4a255ffc9c077b
|
|
4
|
+
data.tar.gz: 2b79664ef0cc2afa4d238f94e3390d773b971db6098ea6ff204fc500103c940c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d45b1a8798004e9bd7f5558c4a191b0bb7d2bfc7c78fa61b863eec7b0292eed1c9786e6e1241ced39da80c6294428cc2d63b54e83b7cda80ba361af08f3e7d6b
|
|
7
|
+
data.tar.gz: 132ed13cebc7f079e2050259c7af4d294d2671d9b72087ee5d5f7f273eba724f13d7741a824588829d967955283bc95b6ccd8c77a68566b0bca658ef4c475e5d
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.3.0] - 2026-11-23
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- A document type takes `reading:` with `seconds:`, `scroll: true` or `open: true`, and the accept, signing and record pages refuse an acceptance or signature sent before the minimum time has passed since the page was first shown (#57, #64)
|
|
10
|
+
- The accept, signing and record pages hold their button with keystone_ui's reading hold, showing the seconds left and waiting for the end of the document when scrolling is required (#62, #63, #64)
|
|
11
|
+
- Each acceptance and signature keeps its reading evidence: the minimum time and the seconds the server measured, the browser's report of reaching the end, and where and when the document was opened (#57, #59, #63, #64)
|
|
12
|
+
- Host code asks `agreement_engine_opened(:type)` whether the session opened a document's public page, and `accept_version!` takes the answer as `reading:` (#59)
|
|
13
|
+
- The signer's copy lists the reading evidence, and the acceptance event exposes it as `reading` (#66)
|
|
14
|
+
- `config.layout` names the layout the accept, consent, signing, record and verification pages render in (#58)
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- The gem's accept, consent, signing, record and verification pages render in the host's `application` layout by default; name `"agreement_engine/minimal"` to keep the old look (#58)
|
|
19
|
+
- The accept, signing, record and consent pages are drawn with keystone_ui components, and a refused signature keeps its typed name (#62, #64)
|
|
20
|
+
- agreement_engine depends on keystone_ui 0.106.0 or later (#62)
|
|
21
|
+
- A mistyped reading requirement stops the app at boot, and host code accepting a type that requires opening without an opening of that version raises (#60, #61)
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- An acceptance refused on the accept page now counts the time spent on the page shown with the refusal toward the minimum reading time (#68)
|
|
26
|
+
|
|
5
27
|
## [0.2.2] - 2026-11-20
|
|
6
28
|
|
|
7
29
|
### Added
|
data/README.md
CHANGED
|
@@ -327,6 +327,22 @@ What the app gains: editing documents in the page builder, a hash on every
|
|
|
327
327
|
issued version, a kept record of every acceptance with its evidence, consent to
|
|
328
328
|
electronic records, signatures, documents for one record and the signer's copy.
|
|
329
329
|
|
|
330
|
+
### The layout of the gem's pages
|
|
331
|
+
|
|
332
|
+
The accept, consent, signing, record and verification pages render in the
|
|
333
|
+
host's `application` layout, so they load the app's JavaScript and styles.
|
|
334
|
+
Before this they rendered in the gem's own minimal layout, which loads neither.
|
|
335
|
+
Name another of the app's layouts, or the minimal layout to keep the old look:
|
|
336
|
+
|
|
337
|
+
```ruby
|
|
338
|
+
AgreementEngine.configure do |config|
|
|
339
|
+
config.layout = "agreement_engine/minimal"
|
|
340
|
+
end
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
An app that put its own copy of `layouts/agreement_engine/minimal` in its views
|
|
344
|
+
to get its layout can delete that copy.
|
|
345
|
+
|
|
330
346
|
## Auth Configuration
|
|
331
347
|
|
|
332
348
|
AgreementEngine defaults to Devise conventions. Override for other auth systems:
|
|
@@ -2,19 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
module AgreementEngine
|
|
4
4
|
class AgreementsController < ::ApplicationController
|
|
5
|
+
include AgreementEngine::ReadingCheck
|
|
6
|
+
|
|
5
7
|
skip_before_action :require_accepted_agreements!, raise: false
|
|
6
8
|
before_action :agreement_engine_authenticate_user!
|
|
7
9
|
before_action :set_agreement
|
|
8
10
|
before_action :set_version
|
|
9
11
|
|
|
10
|
-
layout
|
|
12
|
+
layout -> { AgreementEngine.config.layout }
|
|
11
13
|
|
|
12
14
|
def show
|
|
15
|
+
record_served
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def update
|
|
19
|
+
return refuse(too_soon_reason(:accepting)) if @version && too_soon?
|
|
20
|
+
|
|
16
21
|
if @version
|
|
17
|
-
AgreementEngine::Acceptance.record!(signer: agreement_engine_current_user, document: @version, request: request, statement: t("agreement_engine.agreements.show.description", agreement: @agreement.title), button_text: t("agreement_engine.agreements.show.accept"), evidence: AgreementEngine.config.evidence(self, agreement_engine_current_user))
|
|
22
|
+
AgreementEngine::Acceptance.record!(signer: agreement_engine_current_user, document: @version, request: request, statement: t("agreement_engine.agreements.show.description", agreement: @agreement.title), button_text: t("agreement_engine.agreements.show.accept"), evidence: AgreementEngine.config.evidence(self, agreement_engine_current_user), reading: reading_evidence)
|
|
18
23
|
end
|
|
19
24
|
redirect_to after_accepted_path, status: :see_other
|
|
20
25
|
end
|
|
@@ -50,6 +55,20 @@ module AgreementEngine
|
|
|
50
55
|
@version = @agreement && AgreementEngine::Document.current(@agreement.key)
|
|
51
56
|
end
|
|
52
57
|
|
|
58
|
+
def refuse(reason)
|
|
59
|
+
@error = reason
|
|
60
|
+
record_served
|
|
61
|
+
render :show, status: :unprocessable_entity
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def reading_type
|
|
65
|
+
@agreement
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def opened_on_page
|
|
69
|
+
"accept_page"
|
|
70
|
+
end
|
|
71
|
+
|
|
53
72
|
def after_accepted_path
|
|
54
73
|
stored_location_for(:user) || main_app.root_path
|
|
55
74
|
end
|
|
@@ -7,6 +7,14 @@ module AgreementEngine
|
|
|
7
7
|
return head(:not_found) unless @type&.standing?
|
|
8
8
|
|
|
9
9
|
@version = AgreementEngine::Document.current(@type.key)
|
|
10
|
+
record_opened if @version
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def record_opened
|
|
16
|
+
opened = session[:agreement_engine_opened] ||= {}
|
|
17
|
+
opened[@version.id.to_s] ||= Time.current.to_i
|
|
10
18
|
end
|
|
11
19
|
end
|
|
12
20
|
end
|
|
@@ -5,13 +5,19 @@ module AgreementEngine
|
|
|
5
5
|
def update
|
|
6
6
|
return super if @type.signature?
|
|
7
7
|
|
|
8
|
+
if too_soon?
|
|
9
|
+
@error = too_soon_reason(:accepting)
|
|
10
|
+
return render(:show, status: :unprocessable_entity)
|
|
11
|
+
end
|
|
12
|
+
|
|
8
13
|
AgreementEngine::Acceptance.record!(
|
|
9
14
|
signer: signer,
|
|
10
15
|
document: @version,
|
|
11
16
|
request: request,
|
|
12
17
|
statement: t("agreement_engine.record_documents.show.statement", document: @type.title),
|
|
13
18
|
button_text: t("agreement_engine.record_documents.show.accept"),
|
|
14
|
-
evidence: AgreementEngine.config.evidence(self, signer)
|
|
19
|
+
evidence: AgreementEngine.config.evidence(self, signer),
|
|
20
|
+
reading: reading_evidence
|
|
15
21
|
)
|
|
16
22
|
redirect_to after_signing_path, status: :see_other, notice: t("agreement_engine.record_documents.update.accepted", document: @type.title)
|
|
17
23
|
end
|
|
@@ -2,21 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
module AgreementEngine
|
|
4
4
|
class SignaturesController < ::ApplicationController
|
|
5
|
+
include AgreementEngine::ReadingCheck
|
|
6
|
+
|
|
5
7
|
skip_before_action :require_accepted_agreements!, raise: false
|
|
6
8
|
before_action :require_signed_in
|
|
7
9
|
before_action :set_type_and_version
|
|
8
10
|
before_action :require_consent
|
|
9
11
|
|
|
10
|
-
layout
|
|
12
|
+
layout -> { AgreementEngine.config.layout }
|
|
11
13
|
|
|
12
14
|
def show
|
|
15
|
+
record_served
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def update
|
|
16
19
|
if stale?
|
|
17
20
|
@error = t("agreement_engine.signatures.update.stale")
|
|
18
21
|
@version = current_version
|
|
22
|
+
record_served
|
|
19
23
|
render :show, status: :conflict
|
|
24
|
+
elsif too_soon?
|
|
25
|
+
@error = too_soon_reason(:signing)
|
|
26
|
+
render :show, status: :unprocessable_entity
|
|
20
27
|
elsif already_signed?
|
|
21
28
|
redirect_to after_signing_path, status: :see_other, notice: t("agreement_engine.signatures.update.signed", document: @type.title)
|
|
22
29
|
elsif typed_name.blank?
|
|
@@ -30,7 +37,8 @@ module AgreementEngine
|
|
|
30
37
|
statement: t("agreement_engine.signatures.show.statement", document: @type.title),
|
|
31
38
|
button_text: t("agreement_engine.signatures.show.sign"),
|
|
32
39
|
evidence: AgreementEngine.config.evidence(self, signer),
|
|
33
|
-
signature: {strength: "signature", typed_name: typed_name, consent: signer.held_consent}
|
|
40
|
+
signature: {strength: "signature", typed_name: typed_name, consent: signer.held_consent},
|
|
41
|
+
reading: reading_evidence
|
|
34
42
|
)
|
|
35
43
|
redirect_to after_signing_path, status: :see_other, notice: t("agreement_engine.signatures.update.signed", document: @type.title)
|
|
36
44
|
end
|
|
@@ -40,6 +48,10 @@ module AgreementEngine
|
|
|
40
48
|
|
|
41
49
|
private
|
|
42
50
|
|
|
51
|
+
def reading_type
|
|
52
|
+
@type
|
|
53
|
+
end
|
|
54
|
+
|
|
43
55
|
def already_signed?
|
|
44
56
|
@version.acceptances.exists?(signer: signer, strength: "signature")
|
|
45
57
|
end
|
|
@@ -18,7 +18,7 @@ module AgreementEngine
|
|
|
18
18
|
has_one :consent_withdrawal, class_name: "AgreementEngine::ConsentWithdrawal"
|
|
19
19
|
belongs_to :consent, class_name: "AgreementEngine::Acceptance", optional: true
|
|
20
20
|
|
|
21
|
-
def self.record!(signer:, document:, request:, statement:, button_text:, evidence: {}, signature: {})
|
|
21
|
+
def self.record!(signer:, document:, request:, statement:, button_text:, evidence: {}, signature: {}, reading: nil)
|
|
22
22
|
create!(
|
|
23
23
|
signer: signer,
|
|
24
24
|
person: person_snapshot(signer).merge(evidence[:person].to_h.stringify_keys),
|
|
@@ -34,6 +34,7 @@ module AgreementEngine
|
|
|
34
34
|
user_agent: request.user_agent,
|
|
35
35
|
statement: statement,
|
|
36
36
|
button_text: button_text,
|
|
37
|
+
reading: reading,
|
|
37
38
|
**signature
|
|
38
39
|
)
|
|
39
40
|
end
|
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
<div class="max-w-4xl mx-auto p-4 my-8 lg:my-24">
|
|
2
|
-
|
|
2
|
+
<%= ui_heading(text: t(".title", agreement: @agreement.title), size: :lg) %>
|
|
3
3
|
|
|
4
4
|
<% if @version %>
|
|
5
|
-
<%=
|
|
5
|
+
<%= ui_caption(text: t(".last_updated", date: l(@version.effective_at.to_date, format: :long)), normal_case: true) %>
|
|
6
6
|
|
|
7
7
|
<% if (period = AgreementEngine::Period.describe(@version.frozen_copy.to_h["period"])) %>
|
|
8
|
-
|
|
8
|
+
<%= ui_paragraph(text: "Period: #{period}") %>
|
|
9
|
+
<% end %>
|
|
10
|
+
<%= ui_reading_hold(**reading_hold_options, waiting: t(".waiting"), ready: t(".ready")) do |hold| %>
|
|
11
|
+
<% hold.with_action do %>
|
|
12
|
+
<% if @error %>
|
|
13
|
+
<%= ui_alert(message: @error, type: :error) %>
|
|
14
|
+
<% end %>
|
|
15
|
+
<%= ui_paragraph(text: t(".description", agreement: @agreement.title)) %>
|
|
16
|
+
<%= ui_form(action: agreement_engine.agreement_path(@agreement), method: :patch) do %>
|
|
17
|
+
<%= ui_button(label: t(".accept"), data: {reading_hold_target: "button"}) %>
|
|
18
|
+
<% end %>
|
|
19
|
+
<% end %>
|
|
20
|
+
<article class="prose prose-gray dark:prose-invert max-w-none">
|
|
21
|
+
<%= render "agreement_engine/documents/issued_version", document: @version %>
|
|
22
|
+
</article>
|
|
9
23
|
<% end %>
|
|
10
|
-
<article class="prose prose-gray dark:prose-invert max-w-none">
|
|
11
|
-
<%= render "agreement_engine/documents/issued_version", document: @version %>
|
|
12
|
-
</article>
|
|
13
24
|
<% else %>
|
|
14
25
|
<p class="text-gray-500">No version has been published yet.</p>
|
|
15
26
|
<% end %>
|
|
16
27
|
|
|
17
28
|
<div class="mt-8 sm:mt-16">
|
|
18
|
-
<div class="text-center">
|
|
19
|
-
<%= t(".description", agreement: @agreement.title) %>
|
|
20
|
-
</div>
|
|
21
|
-
|
|
22
29
|
<div class="mt-4 flex items-center justify-center gap-2">
|
|
23
|
-
<%=
|
|
24
|
-
|
|
30
|
+
<%= ui_form(action: agreement_engine.agreement_path(@agreement), method: :delete) do %>
|
|
31
|
+
<%= ui_button(label: t(".decline"), variant: :secondary) %>
|
|
32
|
+
<% end %>
|
|
25
33
|
</div>
|
|
26
34
|
</div>
|
|
27
35
|
</div>
|
|
@@ -5,14 +5,18 @@
|
|
|
5
5
|
|
|
6
6
|
<div class="mt-8 sm:mt-16 text-center">
|
|
7
7
|
<% if AgreementEngine.config.current_user(controller).held_consent %>
|
|
8
|
-
|
|
8
|
+
<%= ui_paragraph(text: t(".held")) %>
|
|
9
9
|
<div class="mt-4 flex items-center justify-center gap-2">
|
|
10
|
-
<%=
|
|
10
|
+
<%= ui_form(action: agreement_engine.consent_path, method: :delete) do %>
|
|
11
|
+
<%= ui_button(label: t(".withdraw"), variant: :secondary) %>
|
|
12
|
+
<% end %>
|
|
11
13
|
</div>
|
|
12
14
|
<% else %>
|
|
13
|
-
|
|
15
|
+
<%= ui_paragraph(text: t(".statement")) %>
|
|
14
16
|
<div class="mt-4 flex items-center justify-center gap-2">
|
|
15
|
-
<%=
|
|
17
|
+
<%= ui_form(action: agreement_engine.consent_path, method: :post) do %>
|
|
18
|
+
<%= ui_button(label: t(".consent")) %>
|
|
19
|
+
<% end %>
|
|
16
20
|
</div>
|
|
17
21
|
<% end %>
|
|
18
22
|
</div>
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
<div class="max-w-4xl mx-auto p-4 my-8 lg:my-24">
|
|
2
|
-
|
|
2
|
+
<%= ui_heading(text: @type.title, size: :lg) %>
|
|
3
3
|
|
|
4
4
|
<% if (period = AgreementEngine::Period.describe(@version.frozen_copy.to_h["period"])) %>
|
|
5
|
-
|
|
5
|
+
<%= ui_paragraph(text: "Period: #{period}") %>
|
|
6
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
7
|
|
|
11
|
-
<%=
|
|
12
|
-
|
|
8
|
+
<%= ui_reading_hold(**reading_hold_options, waiting: t("agreement_engine.signatures.show.waiting"), ready: t("agreement_engine.signatures.show.ready")) do |hold| %>
|
|
9
|
+
<% hold.with_action do %>
|
|
10
|
+
<%= form_with(scope: :signature, url: form_url, method: :patch, class: "mt-8 sm:mt-16 space-y-4") do |form| %>
|
|
11
|
+
<%= form.hidden_field :content_hash, value: @version.content_hash %>
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
<% if @error %>
|
|
14
|
+
<%= ui_alert(message: @error, type: :error) %>
|
|
15
|
+
<% end %>
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
<% if @type.signature? %>
|
|
18
|
+
<%= ui_paragraph(text: t("agreement_engine.signatures.show.statement", document: @type.title)) %>
|
|
20
19
|
|
|
21
|
-
|
|
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>
|
|
20
|
+
<%= ui_form_field(attribute: "signature[typed_name]", label: t("agreement_engine.signatures.show.typed_name"), value: params.dig(:signature, :typed_name), autocomplete: "name") %>
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
<div>
|
|
23
|
+
<%= ui_button(label: t("agreement_engine.signatures.show.sign"), data: {reading_hold_target: "button"}) %>
|
|
24
|
+
</div>
|
|
25
|
+
<% else %>
|
|
26
|
+
<%= ui_paragraph(text: t("agreement_engine.record_documents.show.statement", document: @type.title)) %>
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
<div>
|
|
29
|
+
<%= ui_button(label: t("agreement_engine.record_documents.show.accept"), data: {reading_hold_target: "button"}) %>
|
|
30
|
+
</div>
|
|
31
|
+
<% end %>
|
|
32
|
+
<% end %>
|
|
35
33
|
<% end %>
|
|
34
|
+
<article class="prose prose-gray dark:prose-invert max-w-none">
|
|
35
|
+
<%= render "agreement_engine/documents/issued_version", document: @version %>
|
|
36
|
+
</article>
|
|
36
37
|
<% end %>
|
|
37
38
|
</div>
|
data/config/locales/en.yml
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
en:
|
|
2
2
|
agreement_engine:
|
|
3
|
+
reading:
|
|
4
|
+
too_soon:
|
|
5
|
+
accepting: "Read the %{document} for at least %{seconds} seconds before accepting."
|
|
6
|
+
signing: "Read the %{document} for at least %{seconds} seconds before signing."
|
|
3
7
|
agreements:
|
|
4
8
|
show:
|
|
5
9
|
title: "%{agreement} Changed"
|
|
@@ -7,6 +11,9 @@ en:
|
|
|
7
11
|
description: "Before you can proceed, you must read and accept the new %{agreement}."
|
|
8
12
|
accept: "I Accept"
|
|
9
13
|
decline: "I Decline"
|
|
14
|
+
waiting: "You can accept in {seconds} seconds."
|
|
15
|
+
ready: "You can now accept."
|
|
16
|
+
update:
|
|
10
17
|
destroy:
|
|
11
18
|
declined: "To continue using the service, please sign in and accept the %{agreement}."
|
|
12
19
|
consents:
|
|
@@ -24,6 +31,8 @@ en:
|
|
|
24
31
|
statement: "By typing your full name and selecting Sign, you sign the %{document} above electronically, and your electronic signature has the same effect as a handwritten one."
|
|
25
32
|
typed_name: "Your full name"
|
|
26
33
|
sign: "Sign"
|
|
34
|
+
waiting: "You can sign in {seconds} seconds."
|
|
35
|
+
ready: "You can now sign."
|
|
27
36
|
update:
|
|
28
37
|
blank: "Type your full name to sign."
|
|
29
38
|
stale: "This document changed while you were reading it. Read the current version below and sign again."
|
|
@@ -15,6 +15,7 @@ module AgreementEngine
|
|
|
15
15
|
def document_type = document.document_type.to_sym
|
|
16
16
|
def person = acceptance.person
|
|
17
17
|
def account = acceptance.account
|
|
18
|
+
def reading = acceptance.reading
|
|
18
19
|
def strength = acceptance.strength.to_sym
|
|
19
20
|
def subject = document.subject
|
|
20
21
|
def first_signature? = first_signature
|
|
@@ -17,10 +17,12 @@ module AgreementEngine
|
|
|
17
17
|
attr_accessor :copy_email_types
|
|
18
18
|
attr_accessor :mailer_from
|
|
19
19
|
attr_accessor :pages_place
|
|
20
|
+
attr_accessor :layout
|
|
20
21
|
|
|
21
22
|
def initialize
|
|
22
23
|
@document_types = []
|
|
23
24
|
@copy_email_types = []
|
|
25
|
+
@layout = "application"
|
|
24
26
|
|
|
25
27
|
@current_user_method = ->(c) { c.current_user }
|
|
26
28
|
@signed_in_method = ->(c) { c.user_signed_in? }
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module AgreementEngine
|
|
4
|
-
DocumentType = Data.define(:key, :title, :kind, :strength, :template, :prompts) do
|
|
5
|
-
def initialize(key:, title:, kind:, strength:, template: nil, prompts: false)
|
|
4
|
+
DocumentType = Data.define(:key, :title, :kind, :strength, :template, :prompts, :reading) do
|
|
5
|
+
def initialize(key:, title:, kind:, strength:, template: nil, prompts: false, reading: nil)
|
|
6
|
+
check_reading(key, kind, reading.to_h)
|
|
6
7
|
super
|
|
7
8
|
end
|
|
8
9
|
|
|
@@ -18,6 +19,29 @@ module AgreementEngine
|
|
|
18
19
|
!per_record?
|
|
19
20
|
end
|
|
20
21
|
|
|
22
|
+
def minimum_reading_seconds
|
|
23
|
+
reading.to_h[:seconds].to_i
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def requires_opening?
|
|
27
|
+
reading.to_h[:open] == true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def requires_scroll?
|
|
31
|
+
reading.to_h[:scroll] == true
|
|
32
|
+
end
|
|
33
|
+
|
|
21
34
|
def to_param = key.to_s
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def check_reading(key, kind, reading)
|
|
39
|
+
unknown = reading.keys - %i[seconds open scroll]
|
|
40
|
+
raise ArgumentError, "Document type #{key} has an unknown reading setting: #{unknown.join(", ")}." if unknown.any?
|
|
41
|
+
raise ArgumentError, "Document type #{key} cannot require opening, because per-record documents have no public page." if reading[:open] && kind.to_sym == :per_record
|
|
42
|
+
|
|
43
|
+
seconds = reading[:seconds]
|
|
44
|
+
raise ArgumentError, "Document type #{key} needs its minimum reading time as a positive whole number of seconds." unless seconds.nil? || (seconds.is_a?(Integer) && seconds.positive?)
|
|
45
|
+
end
|
|
22
46
|
end
|
|
23
47
|
end
|
|
@@ -17,5 +17,13 @@ module AgreementEngine
|
|
|
17
17
|
store_location_for(:user, request.fullpath) unless request.fullpath.start_with?("/agreements/")
|
|
18
18
|
redirect_to agreement_engine.agreement_path(type)
|
|
19
19
|
end
|
|
20
|
+
|
|
21
|
+
def agreement_engine_opened(document_type)
|
|
22
|
+
version = AgreementEngine::Document.current(document_type)
|
|
23
|
+
opened_at = version && session.dig(:agreement_engine_opened, version.id.to_s)
|
|
24
|
+
return unless opened_at
|
|
25
|
+
|
|
26
|
+
{opened_on: "public_page", opened_at: Time.zone.at(opened_at).iso8601, version_id: version.id}
|
|
27
|
+
end
|
|
20
28
|
end
|
|
21
29
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AgreementEngine
|
|
4
|
+
module ReadingCheck
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
helper_method :reading_hold_options
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def record_served
|
|
14
|
+
return unless @version
|
|
15
|
+
|
|
16
|
+
served = session[:agreement_engine_served] ||= {}
|
|
17
|
+
served[@version.id.to_s] ||= Time.current.to_i
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def too_soon?
|
|
21
|
+
minimum = reading_type.minimum_reading_seconds
|
|
22
|
+
return false if minimum.zero?
|
|
23
|
+
|
|
24
|
+
served_at.nil? || Time.current.to_i - served_at < minimum
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def too_soon_reason(doing)
|
|
28
|
+
I18n.t("agreement_engine.reading.too_soon.#{doing}", document: reading_type.title, seconds: reading_type.minimum_reading_seconds)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def reading_evidence
|
|
32
|
+
evidence = {}
|
|
33
|
+
minimum = reading_type.minimum_reading_seconds
|
|
34
|
+
evidence.merge!(minimum_seconds: minimum, measured_seconds: Time.current.to_i - served_at) unless minimum.zero?
|
|
35
|
+
evidence.merge!(opened_on: opened_on_page, opened_at: Time.zone.at(served_at).iso8601) if opened_on_page && reading_type.requires_opening? && served_at
|
|
36
|
+
evidence.merge!(scroll: scroll_report) if reading_type.requires_scroll?
|
|
37
|
+
evidence.presence
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def scroll_report
|
|
41
|
+
report = params[:reading]
|
|
42
|
+
return {reported_by: nil} unless report
|
|
43
|
+
|
|
44
|
+
{reported_by: "browser", end_reached: report[:end_reached] == "true", end_in_view_on_load: report[:end_in_view_on_load] == "true"}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def reading_hold_options
|
|
48
|
+
{seconds: reading_type.minimum_reading_seconds, elapsed: elapsed_reading_seconds, require_end: reading_type.requires_scroll?}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def elapsed_reading_seconds
|
|
52
|
+
served_at ? Time.current.to_i - served_at : 0
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def served_at
|
|
56
|
+
session.dig(:agreement_engine_served, @version.id.to_s)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def opened_on_page
|
|
60
|
+
nil
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -23,10 +23,35 @@ module AgreementEngine
|
|
|
23
23
|
"Accepted: #{acceptance.accepted_at.utc.strftime("%Y-%m-%d %H:%M:%S UTC")}",
|
|
24
24
|
("Typed name: #{acceptance.typed_name}" if acceptance.typed_name.present?),
|
|
25
25
|
period_line(acceptance),
|
|
26
|
+
reading_time_line(acceptance.reading.to_h),
|
|
27
|
+
scroll_line(acceptance.reading.to_h["scroll"]),
|
|
28
|
+
opened_line(acceptance.reading.to_h),
|
|
26
29
|
"agreement_engine #{acceptance.engine_version}, keystone_ui-pages #{acceptance.pages_version}"
|
|
27
30
|
].compact
|
|
28
31
|
end
|
|
29
32
|
|
|
33
|
+
def reading_time_line(reading)
|
|
34
|
+
return unless reading["minimum_seconds"]
|
|
35
|
+
|
|
36
|
+
"Reading time: #{reading["minimum_seconds"]} seconds required, #{reading["measured_seconds"]} seconds measured by the server"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def scroll_line(scroll)
|
|
40
|
+
return unless scroll
|
|
41
|
+
return "End of the document: not reported by the browser" unless scroll["reported_by"]
|
|
42
|
+
|
|
43
|
+
reached = scroll["end_reached"] ? "reached" : "not reached"
|
|
44
|
+
on_load = scroll["end_in_view_on_load"] ? "in view when first shown" : "not in view when first shown"
|
|
45
|
+
"End of the document: #{reached}, #{on_load}, as reported by the browser"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def opened_line(reading)
|
|
49
|
+
return unless reading["opened_on"]
|
|
50
|
+
|
|
51
|
+
at = Time.iso8601(reading["opened_at"]).utc.strftime("%Y-%m-%d %H:%M:%S UTC")
|
|
52
|
+
"Opened: on the #{reading["opened_on"].tr("_", " ")}, #{at}, as recorded by the server"
|
|
53
|
+
end
|
|
54
|
+
|
|
30
55
|
def period_line(acceptance)
|
|
31
56
|
described = Period.describe(acceptance.document.frozen_copy.to_h["period"])
|
|
32
57
|
return unless described
|
|
@@ -32,8 +32,11 @@ module AgreementEngine
|
|
|
32
32
|
!accepted_current?(document_type)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
def accept_version!(version)
|
|
36
|
-
|
|
35
|
+
def accept_version!(version, reading: nil)
|
|
36
|
+
type = AgreementEngine.document_type(version.document_type)
|
|
37
|
+
raise ArgumentError, "Document type #{type.key} requires opening, and no opening of this version was passed." if type&.requires_opening? && reading.to_h.transform_keys(&:to_sym)[:version_id] != version.id
|
|
38
|
+
|
|
39
|
+
AgreementEngine::Acceptance.create!(signer: self, person: AgreementEngine::Acceptance.person_snapshot(self), document: version, content_hash: version.content_hash, byte_form_version: version.byte_form_version, accepted_at: Time.current, reading: reading)
|
|
37
40
|
end
|
|
38
41
|
end
|
|
39
42
|
end
|
data/lib/agreement_engine.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: agreement_engine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tylercschneider
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - "<"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '3'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: keystone_ui
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.106.0
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.106.0
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: keystone_ui-pages
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -105,6 +119,7 @@ files:
|
|
|
105
119
|
- db/migrate/20261120141925_add_period_to_agreement_engine_acceptances.rb
|
|
106
120
|
- db/migrate/20261120143946_add_database_guards_to_agreement_engine.rb
|
|
107
121
|
- db/migrate/20261120145611_add_one_signature_index_to_agreement_engine_acceptances.rb
|
|
122
|
+
- db/migrate/20261123171528_add_reading_to_agreement_engine_acceptances.rb
|
|
108
123
|
- docs/byte-form.md
|
|
109
124
|
- docs/byte-form/examples/blank-standing/bytes.json
|
|
110
125
|
- docs/byte-form/examples/blank-standing/input.json
|
|
@@ -126,6 +141,7 @@ files:
|
|
|
126
141
|
- lib/agreement_engine/integrity.rb
|
|
127
142
|
- lib/agreement_engine/pages_elements.rb
|
|
128
143
|
- lib/agreement_engine/period.rb
|
|
144
|
+
- lib/agreement_engine/reading_check.rb
|
|
129
145
|
- lib/agreement_engine/receipt.rb
|
|
130
146
|
- lib/agreement_engine/seed.rb
|
|
131
147
|
- lib/agreement_engine/signable.rb
|