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

Remove getDB and hasAuthorization #3437

Merged
merged 2 commits into from
Oct 17, 2022
Merged

Remove getDB and hasAuthorization #3437

merged 2 commits into from
Oct 17, 2022

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Oct 12, 2022

Summary

Best viewed by individual commit.

getDB was deprecated a while ago, when we added RequestContext. We left it for a bit to make sure we had the right interface for RequestContext. It seems to be working well, so now we can remove it.

We had 3 different ways to authorize a request (hasAuthorization, RequireInfraRole, and Can which was recently renamed to IsAuthorized). We've been replacing the use of hasAuthorization with a check in the caller to compare the requested ID to the authorized user. This PR replaces the last few callers to use the pattern we have in other place. It also changes isIdentitySelf to accept a RequestContext and remove the error return (since it always returned nil). This reduces the number of ways to authorize a request to 2. We should be able to reduce it to a single function in the future.

if err != nil {
return nil, HandleAuthErr(err, "organizations", "get", models.InfraSupportAdminRole)
rCtx := GetRequestContext(c)
if user := rCtx.Authenticated.User; user != nil && user.OrganizationID == id {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made one small change here from the implementation we had in isOrganizationSelf. It now checks the authorized user.OrganizationID instead of the authenticated organization.ID.

On unauthenticated routes the authenticated organization is still set, so the authenticated user.OrganizationID is a slightly safer pattern. In this case it doesn't really matter because the route required authentication.

Call the identity check directly, like we do in other places.
@dnephin dnephin merged commit 495208f into main Oct 17, 2022
@dnephin dnephin deleted the dnephin/remove-get-db branch October 17, 2022 15:50
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.

2 participants