Skip to content

Logging Audit on Checkin/out #16679

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 13 commits into
base: develop
Choose a base branch
from

Conversation

akemidx
Copy link
Member

@akemidx akemidx commented Apr 9, 2025

Adding in an option to log an audit when you check in or out an asset.
Screenshot 2025-04-09 at 7 29 22 PM

Screenshot 2025-04-09 at 7 30 02 PM

There is less information on the audit itself, but all changes to an asset will be logged on the checkin or out.

NOTE: This action does not allow a user to manually set a next audit date OR upload a picture as these are not options on checkin or checkout

Copy link

what-the-diff bot commented Apr 9, 2025

PR Summary

  • Improvement in Asset Tracking
    The system now records all instances where assets are either checked in or out. This enhanced tracking feature includes new mechanisms for verifying user permissions and keeping track of these actions in AssetCheckinController and AssetCheckoutController.

  • Enhanced User Interface Language
    New entries have been introduced to the language files to support the newly introduced audit feature. This includes new text for checkboxes and additional help text to guide users through the process.

  • Check-In View Modification
    The check-in form now features a checkbox that allows enabling or disabling the audit log. Its display is subject to the respective user's permissions.

  • Check-Out View Modification
    Much like the check-in view, the check-out form also features a checkbox that governs the audit log. It too is displayed depending on the permissions granted to the user.

@@ -71,6 +71,10 @@ public function store(AssetCheckoutRequest $request, $assetId) : RedirectRespons

$admin = auth()->user();

if($request->filled('audit_on_checkinout') == "1") {
$this->authorize('audit', Asset::class);
Copy link
Member

Choose a reason for hiding this comment

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

This will probably result in a forbidden error, which is probably not what we want. We probably want to quietly ignore if they don't have permission to audit.

Copy link
Member Author

Choose a reason for hiding this comment

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

okay yea. i see how that could happen.

Copy link
Member Author

Choose a reason for hiding this comment

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

unsure how to fix this. originally thought was if the checkbox is filled, then check if they can do it, but don't check if its not a checked box. i am stumped on reversing that logic. may just need to write it out on my whiteboard. reverse causality and such.

Copy link
Member

@snipe snipe Apr 16, 2025

Choose a reason for hiding this comment

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

We should hide the checkbox in the blade if they're not allowed to audit (using @can) and then check the Gate in the controller.

Copy link
Member Author

Choose a reason for hiding this comment

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

i think i did this already while i was mulling over how to fix it. if you could double check the more recent changes?

@akemidx akemidx requested a review from snipe April 16, 2025 19:20
@@ -75,6 +76,12 @@ public function store(AssetCheckinRequest $request, $assetId = null, $backto = n

$this->authorize('checkin', $asset);

if(Gate::allows('audit',$asset)) {
if ($request->filled('log_audit') == "1") {
$this->authorize('audit', Asset::class);
Copy link
Member

Choose a reason for hiding this comment

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

This duplicates the gate right above, and on failure will cause a forbidden error.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see a gate above it? only the $this->authorize('checking',$asset);
then everything else in the store method is just checking for the asset to exist?

Copy link
Member

Choose a reason for hiding this comment

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

Line 79

Copy link
Member Author

Choose a reason for hiding this comment

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

line 79 is what I put there? so you're saying the $this->authorize is what duplicates the gate ya?

@@ -133,7 +140,9 @@ function (Builder $query) use ($asset) {
$asset->customFieldsForCheckinCheckout('display_checkin');

if ($asset->save()) {

if($request->filled('log_audit') == "1") {
Copy link
Member

Choose a reason for hiding this comment

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

This is where the gate belongs.

@@ -71,6 +72,12 @@ public function store(AssetCheckoutRequest $request, $assetId) : RedirectRespons

$admin = auth()->user();

if(Gate::allows('audit',$asset)) {
if ($request->filled('log_audit') == "1") {
$this->authorize('audit', Asset::class);
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here

@@ -114,6 +121,9 @@ public function store(AssetCheckoutRequest $request, $assetId) : RedirectRespons
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);

if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) {
if($request->filled('log_audit') == "1") {
Copy link
Member

Choose a reason for hiding this comment

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

And here

@@ -283,6 +283,8 @@
'require_accept_signature_help_text' => 'Enabling this feature will require users to physically sign off on accepting an asset.',
'require_checkinout_notes' => 'Require Notes on Checkin/Checkout',
'require_checkinout_notes_help_text' => 'Enabling this feature will require the note fields to be populated when checking in or checking out an asset.',
'log_audit' => 'Mark as audited',
'log_audit_help_text' => 'Check this box to also log an audit in addition to this',
Copy link
Member

Choose a reason for hiding this comment

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

This phrasing seems a little clunky to me.

Copy link
Member Author

@akemidx akemidx Apr 16, 2025

Choose a reason for hiding this comment

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

It does, but words are not my strong suit.
However, this seems clunky since at the END after 'this' it will say checkin or checkout

example:
{{ trans('admin/settings/general.log_audit_help_text') . " " . trans('general.checkin') . "." }}

Copy link
Member

Choose a reason for hiding this comment

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

See my example in the PR review comment. I suggested different phrasing altogether :)

@@ -253,7 +253,6 @@
</div>
<!-- /.form-group -->


Copy link
Member

Choose a reason for hiding this comment

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

Try not to commit changed files that only contain whitespace please.

Copy link
Member Author

Choose a reason for hiding this comment

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

funny story about this, Marcus actually said to ignore it cause it was removing empty white space. but yes, I understand not wanting that one extra file to be changed.

Copy link
Member

@snipe snipe left a comment

Choose a reason for hiding this comment

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

This is a good start, but I'd like to see a few changes.

There's no real reason why we can't include the audit image upload and next audit date on that form. If the checkbox is checked, we show those fields. If it's unchecked, we hide them.

Additionally, I think I'd prefer the UI to look a little more like:

[no visible label] [x] Also log an audit

Once that checkbox is clicked, the image upload, audit note, and next audit date fields are shown.

@akemidx
Copy link
Member Author

akemidx commented Apr 16, 2025

okay, overall made the requested changed, but I think we still would get the 403 on the checkbox check->authroize yea?

I'll keep thinking about it.

@akemidx
Copy link
Member Author

akemidx commented Apr 16, 2025

okay, overall made the requested changed, but I think we still would get the 403 on the checkbox check->authroize yea?

I'll keep thinking about it.

wait, wouldn't that just get removed, and only check for the gate/authorization like on the save. cause THAT is where the actual log action is happening.

@@ -75,6 +76,10 @@ public function store(AssetCheckinRequest $request, $assetId = null, $backto = n

$this->authorize('checkin', $asset);

if ($request->filled('log_audit') == "1") {
$this->authorize('audit', Asset::class);
Copy link
Member

Choose a reason for hiding this comment

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

This will cause a forbidden error. We don't need the entire block in this section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants