-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[backend] Fix the file change right #5587
Conversation
// Get Files paginated with auto enrichment | ||
// Images metadata for users | ||
// In progress virtual files from export | ||
export const paginatedForPathsWithEnrichment = async (context: AuthContext, user: AuthUser, paths: string[], opts?: FilesOptions<BasicStoreEntityDocument>) => { | ||
export const paginatedForPathsWithEnrichment = async (context: AuthContext, user: AuthUser, path: string, entity_id: string, opts?: FilesOptions<BasicStoreEntityDocument>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's now singular "path" instead of "paths", maybe we can rename the method too ? paginatedForPathWithEnrichment or paginatedFilesWithEnrichment so it's not dependent on the parameters
@@ -133,15 +159,14 @@ export const paginatedForPathsWithEnrichment = async (context: AuthContext, user | |||
orderOptions.orderMode = OrderingMode.Desc; | |||
} | |||
const listOptions = { ...opts, ...findOpts, ...orderOptions }; | |||
const pagination = await listEntitiesPaginated<BasicStoreEntityDocument>(context, user, [ENTITY_TYPE_INTERNAL_FILE], listOptions); | |||
|
|||
await checkFileAccess(context, user, entity_id, { entity_id, id: path, filename: '' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the third parameter of checkFileAccess
is scope
and here it's set with entity_id
, doesn't seem right, no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's the scope for the "UserAction" log, so I think it's a good call to have the entity_id to tell "User A tried to access files of this specific entity and cannot". But I'm open to other thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're completely right, my bad I'll change that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's even defined in UserActionListener, all event_scope
are typed with specific values
}, | ||
pendingFiles: (stixCoreObject, { first }, context) => { | ||
return paginatedForPathsWithEnrichment(context, context.user, ['import/pending'], { first, entity_id: stixCoreObject.id }); | ||
return paginatedForPathWithEnrichment(context, context.user, 'import/pending', stixCoreObject.id, { first }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the entity_id is not part of the options, it won't be used as a filter to list only files linked to this entity_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix analyst workbench list displayed in an entity data tab (should be filtered by entity, it displays all analyst workbenches)
// Get Files paginated with auto enrichment | ||
// Images metadata for users | ||
// In progress virtual files from export | ||
export const paginatedForPathsWithEnrichment = async (context: AuthContext, user: AuthUser, paths: string[], opts?: FilesOptions<BasicStoreEntityDocument>) => { | ||
export const paginatedForPathWithEnrichment = async (context: AuthContext, user: AuthUser, path: string, entity_id: string, opts?: FilesOptions<BasicStoreEntityDocument>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand why entity_id
has been extracted from opts as a separate parameter knowing that FilesOptions
type still has entity_id
. Why not keep entity_id inside opts and extract in the method ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit of semantic actually. We want to enforce that entity_id is a important prop from this function to get files and not just some stuff you can add in opts.
I understand your concern, we've discussed that with Julien and thougth it would be more explicit that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally and it seem to work well ✅
Closes #5435