Skip to content

Commit

Permalink
[BACK-2781] Allow care_partner users to create custodial accounts.
Browse files Browse the repository at this point in the history
  • Loading branch information
lostlevels committed Jul 3, 2024
1 parent a5c9ff2 commit e163d1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions user/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ func (a *Api) CreateCustodialUser(res http.ResponseWriter, req *http.Request, va
return
} else {
permissions := clients.Permissions{"custodian": clients.Allowed, "view": clients.Allowed, "upload": clients.Allowed}
if custodianUserID != "" {
custodian, err := a.Store.WithContext(req.Context()).FindUser(&User{Id: custodianUserID})
if err != nil {
a.sendError(res, http.StatusNotFound, STATUS_USER_NOT_FOUND, err)
return
}
if custodian.HasRole(RoleCarePartner) {
permissions["care_partner"] = clients.Allowed
}
}
if _, err := a.perms.SetPermissions(custodianUserID, newCustodialUser.Id, permissions); err != nil {
a.sendError(res, http.StatusInternalServerError, STATUS_ERR_CREATING_USR, err)
} else {
Expand Down
2 changes: 2 additions & 0 deletions user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
const (
TimestampFormat = "2006-01-02T15:04:05-07:00"
custodialEmailFormat = "unclaimed-custodial-automation+%020d@tidepool.org"
RoleCarePartner = "care_partner"
RoleClinic = "clinic"
RoleClinician = "clinician"
RoleCustodialAccount = "custodial_account"
Expand All @@ -28,6 +29,7 @@ var custodialAccountRegexp = regexp.MustCompile("unclaimed-custodial-automation\

var validRoles = map[string]struct{}{
RoleBrokered: {},
RoleCarePartner: {},
RoleClinic: {},
RoleClinician: {},
RoleCustodialAccount: {},
Expand Down

0 comments on commit e163d1d

Please sign in to comment.