-
Notifications
You must be signed in to change notification settings - Fork 969
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
fix: identity sessions list response includes pagination headers #2763
fix: identity sessions list response includes pagination headers #2763
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2763 +/- ##
=======================================
Coverage 76.04% 76.04%
=======================================
Files 302 302
Lines 17980 17980
=======================================
Hits 13672 13672
Misses 3268 3268
Partials 1040 1040 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your contribution. This is awesome 🎉
Could you add some tests, that prove your change does what it's supposed to?
- for the persister changes: https://github.com/ory/kratos/blob/master/session/test/persistence.go
And to run the tests execute the tests in here: https://github.com/ory/kratos/blob/master/persistence/sql/persister_test.go - And for the handler here: https://github.com/ory/kratos/blob/master/session/handler_test.go
Oh yeah totally! I got a little excited about opening the PR yesterday and completely forgot about adding tests- sorry about that 😅 Thanks for highlighting where the relevant tests should go, I'll get them added over lunch later today 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for coming up with this PR 👍
I have an idea how to simplify it and reduce the code you have to test 😉
persistence/sql/persister_session.go
Outdated
@@ -76,6 +76,24 @@ func (p *Persister) ListSessionsByIdentity(ctx context.Context, iID uuid.UUID, a | |||
return s, nil | |||
} | |||
|
|||
func (p *Persister) CountSessionsByIdentity(ctx context.Context, iID uuid.UUID, active *bool) (int64, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can avoid this whole function and instead use the (*pop.Query).Paginator.TotalEntriesSize
form the original
func (p *Persister) ListSessionsByIdentity(ctx context.Context, iID uuid.UUID, active *bool, page, perPage int, except uuid.UUID) ([]*session.Session, error) { |
So changing the signature of
ListSessionsByIdentity
to return (sessions []*session.Session, totalCount int64, err error)
6c0a08e
to
4a26981
Compare
if err != nil { | ||
h.r.Writer().WriteError(w, r, err) | ||
return | ||
} | ||
|
||
x.PaginationHeader(w, urlx.AppendPaths(h.r.Config().SelfAdminURL(r.Context()), RouteCollection), total, page, perPage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't noticed this listSessions
function yesterday when I made my first set of changes. Since it accepts the pagination query params, it seemed reasonable to add the pagination headers to this endpoint as well.
Thank you both for guidance there- I've force pushed an update with the requested changes 👍 My couple comments above are just calling out noteworthy changes in this latest push I don't mean to distract the focus of this review, but while testing, I noticed that when the page size exactly matches the total number of items, the "prev" link will be added to the pagination with the page number
I took a quick look at open issues on the ory/x repo and didn't see anything mentioning this. If this is not intentional, I can open an issue for this over on that repo. Just let me know |
4a26981
to
e6c141d
Compare
Hi, could you please resolve the merge conflicts and also fix the tests? :) |
Hey! Really sorry for the radio silence here- yeah I am still planning to rebase this and fix up the tests. This week has been a bit hectic and time has gotten away from me is all 😅 Am hoping to dedicate more time to this tomorrow 👍 |
This resolves issue ory#2762
1dd145f
to
67c8590
Compare
67c8590
to
722c159
Compare
I think I was having an off day when I first wrote those tests 😅 I've improved them a bit and added an extra set of tests for the admin sessions list as well, so it looks like this should be set now 👍 If there's anything else yall need for reviewing this, just let me know |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Nice work! And sorry for the delay. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, thank you!
No problemo! Thanks for considering and accepting the contributions 😁 |
This resolves issue #2762
This resolves the issue of missing pagination headers in the response to the
/admin/identities/{id}/sessions
endpoint by adding aCountSessionsByIdentity
function to thepersistence
module, and then using that new function within the api handler to get the total records count needed for calling thex.PaginationHeader
function.The
CountSessionsByIdentity
function is scoped to the provided Identity ID, and respects theactive
query parameter if it was present.Changelog entry:
Related issue(s)
This PR resolves the following ticket, which I just opened a short bit ago to comply with the Contributions guide. That ticket details the issue more thoroughly, including the steps for reproducing the issue.
#2762
Checklist
introduces a new feature. (not applicable, I think)
contributing code guidelines.
vulnerability. If this pull request addresses a security vulnerability, I
confirm that I got the approval (please contact
security@ory.sh) from the maintainers to push
the changes.
works.
(This is checked because technically this change fixes compliance with the existing documentation
Further Comments
I opened this PR pretty quickly after opening the linked issue, even though no feedback has been provided on said issue. After digging through the code, I was pretty confident that this omission is actually a bug and not an intentional design decision. It only took a few minutes to track through the codebase to make the necessary changes, so I figured it was worth opening the PR before receiving feedback on the issue 🤷