Skip to content

Commit

Permalink
[api/frontend] Fix deletion of user, relation handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Hassine committed Feb 19, 2020
1 parent 2875e5b commit c41d68d
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ListItemText from '@material-ui/core/ListItemText';
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
import Checkbox from '@material-ui/core/Checkbox';
import Avatar from '@material-ui/core/Avatar';
import Alert from '@material-ui/lab/Alert/Alert';
import { commitMutation, QueryRenderer } from '../../../../relay/environment';
import inject18n from '../../../../components/i18n';
import { markingDefinitionsLinesSearchQuery } from '../marking_definitions/MarkingDefinitionsLines';
Expand Down Expand Up @@ -83,14 +84,19 @@ class GroupEditionPermissionsComponent extends Component {
}

render() {
const { classes, group } = this.props;
const { classes, group, t } = this.props;
const groupMarkingDefinitions = pipe(
pathOr([], ['permissions', 'edges']),
map((n) => ({ id: n.node.id, relation: n.relation.id })),
)(group);

return (
<div>
<div style={{ paddingTop: 15 }}>
<Alert severity="warning" style={{ marginBottom: 10 }}>
{t(
'Groups permissions on data marking is not fully implemented yet.',
)}
</Alert>
<QueryRenderer
query={markingDefinitionsLinesSearchQuery}
variables={{ search: '' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class UserCreation extends Component {
</div>
<div className={classes.container}>
<Alert severity="info">{t('User will be created with default roles.')}</Alert>
<br />
<Formik
initialValues={{
name: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ class UserEditionOverviewComponent extends Component {
<MenuItem value="auto">
<em>{t('Automatic')}</em>
</MenuItem>
RO
<MenuItem value="en">English</MenuItem>
<MenuItem value="fr">Français</MenuItem>
</SelectField>
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/src/utils/Localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ const i18n = {
'Direct targeting of this sector': 'Ciblage direct de ce secteur',
'Direct targeting of this region': 'Ciblage direct de cette région',
'Direct targeting of this country': 'Ciblage direct de ce pays',
'Groups permissions on data marking is not fully implemented yet.':
"Les permissions des groupes sur le marquage des données n'est pas encore implémenté.",
// Menu
Dashboard: 'Tableau de bord',
Visualization: 'Visualisation',
Expand Down
8 changes: 7 additions & 1 deletion opencti-platform/opencti-graphql/src/config/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const BUS_TOPICS = {
KillChainPhase: {
EDIT_TOPIC: 'KILL_CHAIN_PHASE_EDIT_TOPIC',
ADDED_TOPIC: 'KILL_CHAIN_PHASE_ADDED_TOPIC'
},
Group: {
EDIT_TOPIC: 'GROUP_EDIT_TOPIC',
ADDED_TOPIC: 'GROUP_ADDED_TOPIC'
}
};

Expand Down Expand Up @@ -118,6 +122,8 @@ logger.add(
);

// eslint-disable-next-line
logger.info(`🚀 OpenCTI started in ${environment} mode with ${externalConfigurationFile ? 'external' : 'embedded'} file`);
logger.info(
`🚀 OpenCTI started in ${environment} mode with ${externalConfigurationFile ? 'external' : 'embedded'} file`
);
export const isAppRealTime = nconf.get('app:reactive') && JSON.parse(nconf.get('app:reactive'));
export default nconf;
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ const elMergeRelation = (concept, fromConnection, toConnection) => {
};
const elReconstructRelation = (concept, relationsMap = null) => {
const naturalDirections = rolesMap[concept.relationship_type];
if (!naturalDirections) {
throw new Error(`[ELASTIC] Missing rolesMap of the relation type ${concept.relationship_type}`);
}
const bindingByAlias = invertObj(naturalDirections);
const { connections } = concept;
// Need to rebuild the from and the to.
Expand Down
4 changes: 4 additions & 0 deletions opencti-platform/opencti-graphql/src/database/graknRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export const rolesMap = {
allowed: 'from',
allow: 'to'
},
user_role: {
client: 'from',
position: 'to'
},
// endregion
// region relation_embedded
authored_by: {
Expand Down
3 changes: 1 addition & 2 deletions opencti-platform/opencti-graphql/src/domain/connector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assoc, filter, includes, isNil, map, pipe } from 'ramda';
import { assoc, filter, includes, map, pipe } from 'ramda';
import {
createEntity,
deleteEntityById,
Expand All @@ -11,7 +11,6 @@ import {
updateAttribute
} from '../database/grakn';
import { connectorConfig, registerConnectorQueues } from '../database/rabbitmq';
import { ForbiddenAccess } from '../config/errors';

export const CONNECTOR_INTERNAL_IMPORT_FILE = 'INTERNAL_IMPORT_FILE'; // Files mime types to support (application/json, ...) -> import-
export const CONNECTOR_INTERNAL_EXPORT_FILE = 'INTERNAL_EXPORT_FILE'; // Files mime types to generate (application/pdf, ...) -> export-
Expand Down
17 changes: 15 additions & 2 deletions opencti-platform/opencti-graphql/src/domain/group.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
createEntity,
createRelation,
deleteEntityById,
deleteRelationById,
escapeString,
executeWrite,
findWithConnectedRelations,
Expand Down Expand Up @@ -41,7 +43,7 @@ export const permissions = async groupId => {

export const addGroup = async (user, group) => {
const created = await createEntity(group, 'Group', { modelType: TYPE_OPENCTI_INTERNAL });
return notify(BUS_TOPICS.StixDomainEntity.ADDED_TOPIC, created, user);
return notify(BUS_TOPICS.Group.ADDED_TOPIC, created, user);
};
export const groupDelete = groupId => deleteEntityById(groupId, 'Group');

Expand All @@ -50,6 +52,17 @@ export const groupEditField = (user, groupId, input) => {
return updateAttribute(groupId, 'Group', input, wTx);
}).then(async () => {
const group = await loadEntityById(groupId, 'Group');
return notify(BUS_TOPICS.StixDomainEntity.EDIT_TOPIC, group, user);
return notify(BUS_TOPICS.Group.EDIT_TOPIC, group, user);
});
};

export const groupAddRelation = async (user, groupId, input) => {
const data = await createRelation(groupId, input, {}, 'Group', null);
return notify(BUS_TOPICS.Group.EDIT_TOPIC, data, user);
};

export const groupDeleteRelation = async (user, groupId, relationId) => {
await deleteRelationById(relationId, 'relation');
const data = await loadEntityById(groupId, 'Group');
return notify(BUS_TOPICS.Group.EDIT_TOPIC, data, user);
};
12 changes: 3 additions & 9 deletions opencti-platform/opencti-graphql/src/domain/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,11 @@ export const userAddRelation = async (user, userId, input) => {
const data = await createRelation(userId, input, {}, 'User', null);
return notify(BUS_TOPICS.StixDomainEntity.EDIT_TOPIC, data, user);
};
export const userDeleteRelation = async (
user,
userId,
relationId = null,
toId = null,
relationType = 'stix_relation_embedded'
) => {
export const userDeleteRelation = async (user, userId, relationId = null, toId = null, relationType = 'relation') => {
if (relationId) {
await deleteRelationById(relationId, 'stix_relation_embedded');
await deleteRelationById(relationId, 'relation');
} else if (toId) {
await deleteRelationsByFromAndTo(userId, toId, relationType, 'stix_relation_embedded');
await deleteRelationsByFromAndTo(userId, toId, relationType, 'relation');
} else {
throw new Error('Cannot delete the relation, missing relationId or toId');
}
Expand Down
21 changes: 13 additions & 8 deletions opencti-platform/opencti-graphql/src/resolvers/group.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { addGroup, groupDelete, findAll, findById, members, permissions, groupEditField } from '../domain/group';
import {
stixDomainEntityEditContext,
stixDomainEntityCleanContext,
stixDomainEntityAddRelation,
stixDomainEntityDeleteRelation
} from '../domain/stixDomainEntity';
addGroup,
groupDelete,
findAll,
findById,
members,
permissions,
groupEditField,
groupDeleteRelation,
groupAddRelation
} from '../domain/group';
import { stixDomainEntityEditContext, stixDomainEntityCleanContext } from '../domain/stixDomainEntity';
import { fetchEditContext } from '../database/redis';

const groupResolvers = {
Expand All @@ -23,8 +28,8 @@ const groupResolvers = {
fieldPatch: ({ input }) => groupEditField(user, id, input),
contextPatch: ({ input }) => stixDomainEntityEditContext(user, id, input),
contextClean: () => stixDomainEntityCleanContext(user, id),
relationAdd: ({ input }) => stixDomainEntityAddRelation(user, id, input),
relationDelete: ({ relationId }) => stixDomainEntityDeleteRelation(user, id, relationId)
relationAdd: ({ input }) => groupAddRelation(user, id, input),
relationDelete: ({ relationId }) => groupDeleteRelation(user, id, relationId)
}),
groupAdd: (_, { input }, { user }) => addGroup(user, input)
}
Expand Down

0 comments on commit c41d68d

Please sign in to comment.