Skip to content

Add papertrail gem #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 94 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
e98d484
Add papertrail gem
Apr 1, 2022
8db48ad
Replaced papertrail with paper_trail gem
Apr 1, 2022
9317dcd
Sort gems alphabetically
Apr 1, 2022
5cd488a
Add papertrail to model and migration
Apr 1, 2022
e9d37a3
Add ignore to papertrail
Apr 1, 2022
045b832
Fixed rubocop error
Apr 1, 2022
7983e14
Changed show function to touch
Apr 1, 2022
e20bd83
Add spec for touch
Apr 1, 2022
7f50548
Add specs for papertrail
Apr 1, 2022
8775a62
Change rubocop rule to allow touch method
Apr 3, 2022
5c9f03a
add route to logs and first draft of logs_controller
RamonaChristen Apr 3, 2022
96a63c0
Fix rubocop and spec
Apr 3, 2022
610a59b
Add log policy
Apr 3, 2022
f33f40f
Change show to index
Apr 5, 2022
2473cb2
Refactor index? method
Apr 5, 2022
acfc099
Re-add show restriction
Apr 5, 2022
d73cae2
add controller spec
RamonaChristen Apr 5, 2022
3744505
Fixed encryptable controller spec
Apr 5, 2022
c135350
extend controller spec, specs fail because controller doesn't work as…
RamonaChristen Apr 5, 2022
f9efbb4
add logs serializer and fix controller
RamonaChristen Apr 6, 2022
f265b72
fix rubocop error
RamonaChristen Apr 6, 2022
ad72818
Add logs component
Apr 6, 2022
590be35
Merge branch '564-LOG_encryptable_read_access' of https://github.com/…
Apr 6, 2022
cf7c8b7
restrict access for api users, add specs
RamonaChristen Apr 7, 2022
d2a96b3
Change policy to check for team membership
Apr 7, 2022
d744841
Add tabs for logs
Apr 7, 2022
9ae217a
Removed tautologous expectation+
Apr 7, 2022
6be41fe
Remove pry
Apr 7, 2022
739a20f
Add stub components for table and table row
Apr 7, 2022
5a064b1
add logs model to frontend
RamonaChristen Apr 7, 2022
fbe53cf
Merge remote-tracking branch 'origin/564-LOG_encryptable_read_access'…
RamonaChristen Apr 7, 2022
ab7e6cb
Fix log model not found error
Apr 7, 2022
00dd3e1
implement table-row.hbs, work on getting logs to frontend
RamonaChristen Apr 8, 2022
477125a
Add adapter and fix component
Apr 8, 2022
5b61e29
Change log adapter name
Apr 8, 2022
8508e8a
Fix backend to frontend serialization
Robin481 Apr 8, 2022
1b63d3a
Fix table and add update to papertrail
Apr 8, 2022
04d1424
fix logs table, make prettier
RamonaChristen Apr 8, 2022
cc89947
log username instead of userid
RamonaChristen Apr 11, 2022
1017f8c
Merge branch 'master' of https://github.com/puzzle/cryptopus into 564…
Apr 12, 2022
133b5a5
log view access
RamonaChristen Apr 12, 2022
cb57571
add translations for log entry event
RamonaChristen Apr 12, 2022
6ac6a91
Merge branch '564-LOG_encryptable_read_access' of https://github.com/…
Apr 13, 2022
d537036
reload logs when switching tabs, fix linting errors
RamonaChristen Apr 23, 2022
b88a00e
fix rubocop errors
RamonaChristen Apr 23, 2022
e98beef
Merge branch 'master' of https://github.com/puzzle/cryptopus into 564…
Apr 25, 2022
1417b36
Rebase with master
Apr 25, 2022
5c1ac4b
Add encryptable specs
Apr 26, 2022
df3a9c9
add username and userid to log
RamonaChristen Apr 27, 2022
5aec2e0
Merge remote-tracking branch 'origin/564-LOG_encryptable_read_access'…
RamonaChristen Apr 27, 2022
b991304
correct spelling of model attribute
RamonaChristen Apr 28, 2022
0de70d1
add more frontend tests
RamonaChristen Apr 28, 2022
a1aabdd
improve frontend tests and add id to tabs
RamonaChristen Apr 28, 2022
51c8933
fix serializer and backend specs
RamonaChristen Apr 28, 2022
23fd312
use correct date format in paper_trail table
RamonaChristen Apr 29, 2022
f79ad57
user save_with_version on encryptable show
RamonaChristen Apr 29, 2022
c06353f
fix mistake
RamonaChristen Apr 29, 2022
6d84e7f
Add destroy on delete to encryptable
Apr 29, 2022
b355ea1
merge master
RamonaChristen May 1, 2022
e055936
log all update actions, fix problem with sorting logs on update
RamonaChristen May 1, 2022
5b352a9
limit query to only get 20 logs
RamonaChristen May 1, 2022
37a0ba0
add load more button to always load 10 logs at a time
RamonaChristen May 1, 2022
3286250
Change find_by to find
May 2, 2022
143eb24
Format code
May 2, 2022
791a15e
Fix rubocop issue
May 3, 2022
25937f6
Merge branch 'master' of https://github.com/puzzle/cryptopus into 564…
May 3, 2022
93aebfb
Adjust to PR review
May 4, 2022
30b9714
add system spec for view log
RamonaChristen May 4, 2022
77d08a7
add test for edit log (doesnt pass yet)
RamonaChristen May 5, 2022
d478e36
fix bug where view access is logged as update
RamonaChristen May 5, 2022
c56df1a
Replace alice with bob to fix spec
May 6, 2022
679ea3f
Restructure specs
May 6, 2022
17bb5d9
adjust frontend log model to backend model
RamonaChristen May 7, 2022
f439030
load logs directly from Versions table, optimize viewed access log
RamonaChristen May 9, 2022
b737cbc
Change parent class of log policy
May 9, 2022
58f413c
Merge branch '564-LOG_encryptable_read_access' of https://github.com/…
May 9, 2022
f19dc36
Move papertrail spec to encryptable controller spec
May 9, 2022
8402150
change header names in logs table, add space between tabs and log table
RamonaChristen May 9, 2022
c2096e0
Add encryptables controller show test
May 9, 2022
f21bbbf
Merge branch '564-LOG_encryptable_read_access' of https://github.com/…
May 9, 2022
94f42b4
Remove trailing whitespaces
May 9, 2022
b4a0fa5
query for username in log query to aviod n+1
RamonaChristen May 13, 2022
8aa4ddc
add version model
RamonaChristen May 17, 2022
93dc302
use includes to get username to logs, refactor from paper-trail-versi…
RamonaChristen May 17, 2022
41e728c
Merge branch 'master' into 564-LOG_encryptable_read_access
RamonaChristen May 18, 2022
67661b0
Fix frontend test after merge conflict
RamonaChristen May 18, 2022
1217ef4
improve load more function
RamonaChristen May 18, 2022
ee2bc92
extend versions destroy spec
RamonaChristen May 24, 2022
8c7782a
572 log recent credentials on dashboard (#608)
renato-oester May 24, 2022
65b5d3d
Merge remote-tracking branch 'origin/master' into 564-LOG_encryptable…
RamonaChristen May 24, 2022
7923d78
Merge branch 'master' into 564-LOG_encryptable_read_access
RamonaChristen Jun 3, 2022
0b45274
change translations in line with changes on main
RamonaChristen Jun 3, 2022
f3a4e62
Merge branch 'master' into 564-LOG_encryptable_read_access
RamonaChristen Jun 10, 2022
1ad9130
Merge branch 'master' into 564-LOG_encryptable_read_access
RamonaChristen Jun 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/models/encryptable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

class Encryptable < ApplicationRecord

has_paper_trail on: [:touch, :update], ignore: [:tag, :type, :encrypted_data]
has_paper_trail on: [:touch, :update], ignore: [:tag, :type, :encrypted_data], dependent: :destroy

before_destroy :destroy_versions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that necessary? (not necessarily criticizing just trying to understand)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Robin481 The papertrail versions are not deleted from the db by default, if the encryptable they correspond to is deleted. We discussed if it would make sense to keep the old versions because the api user may still want to know what happened to an encryptable that doesn't exist anymore. However, keeping the old encryptables may pollute the db quite heavily. What do you think?

Copy link
Member

@Robin481 Robin481 May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes deleting them makes sense.
However, dependent: :destroy should already do that, that is why I am asking. 😁
(there was more text here that I deleted because I got confused by which branch i was on 😂 )

Copy link
Contributor Author

@Drinion Drinion May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Robin481 Yes, dependent: :destroy should do that but it doesn't. There might be something wrong with the way we used active record with regards to paper_trail. I look into it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update on this front?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be a bug within the papertrail gem, dependent: :destroy does not work here but I extended the encryptable_spec to make sure that our :destroy versions method deletes everything it need to and nothing more so I think we should leave it like this


serialize :encrypted_data, ::EncryptedData

Expand Down Expand Up @@ -72,4 +74,8 @@ def decrypt_attr(attr, team_password)
instance_variable_set("@cleartext_#{attr}", cleartext_value)
end

def destroy_versions
self.versions.destroy_all
end

end
15 changes: 14 additions & 1 deletion spec/models/encryptable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'spec_helper'

describe Encryptable do

let(:bob) { users(:bob) }
Expand Down Expand Up @@ -85,6 +84,20 @@
end

context 'papertrail', versioning: true do
context 'delete' do
it 'deletes log history if encryptable is delted' do
1000.times do
encryptable.touch
end

expect(encryptable.versions.size).to eq(1000)

encryptable.destroy

expect(PaperTrail::Version.all.size).to be(0)
end
end

context 'touch' do
it 'creates a log entry' do
encryptable.touch
Expand Down