mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-19 01:17:18 +02:00
chore: import IUser instead of User for auth (#5269)
## About the changes A very subtle change in the way we import IUser makes a huge difference because previously, instead of importing IUser interface we were importing User and naming it IUser here:6f8f21fd48/src/lib/routes/unleash-types.ts (L2)
whereas the correct way of importing the interface is:eec64b119e/src/lib/routes/unleash-types.ts (L2)
This commit is contained in:
parent
5c3fe631f0
commit
f16ad4e899
@ -1,14 +1,14 @@
|
|||||||
import User from '../../types/user';
|
import { IUser } from '../../types/user';
|
||||||
|
|
||||||
export interface IChangeRequestAccessReadModel {
|
export interface IChangeRequestAccessReadModel {
|
||||||
canBypassChangeRequest(
|
canBypassChangeRequest(
|
||||||
project: string,
|
project: string,
|
||||||
environment: string,
|
environment: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
): Promise<boolean>;
|
): Promise<boolean>;
|
||||||
canBypassChangeRequestForProject(
|
canBypassChangeRequestForProject(
|
||||||
project: string,
|
project: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
): Promise<boolean>;
|
): Promise<boolean>;
|
||||||
isChangeRequestsEnabled(
|
isChangeRequestsEnabled(
|
||||||
project: string,
|
project: string,
|
||||||
|
@ -4,7 +4,7 @@ import { IDependentFeaturesStore } from './dependent-features-store-type';
|
|||||||
import { FeatureDependency, FeatureDependencyId } from './dependent-features';
|
import { FeatureDependency, FeatureDependencyId } from './dependent-features';
|
||||||
import { IDependentFeaturesReadModel } from './dependent-features-read-model-type';
|
import { IDependentFeaturesReadModel } from './dependent-features-read-model-type';
|
||||||
import { EventService } from '../../services';
|
import { EventService } from '../../services';
|
||||||
import { User } from '../../server-impl';
|
import { IUser } from '../../server-impl';
|
||||||
import { SKIP_CHANGE_REQUEST } from '../../types';
|
import { SKIP_CHANGE_REQUEST } from '../../types';
|
||||||
import { IChangeRequestAccessReadModel } from '../change-request-access-service/change-request-access-read-model';
|
import { IChangeRequestAccessReadModel } from '../change-request-access-service/change-request-access-read-model';
|
||||||
import { extractUsernameFromUser } from '../../util';
|
import { extractUsernameFromUser } from '../../util';
|
||||||
@ -72,7 +72,7 @@ export class DependentFeaturesService {
|
|||||||
async upsertFeatureDependency(
|
async upsertFeatureDependency(
|
||||||
{ child, projectId }: { child: string; projectId: string },
|
{ child, projectId }: { child: string; projectId: string },
|
||||||
dependentFeature: CreateDependentFeatureSchema,
|
dependentFeature: CreateDependentFeatureSchema,
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.stopWhenChangeRequestsEnabled(projectId, user);
|
await this.stopWhenChangeRequestsEnabled(projectId, user);
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ export class DependentFeaturesService {
|
|||||||
async deleteFeatureDependency(
|
async deleteFeatureDependency(
|
||||||
dependency: FeatureDependencyId,
|
dependency: FeatureDependencyId,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.stopWhenChangeRequestsEnabled(projectId, user);
|
await this.stopWhenChangeRequestsEnabled(projectId, user);
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ export class DependentFeaturesService {
|
|||||||
async deleteFeaturesDependencies(
|
async deleteFeaturesDependencies(
|
||||||
features: string[],
|
features: string[],
|
||||||
projectId: string,
|
projectId: string,
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.stopWhenChangeRequestsEnabled(projectId, user);
|
await this.stopWhenChangeRequestsEnabled(projectId, user);
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ export class DependentFeaturesService {
|
|||||||
return this.dependentFeaturesReadModel.hasAnyDependencies();
|
return this.dependentFeaturesReadModel.hasAnyDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async stopWhenChangeRequestsEnabled(project: string, user?: User) {
|
private async stopWhenChangeRequestsEnabled(project: string, user?: IUser) {
|
||||||
const canBypass =
|
const canBypass =
|
||||||
await this.changeRequestAccessReadModel.canBypassChangeRequestForProject(
|
await this.changeRequestAccessReadModel.canBypassChangeRequestForProject(
|
||||||
project,
|
project,
|
||||||
|
@ -27,7 +27,7 @@ import {
|
|||||||
ImportTogglesSchema,
|
ImportTogglesSchema,
|
||||||
ImportTogglesValidateSchema,
|
ImportTogglesValidateSchema,
|
||||||
} from '../../openapi';
|
} from '../../openapi';
|
||||||
import User from '../../types/user';
|
import { IUser } from '../../types/user';
|
||||||
import { BadDataError } from '../../error';
|
import { BadDataError } from '../../error';
|
||||||
import { extractUsernameFromUser } from '../../util';
|
import { extractUsernameFromUser } from '../../util';
|
||||||
import {
|
import {
|
||||||
@ -56,10 +56,10 @@ import { ISegmentService } from '../../segments/segment-service-interface';
|
|||||||
export type IImportService = {
|
export type IImportService = {
|
||||||
validate(
|
validate(
|
||||||
dto: ImportTogglesSchema,
|
dto: ImportTogglesSchema,
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<ImportTogglesValidateSchema>;
|
): Promise<ImportTogglesValidateSchema>;
|
||||||
|
|
||||||
import(dto: ImportTogglesSchema, user: User): Promise<void>;
|
import(dto: ImportTogglesSchema, user: IUser): Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IExportService = {
|
export type IExportService = {
|
||||||
@ -184,7 +184,7 @@ export default class ExportImportService
|
|||||||
|
|
||||||
async validate(
|
async validate(
|
||||||
dto: ImportTogglesSchema,
|
dto: ImportTogglesSchema,
|
||||||
user: User,
|
user: IUser,
|
||||||
mode = 'regular' as Mode,
|
mode = 'regular' as Mode,
|
||||||
): Promise<ImportTogglesValidateSchema> {
|
): Promise<ImportTogglesValidateSchema> {
|
||||||
const [
|
const [
|
||||||
@ -249,7 +249,7 @@ export default class ExportImportService
|
|||||||
|
|
||||||
async importVerify(
|
async importVerify(
|
||||||
dto: ImportTogglesSchema,
|
dto: ImportTogglesSchema,
|
||||||
user: User,
|
user: IUser,
|
||||||
mode = 'regular' as Mode,
|
mode = 'regular' as Mode,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@ -264,7 +264,7 @@ export default class ExportImportService
|
|||||||
|
|
||||||
async importFeatureData(
|
async importFeatureData(
|
||||||
dto: ImportTogglesSchema,
|
dto: ImportTogglesSchema,
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.createOrUpdateToggles(dto, user);
|
await this.createOrUpdateToggles(dto, user);
|
||||||
await this.importToggleVariants(dto, user);
|
await this.importToggleVariants(dto, user);
|
||||||
@ -273,7 +273,7 @@ export default class ExportImportService
|
|||||||
await this.importContextFields(dto, user);
|
await this.importContextFields(dto, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async import(dto: ImportTogglesSchema, user: User): Promise<void> {
|
async import(dto: ImportTogglesSchema, user: IUser): Promise<void> {
|
||||||
const cleanedDto = await this.cleanData(dto);
|
const cleanedDto = await this.cleanData(dto);
|
||||||
|
|
||||||
await this.importVerify(cleanedDto, user);
|
await this.importVerify(cleanedDto, user);
|
||||||
@ -291,7 +291,7 @@ export default class ExportImportService
|
|||||||
|
|
||||||
async importEnvironmentData(
|
async importEnvironmentData(
|
||||||
dto: ImportTogglesSchema,
|
dto: ImportTogglesSchema,
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.deleteStrategies(dto);
|
await this.deleteStrategies(dto);
|
||||||
await this.importStrategies(dto, user);
|
await this.importStrategies(dto, user);
|
||||||
@ -299,7 +299,7 @@ export default class ExportImportService
|
|||||||
await this.importDependencies(dto, user);
|
await this.importDependencies(dto, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importDependencies(dto: ImportTogglesSchema, user: User) {
|
private async importDependencies(dto: ImportTogglesSchema, user: IUser) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
(dto.data.dependencies || []).flatMap((dependency) => {
|
(dto.data.dependencies || []).flatMap((dependency) => {
|
||||||
const projectId = dto.data.features.find(
|
const projectId = dto.data.features.find(
|
||||||
@ -319,7 +319,7 @@ export default class ExportImportService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importToggleStatuses(dto: ImportTogglesSchema, user: User) {
|
private async importToggleStatuses(dto: ImportTogglesSchema, user: IUser) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
(dto.data.featureEnvironments || []).map((featureEnvironment) =>
|
(dto.data.featureEnvironments || []).map((featureEnvironment) =>
|
||||||
this.featureToggleService.updateEnabled(
|
this.featureToggleService.updateEnabled(
|
||||||
@ -334,7 +334,7 @@ export default class ExportImportService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importStrategies(dto: ImportTogglesSchema, user: User) {
|
private async importStrategies(dto: ImportTogglesSchema, user: IUser) {
|
||||||
const hasFeatureName = (
|
const hasFeatureName = (
|
||||||
featureStrategy: FeatureStrategySchema,
|
featureStrategy: FeatureStrategySchema,
|
||||||
): featureStrategy is WithRequired<
|
): featureStrategy is WithRequired<
|
||||||
@ -371,7 +371,7 @@ export default class ExportImportService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importTags(dto: ImportTogglesSchema, user: User) {
|
private async importTags(dto: ImportTogglesSchema, user: IUser) {
|
||||||
await this.importTogglesStore.deleteTagsForFeatures(
|
await this.importTogglesStore.deleteTagsForFeatures(
|
||||||
dto.data.features.map((feature) => feature.name),
|
dto.data.features.map((feature) => feature.name),
|
||||||
);
|
);
|
||||||
@ -391,7 +391,7 @@ export default class ExportImportService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importContextFields(dto: ImportTogglesSchema, user: User) {
|
private async importContextFields(dto: ImportTogglesSchema, user: IUser) {
|
||||||
const newContextFields = (await this.getNewContextFields(dto)) || [];
|
const newContextFields = (await this.getNewContextFields(dto)) || [];
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
newContextFields.map((contextField) =>
|
newContextFields.map((contextField) =>
|
||||||
@ -408,7 +408,7 @@ export default class ExportImportService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importTagTypes(dto: ImportTogglesSchema, user: User) {
|
private async importTagTypes(dto: ImportTogglesSchema, user: IUser) {
|
||||||
const newTagTypes = await this.getNewTagTypes(dto);
|
const newTagTypes = await this.getNewTagTypes(dto);
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
newTagTypes.map((tagType) => {
|
newTagTypes.map((tagType) => {
|
||||||
@ -422,7 +422,7 @@ export default class ExportImportService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importToggleVariants(dto: ImportTogglesSchema, user: User) {
|
private async importToggleVariants(dto: ImportTogglesSchema, user: IUser) {
|
||||||
const featureEnvsWithVariants =
|
const featureEnvsWithVariants =
|
||||||
dto.data.featureEnvironments?.filter(
|
dto.data.featureEnvironments?.filter(
|
||||||
(featureEnvironment) =>
|
(featureEnvironment) =>
|
||||||
@ -444,7 +444,7 @@ export default class ExportImportService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createOrUpdateToggles(dto: ImportTogglesSchema, user: User) {
|
private async createOrUpdateToggles(dto: ImportTogglesSchema, user: IUser) {
|
||||||
const existingFeatures = await this.getExistingProjectFeatures(dto);
|
const existingFeatures = await this.getExistingProjectFeatures(dto);
|
||||||
const username = extractUsernameFromUser(user);
|
const username = extractUsernameFromUser(user);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { IImportTogglesStore } from './import-toggles-store-type';
|
|||||||
import { AccessService, ContextService, TagTypeService } from '../../services';
|
import { AccessService, ContextService, TagTypeService } from '../../services';
|
||||||
import { ContextFieldSchema, ImportTogglesSchema } from '../../openapi';
|
import { ContextFieldSchema, ImportTogglesSchema } from '../../openapi';
|
||||||
import { ITagType } from '../../types/stores/tag-type-store';
|
import { ITagType } from '../../types/stores/tag-type-store';
|
||||||
import User from '../../types/user';
|
import { IUser } from '../../types/user';
|
||||||
import {
|
import {
|
||||||
CREATE_CONTEXT_FIELD,
|
CREATE_CONTEXT_FIELD,
|
||||||
CREATE_FEATURE,
|
CREATE_FEATURE,
|
||||||
@ -67,7 +67,7 @@ export class ImportPermissionsService {
|
|||||||
|
|
||||||
async getMissingPermissions(
|
async getMissingPermissions(
|
||||||
dto: ImportTogglesSchema,
|
dto: ImportTogglesSchema,
|
||||||
user: User,
|
user: IUser,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
const [
|
const [
|
||||||
@ -140,7 +140,7 @@ export class ImportPermissionsService {
|
|||||||
|
|
||||||
async verifyPermissions(
|
async verifyPermissions(
|
||||||
dto: ImportTogglesSchema,
|
dto: ImportTogglesSchema,
|
||||||
user: User,
|
user: IUser,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const missingPermissions = await this.getMissingPermissions(
|
const missingPermissions = await this.getMissingPermissions(
|
||||||
|
@ -27,7 +27,6 @@ import {
|
|||||||
IFeatureOverview,
|
IFeatureOverview,
|
||||||
IFeatureStrategy,
|
IFeatureStrategy,
|
||||||
IFeatureTagStore,
|
IFeatureTagStore,
|
||||||
IFeatureToggleClient,
|
|
||||||
IFeatureToggleClientStore,
|
IFeatureToggleClientStore,
|
||||||
IFeatureToggleQuery,
|
IFeatureToggleQuery,
|
||||||
IFeatureToggleStore,
|
IFeatureToggleStore,
|
||||||
@ -92,7 +91,7 @@ import {
|
|||||||
getProjectDefaultStrategy,
|
getProjectDefaultStrategy,
|
||||||
} from '../playground/feature-evaluator/helpers';
|
} from '../playground/feature-evaluator/helpers';
|
||||||
import { AccessService } from '../../services/access-service';
|
import { AccessService } from '../../services/access-service';
|
||||||
import { User } from '../../server-impl';
|
import { IUser } from '../../server-impl';
|
||||||
import { IFeatureProjectUserParams } from './feature-toggle-controller';
|
import { IFeatureProjectUserParams } from './feature-toggle-controller';
|
||||||
import { unique } from '../../util/unique';
|
import { unique } from '../../util/unique';
|
||||||
import { ISegmentService } from 'lib/segments/segment-service-interface';
|
import { ISegmentService } from 'lib/segments/segment-service-interface';
|
||||||
@ -464,7 +463,7 @@ class FeatureToggleService {
|
|||||||
context: IFeatureStrategyContext,
|
context: IFeatureStrategyContext,
|
||||||
sortOrders: SetStrategySortOrderSchema,
|
sortOrders: SetStrategySortOrderSchema,
|
||||||
createdBy: string,
|
createdBy: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
): Promise<Saved<any>> {
|
): Promise<Saved<any>> {
|
||||||
await this.stopWhenChangeRequestsEnabled(
|
await this.stopWhenChangeRequestsEnabled(
|
||||||
context.projectId,
|
context.projectId,
|
||||||
@ -548,7 +547,7 @@ class FeatureToggleService {
|
|||||||
strategyConfig: Unsaved<IStrategyConfig>,
|
strategyConfig: Unsaved<IStrategyConfig>,
|
||||||
context: IFeatureStrategyContext,
|
context: IFeatureStrategyContext,
|
||||||
createdBy: string,
|
createdBy: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
): Promise<Saved<IStrategyConfig>> {
|
): Promise<Saved<IStrategyConfig>> {
|
||||||
await this.stopWhenChangeRequestsEnabled(
|
await this.stopWhenChangeRequestsEnabled(
|
||||||
context.projectId,
|
context.projectId,
|
||||||
@ -671,7 +670,7 @@ class FeatureToggleService {
|
|||||||
updates: Partial<IStrategyConfig>,
|
updates: Partial<IStrategyConfig>,
|
||||||
context: IFeatureStrategyContext,
|
context: IFeatureStrategyContext,
|
||||||
userName: string,
|
userName: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
): Promise<Saved<IStrategyConfig>> {
|
): Promise<Saved<IStrategyConfig>> {
|
||||||
await this.stopWhenChangeRequestsEnabled(
|
await this.stopWhenChangeRequestsEnabled(
|
||||||
context.projectId,
|
context.projectId,
|
||||||
@ -835,7 +834,7 @@ class FeatureToggleService {
|
|||||||
id: string,
|
id: string,
|
||||||
context: IFeatureStrategyContext,
|
context: IFeatureStrategyContext,
|
||||||
createdBy: string,
|
createdBy: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.stopWhenChangeRequestsEnabled(
|
await this.stopWhenChangeRequestsEnabled(
|
||||||
context.projectId,
|
context.projectId,
|
||||||
@ -1488,7 +1487,7 @@ class FeatureToggleService {
|
|||||||
|
|
||||||
async archiveToggle(
|
async archiveToggle(
|
||||||
featureName: string,
|
featureName: string,
|
||||||
user: User,
|
user: IUser,
|
||||||
projectId?: string,
|
projectId?: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
@ -1542,7 +1541,7 @@ class FeatureToggleService {
|
|||||||
|
|
||||||
async archiveToggles(
|
async archiveToggles(
|
||||||
featureNames: string[],
|
featureNames: string[],
|
||||||
user: User,
|
user: IUser,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.stopWhenChangeRequestsEnabled(projectId, undefined, user);
|
await this.stopWhenChangeRequestsEnabled(projectId, undefined, user);
|
||||||
@ -1641,7 +1640,7 @@ class FeatureToggleService {
|
|||||||
environment: string,
|
environment: string,
|
||||||
enabled: boolean,
|
enabled: boolean,
|
||||||
createdBy: string,
|
createdBy: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
shouldActivateDisabledStrategies = false,
|
shouldActivateDisabledStrategies = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@ -1665,7 +1664,7 @@ class FeatureToggleService {
|
|||||||
environment: string,
|
environment: string,
|
||||||
enabled: boolean,
|
enabled: boolean,
|
||||||
createdBy: string,
|
createdBy: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
shouldActivateDisabledStrategies = false,
|
shouldActivateDisabledStrategies = false,
|
||||||
): Promise<FeatureToggle> {
|
): Promise<FeatureToggle> {
|
||||||
await this.stopWhenChangeRequestsEnabled(project, environment, user);
|
await this.stopWhenChangeRequestsEnabled(project, environment, user);
|
||||||
@ -2055,7 +2054,7 @@ class FeatureToggleService {
|
|||||||
featureName: string,
|
featureName: string,
|
||||||
project: string,
|
project: string,
|
||||||
newVariants: Operation[],
|
newVariants: Operation[],
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<FeatureToggle> {
|
): Promise<FeatureToggle> {
|
||||||
const ft =
|
const ft =
|
||||||
await this.featureStrategiesStore.getFeatureToggleWithVariantEnvs(
|
await this.featureStrategiesStore.getFeatureToggleWithVariantEnvs(
|
||||||
@ -2082,7 +2081,7 @@ class FeatureToggleService {
|
|||||||
project: string,
|
project: string,
|
||||||
environment: string,
|
environment: string,
|
||||||
newVariants: Operation[],
|
newVariants: Operation[],
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<IVariant[]> {
|
): Promise<IVariant[]> {
|
||||||
const oldVariants = await this.getVariantsForEnv(
|
const oldVariants = await this.getVariantsForEnv(
|
||||||
featureName,
|
featureName,
|
||||||
@ -2136,7 +2135,7 @@ class FeatureToggleService {
|
|||||||
featureName: string,
|
featureName: string,
|
||||||
environment: string,
|
environment: string,
|
||||||
newVariants: IVariant[],
|
newVariants: IVariant[],
|
||||||
user: User,
|
user: IUser,
|
||||||
oldVariants?: IVariant[],
|
oldVariants?: IVariant[],
|
||||||
): Promise<IVariant[]> {
|
): Promise<IVariant[]> {
|
||||||
await variantsArraySchema.validateAsync(newVariants);
|
await variantsArraySchema.validateAsync(newVariants);
|
||||||
@ -2174,7 +2173,7 @@ class FeatureToggleService {
|
|||||||
featureName: string,
|
featureName: string,
|
||||||
environment: string,
|
environment: string,
|
||||||
newVariants: IVariant[],
|
newVariants: IVariant[],
|
||||||
user: User,
|
user: IUser,
|
||||||
oldVariants?: IVariant[],
|
oldVariants?: IVariant[],
|
||||||
): Promise<IVariant[]> {
|
): Promise<IVariant[]> {
|
||||||
await this.stopWhenChangeRequestsEnabled(projectId, environment, user);
|
await this.stopWhenChangeRequestsEnabled(projectId, environment, user);
|
||||||
@ -2193,7 +2192,7 @@ class FeatureToggleService {
|
|||||||
featureName: string,
|
featureName: string,
|
||||||
environments: string[],
|
environments: string[],
|
||||||
newVariants: IVariant[],
|
newVariants: IVariant[],
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<IVariant[]> {
|
): Promise<IVariant[]> {
|
||||||
for (const env of environments) {
|
for (const env of environments) {
|
||||||
await this.stopWhenChangeRequestsEnabled(projectId, env);
|
await this.stopWhenChangeRequestsEnabled(projectId, env);
|
||||||
@ -2212,7 +2211,7 @@ class FeatureToggleService {
|
|||||||
featureName: string,
|
featureName: string,
|
||||||
environments: string[],
|
environments: string[],
|
||||||
newVariants: IVariant[],
|
newVariants: IVariant[],
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<IVariant[]> {
|
): Promise<IVariant[]> {
|
||||||
await variantsArraySchema.validateAsync(newVariants);
|
await variantsArraySchema.validateAsync(newVariants);
|
||||||
const fixedVariants = this.fixVariantWeights(newVariants);
|
const fixedVariants = this.fixVariantWeights(newVariants);
|
||||||
@ -2290,7 +2289,7 @@ class FeatureToggleService {
|
|||||||
private async stopWhenChangeRequestsEnabled(
|
private async stopWhenChangeRequestsEnabled(
|
||||||
project: string,
|
project: string,
|
||||||
environment?: string,
|
environment?: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
) {
|
) {
|
||||||
const canBypass = environment
|
const canBypass = environment
|
||||||
? await this.changeRequestAccessReadModel.canBypassChangeRequest(
|
? await this.changeRequestAccessReadModel.canBypassChangeRequest(
|
||||||
@ -2311,7 +2310,7 @@ class FeatureToggleService {
|
|||||||
project: string,
|
project: string,
|
||||||
environment: string,
|
environment: string,
|
||||||
featureName: string,
|
featureName: string,
|
||||||
user?: User,
|
user?: IUser,
|
||||||
) {
|
) {
|
||||||
const hasEnvironment =
|
const hasEnvironment =
|
||||||
await this.featureEnvironmentStore.featureHasEnvironment(
|
await this.featureEnvironmentStore.featureHasEnvironment(
|
||||||
|
@ -461,9 +461,6 @@ test('If change requests are enabled, cannot change variants without going via C
|
|||||||
permissions: [],
|
permissions: [],
|
||||||
seenAt: irrelevantDate,
|
seenAt: irrelevantDate,
|
||||||
username: '',
|
username: '',
|
||||||
generateImageUrl(): string {
|
|
||||||
return '';
|
|
||||||
},
|
|
||||||
isAPI: true,
|
isAPI: true,
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
@ -553,9 +550,6 @@ test('If CRs are protected for any environment in the project stops bulk update
|
|||||||
permissions: [],
|
permissions: [],
|
||||||
seenAt: irrelevantDate,
|
seenAt: irrelevantDate,
|
||||||
username: '',
|
username: '',
|
||||||
generateImageUrl(): string {
|
|
||||||
return '';
|
|
||||||
},
|
|
||||||
isAPI: true,
|
isAPI: true,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -16,7 +16,7 @@ import { ApiTokenService } from '../../services/api-token-service';
|
|||||||
import { Logger } from '../../logger';
|
import { Logger } from '../../logger';
|
||||||
import { AccessService } from '../../services/access-service';
|
import { AccessService } from '../../services/access-service';
|
||||||
import { IAuthRequest } from '../unleash-types';
|
import { IAuthRequest } from '../unleash-types';
|
||||||
import User from '../../types/user';
|
import { IUser } from '../../types/user';
|
||||||
import { IUnleashConfig } from '../../types/option';
|
import { IUnleashConfig } from '../../types/option';
|
||||||
import { ApiTokenType, IApiToken } from '../../types/models/api-token';
|
import { ApiTokenType, IApiToken } from '../../types/models/api-token';
|
||||||
import { createApiToken } from '../../schema/api-token-schema';
|
import { createApiToken } from '../../schema/api-token-schema';
|
||||||
@ -400,13 +400,13 @@ export class ApiTokenController extends Controller {
|
|||||||
|
|
||||||
private async accessibleTokensByName(
|
private async accessibleTokensByName(
|
||||||
tokenName: string,
|
tokenName: string,
|
||||||
user: User,
|
user: IUser,
|
||||||
): Promise<IApiToken[]> {
|
): Promise<IApiToken[]> {
|
||||||
const allTokens = await this.accessibleTokens(user);
|
const allTokens = await this.accessibleTokens(user);
|
||||||
return allTokens.filter((token) => token.tokenName === tokenName);
|
return allTokens.filter((token) => token.tokenName === tokenName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async accessibleTokens(user: User): Promise<IApiToken[]> {
|
private async accessibleTokens(user: IUser): Promise<IApiToken[]> {
|
||||||
const allTokens = await this.apiTokenService.getAllTokens();
|
const allTokens = await this.apiTokenService.getAllTokens();
|
||||||
|
|
||||||
if (user.isAPI && user.permissions.includes(ADMIN)) {
|
if (user.isAPI && user.permissions.includes(ADMIN)) {
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
resourceCreatedResponseSchema,
|
resourceCreatedResponseSchema,
|
||||||
} from '../../../openapi';
|
} from '../../../openapi';
|
||||||
import { getStandardResponses } from '../../../openapi/util/standard-responses';
|
import { getStandardResponses } from '../../../openapi/util/standard-responses';
|
||||||
import User from '../../../types/user';
|
import { IUser } from '../../../types/user';
|
||||||
import {
|
import {
|
||||||
ADMIN,
|
ADMIN,
|
||||||
CREATE_PROJECT_API_TOKEN,
|
CREATE_PROJECT_API_TOKEN,
|
||||||
@ -238,7 +238,7 @@ export class ProjectApiTokenController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async accessibleTokens(
|
private async accessibleTokens(
|
||||||
user: User,
|
user: IUser,
|
||||||
project: string,
|
project: string,
|
||||||
): Promise<IApiToken[]> {
|
): Promise<IApiToken[]> {
|
||||||
const allTokens = await this.apiTokenService.getAllTokens();
|
const allTokens = await this.apiTokenService.getAllTokens();
|
||||||
|
@ -18,7 +18,7 @@ import { createRequestSchema } from '../../../openapi/util/create-request-schema
|
|||||||
import { createResponseSchema } from '../../../openapi/util/create-response-schema';
|
import { createResponseSchema } from '../../../openapi/util/create-response-schema';
|
||||||
import { AccessService } from '../../../services';
|
import { AccessService } from '../../../services';
|
||||||
import { BadDataError, PermissionError } from '../../../../lib/error';
|
import { BadDataError, PermissionError } from '../../../../lib/error';
|
||||||
import { User } from 'lib/server-impl';
|
import { IUser } from 'lib/server-impl';
|
||||||
import { PushVariantsSchema } from 'lib/openapi/spec/push-variants-schema';
|
import { PushVariantsSchema } from 'lib/openapi/spec/push-variants-schema';
|
||||||
import { getStandardResponses } from '../../../openapi';
|
import { getStandardResponses } from '../../../openapi';
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ The backend will also distribute remaining weight up to 1000 after adding the va
|
|||||||
}
|
}
|
||||||
|
|
||||||
async checkAccess(
|
async checkAccess(
|
||||||
user: User,
|
user: IUser,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
environments: string[],
|
environments: string[],
|
||||||
permission: string,
|
permission: string,
|
||||||
|
@ -4,9 +4,9 @@ import { IUnleashServices } from '../../types';
|
|||||||
import { IUnleashConfig } from '../../types/option';
|
import { IUnleashConfig } from '../../types/option';
|
||||||
import { Logger } from '../../logger';
|
import { Logger } from '../../logger';
|
||||||
import ClientInstanceService from '../../services/client-metrics/instance-service';
|
import ClientInstanceService from '../../services/client-metrics/instance-service';
|
||||||
import { IAuthRequest, User } from '../../server-impl';
|
import { IAuthRequest, IUser } from '../../server-impl';
|
||||||
import { IClientApp } from '../../types/model';
|
import { IClientApp } from '../../types/model';
|
||||||
import ApiUser from '../../types/api-user';
|
import ApiUser, { IApiUser } from '../../types/api-user';
|
||||||
import { ALL } from '../../types/models/api-token';
|
import { ALL } from '../../types/models/api-token';
|
||||||
import { NONE } from '../../types/permissions';
|
import { NONE } from '../../types/permissions';
|
||||||
import { OpenApiService } from '../../services/openapi-service';
|
import { OpenApiService } from '../../services/openapi-service';
|
||||||
@ -61,7 +61,10 @@ export default class RegisterController extends Controller {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static resolveEnvironment(user: User, data: Partial<IClientApp>) {
|
private static resolveEnvironment(
|
||||||
|
user: IUser | IApiUser,
|
||||||
|
data: Partial<IClientApp>,
|
||||||
|
) {
|
||||||
if (user instanceof ApiUser) {
|
if (user instanceof ApiUser) {
|
||||||
if (user.environment !== ALL) {
|
if (user.environment !== ALL) {
|
||||||
return user.environment;
|
return user.environment;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import IUser from '../types/user';
|
import { IUser } from '../types/user';
|
||||||
import { IApiUser } from '../types';
|
import { IApiUser } from '../types';
|
||||||
|
|
||||||
export interface IAuthRequest<
|
export interface IAuthRequest<
|
||||||
|
@ -21,7 +21,7 @@ import {
|
|||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
import User, { IUser } from './types/user';
|
import User, { IUser } from './types/user';
|
||||||
import ApiUser from './types/api-user';
|
import ApiUser, { IApiUser } from './types/api-user';
|
||||||
import { Logger, LogLevel } from './logger';
|
import { Logger, LogLevel } from './logger';
|
||||||
import AuthenticationRequired from './types/authentication-required';
|
import AuthenticationRequired from './types/authentication-required';
|
||||||
import Controller from './routes/controller';
|
import Controller from './routes/controller';
|
||||||
@ -207,6 +207,7 @@ export type {
|
|||||||
IUnleashOptions,
|
IUnleashOptions,
|
||||||
IUnleashConfig,
|
IUnleashConfig,
|
||||||
IUser,
|
IUser,
|
||||||
|
IApiUser,
|
||||||
IUnleashServices,
|
IUnleashServices,
|
||||||
IAuthRequest,
|
IAuthRequest,
|
||||||
IApiRequest,
|
IApiRequest,
|
||||||
|
@ -7,15 +7,11 @@ import {
|
|||||||
IClientMetricsStoreV2,
|
IClientMetricsStoreV2,
|
||||||
} from '../../types/stores/client-metrics-store-v2';
|
} from '../../types/stores/client-metrics-store-v2';
|
||||||
import { clientMetricsSchema } from './schema';
|
import { clientMetricsSchema } from './schema';
|
||||||
import {
|
import { compareAsc } from 'date-fns';
|
||||||
compareAsc,
|
|
||||||
hoursToMilliseconds,
|
|
||||||
secondsToMilliseconds,
|
|
||||||
} from 'date-fns';
|
|
||||||
import { CLIENT_METRICS } from '../../types/events';
|
import { CLIENT_METRICS } from '../../types/events';
|
||||||
import ApiUser, { IApiUser } from '../../types/api-user';
|
import ApiUser, { IApiUser } from '../../types/api-user';
|
||||||
import { ALL } from '../../types/models/api-token';
|
import { ALL } from '../../types/models/api-token';
|
||||||
import User from '../../types/user';
|
import { IUser } from '../../types/user';
|
||||||
import { collapseHourlyMetrics } from '../../util/collapseHourlyMetrics';
|
import { collapseHourlyMetrics } from '../../util/collapseHourlyMetrics';
|
||||||
import { LastSeenService } from './last-seen/last-seen-service';
|
import { LastSeenService } from './last-seen/last-seen-service';
|
||||||
import { generateHourBuckets } from '../../util/time-utils';
|
import { generateHourBuckets } from '../../util/time-utils';
|
||||||
@ -222,7 +218,7 @@ export default class ClientMetricsServiceV2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolveMetricsEnvironment(
|
resolveMetricsEnvironment(
|
||||||
user: User | ApiUser,
|
user: IUser | IApiUser,
|
||||||
data: { environment?: string },
|
data: { environment?: string },
|
||||||
): string {
|
): string {
|
||||||
if (user instanceof ApiUser) {
|
if (user instanceof ApiUser) {
|
||||||
|
@ -9,19 +9,19 @@ import {
|
|||||||
PROJECT_FAVORITED,
|
PROJECT_FAVORITED,
|
||||||
PROJECT_UNFAVORITED,
|
PROJECT_UNFAVORITED,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import User from '../types/user';
|
import { IUser } from '../types/user';
|
||||||
import { extractUsernameFromUser } from '../util';
|
import { extractUsernameFromUser } from '../util';
|
||||||
import { IFavoriteProjectKey } from '../types/stores/favorite-projects';
|
import { IFavoriteProjectKey } from '../types/stores/favorite-projects';
|
||||||
import EventService from './event-service';
|
import EventService from './event-service';
|
||||||
|
|
||||||
export interface IFavoriteFeatureProps {
|
export interface IFavoriteFeatureProps {
|
||||||
feature: string;
|
feature: string;
|
||||||
user: User;
|
user: IUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IFavoriteProjectProps {
|
export interface IFavoriteProjectProps {
|
||||||
project: string;
|
project: string;
|
||||||
user: User;
|
user: IUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FavoritesService {
|
export class FavoritesService {
|
||||||
|
@ -4,7 +4,7 @@ import { IPatStore } from '../types/stores/pat-store';
|
|||||||
import { PAT_CREATED, PAT_DELETED } from '../types/events';
|
import { PAT_CREATED, PAT_DELETED } from '../types/events';
|
||||||
import { IPat } from '../types/models/pat';
|
import { IPat } from '../types/models/pat';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import User from '../types/user';
|
import { IUser } from '../types/user';
|
||||||
import BadDataError from '../error/bad-data-error';
|
import BadDataError from '../error/bad-data-error';
|
||||||
import NameExistsError from '../error/name-exists-error';
|
import NameExistsError from '../error/name-exists-error';
|
||||||
import { OperationDeniedError } from '../error/operation-denied-error';
|
import { OperationDeniedError } from '../error/operation-denied-error';
|
||||||
@ -31,7 +31,11 @@ export default class PatService {
|
|||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPat(pat: IPat, forUserId: number, editor: User): Promise<IPat> {
|
async createPat(
|
||||||
|
pat: IPat,
|
||||||
|
forUserId: number,
|
||||||
|
editor: IUser,
|
||||||
|
): Promise<IPat> {
|
||||||
await this.validatePat(pat, forUserId);
|
await this.validatePat(pat, forUserId);
|
||||||
pat.secret = this.generateSecretKey();
|
pat.secret = this.generateSecretKey();
|
||||||
pat.userId = forUserId;
|
pat.userId = forUserId;
|
||||||
@ -54,7 +58,7 @@ export default class PatService {
|
|||||||
async deletePat(
|
async deletePat(
|
||||||
id: number,
|
id: number,
|
||||||
forUserId: number,
|
forUserId: number,
|
||||||
editor: User,
|
editor: IUser,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const pat = await this.patStore.get(id);
|
const pat = await this.patStore.get(id);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { IUnleashStores } from '../types/stores';
|
import { IUnleashStores } from '../types/stores';
|
||||||
import { IUnleashConfig } from '../types/option';
|
import { IUnleashConfig } from '../types/option';
|
||||||
import User from '../types/user';
|
import { IUser } from '../types/user';
|
||||||
import {
|
import {
|
||||||
IUserFeedback,
|
IUserFeedback,
|
||||||
IUserFeedbackStore,
|
IUserFeedbackStore,
|
||||||
@ -20,7 +20,7 @@ export default class UserFeedbackService {
|
|||||||
this.logger = getLogger('services/user-feedback-service.js');
|
this.logger = getLogger('services/user-feedback-service.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllUserFeedback(user: User): Promise<IUserFeedback[]> {
|
async getAllUserFeedback(user: IUser): Promise<IUserFeedback[]> {
|
||||||
if (user.isAPI) {
|
if (user.isAPI) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ class UserService {
|
|||||||
|
|
||||||
async createUser(
|
async createUser(
|
||||||
{ username, email, name, password, rootRole }: ICreateUser,
|
{ username, email, name, password, rootRole }: ICreateUser,
|
||||||
updatedBy?: User,
|
updatedBy?: IUser,
|
||||||
): Promise<IUser> {
|
): Promise<IUser> {
|
||||||
if (!username && !email) {
|
if (!username && !email) {
|
||||||
throw new BadDataError('You must specify username or email');
|
throw new BadDataError('You must specify username or email');
|
||||||
@ -244,7 +244,7 @@ class UserService {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCreatedBy(updatedBy: User = systemUser) {
|
private getCreatedBy(updatedBy: IUser = systemUser) {
|
||||||
return updatedBy.username || updatedBy.email;
|
return updatedBy.username || updatedBy.email;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ class UserService {
|
|||||||
|
|
||||||
async updateUser(
|
async updateUser(
|
||||||
{ id, name, email, rootRole }: IUpdateUser,
|
{ id, name, email, rootRole }: IUpdateUser,
|
||||||
updatedBy?: User,
|
updatedBy?: IUser,
|
||||||
): Promise<IUser> {
|
): Promise<IUser> {
|
||||||
const preUser = await this.store.get(id);
|
const preUser = await this.store.get(id);
|
||||||
|
|
||||||
@ -294,7 +294,7 @@ class UserService {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteUser(userId: number, updatedBy?: User): Promise<void> {
|
async deleteUser(userId: number, updatedBy?: IUser): Promise<void> {
|
||||||
const user = await this.store.get(userId);
|
const user = await this.store.get(userId);
|
||||||
await this.accessService.wipeUserPermissions(userId);
|
await this.accessService.wipeUserPermissions(userId);
|
||||||
await this.sessionService.deleteSessionsForUser(userId);
|
await this.sessionService.deleteSessionsForUser(userId);
|
||||||
@ -451,7 +451,7 @@ class UserService {
|
|||||||
|
|
||||||
async createResetPasswordEmail(
|
async createResetPasswordEmail(
|
||||||
receiverEmail: string,
|
receiverEmail: string,
|
||||||
user: User = systemUser,
|
user: IUser = systemUser,
|
||||||
): Promise<URL> {
|
): Promise<URL> {
|
||||||
const receiver = await this.getByEmail(receiverEmail);
|
const receiver = await this.getByEmail(receiverEmail);
|
||||||
if (!receiver) {
|
if (!receiver) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { IUnleashStores } from '../types/stores';
|
import { IUnleashStores } from '../types/stores';
|
||||||
import { IUnleashConfig } from '../types/option';
|
import { IUnleashConfig } from '../types/option';
|
||||||
import User from '../types/user';
|
import { IUser } from '../types/user';
|
||||||
import {
|
import {
|
||||||
IUserSplash,
|
IUserSplash,
|
||||||
IUserSplashStore,
|
IUserSplashStore,
|
||||||
@ -20,7 +20,7 @@ export default class UserSplashService {
|
|||||||
this.logger = getLogger('services/user-splash-service.js');
|
this.logger = getLogger('services/user-splash-service.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllUserSplashes(user: User): Promise<Record<string, boolean>> {
|
async getAllUserSplashes(user: IUser): Promise<Record<string, boolean>> {
|
||||||
if (user.isAPI) {
|
if (user.isAPI) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ export interface UserData {
|
|||||||
|
|
||||||
export interface IUser {
|
export interface IUser {
|
||||||
id: number;
|
id: number;
|
||||||
name?: string;
|
name: string;
|
||||||
username?: string;
|
username: string;
|
||||||
email?: string;
|
email: string;
|
||||||
inviteLink?: string;
|
inviteLink?: string;
|
||||||
seenAt?: Date;
|
seenAt?: Date;
|
||||||
createdAt?: Date;
|
createdAt?: Date;
|
||||||
|
3
src/test/fixtures/fake-user-store.ts
vendored
3
src/test/fixtures/fake-user-store.ts
vendored
@ -137,6 +137,9 @@ class UserStoreMock implements IUserStore {
|
|||||||
permissions: [],
|
permissions: [],
|
||||||
loginAttempts: 0,
|
loginAttempts: 0,
|
||||||
imageUrl: '',
|
imageUrl: '',
|
||||||
|
name: user.name ?? '',
|
||||||
|
username: user.username ?? '',
|
||||||
|
email: user.email ?? '',
|
||||||
...user,
|
...user,
|
||||||
});
|
});
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
|
Loading…
Reference in New Issue
Block a user