mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
fix: do not allow segment deletion when used in private projects (#5236)
This commit is contained in:
parent
74bbc7799e
commit
598d022a5a
@ -348,7 +348,10 @@ export class SegmentsController extends Controller {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
const { user } = req;
|
const { user } = req;
|
||||||
const strategies = await this.segmentService.getStrategies(id, user.id);
|
const strategies = await this.segmentService.getVisibleStrategies(
|
||||||
|
id,
|
||||||
|
user.id,
|
||||||
|
);
|
||||||
|
|
||||||
// Remove unnecessary IFeatureStrategy fields from the response.
|
// Remove unnecessary IFeatureStrategy fields from the response.
|
||||||
const segmentStrategies = strategies.map((strategy) => ({
|
const segmentStrategies = strategies.map((strategy) => ({
|
||||||
@ -369,8 +372,7 @@ export class SegmentsController extends Controller {
|
|||||||
res: Response,
|
res: Response,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const id = Number(req.params.id);
|
const id = Number(req.params.id);
|
||||||
const { user } = req;
|
const strategies = await this.segmentService.getAllStrategies(id);
|
||||||
const strategies = await this.segmentService.getStrategies(id, user.id);
|
|
||||||
|
|
||||||
if (strategies.length > 0) {
|
if (strategies.length > 0) {
|
||||||
res.status(409).send();
|
res.status(409).send();
|
||||||
|
@ -13,7 +13,17 @@ export interface ISegmentService {
|
|||||||
|
|
||||||
get(id: number): Promise<ISegment>;
|
get(id: number): Promise<ISegment>;
|
||||||
|
|
||||||
getStrategies(id: number, userId: number): Promise<IFeatureStrategy[]>;
|
/**
|
||||||
|
* Gets all strategies for a segment
|
||||||
|
* This is NOT considering the private projects
|
||||||
|
* For most use cases, use `getVisibleStrategies`
|
||||||
|
*/
|
||||||
|
getAllStrategies(id: number): Promise<IFeatureStrategy[]>;
|
||||||
|
|
||||||
|
getVisibleStrategies(
|
||||||
|
id: number,
|
||||||
|
userId: number,
|
||||||
|
): Promise<IFeatureStrategy[]>;
|
||||||
|
|
||||||
validateName(name: string): Promise<void>;
|
validateName(name: string): Promise<void>;
|
||||||
|
|
||||||
|
@ -77,18 +77,15 @@ export class SegmentService implements ISegmentService {
|
|||||||
return this.segmentStore.getActiveForClient();
|
return this.segmentStore.getActiveForClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used by unleash-enterprise.
|
|
||||||
async getByStrategy(strategyId: string): Promise<ISegment[]> {
|
async getByStrategy(strategyId: string): Promise<ISegment[]> {
|
||||||
return this.segmentStore.getByStrategy(strategyId);
|
return this.segmentStore.getByStrategy(strategyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used by unleash-enterprise.
|
async getVisibleStrategies(
|
||||||
async getStrategies(
|
|
||||||
id: number,
|
id: number,
|
||||||
userId: number,
|
userId: number,
|
||||||
): Promise<IFeatureStrategy[]> {
|
): Promise<IFeatureStrategy[]> {
|
||||||
const strategies =
|
const strategies = await this.getAllStrategies(id);
|
||||||
await this.featureStrategiesStore.getStrategiesBySegment(id);
|
|
||||||
if (this.flagResolver.isEnabled('privateProjects')) {
|
if (this.flagResolver.isEnabled('privateProjects')) {
|
||||||
const accessibleProjects =
|
const accessibleProjects =
|
||||||
await this.privateProjectChecker.getUserAccessibleProjects(
|
await this.privateProjectChecker.getUserAccessibleProjects(
|
||||||
@ -105,6 +102,12 @@ export class SegmentService implements ISegmentService {
|
|||||||
return strategies;
|
return strategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAllStrategies(id: number): Promise<IFeatureStrategy[]> {
|
||||||
|
const strategies =
|
||||||
|
await this.featureStrategiesStore.getStrategiesBySegment(id);
|
||||||
|
return strategies;
|
||||||
|
}
|
||||||
|
|
||||||
async create(
|
async create(
|
||||||
data: unknown,
|
data: unknown,
|
||||||
user: Partial<Pick<User, 'username' | 'email'>>,
|
user: Partial<Pick<User, 'username' | 'email'>>,
|
||||||
|
Loading…
Reference in New Issue
Block a user