Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release'
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Sep 21, 2020
2 parents 4d14825 + ac0f6a8 commit dc37f4c
Show file tree
Hide file tree
Showing 47 changed files with 2,554 additions and 4,377 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
"plugins": [
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-typeof-symbol",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
[
"module-resolver",
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Snyk
name: Modules security check

on: [push]

jobs:
snyk:
yarn-audit:
runs-on: ubuntu-latest
steps:
- name: Use Node.js 14.6.x
Expand All @@ -18,8 +18,4 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: install dependencies
run: yarn install
- run: yarn add snyk
- run: /home/runner/work/uwazi/uwazi/node_modules/.bin/snyk auth ${{ secrets.SNYK_TOKEN }}
- run: /home/runner/work/uwazi/uwazi/node_modules/.bin/snyk test


- run: yarn audit --level moderate --groups development
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable no-await-in-loop */
export default {
delta: 28,

name: 'remove_not_allowed_metadata_properties',

description:
'remove metadata properties from entities that is no longer on the template they belong',

async up(db) {
const cursor = db.collection('entities').find({});
let index = 1;
const templatesProperties = {};

while (await cursor.hasNext()) {
const entity = await cursor.next();
const entityTemplate = entity.template ? entity.template.toString() : 'empty';

if (!templatesProperties[entityTemplate]) {
const template = await db.collection('templates').findOne({ _id: entity.template });
templatesProperties[entityTemplate] = [];

if (template) {
templatesProperties[entityTemplate] = template.properties.map(p => p.name);
}
}

const propertiesOnTemplate = templatesProperties[entityTemplate];
const metadata = propertiesOnTemplate.reduce((newMetadata, prop) => {
if (entity.metadata && entity.metadata[prop]) {
//eslint-disable-next-line no-param-reassign
newMetadata[prop] = entity.metadata[prop];
}
return newMetadata;
}, {});

await db.collection('entities').updateOne({ _id: entity._id }, { $set: { metadata } });

process.stdout.write(`-> processed: ${index} \r`);
index += 1;
}

process.stdout.write('\r\n');
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { testingDB } from 'api/utils/testing_db';
import migration from '../index.js';
import fixtures, { template1, template2 } from './fixtures.js';

describe('migration remove_not_allowed_metadata_properties', () => {
beforeEach(async () => {
spyOn(process.stdout, 'write');
await testingDB.clearAllAndLoad(fixtures);
});

afterAll(async () => {
await testingDB.disconnect();
});

it('should have a delta number', () => {
expect(migration.delta).toBe(28);
});

it('should remove metadata properties from entities that do not exist on the template they belong', async () => {
await migration.up(testingDB.mongodb);

const template1Entities = await testingDB.mongodb
.collection('entities')
.find({ template: template1 })
.toArray();

const template2Entities = await testingDB.mongodb
.collection('entities')
.find({ template: template2 })
.toArray();

const entitiesNoTemplate = await testingDB.mongodb
.collection('entities')
.find({ template: { $exists: false } })
.toArray();

expect(entitiesNoTemplate).toEqual([expect.objectContaining({ metadata: {} })]);

expect(template1Entities).toEqual([
expect.objectContaining({
metadata: {
text: [{ value: 'value' }],
text_2: [{ value: 'value2' }],
},
}),
expect.objectContaining({
metadata: {
text: [{ value: 'value' }],
text_2: [{ value: 'value2' }],
},
}),
]);

expect(template2Entities).toEqual([
expect.objectContaining({
metadata: {
text_3: [{ value: 'value3' }],
},
}),
expect.objectContaining({ title: 'entity without metadata' }),
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { testingDB } from 'api/utils/testing_db';

const template1 = testingDB.id();
const template2 = testingDB.id();

export default {
templates: [
{
_id: template1,
properties: [
{ id: '1', type: 'text', name: 'text' },
{ id: '2', type: 'text', name: 'text_2' },
{ id: '3', type: 'text', name: 'not_present_on_entity' },
],
},
{
_id: template2,
properties: [{ id: '1', type: 'text', name: 'text_3' }],
},
],
entities: [
{
template: template1,
metadata: {
text: [{ value: 'value' }],
text_2: [{ value: 'value2' }],
text_3: [{ value: 'value3' }],
text_4: [{ value: 'value4' }],
},
},
{
title: 'entity without template',
metadata: {
text: [{ value: 'value' }],
text_2: [{ value: 'value2' }],
text_3: [{ value: 'value3' }],
text_4: [{ value: 'value4' }],
},
},
{
template: template1,
metadata: {
text: [{ value: 'value' }],
text_2: [{ value: 'value2' }],
text_3: [{ value: 'value3' }],
text_4: [{ value: 'value4' }],
},
},
{
template: template2,
metadata: {
text: [{ value: 'value' }],
text_2: [{ value: 'value2' }],
text_3: [{ value: 'value3' }],
text_4: [{ value: 'value4' }],
},
},
{
title: 'entity without metadata',
template: template2,
},
],
};

export { template1, template2 };
1 change: 1 addition & 0 deletions app/react/App/scss/modules/_document.scss
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ mark.searchTerm {

.copy-from {
flex: 1;
min-width: 50%;

.copy-from-buttons {
position: absolute;
Expand Down
1 change: 0 additions & 1 deletion app/react/App/specs/RouteHandler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/* eslint-disable max-statements */
import React from 'react';
import backend from 'fetch-mock';
import 'jasmine-immutablejs-matchers';
import { shallow } from 'enzyme';
import Immutable from 'immutable';
import moment from 'moment';
Expand Down
12 changes: 4 additions & 8 deletions app/react/Connections/components/ActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Map } from 'immutable';
import validate from 'validate.js';
import { Icon } from 'UI';
import { saveConnection, selectRangedTarget } from '../actions/actions';

Expand Down Expand Up @@ -32,21 +31,18 @@ export class ActionButton extends Component {

render() {
const connection = this.props.connection.toJS();
const validator = {
sourceDocument: { presence: true },
targetDocument: { presence: true },
template: { presence: true },
};

let connectionValid =
connection.sourceDocument && connection.targetDocument && connection.template;

if (this.props.type === 'basic') {
delete connection.sourceRange;
}

if (this.props.type !== 'basic') {
validator.sourceRange = { presence: true };
connectionValid = connectionValid && connection.sourceRange;
}

const connectionValid = !validate(connection, validator);
const enabled = connectionValid && !this.props.busy;
const buttonClass =
this.props.action === 'save' ? 'btn btn-success' : 'edit-metadata btn btn-success';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'jasmine-immutablejs-matchers';

import { fromJS as Immutable } from 'immutable';

import reducer from '../connectionReducer';
Expand Down
1 change: 0 additions & 1 deletion app/react/Connections/reducers/specs/uiReducer.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { fromJS as Immutable } from 'immutable';
import 'jasmine-immutablejs-matchers';

import uiReducer from '../uiReducer';

Expand Down
Loading

0 comments on commit dc37f4c

Please sign in to comment.