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

User asset history mistakes software log entries for hardware #937

Closed
bskertchly opened this issue Jul 21, 2015 · 7 comments
Closed

User asset history mistakes software log entries for hardware #937

bskertchly opened this issue Jul 21, 2015 · 7 comments
Milestone

Comments

@bskertchly
Copy link

On a user page, their asset history is displayed. The grid seems to think that every entry in the asset_logs table is hardware-related (essentially ignoring the asset_type column). The SQL it generates must be something along these lines:

SELECT *
FROM asset_logs l
INNER JOIN assets a ON l.asset_id = a.id
INNER JOIN users u ON l.checkedout_to = u.id
WHERE l.checkedout_to = AUserID;

If there is a license and an an asset with the same ID, the query will interpret a software entry to be for the piece of hardware that is completely unrelated. Thus, we could have servers show up in users' histories :).

I think the query should look something more like this:

SELECT *
FROM asset_logs l
LEFT JOIN assets a ON l.asset_id = a.id AND l.asset_type = 'hardware'
LEFT JOIN licenses lc ON l.asset_id = lc.id AND l.asset_type = 'software'
INNER JOIN users u ON l.checkedout_to = u.id
WHERE l.checkedout_to = AUserID;

or maybe exclude the software ones, if that's easier:

SELECT *
FROM asset_logs l
INNER JOIN assets a ON l.asset_id = a.id
INNER JOIN users u ON l.checkedout_to = u.id
WHERE l.checkedout_to = AUserID AND l.asset_type = 'hardware';
@bskertchly
Copy link
Author

I'm not familiar with the ORM that snipe-it uses (or much PHP, for that matter), but looking at the code for ActionLog, I think the fix would be to replace:

public function assetlog()
{
    return $this->belongsTo('Asset','asset_id')->withTrashed();
}
...
public function licenselog()
{
    return $this->belongsTo('License','asset_id')->withTrashed();
}

with

public function assetlog()
{
    return $this->belongsTo('Asset','asset_id')->where('asset_type','=','hardware')->withTrashed();
}
...
public function licenselog()
{
    return $this->belongsTo('License','asset_id')->where('asset_type','=','software')->withTrashed();
}

@snipe
Copy link
Owner

snipe commented Jul 21, 2015

How about you start with telling me what version of Snipe-IT you're using, and where you're seeing the bug?

@snipe
Copy link
Owner

snipe commented Jul 21, 2015

Is this only on the user page?

@bskertchly
Copy link
Author

Sorry, I meant to post my version details, but forgot.

v1.2.7 running on Ubuntu.

I've only noticed it in the user page. I'm checking other pages to see if it happens elsewhere.

@bskertchly
Copy link
Author

I could only get it to happen on the user page.

@snipe
Copy link
Owner

snipe commented Jul 25, 2015

This is in the log at the bottom of the user detail view page, correct?

snipe added a commit that referenced this issue Jul 25, 2015
@snipe
Copy link
Owner

snipe commented Jul 25, 2015

This is fixed in 2.0

@snipe snipe closed this as completed Jul 25, 2015
@snipe snipe added this to the v.2.0 milestone Jul 27, 2015
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

2 participants