Skip to content
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

Deleting files from an asset removes the log of its creation and does not log the deletion #8444

Open
2 tasks done
med-tascoe opened this issue Sep 16, 2020 · 4 comments
Open
2 tasks done

Comments

@med-tascoe
Copy link

Please confirm you have done the following before posting your bug report:

Describe the bug
When deleting files from an asset the log of the file's upload is removed and the deletion is not logged. I consider this a bug as from an auditing perspective eliminates the audit of the file.

To Reproduce
Steps to reproduce the behavior:

  1. Go to an asset and view that Asset
  2. Click on Files
  3. Upload a file
  4. Delete the file.
  5. Check activity.

Expected behavior
I would expect the original upload activity to remain and the deletion activity to be logged.

Screenshots
If applicable, add screenshots to help explain your problem.

Server (please complete the following information):

  • Snipe-IT Version: v4.9.3 build 4395 (g9a2440dc4)
  • OS: Windows Server 2016
  • Web Server: IIS 10
  • PHP Version 7.2.26

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Firefox Developer
  • Version 79.0b5

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Error Messages
N/A

Additional context

  • Is this a fresh install or an upgrade? Fresh Install
  • What method you used to install Snipe-IT: manual installation
  • Indicate whether or not you've manually edited any data directly in the database: I have not

Add any other context about the problem here.

@med-tascoe
Copy link
Author

med-tascoe commented Sep 17, 2020

This seems to be a design issue. Files attached to assets are tracked via the activity tracker and is therefore difficult achieve the desire result. However, I crated a work around with the following code in the file \app\Http\Controllers\AssetFilesController.php under the destroy function in the "if ($log)" section under where it unlinks the file.
use Auth;

// Log the deletion of the file.
$logAction = new Actionlog();
$logAction->item_type = Asset::class;
$logAction->item_id = $asset->id;
$logAction->created_at =  date("Y-m-d H:i:s");
$logAction->user_id = Auth::id();
$changed = [];
$changed['file']['old'] = null;
$changed['file']['new'] = '('.$fileId.') '.$log->filename;
$logAction->log_meta = json_encode($changed);
$logAction->logaction('delete');

// Instead of deleting it just disassociate the file from the item.
$changed2 = [];
$changed2['file']['old'] = null;
$changed2['file']['new'] = 'Asset: '.$log->item_id.' File: ('.$fileId.') '.$log->filename;
$log->log_meta = json_encode($changed2);
$log->filename = null;
$log->item_id = $log->id;
$log->save();

This will log the deletion as well as update the upload entry to still remain but not linking itself to the item for display under that item.

@med-tascoe
Copy link
Author

I also resolved another error with files NOT actually deleting off the server when being deleted.
$destinationPath = config('app.private_uploads').'/imports/assets';
was changed to
$destinationPath = config('app.private_uploads').'/assets';

@stale
Copy link

stale bot commented Dec 25, 2020

Is this still relevant? We haven't heard from anyone in a bit. If so, please comment with any updates or additional detail.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Don't take it personally, we just need to keep a handle on things. Thank you for your contributions!

@stale stale bot added the stale label Dec 25, 2020
@stale
Copy link

stale bot commented May 3, 2021

Okay, it looks like this issue or feature request might still be important. We'll re-open it for now. Thank you for letting us know!

@stale stale bot removed the stale label May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant