Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions app/Helpers/IconHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static function icon($type) {
case 'clone':
return 'far fa-clone';
case 'delete':
case 'upload deleted':
return 'fas fa-trash';
case 'create':
return 'fa-solid fa-plus';
Expand Down
8 changes: 2 additions & 6 deletions app/Http/Controllers/Api/UploadedFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ public function index(Request $request, $object_type, $id) : JsonResponse | arra
];


$uploads = Actionlog::select('action_logs.*')
->whereNotNull('filename')
->where('item_type', self::$map_object_type[$object_type])
->where('item_id', $object->id)
->where('action_type', '=', 'uploaded')
$uploads = self::$map_object_type[$object_type]::withTrashed()->find($id)->uploads()
->with('adminuser');

$offset = ($request->input('offset') > $uploads->count()) ? $uploads->count() : abs($request->input('offset'));
Expand Down Expand Up @@ -206,7 +202,7 @@ public function destroy($object_type, $id, $file_id) : JsonResponse
Storage::delete(self::$map_storage_path[$object_type].'/'.$log->filename);
}
// Delete the record of the file
if ($log->delete()) {
if ($log->logUploadDelete($object, $log->filename)) {
return response()->json(Helper::formatStandardApiResponse('success', null, trans_choice('general.file_upload_status.delete.success', 1)), 200);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UploadedFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function destroy($object_type, $id, $file_id) : RedirectResponse
Storage::delete(self::$map_storage_path[$object_type].'/'.$log->filename);
}
// Delete the record of the file
if ($log->delete()) {
if ($log->logUploadDelete($object, $log->filename)) {
return redirect()->back()->withFragment('files')->with('success', trans_choice('general.file_upload_status.delete.success', 1));
}

Expand Down
9 changes: 6 additions & 3 deletions app/Http/Transformers/ActionlogsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ private function clean_field($value)

public function transformActionlog (Actionlog $actionlog, $settings = null)
{

$icon = $actionlog->present()->icon();

if (($actionlog->filename!='') && ($actionlog->action_type!='upload deleted')) {
$icon = Helper::filetype_icon($actionlog->filename);
}

static $custom_fields = false;

if ($custom_fields === false) {
$custom_fields = CustomField::all();
}

if ($actionlog->filename!='') {
$icon = Helper::filetype_icon($actionlog->filename);
}


// This is necessary since we can't escape special characters within a JSON object
if (($actionlog->log_meta) && ($actionlog->log_meta!='')) {
Expand Down
33 changes: 20 additions & 13 deletions app/Models/Actionlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,6 @@ public function targetType()
}


/**
* Establishes the actionlog -> uploads relationship
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function uploads()
{
return $this->morphTo('item')
->where('action_type', '=', 'uploaded')
->withTrashed();
}

/**
* Establishes the actionlog -> userlog relationship
Expand Down Expand Up @@ -456,6 +443,26 @@ public function determineActionSource(): string

}


/**
* @author Godfrey Martinez
* @since [v8.0.4]
* @return \App\Models\Actionlog
*/
public function logUploadDelete($object, $filename)
{
$log = new Actionlog;
$log->item_type = $object instanceof SnipeModel ? get_class($object) : $object;
$log->item_id = $object->id;
$log->created_by = auth()->id();
$log->target_id = null;
$log->filename = $filename;
$log->created_at = date('Y-m-d H:i:s');
$log->logaction('upload deleted');

return $log;
}

public function uploads_file_url()
{

Expand Down
9 changes: 8 additions & 1 deletion app/Models/Traits/HasUploads.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ public function uploads()
return $this->hasMany(Actionlog::class, 'item_id')
->where('item_type', self::class)
->where('action_type', '=', 'uploaded')
->whereNotNull('filename');
->whereNotNull('filename')
->whereNotIn('filename', function ($query) {
$query->select('filename')
->from('action_logs')
->where('item_type', '=', self::class)
->where('action_type', '=', 'upload deleted')
->where('item_id', $this->id);
});
}


Expand Down
6 changes: 5 additions & 1 deletion app/Presenters/ActionlogPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function icon()
return 'fa-solid fa-user-minus';
}

if ($this->action_type == 'upload deleted') {
return 'fa-solid fa-trash';
}

if ($this->action_type == 'update') {
return 'fa-solid fa-user-pen';
}
Expand All @@ -74,7 +78,7 @@ public function icon()
return 'fa-solid fa-plus';
}

if ($this->action_type == 'delete') {
if (($this->action_type == 'delete') || ($this->action_type == 'upload deleted')) {
return 'fa-solid fa-trash';
}

Expand Down
1 change: 1 addition & 0 deletions resources/lang/en-US/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@
'use_cloned_no_image_help' => 'This item does not have an associated image and instead inherits from the model or category it belongs to. If you would like to use a specific image for this item, you can upload a new one below.',
'footer_credit' => '<a target="_blank" href="https://snipeitapp.com" rel="noopener">Snipe-IT</a> is open source software, made with <i class="fa fa-heart" aria-hidden="true" style="color: #a94442; font-size: 10px" /></i><span class="sr-only">love</span> by <a href="https://bsky.app/profile/snipeitapp.com" rel="noopener">@snipeitapp.com</a>.',
'set_password' => 'Set a Password',
'upload_deleted' => 'Upload Deleted',

// Add form placeholders here
'placeholders' => [
Expand Down
Loading