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

Added created_by to users #11383

Merged
merged 12 commits into from
Jun 24, 2022
Merged

Added created_by to users #11383

merged 12 commits into from
Jun 24, 2022

Conversation

snipe
Copy link
Owner

@snipe snipe commented Jun 24, 2022

I am frankly shocked that I didn't have this on the user's table before - seems like a real boner move TBH - everything else in the system records who created the thing, but we somehow missed it 9 years ago and never noticed. (To be fair, nobody asked for it, but still... weird that I'd have missed something so obvious.)

Anyway... this adds a DB column called created_by to the users table. It is important to note that this is a divergence from our standard convention. We typically use the (very confusing) field name user_id to denote the Snipe-IT user id of the person who created the thing - but since it's confusing, I will be changing that over time to use a more common created_by, so it's clearer what that field means. I didn't want to include that in this PR though, since it's a breaking change to the API.

In the user view blade, we check to see if that admin has been (soft) deleted, and if it has, we strike it through. If not, we link to the person who created the user.

Screen Shot 2022-06-23 at 5 04 50 PM

The API payload is standard for what we return for users, managers, etc.

Screen Shot 2022-06-23 at 5 05 15 PM

Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Copy link
Collaborator

@uberbrady uberbrady left a comment

Choose a reason for hiding this comment

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

This looks GREAT! I had a tiny stylistic nit but you could totally ignore me and it wouldn't bother me much. Very thorough, and I do like the custom scope you used for the ordering - clever, and clean.

app/Models/User.php Outdated Show resolved Hide resolved
app/Models/User.php Outdated Show resolved Hide resolved
Signed-off-by: snipe <snipe@snipe.net>
@snipe snipe requested a review from uberbrady June 24, 2022 01:41
Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Copy link
Collaborator

@uberbrady uberbrady left a comment

Choose a reason for hiding this comment

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

I think createdBy and CreatedBy() methods both existing is gonna be confusing :(

One other nonsense comment I threw in that you should ignore.

@@ -705,7 +705,7 @@ public function scopeOrderDepartment($query, $order)
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderAdmin($query, $order)
public function scopeCreatedBy($query, $order)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be scopeOrderCreatedBy()?

@@ -67,7 +67,7 @@ public function index(Request $request)
'users.remote',
'users.ldap_import',

])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'adminuser',)
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy',)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a silly aesthetic thing, but it's weird that we don't normally use snakeCase and here is the one place where we do. But, that's the Laravel convention and we probably ought to follow it, so this is probably exactly how it should be.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Duly ignored :P

@snipe snipe merged commit f0cc418 into develop Jun 24, 2022
@snipe snipe deleted the features/adds_user_id_to_users branch June 24, 2022 01:48
@snipe
Copy link
Owner Author

snipe commented Jun 24, 2022

Thank you for reviewing :)

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.

None yet

2 participants