-
Notifications
You must be signed in to change notification settings - Fork 799
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/frontend] Add user and group confidence level (#4304) #5436
Conversation
opencti-platform/opencti-front/src/private/components/settings/users/UserEditionOverview.tsx
Outdated
Show resolved
Hide resolved
opencti-platform/opencti-graphql/src/migrations/1704792752287-user-confidence-level.js
Outdated
Show resolved
Hide resolved
...cti-platform/opencti-graphql/src/modules/attributes/internalObject-registrationAttributes.ts
Outdated
Show resolved
Hide resolved
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #5436 +/- ##
==========================================
+ Coverage 66.12% 66.15% +0.03%
==========================================
Files 513 513
Lines 60641 60793 +152
Branches 4434 4448 +14
==========================================
+ Hits 40097 40218 +121
- Misses 20544 20575 +31 ☔ View full report in Codecov by Sentry. |
I'm able to send through the API a partial update like {
"id": "<id>",
"input": {
"key": "user_confidence_level",
"value": {
"max_confidence": 96
}
} Which will update the |
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.
Seems good to me, but I'll let someone else have a look at migration and attributes registrations 😅
opencti-platform/opencti-front/src/private/components/settings/users/UserConfidenceLevel.tsx
Outdated
Show resolved
Hide resolved
opencti-platform/opencti-front/src/private/components/settings/users/UserConfidenceLevel.tsx
Outdated
Show resolved
Hide resolved
Thanks ! |
back to draft : I need to make sure partial edit payload are not accepted |
b42d752
to
d189a00
Compare
f5d2686
to
f376065
Compare
We need to add schema validation when patching a field. Everything in this PR is ok, but we need this validation before merging to master. EDIT: validation will be done in another issue (#5696) , this branch will still serve as feature branch |
32b5a01
to
00ac6e9
Compare
ce1c332
to
76e784f
Compare
<Grid container={true} spacing={3} alignItems="end"> | ||
<Grid container={true} spacing={3} > |
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.
this align the 2 inputs (input number + scale Selector) to the top, keeping alignments when the input number shows an error label below.
<SettingsMessagesBanner /> | ||
<PlatformCriticalAlertDialog alerts={settings.platform_critical_alerts}/> |
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.
New popup dialog for admins when the backend has some "critical alerts" to show.
This is for warning about groups with null confidence levels, but could be extended to other types of alerts
platform_critical_alerts { | ||
message | ||
type | ||
details { | ||
groups { | ||
id | ||
name | ||
} | ||
} | ||
} |
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.
alert details shall depends on alert type... current implem is a bit rough on the edges but we had to move quickly about this.
const max_confidence = n?.node.group_confidence_level | ||
? `${t_i18n('Max Confidence Level:')} ${n.node.group_confidence_level.max_confidence}` | ||
: t_i18n('No confidence level'); | ||
const newLabel = showConfidence | ||
? `${n?.node.name} (${max_confidence})` | ||
: n?.node.name ?? ''; |
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.
old GroupField Select, refactored to typescript, and added opt prop showConfidence to add the group confidence to the label after the name of the group.
effective_confidence_level: { | ||
label: 'confidence', | ||
width: '10%', | ||
isSortable: false, |
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.
effective confidence level is a computed value backend side, not an attribute in DB (depends on user's confidence + his groups confidence)
we cannot craft a query to do this computation, so we cannot paginate and sort properly this value.
if (name === 'group_confidence_level') { | ||
if (group.group_confidence_level) { | ||
commitFieldPatch({ | ||
variables: { | ||
id: group.id, | ||
input: { | ||
key: 'group_confidence_level', | ||
object_path: '/group_confidence_level/max_confidence', | ||
value: parseInt(value, 10), | ||
}, | ||
}, | ||
}); | ||
} else { | ||
commitFieldPatch({ | ||
variables: { | ||
id: group.id, | ||
input: { | ||
key: 'group_confidence_level', | ||
value: { | ||
max_confidence: parseInt(value, 10), | ||
overrides: [], | ||
}, | ||
}, | ||
}, | ||
}); | ||
} |
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 else statement could work in both cases (existing confidence or not) right now, but we will implement soon the overrides definition and edition (6.1). By then we'll need to patch with object_path
anyway.
user_confidence_level_enabled: Yup.boolean(), | ||
user_confidence_level: Yup.number() | ||
.min(0, t('The value must be greater than or equal to 0')) | ||
.max(100, t('The value must be less than or equal to 100')) | ||
.when('user_confidence_level_enabled', { | ||
is: true, | ||
then: (schema) => schema.required(t('This field is required')).nullable(), | ||
otherwise: (schema) => schema.nullable(), | ||
}), |
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.
a technical field (not to submit) associated with a when
. Very useful for validation conditioned on other values!
return computeUserEffectiveConfidenceLevel(user); | ||
}; | ||
|
||
export const computeUserEffectiveConfidenceLevel = (user) => { |
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.
function split for easy unit tests
type PlatformCriticalAlertDetails { | ||
groups: [Group!]! | ||
} |
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.
this is where the critical alert system is a bit limited, not well generalized. details shall depends on type.
I did not have time to overengineer this system, honestly it's a quick bandaid to help admins prepare for 6.0.
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.
Not a problem, thats purely dynamic and so easy to change.
@@ -1704,7 +1704,6 @@ | |||
"INGESTION_MANAGER": "Ingestion manager", | |||
"PLAYBOOK_MANAGER": "Playbook manager", | |||
"FILE_INDEX_MANAGER": "File index manager", | |||
"INDICATOR_DECAY_MANAGER": "Indicator decay manager", |
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.
why has this translation been removed ?
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.
In must have executed an extract script in my branch, pre-rebase.
I'll check and restore the missing keys.
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've done a review, all keys not related to confidence level have been restored (there was a couple)
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 just did a "quick read" review so I share it, I will take take time for a deeper one later.
opencti-platform/opencti-front/src/private/components/settings/groups/GroupLine.tsx
Show resolved
Hide resolved
opencti-platform/opencti-front/src/private/components/settings/groups/GroupConfidenceLevel.tsx
Show resolved
Hide resolved
opencti-platform/opencti-front/src/private/components/settings/users/UserConfidenceLevel.tsx
Show resolved
Hide resolved
const renderSource = () => { | ||
const source = (confidenceLevel as Data_EffectiveConfidenceLevel)?.source; | ||
|
||
// FIXME: if watching the current user's detailed view, the source is {}, hence the check if (source.entity_type && ...) below |
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.
FIXME later ?
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 did not have time to investigate, but it's probably related to how we poorly handle the graphql cache records
Warning: RelayModernRecord: Invalid record update, expected both versions of record 88ec0c6a-13ce-5e39-b486-354fe4a7084f
to have the same __typename
but got conflicting types MeUser
and User
. The GraphQL server likely violated the globally unique id requirement by returning the same id for different objects.
Another whole issue to address, certainly not in this PR.
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'm editing myself, which collides with MeUser
query for instance. The record gets "updated" wrongly somehow.
Co-authored-by: Laurent Bonnet <laurent.bonnet@filigran.io>
Co-authored-by: Sarah Bocognano <98532359+SarahBocognano@users.noreply.github.com>
Co-authored-by: BocognanoSarah <sarah.bocognano@filigran.io>
9f0452f
to
1344932
Compare
Proposed changes
This PR addresses the following issues:
Have a look at each issue description for details.
Code review highlights
The key points to review are backend additions and changes, the model definition.
A lot of stuff in the frontend besides the core job (refactor in TS, solving react warnings) make the review difficult, I'm sorry.
How can you test this PR?
Here are some scenarios to test:
start the platform on this branch -> you shall see the critical alert dialog, inviting you to edit all your groups
Create a user without groups -> they should be created with default groups
Create a user with groups -> they should be created with the specified groups, and not the default group
Create a user without a confidence level and no group
Create a user without a confidence level and no group -> it should be displayed as in error in the various view (list, details, list of users in a group details view)
Create a user with a confidence level -> it should be displayed in the various view (list, details, list of users in a group details view) -> tooltip shall state it's coming from user
Create a user without a confidence level but with a group -> it should be displayed in the various view (list, details, list of users in a group details view) -> tooltip shall state it's coming from a specific group - link clickable in tooltip
Create a group, you must select a confidence level -> value is then displayed correctly in list and details
Open a group without confidence level -> explicit alert in details -> disappears when edited
all groups are set with a confidence level -> refresh page -> no more alert dialog
If you wish to artificially nuke your group confidence level for testing purpose, a GQL query on playground is possible (there is no validation implemented yet - see #5696).
Checklist
Further comments
Now that the new schema definition is in place, the job done on the subject of user's confidence level has been fully reworked.
Thus this PR invalidates the previous PR on the subject: #5283 #5292 #5323