Skip to content

Commit

Permalink
fix: segment project fetch when global (#5311)
Browse files Browse the repository at this point in the history
This fixes an edge case not caught originally in
#5304 - When creating a new
segment on the global level:
 - There is no `projectId`, either in the params or body
- The `UPDATE_PROJECT_SEGMENT` is still a part of the permissions
checked on the endpoint
 - There is no `id` on the params

This made it so that we would run `segmentStore.get(id)` with an
undefined `id`, causing issues.

The fix was simply checking for the presence of `params.id` before
proceeding.
  • Loading branch information
nunogois committed Nov 9, 2023
1 parent 100c22b commit de638b5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/middleware/rbac-middleware.ts
Expand Up @@ -3,7 +3,6 @@ import {
DELETE_FEATURE,
ADMIN,
UPDATE_FEATURE,
DELETE_SEGMENT,
UPDATE_PROJECT_SEGMENT,
} from '../types/permissions';
import { IUnleashConfig } from '../types/option';
Expand Down Expand Up @@ -96,7 +95,8 @@ const rbacMiddleware = (
// This is needed to check if the user has the right permissions on a project level
if (
!projectId &&
permissionsArray.includes(UPDATE_PROJECT_SEGMENT)
permissionsArray.includes(UPDATE_PROJECT_SEGMENT) &&
params.id
) {
const { id } = params;
const { project } = await segmentStore.get(id);
Expand Down

0 comments on commit de638b5

Please sign in to comment.