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

Port changes from release-2.7.patch1 to release-2.7 #11255

Merged
merged 14 commits into from
Jun 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion cypress/e2e/po/components/list-row.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class ListRowPo extends ComponentPo {
column(index: number) {
return this.self().find('td').eq(index);
return this.self().find('td').eq(index).scrollIntoView();
}
}
5 changes: 4 additions & 1 deletion cypress/e2e/po/lists/management.cattle.io.user.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export default class MgmtUsersListPo extends BaseResourceList {
}

clickRowActionMenuItem(name: string, itemLabel:string) {
return this.resourceTable().sortableTable().rowActionMenuOpen(name, 7).getMenuItem(itemLabel)
return this.resourceTable()
.sortableTable()
.rowActionMenuOpen(name, 10)
.getMenuItem(itemLabel)
.click();
}
}
16 changes: 8 additions & 8 deletions cypress/e2e/tests/pages/users-and-auth/users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Users', { tags: '@adminUser' }, () => {

// usersPo.goTo();
usersPo.waitForPage();
usersPo.list().elementWithName(userBaseUsername).should('be.visible');
usersPo.list().elementWithName(userBaseUsername).should('exist');
});

it('can create Standard User and view their details', () => {
Expand All @@ -84,7 +84,7 @@ describe('Users', { tags: '@adminUser' }, () => {
userId = res.response?.body.userId;

usersPo.waitForPage();
usersPo.list().elementWithName(standardUsername).should('be.visible');
usersPo.list().elementWithName(standardUsername).should('exist');

// view user's details
usersPo.list().details(standardUsername, 2).find('a').click();
Expand All @@ -109,11 +109,11 @@ describe('Users', { tags: '@adminUser' }, () => {
// Deactivate user and check state is Inactive
usersPo.goTo();
usersPo.list().clickRowActionMenuItem(standardUsername, 'Deactivate');
usersPo.list().details(standardUsername, 1).should('include.text', 'Inactive');
usersPo.list().details(standardUsername, 1).should('include.text', 'Disabled');

// Activate user and check state is Active
usersPo.list().clickRowActionMenuItem(standardUsername, 'Activate');
usersPo.list().details(standardUsername, 1).should('include.text', 'Active');
usersPo.list().details(standardUsername, 1).should('include.text', 'Enabled');
});

it('can Refresh Group Memberships', () => {
Expand Down Expand Up @@ -192,14 +192,14 @@ describe('Users', { tags: '@adminUser' }, () => {
usersPo.list().selectAll().set();
usersPo.list().deactivate().click();
cy.wait('@updateUsers');
cy.contains('Inactive');
usersPo.list().details('admin', 1).should('include.text', 'Active');
usersPo.list().details(userBaseUsername, 1).should('include.text', 'Inactive');
cy.contains('Disabled');
usersPo.list().details('admin', 1).should('include.text', 'Enabled');
usersPo.list().details(userBaseUsername, 1).should('include.text', 'Disabled');

// Activate user and check state is Active
usersPo.list().activate().click();
cy.wait('@updateUsers');
usersPo.list().details(userBaseUsername, 1).should('include.text', 'Active');
usersPo.list().details(userBaseUsername, 1).should('include.text', 'Enabled');
});

it('can Download YAML', () => {
Expand Down
8 changes: 8 additions & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ suffix:
ib: iB
mib: MiB
gb: GB
ago: ago
revisions: |-
{count, plural,
=1 { Revision }
Expand Down Expand Up @@ -5541,6 +5542,9 @@ tableHeaders:
users: Users
userDisplayName: Display Name
userId: ID
userDeletedIn: Delete After
userDisabledIn: Disable After
userLastLogin: Last Login
userStatus: Status
username: Local Username
value: Value
Expand All @@ -5561,6 +5565,10 @@ target:
placeholder: Select a version

user:
state:
active: 'Enabled'
inactive: 'Disabled'
unknown: 'Unknown'
detail:
username: Username
globalPermissions:
Expand Down
16 changes: 16 additions & 0 deletions shell/components/formatter/LiveDate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export default {
showTooltip: {
type: Boolean,
default: true
},

/**
* Determines if the live date should behave like a countdown by comparing
* the provided value and the current date. When the countdown reaches 0, a
* "-" is rendered.
*/
isCountdown: {
type: Boolean,
default: false,
}
},

Expand Down Expand Up @@ -104,6 +114,12 @@ export default {
return 300;
}

if (this.isCountdown && now.valueOf() > this.dayValue?.valueOf()) {
this.label = '-';

return 300;
}

const diff = diffFrom(this.dayValue, now);
const prefix = (diff.diff < 0 || !this.addPrefix ? '' : '-');

Expand Down
5 changes: 4 additions & 1 deletion shell/config/product/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
STATE, NAME as NAME_COL, NAMESPACE as NAMESPACE_COL, AGE, KEYS,
INGRESS_DEFAULT_BACKEND, INGRESS_TARGET, INGRESS_CLASS,
SPEC_TYPE, TARGET_PORT, SELECTOR, NODE as NODE_COL, TYPE, WORKLOAD_IMAGES, POD_IMAGES,
USER_ID, USERNAME, USER_DISPLAY_NAME, USER_PROVIDER, WORKLOAD_ENDPOINTS, STORAGE_CLASS_DEFAULT,
USER_ID, USERNAME, USER_DISPLAY_NAME, USER_PROVIDER, USER_LAST_LOGIN, USER_DISABLED_IN, USER_DELETED_IN, WORKLOAD_ENDPOINTS, STORAGE_CLASS_DEFAULT,
STORAGE_CLASS_PROVISIONER, PERSISTENT_VOLUME_SOURCE,
HPA_REFERENCE, MIN_REPLICA, MAX_REPLICA, CURRENT_REPLICA,
ACCESS_KEY, DESCRIPTION, EXPIRES, EXPIRY_STATE, SUB_TYPE, AGE_NORMAN, SCOPE_NORMAN, PERSISTENT_VOLUME_CLAIM, RECLAIM_POLICY, PV_REASON, WORKLOAD_HEALTH_SCALE, POD_RESTARTS,
Expand Down Expand Up @@ -259,6 +259,9 @@ export function init(store) {
USER_DISPLAY_NAME,
USER_PROVIDER,
USERNAME,
USER_LAST_LOGIN,
USER_DISABLED_IN,
USER_DELETED_IN,
AGE
]);

Expand Down
27 changes: 27 additions & 0 deletions shell/config/table-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,33 @@ export const USER_PROVIDER = {
sort: 'providerDisplay',
};

export const USER_LAST_LOGIN = {
name: 'user-last-login',
labelKey: 'tableHeaders.userLastLogin',
value: 'userLastLogin',
formatter: 'LiveDate',
formatterOpts: { addSuffix: true },
sort: 'userLastLogin',
};

export const USER_DISABLED_IN = {
name: 'user-disabled-in',
labelKey: 'tableHeaders.userDisabledIn',
value: 'userDisabledInDisplay',
formatter: 'LiveDate',
formatterOpts: { isCountdown: true },
sort: 'userDisabledIn',
};

export const USER_DELETED_IN = {
name: 'user-deleted-in',
labelKey: 'tableHeaders.userDeletedIn',
value: 'userDeletedIn',
formatter: 'LiveDate',
formatterOpts: { isCountdown: true },
sort: 'userDeletedIn',
};

export const USER_ID = {
name: 'user-id',
labelKey: 'tableHeaders.userId',
Expand Down
2 changes: 1 addition & 1 deletion shell/list/management.cattle.io.feature.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default {
},

enableRowActions() {
const schema = this.$store.getters[`management/schemaFor`](MANAGEMENT.SETTING);
const schema = this.$store.getters[`management/schemaFor`](MANAGEMENT.FEATURE);

return schema?.resourceMethods?.includes('PUT');
},
Expand Down
65 changes: 65 additions & 0 deletions shell/models/management.cattle.io.user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NORMAN } from '@shell/config/types';
import HybridModel, { cleanHybridResources } from '@shell/plugins/steve/hybrid-class';
import day from 'dayjs';

export default class User extends HybridModel {
// Preserve description
Expand Down Expand Up @@ -99,6 +100,38 @@ export default class User extends HybridModel {
return this.$rootGetters['i18n/withFallback'](`model.authConfig.provider."${ this.provider }"`, null, this.provider);
}

/**
* Gets the last-login label in milliseconds
* @returns {number}
*/
get userLastLogin() {
return this.metadata?.labels?.['cattle.io/last-login'] * 1000;
}

/**
* Gets the disabled-after label in milliseconds
* @returns {number}
*/
get userDisabledIn() {
return this.metadata?.labels?.['cattle.io/disable-after'] * 1000;
}

/**
* Provides a display value for the userDisabledIn date based on the user
* state.
*/
get userDisabledInDisplay() {
return this.state === 'inactive' ? null : this.userDisabledIn;
}

/**
* Gets the delete-after label in milliseconds
* @returns {number}
*/
get userDeletedIn() {
return this.metadata?.labels?.['cattle.io/delete-after'] * 1000;
}

get state() {
if ( this.enabled === false ) {
return 'inactive';
Expand All @@ -107,6 +140,19 @@ export default class User extends HybridModel {
return this.metadata?.state?.name || 'unknown';
}

get stateDisplay() {
switch (this.state) {
case 'inactive':
return this.t('user.state.inactive');
case 'active':
return this.t('user.state.active');
case 'unknown':
return this.t('user.state.unknown');
default:
return this.state;
}
}

get description() {
return this._description;
}
Expand Down Expand Up @@ -211,6 +257,25 @@ export default class User extends HybridModel {
formatter: 'CopyToClipboard',
content: this.username
},
{ separator: true },
{
label: this.t('tableHeaders.userLastLogin'),
formatter: 'LiveDate',
formatterOpts: { addSuffix: true, suffix: `${ this.t('suffix.ago') } (${ day(this.userLastLogin) })` },
content: this.userLastLogin,
},
{
label: this.t('tableHeaders.userDisabledIn'),
formatter: 'LiveDate',
formatterOpts: { isCountdown: true },
content: this.userDisabledInDisplay,
},
{
label: this.t('tableHeaders.userDeletedIn'),
formatter: 'LiveDate',
formatterOpts: { isCountdown: true },
content: this.userDeletedIn,
},
...this._details
];
}
Expand Down
Loading