Skip to content

Commit

Permalink
Merge branch 'dev' into feature/-1762-validation-and-409-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Yagnik56 authored Sep 26, 2024
2 parents 8924eea + 6d72dfc commit a981c15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class ExperimentAssignmentService {
}

// ============= check if user or group is excluded
const [userExcluded, groupExcluded] = await this.checkUserOrGroupIsGloballyExcluded(userDoc, experiments[0]?.group);
const [userExcluded, groupExcluded] = await this.checkUserOrGroupIsGloballyExcluded(userDoc);

if (userExcluded || groupExcluded.length > 0) {
// no experiments if the user or group is excluded from the experiment
Expand Down Expand Up @@ -371,10 +371,7 @@ export class ExperimentAssignmentService {
}
experiments = experiments.map((exp) => this.experimentService.formatingConditionPayload(exp));

const [userExcluded, groupExcluded] = await this.checkUserOrGroupIsGloballyExcluded(
experimentUser,
experiments[0]?.group
);
const [userExcluded, groupExcluded] = await this.checkUserOrGroupIsGloballyExcluded(experimentUser);

if (userExcluded || groupExcluded.length > 0) {
// return null if the user or group is excluded from the experiment
Expand Down Expand Up @@ -691,10 +688,7 @@ export class ExperimentAssignmentService {
return pool;
}

private async checkUserOrGroupIsGloballyExcluded(
experimentUser: ExperimentUser,
experimentGroup: string
): Promise<[string, string[]]> {
public async checkUserOrGroupIsGloballyExcluded(experimentUser: ExperimentUser): Promise<[string, string[]]> {
let userGroup = [];
userGroup = Object.keys(experimentUser.workingGroup || {}).map((type: string) => {
return `${type}_${experimentUser.workingGroup[type]}`;
Expand Down Expand Up @@ -722,11 +716,7 @@ export class ExperimentAssignmentService {
updatedGlobalExcludeSegmentObj[globalExcludeSegment.id].allExcludedSegmentIds.forEach((segmentId) => {
const foundSegment: Segment = updatedSegmentDetails.find((segment) => segment.id === segmentId);
excludedUsers.push(...foundSegment.individualForSegment.map((individual) => individual.userId));
excludedGroups.push(
...foundSegment.groupForSegment.filter((group) =>
group.type === experimentGroup ? `${group.type}_${group.groupId}` : false
)
);
excludedGroups.push(...foundSegment.groupForSegment.map((group) => `${group.type}_${group.groupId}`));
});

//users and groups excluded from GlobalExclude segment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export class FeatureFlagService {

const filteredFeatureFlags = await this.featureFlagRepository.getFlagsFromContext(context);

const [userExcluded, groupExcluded] = await this.experimentAssignmentService.checkUserOrGroupIsGloballyExcluded(
experimentUserDoc
);

if (userExcluded || groupExcluded.length > 0) {
return [];
}

const includedFeatureFlags = await this.featureFlagLevelInclusionExclusion(filteredFeatureFlags, experimentUserDoc);

// save exposures in db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ describe('Feature Flag Service Testing', () => {
provide: ExperimentAssignmentService,
useValue: {
inclusionExclusionLogic: jest.fn().mockResolvedValue([[mockFlag1.id]]),
checkUserOrGroupIsGloballyExcluded: jest.fn().mockResolvedValue([null, []]),
},
},
{
Expand Down

0 comments on commit a981c15

Please sign in to comment.