Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: Role assign ui fixes #3521

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

Merged
merged 14 commits into from
Aug 16, 2022
Merged

fix: Role assign ui fixes #3521

merged 14 commits into from
Aug 16, 2022

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Aug 15, 2022

What this does

Roles you cannot assign are disabled

Screenshot from 2022-08-15 16-09-40

Fixes

User admin also needs the ability to create organization_members to create a new user. Creating a new user assigns them to the single org atm.

Comment on lines +126 to +129
ResourceRoleAssignment: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
ResourceUser: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
// Full perms to manage org members
ResourceOrganizationMember: {ActionCreate, ActionRead, ActionUpdate, ActionDelete},
Copy link
Member Author

Choose a reason for hiding this comment

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

Needs org_member role to create new users
RoleAssignment to assign roles. They can only assign org_member and member roles right now.

@Emyrk Emyrk marked this pull request as ready for review August 15, 2022 21:18
@Emyrk Emyrk requested a review from a team as a code owner August 15, 2022 21:18
@Emyrk Emyrk requested review from Kira-Pilot and johnstcn August 15, 2022 21:40
export const getSiteRoles = async (): Promise<Array<TypesGen.Role>> => {
const response = await axios.get<Array<TypesGen.Role>>(`/api/v2/users/roles`)
export const getSiteRoles = async (): Promise<Array<TypesGen.AssignableRoles>> => {
const response = await axios.get<Array<TypesGen.AssignableRoles>>(`/api/v2/users/roles`)
Copy link
Member

Choose a reason for hiding this comment

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

Eventually, it would be nice differentiate the two roles endpoints by label a bit more. In the network tab, all I see is "roles" and it's hard to filter or figure out what I'm looking at.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a bad idea

@Kira-Pilot
Copy link
Member

Kira-Pilot commented Aug 15, 2022

Nice job! Do you mind adding two tests?

  1. a new story in RoleSelect.stories.tsx that showcases the disabled state. You can make a new test entity for assignable roles in site/src/testHelpers/entities.ts.
  2. a new test in a new file: site/src/components/RoleSelect/RoleSelect.test.tsx that ensures non-assignable roles are disabled. You can use your new test entity here, too. You should be able to test for disabled state by doing something like:
    expect(stevensListItem).toHaveProperty('disabled', true)

LMK if you need help!

@Emyrk
Copy link
Member Author

Emyrk commented Aug 15, 2022

Nice job! Do you mind adding two tests?

  1. a new story in RoleSelect.stories.tsx that showcases the disabled state. You can make a new test entity for assignable roles in site/src/testHelpers/entities.ts.
  2. a new test in a new file: site/src/components/RoleSelect/RoleSelect.test.tsx that ensures non-assignable roles are disabled. You can use your new test entity here, too. You should be able to test for disabled state by doing something like:
    expect(stevensListItem).toHaveProperty('disabled', true)

LMK if you need help!

Will get on this tomorrow 👍

@@ -251,8 +251,8 @@ func TestRolePermissions(t *testing.T) {
Actions: []rbac.Action{rbac.ActionCreate, rbac.ActionUpdate, rbac.ActionDelete},
Resource: rbac.ResourceRoleAssignment,
AuthorizeMap: map[bool][]authSubject{
true: {admin},
false: {orgAdmin, orgMemberMe, otherOrgAdmin, otherOrgMember, memberMe, templateAdmin, userAdmin},
true: {admin, userAdmin},
Copy link
Member

Choose a reason for hiding this comment

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

I thought we got rid of admin?

Copy link
Member Author

Choose a reason for hiding this comment

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

admin is just the name of the owner user. Forgot to rename the var 👍

export const MockSiteRoles = [MockUserAdminRole, MockAuditorRole]
export const MockAssignableSiteRoles = [MockAssignableOwnerRole, MockAssignableUserAdminRole, MockAssignableAuditorRole]

export function assignableRole(role: TypesGen.Role, assignable: boolean): TypesGen.AssignableRoles {
Copy link
Member

Choose a reason for hiding this comment

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

😍

MockOwnerRole, MockTemplateAdminRole,
MockUserAdminRole,
render
} from "../../testHelpers/renderHelpers"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} from "../../testHelpers/renderHelpers"
} from "testHelpers/renderHelpers"

We're trying to favor absolute paths when we're not in the same directory as whatever we're importing.

Copy link
Member

@Kira-Pilot Kira-Pilot left a comment

Choose a reason for hiding this comment

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

Looking great once CI passes. Thanks for adding those tests.

@Emyrk Emyrk changed the title fix: Role asign ui fix: Role assign ui fixes Aug 16, 2022
@Emyrk Emyrk merged commit 4be61d9 into main Aug 16, 2022
@Emyrk Emyrk deleted the stevenmasley/assign_roles_ui branch August 16, 2022 15:39
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.

3 participants