2022-01-05 16:28:56 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2022-03-16 06:35:32 +00:00
|
|
|
import { Team } from '@/portainer/teams/types';
|
|
|
|
import { Role, User, UserId } from '@/portainer/users/types';
|
|
|
|
|
|
|
|
export function createMockUsers(
|
|
|
|
count: number,
|
|
|
|
roles: Role | Role[] | ((id: UserId) => Role) = () => _.random(1, 3)
|
|
|
|
): User[] {
|
2022-01-05 16:28:56 +00:00
|
|
|
return _.range(1, count + 1).map((value) => ({
|
|
|
|
Id: value,
|
|
|
|
Username: `user${value}`,
|
2022-03-16 06:35:32 +00:00
|
|
|
Role: getRoles(roles, value),
|
2022-01-05 16:28:56 +00:00
|
|
|
UserTheme: '',
|
|
|
|
RoleName: '',
|
|
|
|
AuthenticationMethod: '',
|
|
|
|
Checked: false,
|
|
|
|
EndpointAuthorizations: {},
|
|
|
|
PortainerAuthorizations: {},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-03-16 06:35:32 +00:00
|
|
|
function getRoles(
|
|
|
|
roles: Role | Role[] | ((id: UserId) => Role),
|
|
|
|
id: UserId
|
|
|
|
): Role {
|
|
|
|
if (typeof roles === 'function') {
|
|
|
|
return roles(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof roles === 'number') {
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
return roles[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createMockTeams(count: number): Team[] {
|
2022-01-05 16:28:56 +00:00
|
|
|
return _.range(1, count + 1).map((value) => ({
|
|
|
|
Id: value,
|
|
|
|
Name: `team${value}`,
|
|
|
|
}));
|
|
|
|
}
|
2022-02-24 23:22:56 +00:00
|
|
|
|
|
|
|
export function createMockSubscriptions(count: number) {
|
|
|
|
const subscriptions = _.range(1, count + 1).map((x) => ({
|
|
|
|
id: `/subscriptions/subscription-${x}`,
|
|
|
|
subscriptionId: `subscription-${x}`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return { value: subscriptions };
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createMockResourceGroups(subscription: string, count: number) {
|
|
|
|
const resourceGroups = _.range(1, count + 1).map((x) => ({
|
|
|
|
id: `/subscriptions/${subscription}/resourceGroups/resourceGroup-${x}`,
|
|
|
|
name: `resourcegroup-${x}`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return { value: resourceGroups };
|
|
|
|
}
|