- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
4f18d66
fc8d414
7be7755
1bc2cdf
d88c836
175a03f
3f7e2cb
056fc17
7651a18
dadd284
8988224
521ffcd
dce7f09
cc68903
fa2f704
9bf3298
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -192,7 +192,7 @@ func (r *RootCmd) newCreateAdminUserCommand() *serpent.Command { | ||
HashedPassword: []byte(hashedPassword), | ||
CreatedAt: dbtime.Now(), | ||
UpdatedAt: dbtime.Now(), | ||
RBACRoles: []string{rbac.RoleOwner().String()}, | ||
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. review: | ||
LoginType: database.LoginTypePassword, | ||
}) | ||
if err != nil { | ||
@@ -222,7 +222,7 @@ func (r *RootCmd) newCreateAdminUserCommand() *serpent.Command { | ||
UserID: newUser.ID, | ||
CreatedAt: dbtime.Now(), | ||
UpdatedAt: dbtime.Now(), | ||
Roles: []string{rbac.RoleOrgAdmin()}, | ||
}) | ||
if err != nil { | ||
return xerrors.Errorf("insert organization member: %w", err) | ||
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 _, 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 { | ||
// 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 { | ||
orgID:="" | ||
ifrole.Identifier.OrganizationID !=uuid.Nil { | ||
orgID = role.Identifier.OrganizationID.String() | ||
} | ||
return codersdk.SlimRole{ | ||
DisplayName: role.DisplayName, | ||
Name:role.Identifier.Name, | ||
OrganizationID:orgID, | ||
} | ||
} | ||
func RBACRole(role rbac.Role) codersdk.Role { | ||
slim := SlimRole(role) | ||
orgPerms := role.Org[slim.OrganizationID] | ||
return codersdk.Role{ | ||
Name:slim.Name, | ||
OrganizationID:slim.OrganizationID, | ||
DisplayName:slim.DisplayName, | ||
SitePermissions: List(role.Site, RBACPermission), | ||
OrganizationPermissions: List(orgPerms, RBACPermission), | ||
UserPermissions: List(role.User, RBACPermission), | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.