-
Notifications
You must be signed in to change notification settings - Fork 881
chore: create type for unique role names #13506
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
Changes from all commits
4f18d66
fc8d414
7be7755
1bc2cdf
d88c836
175a03f
3f7e2cb
056fc17
7651a18
dadd284
8988224
521ffcd
dce7f09
cc68903
fa2f704
9bf3298
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,7 +199,8 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs | |
Roles: []codersdk.SlimRole{}, | ||
} | ||
|
||
for _, roleName := range dblog.UserRoles { | ||
for _, input := range dblog.UserRoles { | ||
roleName, _ := rbac.RoleNameFromString(input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we at least drop an error log if we were unable to covert any of the roles rom the db? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is in the convert audit log, I think that could get quite noisy. I agree this is not ideal |
||
rbacRole, _ := rbac.RoleByName(roleName) | ||
user.Roles = append(user.Roles, db2sdk.SlimRole(rbacRole)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,7 +170,12 @@ func User(user database.User, organizationIDs []uuid.UUID) codersdk.User { | |
} | ||
|
||
for _, roleName := range user.RBACRoles { | ||
rbacRole, err := rbac.RoleByName(roleName) | ||
// TODO: Currently the api only returns site wide roles. | ||
// Should it return organization roles? | ||
rbacRole, err := rbac.RoleByName(rbac.RoleIdentifier{ | ||
Name: roleName, | ||
OrganizationID: uuid.Nil, | ||
}) | ||
Comment on lines
+173
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. follow-up for TODO? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not going to do this until we get farther in the organization work. Right now this api is used for the So this is a genuine question if we should expand the roles returned, and on the UI filter out the organization ones. But at present, showing org roles at all is incorrect as orgs do not really exist. |
||
if err == nil { | ||
convertedUser.Roles = append(convertedUser.Roles, SlimRole(rbacRole)) | ||
} else { | ||
|
@@ -519,29 +524,26 @@ func ProvisionerDaemon(dbDaemon database.ProvisionerDaemon) codersdk.Provisioner | |
} | ||
|
||
func SlimRole(role rbac.Role) codersdk.SlimRole { | ||
roleName, orgIDStr, err := rbac.RoleSplit(role.Name) | ||
if err != nil { | ||
roleName = role.Name | ||
orgID := "" | ||
if role.Identifier.OrganizationID != uuid.Nil { | ||
orgID = role.Identifier.OrganizationID.String() | ||
} | ||
|
||
return codersdk.SlimRole{ | ||
DisplayName: role.DisplayName, | ||
Name: roleName, | ||
OrganizationID: orgIDStr, | ||
Name: role.Identifier.Name, | ||
OrganizationID: orgID, | ||
} | ||
} | ||
|
||
func RBACRole(role rbac.Role) codersdk.Role { | ||
roleName, orgIDStr, err := rbac.RoleSplit(role.Name) | ||
if err != nil { | ||
roleName = role.Name | ||
} | ||
orgPerms := role.Org[orgIDStr] | ||
slim := SlimRole(role) | ||
|
||
orgPerms := role.Org[slim.OrganizationID] | ||
return codersdk.Role{ | ||
Name: roleName, | ||
OrganizationID: orgIDStr, | ||
DisplayName: role.DisplayName, | ||
Name: slim.Name, | ||
OrganizationID: slim.OrganizationID, | ||
DisplayName: slim.DisplayName, | ||
SitePermissions: List(role.Site, RBACPermission), | ||
OrganizationPermissions: List(orgPerms, RBACPermission), | ||
UserPermissions: List(role.User, RBACPermission), | ||
|
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.
review:
string
does not implementfmt.Stringer
:(