-
-
Notifications
You must be signed in to change notification settings - Fork 16
[BACK-2780] Add new user profiles endpoint. #698
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
Open
lostlevels
wants to merge
75
commits into
master
Choose a base branch
from
jimmy/BACK-2780-new-profiles-endpoint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 69 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
81964c7
Refactoring and adding shoreline models to platform/user for auth.
lostlevels 6cfa1b2
Cleanup.
lostlevels 5e4e602
Add /v1/profiles/:userId route.
lostlevels 6135115
Renaming.
lostlevels d159e8c
Add the route.
lostlevels ee311c4
Fix build.
lostlevels 962ebc1
Fix test.
lostlevels a746294
Use permissions like in seagull.
lostlevels de33718
Validate the profile.
lostlevels 52fb052
HasWritePermissions.
lostlevels 51706a3
Rename profile routes to be consistent w/ existing ones.
lostlevels 93222a3
Use snakecase attributes for now but don't flatten yet as blip is still
lostlevels 1c6eba9
Have a LegacyUserProfile to support seagull requests.
lostlevels 16f00c9
Change leagcy profile routes for simpler proxying in routetable.
lostlevels d8173c2
Add legacy delete route.
lostlevels 2f46dac
Move keycloak client and keycloak user_accessor to own package.
lostlevels 72d9ebf
Rename to package keycloak.
lostlevels 50d0815
Add user profile config for keycloak 24+.
lostlevels 42420ce
Remove user profile config as that's handled in TF.
lostlevels 7898935
Add custodian field to profile.
lostlevels 1edbbfc
Allow services to retrieve user profile.
lostlevels b4d7e7e
Use "dummy" attribute "profile_has_custodian" for easier keycloak
lostlevels c95095a
patient.fullName is only set for fake children.
lostlevels 7fd9db5
Remove "profile_" prefix from profile keycloak attributes. Add
lostlevels df42975
Use right json.
lostlevels 0167a45
Delete unused shoreline code. Move user.FullUser into user.User.
lostlevels bc83f89
Remove unused hasher code.
lostlevels a4977b5
Remove unused fields.
lostlevels 70c0a29
Add MRN attribute.
lostlevels 80ad018
Copy amoeba's permissions with regards to membership and custodian.
lostlevels 551db76
Remove check from route since part of middleware now.
lostlevels fa04272
Remove unneeded comment.
lostlevels 569050a
Add GroupsForUser as a prelude to some seagull / gatekeeper
lostlevels 0c4f85e
Commence "old" seagull routes that retrieves from the seagull collection
lostlevels 220183a
Update migration status.
lostlevels 0d1a9da
Make sure seagull.value field is preserved properly during updates and
lostlevels cbab818
Use fallback profile accessor to check for profile first in seagull.
lostlevels fb44208
Rename repository for clarity of purpose.
lostlevels 5eab377
Bump gocloak.
lostlevels 7cf807f
role field.
lostlevels ae63ba1
Omit profile fields if empty in response.
lostlevels 742c06a
Add clinic profile fields.
lostlevels 8378b34
Add normalizer methods for profiles.
lostlevels ad31dcd
Account for empty profile fullName.
lostlevels 3265f74
[BACK-3046] Create initial shared users with profiles path w/o
lostlevels 3fca9bb
Start metadata/users/:userid/users filter params.
lostlevels 9a27e5b
Parse users profiles query filter.
lostlevels 1ceb4b9
Update users route to properly filter out users. Document Permission /
lostlevels 62db0a4
Remove unused query filter on users profiles.
lostlevels d58642c
Handle email and emails in legacy seagull profiles.
lostlevels e1de168
Read raw value as map from seagull value.
lostlevels 9fc1750
Allow setting of profile on seagull document's value field.
lostlevels 94d0a00
Migrate diagnosisType.
lostlevels a79c2cd
Remove email field from clinic as confirmed only a few fake clinic pr…
lostlevels 20e6964
Use correct FullName in case of fake children.
lostlevels 374d117
Handle certain incorrect types in legacy seagull profile.
lostlevels 9eb119e
Fix some logic and tests for profiles.
lostlevels d643c07
Set max profile field length to equal keycloak < 24
lostlevels 8737671
Make some profile values pointers so that some legacy migration profiles
lostlevels 32682d6
Export MaxProfileFieldLen
lostlevels d11dc0a
Remove unused field, add tests, synchronize keycloak access.
lostlevels 871f707
Use existing UsersArray type, add update tests.
lostlevels 8c775e5
Make TargetTimezone a value.
lostlevels bc4b082
Remove unused files, remove unneded checks.
lostlevels e425e62
Fix tests broken during rebase.
lostlevels 97daee8
Regenerate.
lostlevels 8dbf5a7
Add same named routes as seagull for clients that connect directly to…
lostlevels f91d213
Fix shadowed variable profile overwriting update.
lostlevels b4d70a9
Add /v1/users/:userId/profile route tests.
lostlevels c2137d6
Updates from code review.
lostlevels 7445261
Update tests.
lostlevels ea76335
Use custodian / root permission fors /users route. Update tests
lostlevels 1dc89ac
Updates from code review. Remove unused fields, fix permissions logic.
lostlevels f4955c2
run imports
lostlevels 4437749
Some updates from PR comments.
lostlevels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package v1 | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/ant0ine/go-json-rest/rest" | ||
|
|
||
| "github.com/tidepool-org/platform/request" | ||
| ) | ||
|
|
||
| // requireCustodian aborts with an error if the user associated w/ the | ||
| // request doesn't have custodian access to the user with the id defined in the | ||
| // url param targetParamUserID. | ||
| // | ||
| // This mimics the logic of amoeba's requireCustodian access. This means a | ||
| // user has access to the target user if any of the following is true: | ||
| // - The is a service call (AuthDetails.IsService() == true) | ||
| // - The requester and target are the same - AuthDetails.UserID == targetParamUserID | ||
| // - The requester has explicit permissions to access targetParamUserID | ||
| func (r *Router) requireCustodian(targetParamUserID string, handlerFunc rest.HandlerFunc) rest.HandlerFunc { | ||
| return func(res rest.ResponseWriter, req *rest.Request) { | ||
| if handlerFunc != nil && res != nil && req != nil { | ||
| targetUserID := req.PathParam(targetParamUserID) | ||
| responder := request.MustNewResponder(res, req) | ||
| ctx := req.Context() | ||
| details := request.GetAuthDetails(ctx) | ||
| if details == nil { | ||
| request.MustNewResponder(res, req).Error(http.StatusUnauthorized, request.ErrorUnauthenticated()) | ||
| return | ||
| } | ||
| if details.IsService() || details.UserID() == targetUserID { | ||
| handlerFunc(res, req) | ||
| return | ||
| } | ||
| hasPerms, err := r.PermissionsClient().HasCustodianPermissions(ctx, details.UserID(), targetUserID) | ||
| if err != nil { | ||
| responder.InternalServerError(err) | ||
| return | ||
| } | ||
| if !hasPerms { | ||
| responder.Empty(http.StatusForbidden) | ||
| return | ||
| } | ||
| handlerFunc(res, req) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // requireMembership proceeds if the user with the id specified in the URL | ||
| // paramter targetParamUserID has some association with the user in the current | ||
| // request - the "requester". This mimics amoeba's requireMembership function. | ||
| // | ||
| // This proceeds if any of the following are true: | ||
| // - The is a service call (AuthDetails.IsService() == true) | ||
| // - The requester and target are the same - AuthDetails.UserID == targetParamUserID | ||
| // - The requester has any permissions to targetParamUserID OR targetParamUserID has permissions to the requester. | ||
| func (r *Router) requireMembership(targetParamUserID string, handlerFunc rest.HandlerFunc) rest.HandlerFunc { | ||
| return func(res rest.ResponseWriter, req *rest.Request) { | ||
| if handlerFunc != nil && res != nil && req != nil { | ||
| targetUserID := req.PathParam(targetParamUserID) | ||
| responder := request.MustNewResponder(res, req) | ||
| ctx := req.Context() | ||
| details := request.GetAuthDetails(ctx) | ||
| if details == nil { | ||
| request.MustNewResponder(res, req).Error(http.StatusUnauthorized, request.ErrorUnauthenticated()) | ||
| return | ||
| } | ||
| if details.IsService() || details.UserID() == targetUserID { | ||
| handlerFunc(res, req) | ||
| return | ||
| } | ||
| hasPerms, err := r.PermissionsClient().HasMembershipRelationship(ctx, details.UserID(), targetUserID) | ||
| if err != nil { | ||
| responder.InternalServerError(err) | ||
| return | ||
| } | ||
| if !hasPerms { | ||
| responder.Empty(http.StatusForbidden) | ||
| return | ||
| } | ||
| handlerFunc(res, req) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // requireWriteAccess aborts with an error if the request isn't a server request | ||
| // or the authenticated user doesn't have access to the user id in the url param, | ||
| // targetParamUserID | ||
| func (r *Router) requireWriteAccess(targetParamUserID string, handlerFunc rest.HandlerFunc) rest.HandlerFunc { | ||
| return func(res rest.ResponseWriter, req *rest.Request) { | ||
| if handlerFunc != nil && res != nil && req != nil { | ||
| targetUserID := req.PathParam(targetParamUserID) | ||
| responder := request.MustNewResponder(res, req) | ||
| ctx := req.Context() | ||
| details := request.GetAuthDetails(ctx) | ||
| if details == nil { | ||
| responder.Empty(http.StatusUnauthorized) | ||
| return | ||
| } | ||
| if details.IsService() { | ||
| handlerFunc(res, req) | ||
| return | ||
| } | ||
| hasPerms, err := r.PermissionsClient().HasWritePermissions(ctx, details.UserID(), targetUserID) | ||
| if err != nil { | ||
| responder.InternalServerError(err) | ||
| return | ||
| } | ||
| if !hasPerms { | ||
| responder.Empty(http.StatusForbidden) | ||
| return | ||
| } | ||
| handlerFunc(res, req) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.