Skip to content
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

Merged
merged 1 commit into from
Jan 22, 2024
Merged

[backend] Fix the file change right #5587

merged 1 commit into from
Jan 22, 2024

Conversation

Kedae
Copy link
Member

@Kedae Kedae commented Jan 18, 2024

Closes #5435

@Kedae Kedae added the filigran team use to identify PR from the Filigran team label Jan 18, 2024
@Kedae Kedae requested a review from richard-julien January 18, 2024 13:31
Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: 39 lines in your changes are missing coverage. Please review.

Comparison is base (6ef714f) 66.12% compared to head (dccdd7d) 66.14%.

Files Patch % Lines
...l/src/modules/internal/document/document-domain.ts 65.00% 14 Missing ⚠️
...-platform/opencti-graphql/src/http/httpPlatform.js 0.00% 10 Missing ⚠️
...rm/opencti-graphql/src/resolvers/stixCoreObject.js 20.00% 4 Missing ⚠️
...opencti-graphql/src/resolvers/externalReference.js 25.00% 3 Missing ⚠️
...encti-graphql/src/resolvers/stixCyberObservable.js 25.00% 3 Missing ⚠️
...cti-platform/opencti-graphql/src/resolvers/file.js 33.33% 2 Missing ⚠️
...ql/src/modules/internal/document/document-types.ts 0.00% 1 Missing ⚠️
...ncti-graphql/src/resolvers/stixCoreRelationship.js 50.00% 1 Missing ⚠️
.../opencti-graphql/src/resolvers/stixDomainObject.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5587      +/-   ##
==========================================
+ Coverage   66.12%   66.14%   +0.01%     
==========================================
  Files         512      512              
  Lines       60398    60400       +2     
  Branches     4401     4406       +5     
==========================================
+ Hits        39936    39949      +13     
+ Misses      20462    20451      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Kedae Kedae removed the request for review from richard-julien January 18, 2024 14:41
// 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>) => {
Copy link
Member

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: '' });
Copy link
Member

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 ?

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scopes should be a limited list of operations I think, but I don't know well the activity logging part. I can see this graph in a user activity analytics which is a distribution based on scope :

image

It might not help to have ids in scope

Copy link
Member Author

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 :)

Copy link
Member

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

@SouadHadjiat
Copy link
Member

There is an issue here : I can see all analyst workbenches in a report (I should see only the report analyst workbenches, none here)
I can't reproduce the issue on testing platform.

image

},
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 });
Copy link
Member

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

Copy link
Member

@SouadHadjiat SouadHadjiat left a 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>) => {
Copy link
Member

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 ?

Copy link
Member Author

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

Copy link
Member

@SouadHadjiat SouadHadjiat left a 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 ✅

@Kedae Kedae merged commit 184a4ca into master Jan 22, 2024
5 checks passed
@SamuelHassine SamuelHassine deleted the issue/5435 branch February 1, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filigran team use to identify PR from the Filigran team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Impossible to see a file uploaded if we are not part of the platform organization
2 participants