feat(server): team quota (#8955)
This commit is contained in:
@@ -26,9 +26,11 @@ import { FeatureService } from './service';
|
||||
})
|
||||
export class FeatureModule {}
|
||||
|
||||
export type { FeatureConfigType } from './feature';
|
||||
export {
|
||||
type CommonFeature,
|
||||
commonFeatureSchema,
|
||||
type FeatureConfig,
|
||||
FeatureKind,
|
||||
Features,
|
||||
FeatureType,
|
||||
|
||||
@@ -69,7 +69,7 @@ export class FeatureManagementService {
|
||||
}
|
||||
|
||||
async listEarlyAccess(type: EarlyAccessType = EarlyAccessType.App) {
|
||||
return this.feature.listFeatureUsers(
|
||||
return this.feature.listUsersByFeature(
|
||||
type === EarlyAccessType.App
|
||||
? FeatureType.EarlyAccess
|
||||
: FeatureType.AIEarlyAccess
|
||||
@@ -132,7 +132,7 @@ export class FeatureManagementService {
|
||||
|
||||
// ======== User Feature ========
|
||||
async getActivatedUserFeatures(userId: string): Promise<FeatureType[]> {
|
||||
const features = await this.feature.getActivatedUserFeatures(userId);
|
||||
const features = await this.feature.getUserActivatedFeatures(userId);
|
||||
return features.map(f => f.feature.name);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ export class FeatureManagementService {
|
||||
}
|
||||
|
||||
async listFeatureWorkspaces(feature: FeatureType) {
|
||||
return this.feature.listFeatureWorkspaces(feature);
|
||||
return this.feature.listWorkspacesByFeature(feature);
|
||||
}
|
||||
|
||||
@OnEvent('user.admin.created')
|
||||
|
||||
@@ -12,14 +12,9 @@ export class FeatureService {
|
||||
|
||||
async getFeature<F extends FeatureType>(feature: F) {
|
||||
const data = await this.prisma.feature.findFirst({
|
||||
where: {
|
||||
feature,
|
||||
type: FeatureKind.Feature,
|
||||
},
|
||||
where: { feature, type: FeatureKind.Feature },
|
||||
select: { id: true },
|
||||
orderBy: {
|
||||
version: 'desc',
|
||||
},
|
||||
orderBy: { version: 'desc' },
|
||||
});
|
||||
|
||||
if (data) {
|
||||
@@ -146,7 +141,7 @@ export class FeatureService {
|
||||
return configs.filter(feature => !!feature.feature);
|
||||
}
|
||||
|
||||
async getActivatedUserFeatures(userId: string) {
|
||||
async getUserActivatedFeatures(userId: string) {
|
||||
const features = await this.prisma.userFeature.findMany({
|
||||
where: {
|
||||
userId,
|
||||
@@ -173,7 +168,7 @@ export class FeatureService {
|
||||
return configs.filter(feature => !!feature.feature);
|
||||
}
|
||||
|
||||
async listFeatureUsers(feature: FeatureType) {
|
||||
async listUsersByFeature(feature: FeatureType) {
|
||||
return this.prisma.userFeature
|
||||
.findMany({
|
||||
where: {
|
||||
@@ -318,7 +313,9 @@ export class FeatureService {
|
||||
return configs.filter(feature => !!feature.feature);
|
||||
}
|
||||
|
||||
async listFeatureWorkspaces(feature: FeatureType): Promise<WorkspaceType[]> {
|
||||
async listWorkspacesByFeature(
|
||||
feature: FeatureType
|
||||
): Promise<WorkspaceType[]> {
|
||||
return this.prisma.workspaceFeature
|
||||
.findMany({
|
||||
where: {
|
||||
|
||||
@@ -76,20 +76,24 @@ export const Features: Feature[] = [
|
||||
|
||||
/// ======== schema infer ========
|
||||
|
||||
export const FeatureConfigSchema = z.discriminatedUnion('feature', [
|
||||
featureCopilot,
|
||||
featureEarlyAccess,
|
||||
featureAIEarlyAccess,
|
||||
featureUnlimitedWorkspace,
|
||||
featureUnlimitedCopilot,
|
||||
featureAdministrator,
|
||||
]);
|
||||
|
||||
export const FeatureSchema = commonFeatureSchema
|
||||
.extend({
|
||||
type: z.literal(FeatureKind.Feature),
|
||||
})
|
||||
.and(
|
||||
z.discriminatedUnion('feature', [
|
||||
featureCopilot,
|
||||
featureEarlyAccess,
|
||||
featureAIEarlyAccess,
|
||||
featureUnlimitedWorkspace,
|
||||
featureUnlimitedCopilot,
|
||||
featureAdministrator,
|
||||
])
|
||||
);
|
||||
.and(FeatureConfigSchema);
|
||||
|
||||
export type FeatureConfig<F extends FeatureType> = (z.infer<
|
||||
typeof FeatureConfigSchema
|
||||
> & { feature: F })['configs'];
|
||||
|
||||
export type Feature = z.infer<typeof FeatureSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user