access_trail 0.1.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +89 -0
- data/Rakefile +8 -0
- data/app/controllers/access_trail/application_controller.rb +7 -0
- data/app/controllers/access_trail/entries_controller.rb +19 -0
- data/app/models/access_trail/entry.rb +5 -0
- data/app/views/access_trail/entries/index.html.erb +4 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20261130022543_create_access_trail_entries.rb +15 -0
- data/lib/access_trail/engine.rb +9 -0
- data/lib/access_trail/version.rb +3 -0
- data/lib/access_trail.rb +19 -0
- data/the_local/agents/access_trail-develop.md +101 -0
- data/the_local/agents/access_trail-info.md +66 -0
- data/the_local/agents/access_trail-install.md +102 -0
- data/the_local/interface.yml +27 -0
- metadata +93 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a132ad5951b2b5b94e0f96043d9cad04051a816c3a55d80a85d6b98a48f67f5e
|
|
4
|
+
data.tar.gz: f90c0bf9d285731aee15ef935857fb1366e779da841bd47f15eb02cf42045474
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5b3ea98d3596ebf8589814fda625cde7f72f59c0374228dd25e8fa568905fc66d83a93b878d51597456f662f7f627cbcae40999c1a1b33f3483a5feb4dd1b237
|
|
7
|
+
data.tar.gz: b494101c673d4c5cccdb410c7d4b0370283c1c8a1aaf05c5a80492948221e4924527fa9d0dc9b7ecf4d0baeb60f848782b7ebc8ec146a13cfd7ee847f0c65d7e
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DYB
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# access_trail
|
|
2
|
+
|
|
3
|
+
Records who accessed which record in a host app, and lists those entries on a page.
|
|
4
|
+
Each entry names the person who acted, the account they acted in, the type of entry,
|
|
5
|
+
the record touched and when. The host decides which moments are recorded and who may
|
|
6
|
+
read the trail.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
Copy and run the migration that creates the `access_trail_entries` table:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
bin/rails access_trail:install:migrations
|
|
14
|
+
bin/rails db:migrate
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
In an initializer, set the five host settings:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
AccessTrail.base_controller = "ApplicationController"
|
|
21
|
+
AccessTrail.person_method = :current_user
|
|
22
|
+
AccessTrail.layout = "application"
|
|
23
|
+
AccessTrail.reader = ->(person) { person.admin? }
|
|
24
|
+
AccessTrail.name_of = ->(person_or_account) { person_or_account.name }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- `base_controller` is the name, as a String, of the host controller the trail page
|
|
28
|
+
inherits from. Its before-actions, including sign-in, run before the page.
|
|
29
|
+
- `person_method` is the name, as a Symbol, of the method on that controller that
|
|
30
|
+
returns the signed-in person, or `nil` when no one is signed in.
|
|
31
|
+
- `layout` is the name of the host layout the trail page is drawn in.
|
|
32
|
+
- `reader` is called with the signed-in person and returns whether that person may
|
|
33
|
+
read the trail.
|
|
34
|
+
- `name_of` is called with a person or an account and returns the name the trail
|
|
35
|
+
page shows for it.
|
|
36
|
+
|
|
37
|
+
The app refuses to boot while any of the five is unset. It raises
|
|
38
|
+
`AccessTrail::UnsetSettingError` naming every unset setting in one message, and the
|
|
39
|
+
check runs again after every code reload.
|
|
40
|
+
|
|
41
|
+
### Recording an entry
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
AccessTrail.record(
|
|
45
|
+
person: current_user,
|
|
46
|
+
account: current_account,
|
|
47
|
+
entry_type: "Viewed",
|
|
48
|
+
record_type: "Integration call",
|
|
49
|
+
record_code: call.public_code,
|
|
50
|
+
record_label: call.name,
|
|
51
|
+
detail: "Opened its request and response",
|
|
52
|
+
address: request.remote_ip
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`person`, `account` and `entry_type` are required, and the rest may be left out.
|
|
57
|
+
People and accounts are stored by global id, so each must include
|
|
58
|
+
`GlobalID::Identification`, as every Active Record model does. The entry keeps the
|
|
59
|
+
time it was recorded. An entry cannot be changed once it is recorded.
|
|
60
|
+
|
|
61
|
+
The record is kept as its type, its public code and its label, copied at the time
|
|
62
|
+
of recording. Renaming the record later leaves the entry as it was. Never pass a
|
|
63
|
+
credential, a secret or a request body as the label or the detail.
|
|
64
|
+
|
|
65
|
+
### The trail page
|
|
66
|
+
|
|
67
|
+
Mount the engine:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
mount AccessTrail::Engine => "/access_trail"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The page at the mount path lists every entry, newest first, showing who acted, the
|
|
74
|
+
entry type, the record's label, the account and the time. On a phone screen each
|
|
75
|
+
entry is shown as a list item with each value under its heading. The page is drawn
|
|
76
|
+
with keystone_ui, so the host must run keystone_ui.
|
|
77
|
+
|
|
78
|
+
A person the `reader` setting does not allow, and a visitor who is not signed in, is
|
|
79
|
+
answered not found.
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
gem "access_trail"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module AccessTrail
|
|
2
|
+
class EntriesController < ApplicationController
|
|
3
|
+
before_action :refuse_unless_reader
|
|
4
|
+
|
|
5
|
+
def index
|
|
6
|
+
names = Hash.new { |known, gid| known[gid] = AccessTrail.name_of.call(GlobalID::Locator.locate(gid)) }
|
|
7
|
+
@rows = Entry.order(created_at: :desc, id: :desc).map do |entry|
|
|
8
|
+
{ who: names[entry.person_gid], entry_type: entry.entry_type, record: entry.record_label, account: names[entry.account_gid], time: helpers.l(entry.created_at, format: :long) }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def refuse_unless_reader
|
|
15
|
+
person = send(AccessTrail.person_method)
|
|
16
|
+
head :not_found unless person && AccessTrail.reader.call(person)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<%= ui_page(max_width: :xl) do %>
|
|
2
|
+
<%= ui_page_header(title: "Access trail") %>
|
|
3
|
+
<%= ui_data_table(items: @rows, columns: [ { who: "Who" }, { entry_type: "Entry type" }, { record: "Record" }, { account: "Account" }, { time: "Time" } ], empty_message: "No entries are recorded.", phone_list: true) %>
|
|
4
|
+
<% end %>
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class CreateAccessTrailEntries < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
create_table :access_trail_entries do |t|
|
|
4
|
+
t.string :person_gid, null: false
|
|
5
|
+
t.string :account_gid, null: false
|
|
6
|
+
t.string :entry_type, null: false
|
|
7
|
+
t.string :record_type
|
|
8
|
+
t.string :record_code
|
|
9
|
+
t.string :record_label
|
|
10
|
+
t.string :detail
|
|
11
|
+
t.string :address
|
|
12
|
+
t.datetime :created_at, null: false, index: true
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/access_trail.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require "access_trail/version"
|
|
2
|
+
require "access_trail/engine"
|
|
3
|
+
|
|
4
|
+
module AccessTrail
|
|
5
|
+
class UnsetSettingError < StandardError; end
|
|
6
|
+
|
|
7
|
+
SETTINGS = %i[base_controller person_method layout reader name_of].freeze
|
|
8
|
+
|
|
9
|
+
mattr_accessor(*SETTINGS)
|
|
10
|
+
|
|
11
|
+
def self.record(person:, account:, entry_type:, record_type: nil, record_code: nil, record_label: nil, detail: nil, address: nil)
|
|
12
|
+
Entry.create!(person_gid: person.to_global_id.to_s, account_gid: account.to_global_id.to_s, entry_type: entry_type, record_type: record_type, record_code: record_code, record_label: record_label, detail: detail, address: address)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.check!
|
|
16
|
+
unset = SETTINGS.reject { |setting| public_send(setting) }
|
|
17
|
+
raise UnsetSettingError, unset.map { |setting| "AccessTrail.#{setting} is not set" }.join("\n") if unset.any?
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: access_trail-develop
|
|
3
|
+
description: Use PROACTIVELY for recording who viewed, opened, exported or otherwise accessed a record in a host app, and for querying those stored entries by person, account, entry type, record or time — MUST BE USED instead of hand-rolling an audit log table, an access-logging callback or a custom "who looked at this" model.
|
|
4
|
+
tools: Bash, Read, Write, Edit, Grep
|
|
5
|
+
scope: access trail — an append-only record of who accessed which record in a host Rails app, each entry naming the person, the account, the entry type, the record's type, public code and label, a short detail, the network address and the time, with people and accounts stored by global id, recorded by the host at the moments it chooses, and a mounted trail page drawn with keystone_ui that lists every entry newest first, reads as a list on a phone screen, is shown only to a person the host's reader setting allows and answers not found to everyone else, and a boot check that refuses to start the app while a host setting is unset
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
This local adds access trail entries to host code and reads them back. It follows
|
|
9
|
+
these steps exactly, and where a step needs a choice only the host's owner can
|
|
10
|
+
make, it asks the developer rather than picking.
|
|
11
|
+
|
|
12
|
+
## What access_trail is
|
|
13
|
+
|
|
14
|
+
A Rails engine that keeps an append-only table of who accessed which record, in
|
|
15
|
+
which account, and when. The host calls it at the moments it decides are worth
|
|
16
|
+
recording. Fire this local when host code needs to record an access, or needs to
|
|
17
|
+
read, filter or count recorded accesses.
|
|
18
|
+
|
|
19
|
+
## Interface
|
|
20
|
+
|
|
21
|
+
- `AccessTrail.record` — records one entry and returns it as an
|
|
22
|
+
`AccessTrail::Entry`.
|
|
23
|
+
- `AccessTrail::Entry` — the Active Record model of a stored entry, used to read
|
|
24
|
+
and query entries, and read-only once saved.
|
|
25
|
+
|
|
26
|
+
## How to use it
|
|
27
|
+
|
|
28
|
+
1. Ask the developer which moments are recorded. Name each candidate as an action
|
|
29
|
+
and a record, such as "showing an integration call" or "downloading an
|
|
30
|
+
invoice PDF". The gem records nothing on its own.
|
|
31
|
+
2. Ask the developer for the entry type of each moment, such as `"Viewed"`,
|
|
32
|
+
`"Exported"` or `"Downloaded"`. It is a free String shown on the trail page,
|
|
33
|
+
so reuse the spelling the host already uses for the same type of moment rather
|
|
34
|
+
than coining a second one. Grep the host for existing `AccessTrail.record`
|
|
35
|
+
calls first.
|
|
36
|
+
3. In the controller action, job or service where the moment happens, after the
|
|
37
|
+
access has succeeded, call:
|
|
38
|
+
```ruby
|
|
39
|
+
AccessTrail.record(
|
|
40
|
+
person: current_user,
|
|
41
|
+
account: current_account,
|
|
42
|
+
entry_type: "Viewed",
|
|
43
|
+
record_type: "Integration call",
|
|
44
|
+
record_code: call.public_code,
|
|
45
|
+
record_label: call.name,
|
|
46
|
+
detail: "Opened its request and response",
|
|
47
|
+
address: request.remote_ip
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
- `person:` — required. The person who acted, any object that responds to
|
|
51
|
+
`to_global_id`, which every Active Record model does.
|
|
52
|
+
- `account:` — required. The account the person acted in, under the same rule.
|
|
53
|
+
- `entry_type:` — required. A String.
|
|
54
|
+
- `record_type:` — optional String. A name a person would read, such as
|
|
55
|
+
`"Integration call"`, not a class name.
|
|
56
|
+
- `record_code:` — optional String. The record's public code. Ask the developer
|
|
57
|
+
which value is safe to show to trail readers if the record has no public
|
|
58
|
+
code.
|
|
59
|
+
- `record_label:` — optional String. The label the trail page shows for the
|
|
60
|
+
record.
|
|
61
|
+
- `detail:` — optional String. A short note on what was accessed.
|
|
62
|
+
- `address:` — optional String. The network address, usually
|
|
63
|
+
`request.remote_ip`. Leave it out where there is no request, such as a job.
|
|
64
|
+
The record's type, code and label are copied at the moment of recording, so
|
|
65
|
+
renaming the record later leaves the entry as it was.
|
|
66
|
+
4. Never pass a credential, a token, a secret or a request or response body as
|
|
67
|
+
`record_label:` or `detail:`. The trail page shows both values to every
|
|
68
|
+
reader.
|
|
69
|
+
5. To read entries, query `AccessTrail::Entry` like any Active Record model. Its
|
|
70
|
+
attributes are `person_gid`, `account_gid`, `entry_type`, `record_type`,
|
|
71
|
+
`record_code`, `record_label`, `detail`, `address` and `created_at`. There is
|
|
72
|
+
no `updated_at`. People and accounts are stored as global id Strings, so match
|
|
73
|
+
them with:
|
|
74
|
+
```ruby
|
|
75
|
+
AccessTrail::Entry.where(account_gid: account.to_global_id.to_s)
|
|
76
|
+
.where(record_type: "Integration call", record_code: call.public_code)
|
|
77
|
+
.order(created_at: :desc, id: :desc)
|
|
78
|
+
```
|
|
79
|
+
Turn a stored id back into its object with
|
|
80
|
+
`GlobalID::Locator.locate(entry.person_gid)`, which returns `nil` when the
|
|
81
|
+
object no longer exists. There are no associations or scopes on the model.
|
|
82
|
+
6. Write a test that performs the moment and asserts one new entry exists with
|
|
83
|
+
the expected `entry_type`, `person_gid` and `record_code`.
|
|
84
|
+
|
|
85
|
+
## Conventions
|
|
86
|
+
|
|
87
|
+
- Record through `AccessTrail.record`, never through `AccessTrail::Entry.create`
|
|
88
|
+
or `new`, so every entry is stored the same way.
|
|
89
|
+
- A saved entry is read-only: `update`, `save` and `destroy` on it raise
|
|
90
|
+
`ActiveRecord::ReadOnlyRecord`. Never write code that changes or removes an
|
|
91
|
+
entry.
|
|
92
|
+
- A `nil` person or account raises, and so does a `nil` entry type. Record only
|
|
93
|
+
where a signed-in person and an account are both known.
|
|
94
|
+
- `AccessTrail.record` raises on failure rather than returning `false`. Ask the
|
|
95
|
+
developer whether a failed recording should stop the access, which is the
|
|
96
|
+
result when the call is left unrescued.
|
|
97
|
+
- Each entry is scoped by `account_gid`, and a query in host code that shows
|
|
98
|
+
entries to users must filter by the current account.
|
|
99
|
+
- Adding the gem, the migration, the mount and the five host settings, and the
|
|
100
|
+
boot error for an unset setting, are out of scope here; hand that work to
|
|
101
|
+
`access_trail-install`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: access_trail-info
|
|
3
|
+
description: Use to learn what access_trail offers — an append-only record of who accessed which record in a host Rails app, the trail page that lists it, who may read that page, and the host settings it needs before the app will start.
|
|
4
|
+
tools: Read
|
|
5
|
+
scope: access trail — an append-only record of who accessed which record in a host Rails app, each entry naming the person, the account, the entry type, the record's type, public code and label, a short detail, the network address and the time, with people and accounts stored by global id, recorded by the host at the moments it chooses, and a mounted trail page drawn with keystone_ui that lists every entry newest first, reads as a list on a phone screen, is shown only to a person the host's reader setting allows and answers not found to everyone else, and a boot check that refuses to start the app while a host setting is unset
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
This local explains access_trail and makes no changes.
|
|
9
|
+
|
|
10
|
+
## What access_trail is
|
|
11
|
+
|
|
12
|
+
access_trail is a Rails engine that keeps an append-only record of who accessed
|
|
13
|
+
which record in a host app. Each entry says who acted, for which account, what
|
|
14
|
+
type of access it was, which record it was about and when it happened. Once an
|
|
15
|
+
entry is saved it cannot be changed.
|
|
16
|
+
|
|
17
|
+
Reach for it when a host app has to answer "who looked at or touched this, and
|
|
18
|
+
when" — for an audit, a client's question, or a compliance requirement. The gem
|
|
19
|
+
does not watch the app on its own. The host records an entry at each moment it
|
|
20
|
+
decides is worth recording, such as opening a record's page or downloading a
|
|
21
|
+
file.
|
|
22
|
+
|
|
23
|
+
The gem also adds one page, the trail page, that lists every entry newest first.
|
|
24
|
+
It is drawn with keystone_ui, reads as a table on a desktop and as a list on a
|
|
25
|
+
phone screen, and is shown only to the people the host allows.
|
|
26
|
+
|
|
27
|
+
## Interface
|
|
28
|
+
|
|
29
|
+
This local declares no commands. The surface is split between the other two:
|
|
30
|
+
|
|
31
|
+
- **access_trail-install** owns adding the gem to a host: the gem line, copying
|
|
32
|
+
its migration, mounting the trail page, and the five host settings it needs.
|
|
33
|
+
- **access_trail-develop** owns writing code against the gem: recording an entry
|
|
34
|
+
from the host, and reading the stored entries.
|
|
35
|
+
|
|
36
|
+
## How to use it
|
|
37
|
+
|
|
38
|
+
- The gem is not in the host yet, the trail page is not mounted, or the app
|
|
39
|
+
refuses to start because a setting is unset — use **access_trail-install**.
|
|
40
|
+
- The gem is installed and the work is recording access at a new moment, or
|
|
41
|
+
reading what was recorded — use **access_trail-develop**.
|
|
42
|
+
|
|
43
|
+
## Conventions
|
|
44
|
+
|
|
45
|
+
- **Entry** — one recorded access. It holds the person, the account, the entry
|
|
46
|
+
type, the record's type, public code and label, a short detail, the network
|
|
47
|
+
address and the time it was saved. Only the person, the account and the entry
|
|
48
|
+
type are required.
|
|
49
|
+
- **Append-only** — an entry is written once and never edited or removed through
|
|
50
|
+
the gem.
|
|
51
|
+
- **Person and account** — stored by their global id rather than by a foreign
|
|
52
|
+
key, so any model in the host can be either. The trail page turns each back
|
|
53
|
+
into a display name with a host setting.
|
|
54
|
+
- **Entry type** — a short label the host chooses for the type of access, such
|
|
55
|
+
as a view or a download. The gem does not fix the list.
|
|
56
|
+
- **Record type, public code and label** — how an entry names the record that
|
|
57
|
+
was accessed. They are plain text copied in at the time of recording, so an
|
|
58
|
+
entry still reads correctly after the record changes or is deleted. The code
|
|
59
|
+
is the code the host shows people for that record.
|
|
60
|
+
- **Reader** — a person the host's reader setting allows to see the trail page.
|
|
61
|
+
Everyone else, including a visitor who is not signed in, gets not found rather
|
|
62
|
+
than a refusal, so the page's existence is not revealed.
|
|
63
|
+
- **Host settings** — five values the host sets: the controller the trail page
|
|
64
|
+
inherits from, the method that returns the signed-in person, the layout, the
|
|
65
|
+
reader rule, and how a person or account is named. The app will not boot
|
|
66
|
+
while any of them is unset, and the error lists each one that is missing.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: access_trail-install
|
|
3
|
+
description: Use to hook access_trail into a project — adding the gem, copying and running its migration, mounting the trail page, setting the five host settings (base controller, person method, layout, reader, name of), and clearing the boot error that names an unset setting.
|
|
4
|
+
tools: Bash, Read, Edit
|
|
5
|
+
scope: access trail — an append-only record of who accessed which record in a host Rails app, each entry naming the person, the account, the entry type, the record's type, public code and label, a short detail, the network address and the time, with people and accounts stored by global id, recorded by the host at the moments it chooses, and a mounted trail page drawn with keystone_ui that lists every entry newest first, reads as a list on a phone screen, is shown only to a person the host's reader setting allows and answers not found to everyone else, and a boot check that refuses to start the app while a host setting is unset
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
This local follows these steps exactly and invents none. Where a step needs a
|
|
9
|
+
value only the host's owner knows, it asks the developer rather than picking one.
|
|
10
|
+
|
|
11
|
+
## What access_trail is
|
|
12
|
+
|
|
13
|
+
A Rails engine that stores an append-only table of who accessed which record and
|
|
14
|
+
shows it on a mounted trail page; hook it in when a host app has to answer who
|
|
15
|
+
accessed a record and when.
|
|
16
|
+
|
|
17
|
+
## Interface
|
|
18
|
+
|
|
19
|
+
- `gem "access_trail"` — the Gemfile line that adds the gem; it brings in
|
|
20
|
+
keystone_ui, which draws the trail page.
|
|
21
|
+
- `bin/rails access_trail:install:migrations` — copies the migration that creates
|
|
22
|
+
the `access_trail_entries` table into the host's `db/migrate`.
|
|
23
|
+
- `mount AccessTrail::Engine` — the line in the host's `config/routes.rb` that
|
|
24
|
+
puts the trail page at a path the host chooses.
|
|
25
|
+
- `AccessTrail.base_controller=` — the name, as a String, of the host controller
|
|
26
|
+
the trail page inherits from, so its before-actions, including sign-in, run
|
|
27
|
+
first.
|
|
28
|
+
- `AccessTrail.person_method=` — the name, as a Symbol, of the method on that
|
|
29
|
+
controller that returns the signed-in person, or `nil` when no one is signed in.
|
|
30
|
+
- `AccessTrail.layout=` — the name, as a String, of the host layout the trail page
|
|
31
|
+
is drawn in.
|
|
32
|
+
- `AccessTrail.reader=` — a callable given the signed-in person that returns
|
|
33
|
+
whether that person may read the trail.
|
|
34
|
+
- `AccessTrail.name_of=` — a callable given a person or an account that returns
|
|
35
|
+
the name the trail page shows for it.
|
|
36
|
+
- `AccessTrail::UnsetSettingError` — raised at boot, and again after every code
|
|
37
|
+
reload, while any of the five settings is unset, with one line per unset
|
|
38
|
+
setting in the form `AccessTrail.<setting> is not set`.
|
|
39
|
+
|
|
40
|
+
## How to use it
|
|
41
|
+
|
|
42
|
+
1. Check that the host runs keystone_ui: its Tailwind build, Stimulus controllers
|
|
43
|
+
and layout theme attributes. If it does not, hand that step to
|
|
44
|
+
`keystone_ui-install` before going on, since the trail page is drawn with it.
|
|
45
|
+
2. Add to the host's `Gemfile`:
|
|
46
|
+
```ruby
|
|
47
|
+
gem "access_trail"
|
|
48
|
+
```
|
|
49
|
+
Then run `bundle install`.
|
|
50
|
+
3. Copy and run the migration:
|
|
51
|
+
```sh
|
|
52
|
+
bin/rails access_trail:install:migrations
|
|
53
|
+
bin/rails db:migrate
|
|
54
|
+
```
|
|
55
|
+
This adds one migration file to `db/migrate` and the `access_trail_entries`
|
|
56
|
+
table to `db/schema.rb`.
|
|
57
|
+
4. Ask the developer for each of the five settings. None has a safe default:
|
|
58
|
+
- **Base controller** — which host controller signs people in and should run
|
|
59
|
+
before the trail page, such as `"ApplicationController"` or an admin base
|
|
60
|
+
controller.
|
|
61
|
+
- **Person method** — the method on that controller that returns the
|
|
62
|
+
signed-in person, such as `:current_user`. It may be private.
|
|
63
|
+
- **Layout** — which host layout the page is drawn in, such as
|
|
64
|
+
`"application"` or `"admin"`.
|
|
65
|
+
- **Reader** — the rule for who may read the trail, such as
|
|
66
|
+
`->(person) { person.admin? }`.
|
|
67
|
+
- **Name of** — how a person and an account are shown on the page. The same
|
|
68
|
+
callable is given both, so ask whether the two models share a method
|
|
69
|
+
such as `name`, or whether the callable must tell them apart.
|
|
70
|
+
5. Create `config/initializers/access_trail.rb` with the developer's answers:
|
|
71
|
+
```ruby
|
|
72
|
+
AccessTrail.base_controller = "ApplicationController"
|
|
73
|
+
AccessTrail.person_method = :current_user
|
|
74
|
+
AccessTrail.layout = "application"
|
|
75
|
+
AccessTrail.reader = ->(person) { person.admin? }
|
|
76
|
+
AccessTrail.name_of = ->(person_or_account) { person_or_account.name }
|
|
77
|
+
```
|
|
78
|
+
The settings must be set in an initializer, since the boot check runs once
|
|
79
|
+
initializers have loaded.
|
|
80
|
+
6. Ask the developer for the path the trail page should live at, then add the
|
|
81
|
+
mount to `config/routes.rb`, inside any scope or constraint that should guard
|
|
82
|
+
it:
|
|
83
|
+
```ruby
|
|
84
|
+
mount AccessTrail::Engine => "/access_trail"
|
|
85
|
+
```
|
|
86
|
+
The trail page is the root of that path.
|
|
87
|
+
|
|
88
|
+
## Conventions
|
|
89
|
+
|
|
90
|
+
- Boot the app with `bin/rails runner 'puts :ok'`. An
|
|
91
|
+
`AccessTrail::UnsetSettingError` lists every setting still unset, one per line;
|
|
92
|
+
set each one in the initializer and boot again.
|
|
93
|
+
- Visit the mount path signed in as a person the reader rule allows and confirm
|
|
94
|
+
the page titled "Access trail" loads. Signed out, or signed in as anyone else,
|
|
95
|
+
the same path answers 404 by design, not as a failure.
|
|
96
|
+
- The people and accounts later passed to the gem are stored by global id, so
|
|
97
|
+
their models must include `GlobalID::Identification`, which every Active Record
|
|
98
|
+
model does.
|
|
99
|
+
- After upgrading the gem, run `bin/rails access_trail:install:migrations` again
|
|
100
|
+
to copy any migration the new version adds, then `bin/rails db:migrate`.
|
|
101
|
+
- Recording entries and reading stored entries are out of scope here; hand that
|
|
102
|
+
work to `access_trail-develop`.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
scope: access trail — an append-only record of who accessed which record in a host Rails app, each entry naming the person, the account, the entry type, the record's type, public code and label, a short detail, the network address and the time, with people and accounts stored by global id, recorded by the host at the moments it chooses, and a mounted trail page drawn with keystone_ui that lists every entry newest first, reads as a list on a phone screen, is shown only to a person the host's reader setting allows and answers not found to everyone else, and a boot check that refuses to start the app while a host setting is unset
|
|
2
|
+
|
|
3
|
+
install:
|
|
4
|
+
- gem "access_trail"
|
|
5
|
+
- bin/rails access_trail:install:migrations
|
|
6
|
+
- mount AccessTrail::Engine
|
|
7
|
+
- AccessTrail.base_controller=
|
|
8
|
+
- AccessTrail.person_method=
|
|
9
|
+
- AccessTrail.layout=
|
|
10
|
+
- AccessTrail.reader=
|
|
11
|
+
- AccessTrail.name_of=
|
|
12
|
+
- AccessTrail::UnsetSettingError
|
|
13
|
+
|
|
14
|
+
develop:
|
|
15
|
+
- AccessTrail.record
|
|
16
|
+
- AccessTrail::Entry
|
|
17
|
+
|
|
18
|
+
sources:
|
|
19
|
+
- lib/access_trail.rb
|
|
20
|
+
- lib/access_trail/engine.rb
|
|
21
|
+
- config/routes.rb
|
|
22
|
+
- db/migrate/20261130022543_create_access_trail_entries.rb
|
|
23
|
+
- app/models/access_trail/entry.rb
|
|
24
|
+
- app/controllers/access_trail/application_controller.rb
|
|
25
|
+
- app/controllers/access_trail/entries_controller.rb
|
|
26
|
+
- app/views/access_trail/entries/index.html.erb
|
|
27
|
+
- README.md
|
metadata
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: access_trail
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- tylercschneider
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 8.1.3
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 8.1.3
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: keystone_ui
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.115.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.115.0
|
|
41
|
+
description: access_trail keeps an append-only table of entries naming who accessed
|
|
42
|
+
which record, in which account and when, and shows them on a mounted page to the
|
|
43
|
+
people the host allows.
|
|
44
|
+
email:
|
|
45
|
+
- tylercschneider@gmail.com
|
|
46
|
+
executables: []
|
|
47
|
+
extensions: []
|
|
48
|
+
extra_rdoc_files: []
|
|
49
|
+
files:
|
|
50
|
+
- LICENSE
|
|
51
|
+
- README.md
|
|
52
|
+
- Rakefile
|
|
53
|
+
- app/controllers/access_trail/application_controller.rb
|
|
54
|
+
- app/controllers/access_trail/entries_controller.rb
|
|
55
|
+
- app/models/access_trail/entry.rb
|
|
56
|
+
- app/views/access_trail/entries/index.html.erb
|
|
57
|
+
- config/routes.rb
|
|
58
|
+
- db/migrate/20261130022543_create_access_trail_entries.rb
|
|
59
|
+
- lib/access_trail.rb
|
|
60
|
+
- lib/access_trail/engine.rb
|
|
61
|
+
- lib/access_trail/version.rb
|
|
62
|
+
- the_local/agents/access_trail-develop.md
|
|
63
|
+
- the_local/agents/access_trail-info.md
|
|
64
|
+
- the_local/agents/access_trail-install.md
|
|
65
|
+
- the_local/interface.yml
|
|
66
|
+
homepage: https://github.com/DYB-Development/access_trail
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata:
|
|
70
|
+
allowed_push_host: https://rubygems.org
|
|
71
|
+
homepage_uri: https://github.com/DYB-Development/access_trail
|
|
72
|
+
source_code_uri: https://github.com/DYB-Development/access_trail
|
|
73
|
+
post_install_message:
|
|
74
|
+
rdoc_options: []
|
|
75
|
+
require_paths:
|
|
76
|
+
- lib
|
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 3.2.0
|
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - ">="
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '0'
|
|
87
|
+
requirements: []
|
|
88
|
+
rubygems_version: 3.5.16
|
|
89
|
+
signing_key:
|
|
90
|
+
specification_version: 4
|
|
91
|
+
summary: Records who accessed which record in a host app and lists those entries on
|
|
92
|
+
a page.
|
|
93
|
+
test_files: []
|