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

Resolving a reference to an undefined lockedExist and adding for project memberships with custom permissions #13543

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions cypress/e2e/po/pages/explorer/cluster-project-members.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import PagePo from '@/cypress/e2e/po/pages/page.po';
import BaseResourceList from '@/cypress/e2e/po/lists/base-resource-list.po';
import SelectPrincipalPo from '@/cypress/e2e/po/components/select-principal.po';
import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po';
import RadioGroupInputPo from '@/cypress/e2e/po/components/radio-group-input.po';
import CheckboxInputPo from '@/cypress/e2e/po/components/checkbox-input.po';
import SortableTablePo from '@/cypress/e2e/po/components/sortable-table.po';

export default class ClusterProjectMembersPo extends PagePo {
private static createPath(clusterId: string, tabId: string) {
Expand All @@ -20,6 +23,12 @@ export default class ClusterProjectMembersPo extends PagePo {
return cy.get('.btn.role-primary.pull-right').click();
}

triggerAddProjectMemberAction(projectLabel: string) {
const cleanLabel = projectLabel.replace(' ', '').toLowerCase();

return cy.get(`[data-testid="add-project-member-${ cleanLabel }"]`).click();
}

selectClusterOrProjectMember(name: string) {
const selectClusterOrProjectMember = new SelectPrincipalPo(`[data-testid="cluster-member-select"]`, this.self());

Expand All @@ -28,6 +37,27 @@ export default class ClusterProjectMembersPo extends PagePo {
selectClusterOrProjectMember.clickOptionWithLabel(name);
}

selectProjectCustomPermission() {
const permissionOptions = new RadioGroupInputPo('[data-testid="permission-options"]');

permissionOptions.checkExists();

permissionOptions.set(3);
}

checkTheseProjectCustomPermissions(permissionIndices: number[]) {
permissionIndices.forEach((permissionIndex) => {
const checkbox = new CheckboxInputPo(`[data-testid="custom-permission-${ permissionIndex }"]`);

checkbox.checkExists();
checkbox.set();
});
}

submitProjectCreateButton() {
return cy.get('[data-testid="card-actions-slot"] button.role-primary').click();
}

saveCreateForm(): AsyncButtonPo {
return new AsyncButtonPo('[data-testid="form-save"]', this.self());
}
Expand All @@ -47,4 +77,8 @@ export default class ClusterProjectMembersPo extends PagePo {
listElementWithName(name:string) {
return this.sortableTable().rowElementWithName(name);
}

projectTable() {
return new SortableTablePo('#project-membership [data-testid="sortable-table-list-container"]');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('Cluster Project and Members', { tags: ['@explorer2', '@adminUser'] },
beforeEach(() => {
cy.login();
});
it('Members added to both Cluster Membership should not show "Loading..." next to their names', () => {

it('Should create a new user', () => {
const usersAdmin = new UsersPo('_');
const userCreate = usersAdmin.createEdit();

Expand All @@ -25,6 +26,10 @@ describe('Cluster Project and Members', { tags: ['@explorer2', '@adminUser'] },
userCreate.confirmNewPass().set(standardPassword);
userCreate.saveCreateWithErrorRetry();
usersAdmin.waitForPageWithExactUrl();
});

it('Members added to both Cluster Membership should not show "Loading..." next to their names', () => {
HomePagePo.goTo();

// add user to Cluster membership
const clusterMembership = new ClusterProjectMembersPo('local', 'cluster-membership');
Expand All @@ -34,6 +39,7 @@ describe('Cluster Project and Members', { tags: ['@explorer2', '@adminUser'] },
clusterMembership.waitForPageWithSpecificUrl('/c/local/explorer');
clusterMembership.navToSideMenuEntryByLabel('Cluster and Project Members');
clusterMembership.triggerAddClusterOrProjectMemberAction();

clusterMembership.selectClusterOrProjectMember(username);
cy.intercept('POST', '/v3/clusterroletemplatebindings').as('createClusterMembership');
clusterMembership.saveCreateForm().click();
Expand Down Expand Up @@ -67,4 +73,33 @@ describe('Cluster Project and Members', { tags: ['@explorer2', '@adminUser'] },
clusterMembership.cancelCreateForm().click();
clusterMembership.waitForPageWithExactUrl();
});
it('Can create a member with custom permissions', () => {
// add user to Cluster membership
const projectMembership = new ClusterProjectMembersPo('local', 'project-membership');

projectMembership.goTo();
projectMembership.waitForPageWithSpecificUrl('/c/local/explorer/members#project-membership');
projectMembership.triggerAddProjectMemberAction('system');
projectMembership.selectProjectCustomPermission();
projectMembership.selectClusterOrProjectMember(username);
projectMembership.checkTheseProjectCustomPermissions([0, 1]);

cy.intercept('POST', '/v3/projectroletemplatebindings').as('createProjectMembership');
projectMembership.submitProjectCreateButton();
cy.wait('@createProjectMembership');
cy.get('.modal-overlay').should('not.exist');

cy.get('body tbody').then((el) => {
if (el.find('tr.no-rows').is(':visible')) {
cy.reload();
}

projectMembership.projectTable().rowElementWithName(username).should('have.length', 1);
projectMembership.projectTable().rowElementWithName(username).find('td:nth-of-type(3)').invoke('text')
.then((t) => {
expect(t).to.include('Create Namespaces');
expect(t).to.include('Manage Config Maps');
});
});
});
});
3 changes: 2 additions & 1 deletion shell/components/ExplorerMembers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ export default {
<button
v-if="canEditProjectMembers"
type="button"
class="create-namespace btn btn-sm role-secondary mr-10 right"
class="btn btn-sm role-secondary mr-10 right"
:data-testid="`add-project-member-${getProjectLabel(group).replace(' ', '').toLowerCase()}`"
@click="addProjectMember(group)"
>
{{ t('members.createActionLabel') }}
Expand Down
9 changes: 6 additions & 3 deletions shell/components/form/ProjectMemberEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default {
return this.customPermissions.reduce((acc, customPermissionsItem) => {
const lockedExist = this.roleTemplates.find((roleTemplateItem) => roleTemplateItem.id === customPermissionsItem.key);

if (lockedExist.locked) {
if (lockedExist && lockedExist.locked) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line is the actual fix. Everything else is just instrumenting/testing.

customPermissionsItem['locked'] = true;
customPermissionsItem['tooltip'] = this.t('members.clusterPermissions.custom.lockedRole');
}
Expand Down Expand Up @@ -261,6 +261,7 @@ export default {
<div class="row mt-10">
<div class="col span-12">
<SelectPrincipal
data-testid="cluster-member-select"
project
class="mb-20"
:mode="mode"
Expand All @@ -285,6 +286,7 @@ export default {
<template v-slot:body>
<RadioGroup
v-model:value="value.permissionGroup"
data-testid="permission-options"
:options="options"
name="permission-group"
/>
Expand All @@ -294,11 +296,12 @@ export default {
:class="{'two-column': useTwoColumnsForCustom}"
>
<div
v-for="(permission, i) in customPermissionsUpdate"
:key="i"
v-for="(permission, i) in customPermissionsUpdate"
:key="i"
>
<Checkbox
v-model:value="permission.value"
:data-testid="`custom-permission-${i}`"
:disabled="permission.locked"
class="mb-5"
:label="permission.label"
Expand Down
Loading