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 #6695: add API endpoint for license seats #8058

Merged
merged 7 commits into from Mar 30, 2021
Merged

Added #6695: add API endpoint for license seats #8058

merged 7 commits into from Mar 30, 2021

Conversation

marcquark
Copy link
Contributor

@marcquark marcquark commented May 17, 2020

This PR implements a dedicated API endpoint for license seats. The endpoint can be used to get all seats of a particular license, get one specific seat aswell as update one specific seat's assignments. The new controller contains logic to determine whether an update operation is a checkin or checkout and adds logs accordingly.

It also deprecates the existing /licenses/{id}/seats route, which was only used in one instance anyway. It the output format remains the same, so should be backwards compatible.

There are also a bunch of tests. I haven't yet fully understood on what data the testing framework operates. But the seeded DB data only contains licenses that haven't been checked out to anyone. Hence i think a proper test for checkin cannot be implemented at the moment.

it makes no sense and we don't have any particular sorting order
so the numbering would be inconsistent anyway
@marcquark marcquark requested a review from snipe as a code owner May 17, 2020 10:34
@marcquark
Copy link
Contributor Author

Hmm, i don't really know how to simplify/reduce the complexity Codacy is complaining about.

Sure, could skip sanity checks and some other validation logic, but i'd rather have a slightly more complex function than an API that doesn't tell the user why the input is not plausible...

Similarly, i could of course make dedicated checkin/checkout functions but the point of this endpoint is to have an easy way of manipulating seats externally. This is especially useful if the user doesn't agree with the way snipe-it determines how and when these fields should be populated (e.g. the annoying bug that seats which are assigned to assets stick with the original user when an asset is reassigned).
But i'd also not like an API endpoint that doesn't log actions. That'll just lead to more confusion for users that only use the GUI.

@jkour
Copy link

jkour commented May 18, 2020

@marcquark Codacy suggestions don't really make sense in this case I believe.

I wonder how would the functions measure if you created smaller functions for all those ifs...

Disclaim: I do not code in php so it is just a general observation

@marcquark
Copy link
Contributor Author

That's what i thought too. For the sanity checks, it feels like there should be some elegant way to inject those into Laravel for specific routes or methods of the controller, but i couldn't find a decent example online. Having that could avoid having to copy+paste the same logic twice. The approach of moving it into a private function and calling that became complex quickly, so i bailed out.

As far as the other logic goes, i'm actually less happy with what i produced now vs the original PR. Got the codacy score slightly lower, but it's now harder to understand imho.

@snipe must there absolutely be a green tick in the codacy check for the PR to be accepted?

@jkour
Copy link

jkour commented May 18, 2020

TBH I don't really follow the suggestion that "else" statements should be completely avoided

@jkour
Copy link

jkour commented May 19, 2020

@marcquark Is it possible to get your fork and install it myself?

@snipe
Copy link
Owner

snipe commented May 20, 2020

Just a heads up - once v5 is out, we're going to be completely reworking the license section to make it work a bit more like asset models, with seats being more like assets.

@jkour
Copy link

jkour commented May 20, 2020

@snipe When do you reckon it will be out? Any plans in place?

@marcquark
Copy link
Contributor Author

@jkour sure you can just pull the develop branch from my forked repo. though i don't know whether that is a wise thing to do. after all if major changes are coming with v5 it's very likely that the endpoint will be shuffled around. don't know how urgently you need the feature but it may not be worth adjusting all you tools and then redo everything in a few months or so

@jkour
Copy link

jkour commented May 25, 2020

@marcquark Not in a rush really...Maybe I will wait for the new version

Thanks anyway

@marcquark
Copy link
Contributor Author

Hi @snipe,

so it looks like v5 didn't include any major changes to the license model and API. Hence i'd like to bring back attention to this PR. Any chance to get it merged at some point? A lot of people have been waiting for this feature for quite some time now.

@snipe snipe merged commit 90b7d34 into snipe:develop Mar 30, 2021
@welcome
Copy link

welcome bot commented Mar 30, 2021

Congrats on merging your first pull request! 🎉🎉🎉

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

Successfully merging this pull request may close these issues.

None yet

3 participants