mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-10 07:58:15 -05:00
fix: review changes
This commit is contained in:
@@ -2,12 +2,12 @@ import { z } from "zod";
|
||||
|
||||
import { GroupsSchema, IdentitiesSchema, OrgMembershipRole, ProjectsSchema, UsersSchema } from "@app/db/schemas";
|
||||
import {
|
||||
EFilterMemberType,
|
||||
EFilterReturnedIdentities,
|
||||
EFilterReturnedProjects,
|
||||
EFilterReturnedUsers,
|
||||
EGroupMembersOrderBy,
|
||||
EGroupProjectsOrderBy
|
||||
FilterMemberType,
|
||||
FilterReturnedIdentities,
|
||||
FilterReturnedProjects,
|
||||
FilterReturnedUsers,
|
||||
GroupMembersOrderBy,
|
||||
GroupProjectsOrderBy
|
||||
} from "@app/ee/services/group/group-types";
|
||||
import { ApiDocsTags, GROUPS } from "@app/lib/api-docs";
|
||||
import { OrderByDirection } from "@app/lib/types";
|
||||
@@ -16,6 +16,11 @@ import { slugSchema } from "@app/server/lib/schemas";
|
||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
|
||||
const GroupIdentityResponseSchema = IdentitiesSchema.pick({
|
||||
id: true,
|
||||
name: true
|
||||
});
|
||||
|
||||
export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
server.route({
|
||||
url: "/",
|
||||
@@ -194,7 +199,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
limit: z.coerce.number().min(1).max(100).default(10).describe(GROUPS.LIST_USERS.limit),
|
||||
username: z.string().trim().optional().describe(GROUPS.LIST_USERS.username),
|
||||
search: z.string().trim().optional().describe(GROUPS.LIST_USERS.search),
|
||||
filter: z.nativeEnum(EFilterReturnedUsers).optional().describe(GROUPS.LIST_USERS.filterUsers)
|
||||
filter: z.nativeEnum(FilterReturnedUsers).optional().describe(GROUPS.LIST_USERS.filterUsers)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@@ -205,12 +210,10 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
lastName: true,
|
||||
id: true
|
||||
})
|
||||
.merge(
|
||||
z.object({
|
||||
isPartOfGroup: z.boolean(),
|
||||
joinedGroupAt: z.date().nullable()
|
||||
})
|
||||
)
|
||||
.extend({
|
||||
isPartOfGroup: z.boolean(),
|
||||
joinedGroupAt: z.date().nullable()
|
||||
})
|
||||
.array(),
|
||||
totalCount: z.number()
|
||||
})
|
||||
@@ -247,21 +250,14 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
offset: z.coerce.number().min(0).default(0).describe(GROUPS.LIST_IDENTITIES.offset),
|
||||
limit: z.coerce.number().min(1).max(100).default(10).describe(GROUPS.LIST_IDENTITIES.limit),
|
||||
search: z.string().trim().optional().describe(GROUPS.LIST_IDENTITIES.search),
|
||||
filter: z.nativeEnum(EFilterReturnedIdentities).optional().describe(GROUPS.LIST_IDENTITIES.filterIdentities)
|
||||
filter: z.nativeEnum(FilterReturnedIdentities).optional().describe(GROUPS.LIST_IDENTITIES.filterIdentities)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
identities: IdentitiesSchema.pick({
|
||||
id: true,
|
||||
name: true
|
||||
})
|
||||
.merge(
|
||||
z.object({
|
||||
isPartOfGroup: z.boolean(),
|
||||
joinedGroupAt: z.date().nullable()
|
||||
})
|
||||
)
|
||||
.array(),
|
||||
identities: GroupIdentityResponseSchema.extend({
|
||||
isPartOfGroup: z.boolean(),
|
||||
joinedGroupAt: z.date().nullable()
|
||||
}).array(),
|
||||
totalCount: z.number()
|
||||
})
|
||||
}
|
||||
@@ -298,13 +294,13 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
limit: z.coerce.number().min(1).max(100).default(10).describe(GROUPS.LIST_MEMBERS.limit),
|
||||
search: z.string().trim().optional().describe(GROUPS.LIST_MEMBERS.search),
|
||||
orderBy: z
|
||||
.nativeEnum(EGroupMembersOrderBy)
|
||||
.default(EGroupMembersOrderBy.Name)
|
||||
.nativeEnum(GroupMembersOrderBy)
|
||||
.default(GroupMembersOrderBy.Name)
|
||||
.optional()
|
||||
.describe(GROUPS.LIST_MEMBERS.orderBy),
|
||||
orderDirection: z.nativeEnum(OrderByDirection).optional().describe(GROUPS.LIST_MEMBERS.orderDirection),
|
||||
memberTypeFilter: z
|
||||
.union([z.nativeEnum(EFilterMemberType), z.array(z.nativeEnum(EFilterMemberType))])
|
||||
.union([z.nativeEnum(FilterMemberType), z.array(z.nativeEnum(FilterMemberType))])
|
||||
.optional()
|
||||
.describe(GROUPS.LIST_MEMBERS.memberTypeFilter)
|
||||
.transform((val) => {
|
||||
@@ -322,21 +318,14 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
id: true
|
||||
}).merge(
|
||||
z.object({
|
||||
joinedGroupAt: z.date().nullable(),
|
||||
memberType: z.literal("user")
|
||||
})
|
||||
),
|
||||
IdentitiesSchema.pick({
|
||||
id: true,
|
||||
name: true
|
||||
}).merge(
|
||||
z.object({
|
||||
joinedGroupAt: z.date().nullable(),
|
||||
memberType: z.literal("identity")
|
||||
})
|
||||
)
|
||||
}).extend({
|
||||
joinedGroupAt: z.date().nullable(),
|
||||
memberType: z.literal("user")
|
||||
}),
|
||||
GroupIdentityResponseSchema.extend({
|
||||
joinedGroupAt: z.date().nullable(),
|
||||
memberType: z.literal("identity")
|
||||
})
|
||||
])
|
||||
.array(),
|
||||
totalCount: z.number()
|
||||
@@ -374,10 +363,10 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
offset: z.coerce.number().min(0).default(0).describe(GROUPS.LIST_PROJECTS.offset),
|
||||
limit: z.coerce.number().min(1).max(100).default(10).describe(GROUPS.LIST_PROJECTS.limit),
|
||||
search: z.string().trim().optional().describe(GROUPS.LIST_PROJECTS.search),
|
||||
filter: z.nativeEnum(EFilterReturnedProjects).optional().describe(GROUPS.LIST_PROJECTS.filterProjects),
|
||||
filter: z.nativeEnum(FilterReturnedProjects).optional().describe(GROUPS.LIST_PROJECTS.filterProjects),
|
||||
orderBy: z
|
||||
.nativeEnum(EGroupProjectsOrderBy)
|
||||
.default(EGroupProjectsOrderBy.Name)
|
||||
.nativeEnum(GroupProjectsOrderBy)
|
||||
.default(GroupProjectsOrderBy.Name)
|
||||
.describe(GROUPS.LIST_PROJECTS.orderBy),
|
||||
orderDirection: z
|
||||
.nativeEnum(OrderByDirection)
|
||||
@@ -393,11 +382,9 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
description: true,
|
||||
type: true
|
||||
})
|
||||
.merge(
|
||||
z.object({
|
||||
joinedGroupAt: z.date().nullable()
|
||||
})
|
||||
)
|
||||
.extend({
|
||||
joinedGroupAt: z.date().nullable()
|
||||
})
|
||||
.array(),
|
||||
totalCount: z.number()
|
||||
})
|
||||
@@ -470,10 +457,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
identityId: z.string().trim().describe(GROUPS.ADD_IDENTITY.identityId)
|
||||
}),
|
||||
response: {
|
||||
200: IdentitiesSchema.pick({
|
||||
id: true,
|
||||
name: true
|
||||
})
|
||||
200: GroupIdentityResponseSchema
|
||||
}
|
||||
},
|
||||
handler: async (req) => {
|
||||
@@ -543,10 +527,7 @@ export const registerGroupRouter = async (server: FastifyZodProvider) => {
|
||||
identityId: z.string().trim().describe(GROUPS.DELETE_IDENTITY.identityId)
|
||||
}),
|
||||
response: {
|
||||
200: IdentitiesSchema.pick({
|
||||
id: true,
|
||||
name: true
|
||||
})
|
||||
200: GroupIdentityResponseSchema
|
||||
}
|
||||
},
|
||||
handler: async (req) => {
|
||||
|
||||
@@ -7,12 +7,12 @@ import { buildFindFilter, ormify, selectAllTableCols, TFindFilter, TFindOpt } fr
|
||||
import { OrderByDirection } from "@app/lib/types";
|
||||
|
||||
import {
|
||||
EFilterMemberType,
|
||||
EFilterReturnedIdentities,
|
||||
EFilterReturnedProjects,
|
||||
EFilterReturnedUsers,
|
||||
EGroupMembersOrderBy,
|
||||
EGroupProjectsOrderBy
|
||||
FilterMemberType,
|
||||
FilterReturnedIdentities,
|
||||
FilterReturnedProjects,
|
||||
FilterReturnedUsers,
|
||||
GroupMembersOrderBy,
|
||||
GroupProjectsOrderBy
|
||||
} from "./group-types";
|
||||
|
||||
export type TGroupDALFactory = ReturnType<typeof groupDALFactory>;
|
||||
@@ -92,7 +92,7 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
limit?: number;
|
||||
username?: string;
|
||||
search?: string;
|
||||
filter?: EFilterReturnedUsers;
|
||||
filter?: FilterReturnedUsers;
|
||||
}) => {
|
||||
try {
|
||||
const query = db
|
||||
@@ -134,10 +134,10 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
|
||||
switch (filter) {
|
||||
case EFilterReturnedUsers.EXISTING_MEMBERS:
|
||||
case FilterReturnedUsers.EXISTING_MEMBERS:
|
||||
void query.andWhere(`${TableName.UserGroupMembership}.createdAt`, "is not", null);
|
||||
break;
|
||||
case EFilterReturnedUsers.NON_MEMBERS:
|
||||
case FilterReturnedUsers.NON_MEMBERS:
|
||||
void query.andWhere(`${TableName.UserGroupMembership}.createdAt`, "is", null);
|
||||
break;
|
||||
default:
|
||||
@@ -162,7 +162,7 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
username: memberUsername,
|
||||
firstName,
|
||||
lastName,
|
||||
isPartOfGroup: !!memberGroupId,
|
||||
isPartOfGroup: Boolean(memberGroupId),
|
||||
joinedGroupAt
|
||||
})
|
||||
),
|
||||
@@ -187,7 +187,7 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
search?: string;
|
||||
filter?: EFilterReturnedIdentities;
|
||||
filter?: FilterReturnedIdentities;
|
||||
}) => {
|
||||
try {
|
||||
const query = db
|
||||
@@ -224,10 +224,10 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
|
||||
switch (filter) {
|
||||
case EFilterReturnedIdentities.ASSIGNED_IDENTITIES:
|
||||
case FilterReturnedIdentities.ASSIGNED_IDENTITIES:
|
||||
void query.andWhere(`${TableName.IdentityGroupMembership}.createdAt`, "is not", null);
|
||||
break;
|
||||
case EFilterReturnedIdentities.NON_ASSIGNED_IDENTITIES:
|
||||
case FilterReturnedIdentities.NON_ASSIGNED_IDENTITIES:
|
||||
void query.andWhere(`${TableName.IdentityGroupMembership}.createdAt`, "is", null);
|
||||
break;
|
||||
default:
|
||||
@@ -240,7 +240,7 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
identities: identities.map(({ name, identityId, joinedGroupAt, groupId: identityGroupId }) => ({
|
||||
id: identityId,
|
||||
name,
|
||||
isPartOfGroup: !!identityGroupId,
|
||||
isPartOfGroup: Boolean(identityGroupId),
|
||||
joinedGroupAt
|
||||
})),
|
||||
// @ts-expect-error col select is raw and not strongly typed
|
||||
@@ -257,7 +257,7 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
offset = 0,
|
||||
limit,
|
||||
search,
|
||||
orderBy = EGroupMembersOrderBy.Name,
|
||||
orderBy = GroupMembersOrderBy.Name,
|
||||
orderDirection = OrderByDirection.ASC,
|
||||
memberTypeFilter
|
||||
}: {
|
||||
@@ -266,9 +266,9 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
search?: string;
|
||||
orderBy?: EGroupMembersOrderBy;
|
||||
orderBy?: GroupMembersOrderBy;
|
||||
orderDirection?: OrderByDirection;
|
||||
memberTypeFilter?: EFilterMemberType[];
|
||||
memberTypeFilter?: FilterMemberType[];
|
||||
}) => {
|
||||
try {
|
||||
// Query for users - subquery for UNION
|
||||
@@ -345,9 +345,9 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
let unionQuery;
|
||||
|
||||
const includeUsers =
|
||||
!memberTypeFilter || memberTypeFilter.length === 0 || memberTypeFilter.includes(EFilterMemberType.USERS);
|
||||
!memberTypeFilter || memberTypeFilter.length === 0 || memberTypeFilter.includes(FilterMemberType.USERS);
|
||||
const includeIdentities =
|
||||
!memberTypeFilter || memberTypeFilter.length === 0 || memberTypeFilter.includes(EFilterMemberType.IDENTITIES);
|
||||
!memberTypeFilter || memberTypeFilter.length === 0 || memberTypeFilter.includes(FilterMemberType.IDENTITIES);
|
||||
|
||||
if (includeUsers && includeIdentities) {
|
||||
unionQuery = db.raw("(? UNION ALL ?)", [usersSubquery, identitiesSubquery]);
|
||||
@@ -366,7 +366,7 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
.from(db.raw("(?) as combined_members", [unionQuery]));
|
||||
|
||||
if (orderBy) {
|
||||
if (orderBy === EGroupMembersOrderBy.Name) {
|
||||
if (orderBy === GroupMembersOrderBy.Name) {
|
||||
const orderDirectionClause = orderDirection === OrderByDirection.ASC ? "ASC" : "DESC";
|
||||
void combinedQuery.orderByRaw(`LOWER("sortName") ${orderDirectionClause}`);
|
||||
}
|
||||
@@ -439,8 +439,8 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
search?: string;
|
||||
filter?: EFilterReturnedProjects;
|
||||
orderBy?: EGroupProjectsOrderBy;
|
||||
filter?: FilterReturnedProjects;
|
||||
orderBy?: GroupProjectsOrderBy;
|
||||
orderDirection?: OrderByDirection;
|
||||
}) => {
|
||||
try {
|
||||
@@ -482,10 +482,10 @@ export const groupDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
|
||||
switch (filter) {
|
||||
case EFilterReturnedProjects.ASSIGNED_PROJECTS:
|
||||
case FilterReturnedProjects.ASSIGNED_PROJECTS:
|
||||
void query.whereNotNull(`${TableName.Membership}.id`);
|
||||
break;
|
||||
case EFilterReturnedProjects.UNASSIGNED_PROJECTS:
|
||||
case FilterReturnedProjects.UNASSIGNED_PROJECTS:
|
||||
void query.whereNull(`${TableName.Membership}.id`);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -504,7 +504,7 @@ export const removeIdentitiesFromGroup = async ({
|
||||
|
||||
if (foundIdentities.length !== identityIdsArray.length) {
|
||||
throw new NotFoundError({
|
||||
message: `Identities not found`
|
||||
message: `Machine identities not found`
|
||||
});
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ export const removeIdentitiesFromGroup = async ({
|
||||
identityIdsArray.forEach((identityId) => {
|
||||
if (!existingIdentityGroupMembershipsIdentityIdsSet.has(identityId)) {
|
||||
throw new ForbiddenRequestError({
|
||||
message: `Identities are not part of the group ${group.slug}`
|
||||
message: `Machine identities are not part of the group ${group.slug}`
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -43,7 +43,7 @@ export type TListGroupUsersDTO = {
|
||||
limit: number;
|
||||
username?: string;
|
||||
search?: string;
|
||||
filter?: EFilterReturnedUsers;
|
||||
filter?: FilterReturnedUsers;
|
||||
} & TGenericPermission;
|
||||
|
||||
export type TListGroupIdentitiesDTO = {
|
||||
@@ -51,7 +51,7 @@ export type TListGroupIdentitiesDTO = {
|
||||
offset: number;
|
||||
limit: number;
|
||||
search?: string;
|
||||
filter?: EFilterReturnedIdentities;
|
||||
filter?: FilterReturnedIdentities;
|
||||
} & TGenericPermission;
|
||||
|
||||
export type TListGroupMembersDTO = {
|
||||
@@ -59,9 +59,9 @@ export type TListGroupMembersDTO = {
|
||||
offset: number;
|
||||
limit: number;
|
||||
search?: string;
|
||||
orderBy?: EGroupMembersOrderBy;
|
||||
orderBy?: GroupMembersOrderBy;
|
||||
orderDirection?: OrderByDirection;
|
||||
memberTypeFilter?: EFilterMemberType[];
|
||||
memberTypeFilter?: FilterMemberType[];
|
||||
} & TGenericPermission;
|
||||
|
||||
export type TListGroupProjectsDTO = {
|
||||
@@ -69,8 +69,8 @@ export type TListGroupProjectsDTO = {
|
||||
offset: number;
|
||||
limit: number;
|
||||
search?: string;
|
||||
filter?: EFilterReturnedProjects;
|
||||
orderBy?: EGroupProjectsOrderBy;
|
||||
filter?: FilterReturnedProjects;
|
||||
orderBy?: GroupProjectsOrderBy;
|
||||
orderDirection?: OrderByDirection;
|
||||
} & TGenericPermission;
|
||||
|
||||
@@ -165,30 +165,30 @@ export type TConvertPendingGroupAdditionsToGroupMemberships = {
|
||||
tx?: Knex;
|
||||
};
|
||||
|
||||
export enum EFilterReturnedUsers {
|
||||
export enum FilterReturnedUsers {
|
||||
EXISTING_MEMBERS = "existingMembers",
|
||||
NON_MEMBERS = "nonMembers"
|
||||
}
|
||||
|
||||
export enum EFilterReturnedIdentities {
|
||||
export enum FilterReturnedIdentities {
|
||||
ASSIGNED_IDENTITIES = "assignedIdentities",
|
||||
NON_ASSIGNED_IDENTITIES = "nonAssignedIdentities"
|
||||
}
|
||||
|
||||
export enum EFilterReturnedProjects {
|
||||
export enum FilterReturnedProjects {
|
||||
ASSIGNED_PROJECTS = "assignedProjects",
|
||||
UNASSIGNED_PROJECTS = "unassignedProjects"
|
||||
}
|
||||
|
||||
export enum EGroupProjectsOrderBy {
|
||||
export enum GroupProjectsOrderBy {
|
||||
Name = "name"
|
||||
}
|
||||
|
||||
export enum EGroupMembersOrderBy {
|
||||
export enum GroupMembersOrderBy {
|
||||
Name = "name"
|
||||
}
|
||||
|
||||
export enum EFilterMemberType {
|
||||
export enum FilterMemberType {
|
||||
USERS = "users",
|
||||
IDENTITIES = "identities"
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
TemporaryPermissionMode,
|
||||
UsersSchema
|
||||
} from "@app/db/schemas";
|
||||
import { EFilterReturnedUsers } from "@app/ee/services/group/group-types";
|
||||
import { FilterReturnedUsers } from "@app/ee/services/group/group-types";
|
||||
import { ApiDocsTags, GROUPS, PROJECTS } from "@app/lib/api-docs";
|
||||
import { ms } from "@app/lib/ms";
|
||||
import { isUuidV4 } from "@app/lib/validator";
|
||||
@@ -368,7 +368,7 @@ export const registerGroupProjectRouter = async (server: FastifyZodProvider) =>
|
||||
limit: z.coerce.number().min(1).max(100).default(10).describe(GROUPS.LIST_USERS.limit),
|
||||
username: z.string().trim().optional().describe(GROUPS.LIST_USERS.username),
|
||||
search: z.string().trim().optional().describe(GROUPS.LIST_USERS.search),
|
||||
filter: z.nativeEnum(EFilterReturnedUsers).optional().describe(GROUPS.LIST_USERS.filterUsers)
|
||||
filter: z.nativeEnum(FilterReturnedUsers).optional().describe(GROUPS.LIST_USERS.filterUsers)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
TemporaryPermissionMode,
|
||||
UsersSchema
|
||||
} from "@app/db/schemas";
|
||||
import { EFilterReturnedUsers } from "@app/ee/services/group/group-types";
|
||||
import { FilterReturnedUsers } from "@app/ee/services/group/group-types";
|
||||
import { ApiDocsTags, GROUPS, PROJECTS } from "@app/lib/api-docs";
|
||||
import { ms } from "@app/lib/ms";
|
||||
import { isUuidV4 } from "@app/lib/validator";
|
||||
@@ -367,7 +367,7 @@ export const registerDeprecatedGroupProjectRouter = async (server: FastifyZodPro
|
||||
limit: z.coerce.number().min(1).max(100).default(10).describe(GROUPS.LIST_USERS.limit),
|
||||
username: z.string().trim().optional().describe(GROUPS.LIST_USERS.username),
|
||||
search: z.string().trim().optional().describe(GROUPS.LIST_USERS.search),
|
||||
filter: z.nativeEnum(EFilterReturnedUsers).optional().describe(GROUPS.LIST_USERS.filterUsers)
|
||||
filter: z.nativeEnum(FilterReturnedUsers).optional().describe(GROUPS.LIST_USERS.filterUsers)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
|
||||
@@ -4,11 +4,11 @@ import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { OrderByDirection } from "../generic/types";
|
||||
import {
|
||||
EFilterMemberType,
|
||||
EFilterReturnedIdentities,
|
||||
EFilterReturnedProjects,
|
||||
EFilterReturnedUsers,
|
||||
EGroupMembersOrderBy,
|
||||
FilterMemberType,
|
||||
FilterReturnedIdentities,
|
||||
FilterReturnedProjects,
|
||||
FilterReturnedUsers,
|
||||
GroupMembersOrderBy,
|
||||
TGroup,
|
||||
TGroupIdentity,
|
||||
TGroupMember,
|
||||
@@ -32,7 +32,7 @@ export const groupKeys = {
|
||||
offset: number;
|
||||
limit: number;
|
||||
search: string;
|
||||
filter?: EFilterReturnedUsers;
|
||||
filter?: FilterReturnedUsers;
|
||||
}) => [...groupKeys.forGroupUserMemberships(slug), { offset, limit, search, filter }] as const,
|
||||
allGroupIdentitiesMemberships: () => ["group-identities-memberships"] as const,
|
||||
forGroupIdentitiesMemberships: (slug: string) =>
|
||||
@@ -48,7 +48,7 @@ export const groupKeys = {
|
||||
offset: number;
|
||||
limit: number;
|
||||
search: string;
|
||||
filter?: EFilterReturnedIdentities;
|
||||
filter?: FilterReturnedIdentities;
|
||||
}) =>
|
||||
[...groupKeys.forGroupIdentitiesMemberships(slug), { offset, limit, search, filter }] as const,
|
||||
allGroupMembers: () => ["group-members"] as const,
|
||||
@@ -66,9 +66,9 @@ export const groupKeys = {
|
||||
offset: number;
|
||||
limit: number;
|
||||
search: string;
|
||||
orderBy?: EGroupMembersOrderBy;
|
||||
orderBy?: GroupMembersOrderBy;
|
||||
orderDirection?: OrderByDirection;
|
||||
memberTypeFilter?: EFilterMemberType[];
|
||||
memberTypeFilter?: FilterMemberType[];
|
||||
}) =>
|
||||
[
|
||||
...groupKeys.forGroupMembers(slug),
|
||||
@@ -89,7 +89,7 @@ export const groupKeys = {
|
||||
offset: number;
|
||||
limit: number;
|
||||
search: string;
|
||||
filter?: EFilterReturnedProjects;
|
||||
filter?: FilterReturnedProjects;
|
||||
orderBy?: string;
|
||||
orderDirection?: OrderByDirection;
|
||||
}) =>
|
||||
@@ -124,7 +124,7 @@ export const useListGroupUsers = ({
|
||||
offset: number;
|
||||
limit: number;
|
||||
search: string;
|
||||
filter?: EFilterReturnedUsers;
|
||||
filter?: FilterReturnedUsers;
|
||||
}) => {
|
||||
return useQuery({
|
||||
queryKey: groupKeys.specificGroupUserMemberships({
|
||||
@@ -171,9 +171,9 @@ export const useListGroupMembers = ({
|
||||
offset: number;
|
||||
limit: number;
|
||||
search: string;
|
||||
orderBy?: EGroupMembersOrderBy;
|
||||
orderBy?: GroupMembersOrderBy;
|
||||
orderDirection?: OrderByDirection;
|
||||
memberTypeFilter?: EFilterMemberType[];
|
||||
memberTypeFilter?: FilterMemberType[];
|
||||
}) => {
|
||||
return useQuery({
|
||||
queryKey: groupKeys.specificGroupMembers({
|
||||
@@ -227,7 +227,7 @@ export const useListGroupIdentities = ({
|
||||
offset: number;
|
||||
limit: number;
|
||||
search: string;
|
||||
filter?: EFilterReturnedIdentities;
|
||||
filter?: FilterReturnedIdentities;
|
||||
}) => {
|
||||
return useQuery({
|
||||
queryKey: groupKeys.specificGroupIdentitiesMemberships({
|
||||
@@ -274,7 +274,7 @@ export const useListGroupProjects = ({
|
||||
search: string;
|
||||
orderBy?: string;
|
||||
orderDirection?: OrderByDirection;
|
||||
filter?: EFilterReturnedProjects;
|
||||
filter?: FilterReturnedProjects;
|
||||
}) => {
|
||||
return useQuery({
|
||||
queryKey: groupKeys.specificGroupProjects({
|
||||
|
||||
@@ -51,24 +51,24 @@ export type TGroupUser = {
|
||||
joinedGroupAt: Date;
|
||||
};
|
||||
|
||||
export enum EGroupMemberType {
|
||||
export enum GroupMemberType {
|
||||
USER = "user",
|
||||
IDENTITY = "identity"
|
||||
}
|
||||
|
||||
export type TGroupMemberUser = TGroupUser & {
|
||||
memberType: EGroupMemberType.USER;
|
||||
memberType: GroupMemberType.USER;
|
||||
};
|
||||
|
||||
export type TGroupMemberIdentity = TGroupIdentity & {
|
||||
memberType: EGroupMemberType.IDENTITY;
|
||||
memberType: GroupMemberType.IDENTITY;
|
||||
};
|
||||
|
||||
export enum EGroupMembersOrderBy {
|
||||
export enum GroupMembersOrderBy {
|
||||
Name = "name"
|
||||
}
|
||||
|
||||
export enum EFilterMemberType {
|
||||
export enum FilterMemberType {
|
||||
USERS = "users",
|
||||
IDENTITIES = "identities"
|
||||
}
|
||||
@@ -90,17 +90,17 @@ export type TGroupProject = {
|
||||
joinedGroupAt: Date;
|
||||
};
|
||||
|
||||
export enum EFilterReturnedUsers {
|
||||
export enum FilterReturnedUsers {
|
||||
EXISTING_MEMBERS = "existingMembers",
|
||||
NON_MEMBERS = "nonMembers"
|
||||
}
|
||||
|
||||
export enum EFilterReturnedIdentities {
|
||||
export enum FilterReturnedIdentities {
|
||||
ASSIGNED_IDENTITIES = "assignedIdentities",
|
||||
NON_ASSIGNED_IDENTITIES = "nonAssignedIdentities"
|
||||
}
|
||||
|
||||
export enum EFilterReturnedProjects {
|
||||
export enum FilterReturnedProjects {
|
||||
ASSIGNED_PROJECTS = "assignedProjects",
|
||||
UNASSIGNED_PROJECTS = "unassignedProjects"
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
import { OrgPermissionGroupActions, OrgPermissionSubjects } from "@app/context";
|
||||
import { useResetPageHelper } from "@app/hooks";
|
||||
import { useAddIdentityToGroup, useListGroupIdentities } from "@app/hooks/api";
|
||||
import { EFilterReturnedIdentities, TGroupIdentity } from "@app/hooks/api/groups/types";
|
||||
import { FilterReturnedIdentities, TGroupIdentity } from "@app/hooks/api/groups/types";
|
||||
|
||||
type Props = {
|
||||
groupId: string;
|
||||
@@ -38,7 +38,7 @@ export const AddGroupIdentitiesTab = ({ groupId, groupSlug, search }: Props) =>
|
||||
offset,
|
||||
limit: perPage,
|
||||
search,
|
||||
filter: EFilterReturnedIdentities.NON_ASSIGNED_IDENTITIES
|
||||
filter: FilterReturnedIdentities.NON_ASSIGNED_IDENTITIES
|
||||
});
|
||||
|
||||
const { totalCount = 0 } = data ?? {};
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
import { OrgPermissionGroupActions, OrgPermissionSubjects } from "@app/context";
|
||||
import { useResetPageHelper } from "@app/hooks";
|
||||
import { useAddUserToGroup, useListGroupUsers } from "@app/hooks/api";
|
||||
import { EFilterReturnedUsers } from "@app/hooks/api/groups/types";
|
||||
import { FilterReturnedUsers } from "@app/hooks/api/groups/types";
|
||||
|
||||
type Props = {
|
||||
groupId: string;
|
||||
@@ -38,7 +38,7 @@ export const AddGroupUsersTab = ({ groupId, groupSlug, search }: Props) => {
|
||||
offset,
|
||||
limit: perPage,
|
||||
search,
|
||||
filter: EFilterReturnedUsers.NON_MEMBERS
|
||||
filter: FilterReturnedUsers.NON_MEMBERS
|
||||
});
|
||||
|
||||
const { totalCount = 0 } = data ?? {};
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
useAddGroupToWorkspace as useAddProjectToGroup,
|
||||
useListGroupProjects
|
||||
} from "@app/hooks/api";
|
||||
import { EFilterReturnedProjects } from "@app/hooks/api/groups/types";
|
||||
import { FilterReturnedProjects } from "@app/hooks/api/groups/types";
|
||||
import { ProjectType } from "@app/hooks/api/projects/types";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
@@ -57,7 +57,7 @@ export const AddGroupProjectModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
offset,
|
||||
limit: perPage,
|
||||
search: debouncedSearch,
|
||||
filter: EFilterReturnedProjects.UNASSIGNED_PROJECTS
|
||||
filter: FilterReturnedProjects.UNASSIGNED_PROJECTS
|
||||
});
|
||||
|
||||
const { totalCount = 0 } = data ?? {};
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
useRemoveIdentityFromGroup,
|
||||
useRemoveUserFromGroup
|
||||
} from "@app/hooks/api";
|
||||
import { EGroupMemberType } from "@app/hooks/api/groups/types";
|
||||
import { GroupMemberType } from "@app/hooks/api/groups/types";
|
||||
import { usePopUp } from "@app/hooks/usePopUp";
|
||||
|
||||
import { AddGroupMembersModal } from "../AddGroupMemberModal";
|
||||
@@ -22,8 +22,8 @@ type Props = {
|
||||
};
|
||||
|
||||
type RemoveMemberData =
|
||||
| { memberType: EGroupMemberType.USER; username: string }
|
||||
| { memberType: EGroupMemberType.IDENTITY; identityId: string; name: string };
|
||||
| { memberType: GroupMemberType.USER; username: string }
|
||||
| { memberType: GroupMemberType.IDENTITY; identityId: string; name: string };
|
||||
|
||||
export const GroupMembersSection = ({ groupId, groupSlug }: Props) => {
|
||||
const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp([
|
||||
@@ -40,7 +40,7 @@ export const GroupMembersSection = ({ groupId, groupSlug }: Props) => {
|
||||
const { mutateAsync: removeIdentityFromGroupMutateAsync } = useRemoveIdentityFromGroup();
|
||||
|
||||
const handleRemoveMemberFromGroup = async (memberData: RemoveMemberData) => {
|
||||
if (memberData.memberType === EGroupMemberType.USER) {
|
||||
if (memberData.memberType === GroupMemberType.USER) {
|
||||
await removeUserFromGroupMutateAsync({
|
||||
groupId,
|
||||
username: memberData.username,
|
||||
@@ -69,7 +69,7 @@ export const GroupMembersSection = ({ groupId, groupSlug }: Props) => {
|
||||
|
||||
const getMemberName = (memberData: RemoveMemberData) => {
|
||||
if (!memberData) return "";
|
||||
if (memberData.memberType === EGroupMemberType.USER) {
|
||||
if (memberData.memberType === GroupMemberType.USER) {
|
||||
return memberData.username;
|
||||
}
|
||||
return memberData.name;
|
||||
|
||||
@@ -44,9 +44,9 @@ import { useOidcManageGroupMembershipsEnabled } from "@app/hooks/api";
|
||||
import { OrderByDirection } from "@app/hooks/api/generic/types";
|
||||
import { useListGroupMembers } from "@app/hooks/api/groups/queries";
|
||||
import {
|
||||
EFilterMemberType,
|
||||
EGroupMembersOrderBy,
|
||||
EGroupMemberType
|
||||
FilterMemberType,
|
||||
GroupMembersOrderBy,
|
||||
GroupMemberType
|
||||
} from "@app/hooks/api/groups/types";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
@@ -74,11 +74,11 @@ export const GroupMembersTable = ({ groupId, groupSlug, handlePopUpOpen }: Props
|
||||
orderDirection,
|
||||
toggleOrderDirection,
|
||||
orderBy
|
||||
} = usePagination(EGroupMembersOrderBy.Name, {
|
||||
} = usePagination(GroupMembersOrderBy.Name, {
|
||||
initPerPage: getUserTablePreference("groupMembersTable", PreferenceKey.PerPage, 20)
|
||||
});
|
||||
|
||||
const [memberTypeFilter, setMemberTypeFilter] = useState<EFilterMemberType[]>([]);
|
||||
const [memberTypeFilter, setMemberTypeFilter] = useState<FilterMemberType[]>([]);
|
||||
|
||||
const handlePerPageChange = (newPerPage: number) => {
|
||||
setPerPage(newPerPage);
|
||||
@@ -113,12 +113,12 @@ export const GroupMembersTable = ({ groupId, groupSlug, handlePopUpOpen }: Props
|
||||
{
|
||||
icon: <UserIcon size={16} />,
|
||||
label: "Users",
|
||||
value: EFilterMemberType.USERS
|
||||
value: FilterMemberType.USERS
|
||||
},
|
||||
{
|
||||
icon: <HardDriveIcon size={16} />,
|
||||
label: "Identities",
|
||||
value: EFilterMemberType.IDENTITIES
|
||||
value: FilterMemberType.IDENTITIES
|
||||
}
|
||||
];
|
||||
|
||||
@@ -209,7 +209,7 @@ export const GroupMembersTable = ({ groupId, groupSlug, handlePopUpOpen }: Props
|
||||
{isPending && <TableSkeleton columns={4} innerKey="group-user-memberships" />}
|
||||
{!isPending &&
|
||||
groupMemberships?.members?.map((userGroupMembership) => {
|
||||
return userGroupMembership.memberType === EGroupMemberType.USER ? (
|
||||
return userGroupMembership.memberType === GroupMemberType.USER ? (
|
||||
<GroupMembershipUserRow
|
||||
key={`user-group-membership-${userGroupMembership.id}`}
|
||||
user={userGroupMembership}
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
Tr
|
||||
} from "@app/components/v2";
|
||||
import { OrgPermissionGroupActions, OrgPermissionSubjects } from "@app/context";
|
||||
import { EGroupMemberType, TGroupMemberIdentity } from "@app/hooks/api/groups/types";
|
||||
import { GroupMemberType, TGroupMemberIdentity } from "@app/hooks/api/groups/types";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
type Props = {
|
||||
@@ -64,7 +64,7 @@ export const GroupMembershipIdentityRow = ({
|
||||
icon={<FontAwesomeIcon icon={faUserMinus} />}
|
||||
onClick={() =>
|
||||
handlePopUpOpen("removeMemberFromGroup", {
|
||||
memberType: EGroupMemberType.IDENTITY,
|
||||
memberType: GroupMemberType.IDENTITY,
|
||||
identityId: id,
|
||||
name
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from "@app/components/v2";
|
||||
import { OrgPermissionGroupActions, OrgPermissionSubjects, useOrganization } from "@app/context";
|
||||
import { useOidcManageGroupMembershipsEnabled } from "@app/hooks/api";
|
||||
import { EGroupMemberType, TGroupMemberUser } from "@app/hooks/api/groups/types";
|
||||
import { GroupMemberType, TGroupMemberUser } from "@app/hooks/api/groups/types";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
type Props = {
|
||||
@@ -81,7 +81,7 @@ export const GroupMembershipUserRow = ({
|
||||
icon={<FontAwesomeIcon icon={faUserMinus} />}
|
||||
onClick={() =>
|
||||
handlePopUpOpen("removeMemberFromGroup", {
|
||||
memberType: EGroupMemberType.USER,
|
||||
memberType: GroupMemberType.USER,
|
||||
username
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
import { usePagination, useResetPageHelper } from "@app/hooks";
|
||||
import { useListGroupProjects } from "@app/hooks/api";
|
||||
import { OrderByDirection } from "@app/hooks/api/generic/types";
|
||||
import { EFilterReturnedProjects } from "@app/hooks/api/groups/types";
|
||||
import { FilterReturnedProjects } from "@app/hooks/api/groups/types";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
import { GroupProjectRow } from "./GroupProjectRow";
|
||||
@@ -78,7 +78,7 @@ export const GroupProjectsTable = ({ groupId, groupSlug, handlePopUpOpen }: Prop
|
||||
search: debouncedSearch,
|
||||
orderBy,
|
||||
orderDirection,
|
||||
filter: EFilterReturnedProjects.ASSIGNED_PROJECTS
|
||||
filter: FilterReturnedProjects.ASSIGNED_PROJECTS
|
||||
});
|
||||
|
||||
const totalCount = groupMemberships?.totalCount ?? 0;
|
||||
|
||||
@@ -46,9 +46,9 @@ import { ActorType } from "@app/hooks/api/auditLogs/enums";
|
||||
import { OrderByDirection } from "@app/hooks/api/generic/types";
|
||||
import { useListGroupMembers } from "@app/hooks/api/groups/queries";
|
||||
import {
|
||||
EFilterMemberType,
|
||||
EGroupMembersOrderBy,
|
||||
EGroupMemberType,
|
||||
FilterMemberType,
|
||||
GroupMembersOrderBy,
|
||||
GroupMemberType,
|
||||
TGroupMembership
|
||||
} from "@app/hooks/api/groups/types";
|
||||
|
||||
@@ -72,7 +72,7 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
|
||||
orderDirection,
|
||||
toggleOrderDirection,
|
||||
orderBy
|
||||
} = usePagination(EGroupMembersOrderBy.Name, {
|
||||
} = usePagination(GroupMembersOrderBy.Name, {
|
||||
initPerPage: getUserTablePreference("projectGroupMembersTable", PreferenceKey.PerPage, 20)
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
|
||||
}
|
||||
}, [username]);
|
||||
|
||||
const [memberTypeFilter, setMemberTypeFilter] = useState<EFilterMemberType[]>([]);
|
||||
const [memberTypeFilter, setMemberTypeFilter] = useState<FilterMemberType[]>([]);
|
||||
|
||||
const { handlePopUpToggle, popUp, handlePopUpOpen } = usePopUp(["assumePrivileges"] as const);
|
||||
|
||||
@@ -158,12 +158,12 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
|
||||
{
|
||||
icon: <UserIcon size={16} />,
|
||||
label: "Users",
|
||||
value: EFilterMemberType.USERS
|
||||
value: FilterMemberType.USERS
|
||||
},
|
||||
{
|
||||
icon: <HardDriveIcon size={16} />,
|
||||
label: "Identities",
|
||||
value: EFilterMemberType.IDENTITIES
|
||||
value: FilterMemberType.IDENTITIES
|
||||
}
|
||||
];
|
||||
|
||||
@@ -254,7 +254,7 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
|
||||
{isPending && <TableSkeleton columns={4} innerKey="group-user-memberships" />}
|
||||
{!isPending &&
|
||||
groupMemberships?.members?.map((userGroupMembership) => {
|
||||
return userGroupMembership.memberType === EGroupMemberType.USER ? (
|
||||
return userGroupMembership.memberType === GroupMemberType.USER ? (
|
||||
<GroupMembershipUserRow
|
||||
key={`user-group-membership-${userGroupMembership.id}`}
|
||||
user={userGroupMembership}
|
||||
|
||||
Reference in New Issue
Block a user