Skip to content

Commit 18042df

Browse files
authored
chore(force-release): release forest-express-mongoose 8.0.0
2 parents d926b61 + e916e3b commit 18042df

26 files changed

+662
-265
lines changed

CHANGELOG.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
# [8.0.0-beta.9](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.0.0-beta.8...v8.0.0-beta.9) (2021-07-19)
2+
3+
# [8.0.0-beta.8](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.0.0-beta.7...v8.0.0-beta.8) (2021-07-19)
4+
5+
6+
### Bug Fixes
7+
8+
* add isSearchable to collection options ([#623](https://github.com/ForestAdmin/forest-express-mongoose/issues/623)) ([bc8a2c1](https://github.com/ForestAdmin/forest-express-mongoose/commit/bc8a2c1b5260523e6c5945c6017ce87792a179fa))
9+
* add missing Json value for FieldType Type ([#620](https://github.com/ForestAdmin/forest-express-mongoose/issues/620)) ([f40126a](https://github.com/ForestAdmin/forest-express-mongoose/commit/f40126ac847254a9cbbedddf25305fff4821c0f7))
10+
11+
# [8.0.0-beta.7](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.0.0-beta.6...v8.0.0-beta.7) (2021-07-09)
12+
13+
14+
### Features
15+
16+
* allow hooks for global and bulk smart action ([#622](https://github.com/ForestAdmin/forest-express-mongoose/issues/622)) ([2c5c7d1](https://github.com/ForestAdmin/forest-express-mongoose/commit/2c5c7d19cd6887b66014c255dd032c20b7bc54df))
17+
18+
19+
### BREAKING CHANGES
20+
21+
* record is no longer send to the hook middleware & values option on smart action is no longer supported
22+
23+
# [8.0.0-beta.6](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.0.0-beta.5...v8.0.0-beta.6) (2021-07-08)
24+
25+
26+
### Bug Fixes
27+
28+
* abstractRecord type ([#624](https://github.com/ForestAdmin/forest-express-mongoose/issues/624)) ([56fbac3](https://github.com/ForestAdmin/forest-express-mongoose/commit/56fbac359c57a7e572de227a9ca2eb85d6496487))
29+
30+
# [8.0.0-beta.5](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.0.0-beta.4...v8.0.0-beta.5) (2021-07-06)
31+
32+
33+
### Bug Fixes
34+
35+
* fix types ([7e2d7f2](https://github.com/ForestAdmin/forest-express-mongoose/commit/7e2d7f220abbcfff79a1f33e3635da5df65c041d))
36+
* **authentication:** error during authentication when the environment is secret passed as a liana option and not an environment variable ([#610](https://github.com/ForestAdmin/forest-express-mongoose/issues/610)) ([26aa456](https://github.com/ForestAdmin/forest-express-mongoose/commit/26aa456dacfc3fe67bcbb029a6ce1ea5eca1fe16))
37+
* **enums:** fix nested enum types not having values in forestadmin-schema ([#612](https://github.com/ForestAdmin/forest-express-mongoose/issues/612)) ([e9a369b](https://github.com/ForestAdmin/forest-express-mongoose/commit/e9a369bbf0da0502c8fe760797701a5c379ca0f5))
38+
* **intercom:** fix date conversion from unix timestamp to js date of intercom attributes ([#604](https://github.com/ForestAdmin/forest-express-mongoose/issues/604)) ([5c824c0](https://github.com/ForestAdmin/forest-express-mongoose/commit/5c824c0d982bf733b2c70b7065768abb869b1021))
39+
* **related-data:** reaching an embedded has-many relationship by URL does not display any records on mongoose ([#614](https://github.com/ForestAdmin/forest-express-mongoose/issues/614)) ([4f608ee](https://github.com/ForestAdmin/forest-express-mongoose/commit/4f608ee5311f05342fb0d96dbfaba1d5f43af29b))
40+
* correctly get the IP address from the request headers ([#592](https://github.com/ForestAdmin/forest-express-mongoose/issues/592)) ([e8349bf](https://github.com/ForestAdmin/forest-express-mongoose/commit/e8349bf7a2e75219382e01086a080b2127e91c80))
41+
* prevent IP check from failing for the proxies including the port in the headers ([#601](https://github.com/ForestAdmin/forest-express-mongoose/issues/601)) ([8e61bd6](https://github.com/ForestAdmin/forest-express-mongoose/commit/8e61bd61258d3dd3c35b57ae74c104da2106267f))
42+
43+
44+
### Features
45+
46+
* add typescript declaration file ([#594](https://github.com/ForestAdmin/forest-express-mongoose/issues/594)) ([fc0264d](https://github.com/ForestAdmin/forest-express-mongoose/commit/fc0264d48f8d5cde6898d7f7b54b5f820a328e8d))
47+
* include role in the user data inside the request ([#597](https://github.com/ForestAdmin/forest-express-mongoose/issues/597)) ([508047b](https://github.com/ForestAdmin/forest-express-mongoose/commit/508047b51cf70a67098648f36cfecd689f9d2b6a))
48+
* **schema:** move some meta data under stack attribute to prevent blocking scenarios on DWO ([#591](https://github.com/ForestAdmin/forest-express-mongoose/issues/591)) ([9ef8c44](https://github.com/ForestAdmin/forest-express-mongoose/commit/9ef8c44ff726d81682708500057b8a5b9b34cfd1))
49+
150
## [7.9.2](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.9.1...v7.9.2) (2021-07-06)
251

352

@@ -12,6 +61,13 @@
1261

1362
* add missing Json value for FieldType Type ([#620](https://github.com/ForestAdmin/forest-express-mongoose/issues/620)) ([f40126a](https://github.com/ForestAdmin/forest-express-mongoose/commit/f40126ac847254a9cbbedddf25305fff4821c0f7))
1463

64+
# [8.0.0-beta.4](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.0.0-beta.3...v8.0.0-beta.4) (2021-07-02)
65+
66+
67+
### Features
68+
69+
* **security:** secure segments queries ([#616](https://github.com/ForestAdmin/forest-express-mongoose/issues/616)) ([f09990a](https://github.com/ForestAdmin/forest-express-mongoose/commit/f09990a64ec27a882e9560007e068ae068bf562f))
70+
1571
# [7.9.0](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.8.5...v7.9.0) (2021-07-01)
1672

1773

@@ -40,6 +96,13 @@
4096

4197
* **authentication:** error during authentication when the environment is secret passed as a liana option and not an environment variable ([#610](https://github.com/ForestAdmin/forest-express-mongoose/issues/610)) ([26aa456](https://github.com/ForestAdmin/forest-express-mongoose/commit/26aa456dacfc3fe67bcbb029a6ce1ea5eca1fe16))
4298

99+
# [8.0.0-beta.3](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.0.0-beta.2...v8.0.0-beta.3) (2021-06-22)
100+
101+
102+
### Bug Fixes
103+
104+
* broken value charts due to missing user on ValueStatGetter constructor ([#609](https://github.com/ForestAdmin/forest-express-mongoose/issues/609)) ([0b52930](https://github.com/ForestAdmin/forest-express-mongoose/commit/0b52930dd6ced63bf3defe7c3263b27a8cb8f793))
105+
43106
## [7.8.2](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.8.1...v7.8.2) (2021-06-15)
44107

45108

@@ -61,6 +124,19 @@
61124

62125
* include role in the user data inside the request ([#597](https://github.com/ForestAdmin/forest-express-mongoose/issues/597)) ([508047b](https://github.com/ForestAdmin/forest-express-mongoose/commit/508047b51cf70a67098648f36cfecd689f9d2b6a))
63126

127+
# [8.0.0-beta.2](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.0.0-beta.1...v8.0.0-beta.2) (2021-06-07)
128+
129+
130+
### Features
131+
132+
* **smart-action:** user can add dynamically field with hook on smart action form ([#593](https://github.com/ForestAdmin/forest-express-mongoose/issues/593)) ([90b4330](https://github.com/ForestAdmin/forest-express-mongoose/commit/90b4330e073c78da79a2ebbbbb2055e9e459a940))
133+
134+
135+
### BREAKING CHANGES
136+
137+
* **smart-action:** fields parameters on hook function is no longer a map of field, it is now an array.
138+
change hook is no longer choosen by the field name, field need to have hook defined inside it definition by addin a props hook.
139+
64140
## [7.7.1](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.7.0...v7.7.1) (2021-06-03)
65141

66142

@@ -75,6 +151,16 @@
75151

76152
* **schema:** move some meta data under stack attribute to prevent blocking scenarios on DWO ([#591](https://github.com/ForestAdmin/forest-express-mongoose/issues/591)) ([9ef8c44](https://github.com/ForestAdmin/forest-express-mongoose/commit/9ef8c44ff726d81682708500057b8a5b9b34cfd1))
77153

154+
# [8.0.0-beta.1](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.6.2...v8.0.0-beta.1) (2021-05-31)
155+
156+
157+
* feat(scopes)!: enforce scopes restrictions on a wider range of requests (#586) ([2ce0904](https://github.com/ForestAdmin/forest-express-mongoose/commit/2ce09043f0115a791f0b831ab49b08c534c50f2e)), closes [#586](https://github.com/ForestAdmin/forest-express-mongoose/issues/586)
158+
159+
160+
### BREAKING CHANGES
161+
162+
* the public API of forest-express has changed to include the parameters which are needed to evaluate scope filters. This includes PermissionMiddlewareCreator, all classes on the /exposed folder and most services. Many routes now require providing the current user timezone.
163+
78164
## [7.6.2](https://github.com/ForestAdmin/forest-express-mongoose/compare/v7.6.1...v7.6.2) (2021-05-25)
79165

80166

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "forest-express-mongoose",
33
"description": "Official Express/Mongoose Liana for Forest",
4-
"version": "7.9.2",
4+
"version": "8.0.0-beta.9",
55
"author": "Sandro Munda <[email protected]>",
66
"contributors": [
77
"Arnaud Besnier <[email protected]>",
@@ -27,7 +27,7 @@
2727
"dependencies": {
2828
"@babel/runtime": "7.10.1",
2929
"bluebird": "2.9.25",
30-
"forest-express": "8.7.5",
30+
"forest-express": "9.0.0",
3131
"http-errors": "1.7.2",
3232
"lodash": "4.17.21",
3333
"moment": "2.24.0",
@@ -48,6 +48,7 @@
4848
"@types/jest": "26.0.13",
4949
"@typescript-eslint/eslint-plugin": "4.27.0",
5050
"@typescript-eslint/parser": "4.27.0",
51+
"@types/express": "4.17.13",
5152
"babel-eslint": "10.0.3",
5253
"eslint": "6.7.2",
5354
"eslint-config-airbnb-base": "14.0.0",

src/services/has-many-getter.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
const _ = require('lodash');
2-
const Interface = require('forest-express');
3-
const SearchBuilder = require('./search-builder');
4-
const utils = require('../utils/schema');
5-
const FiltersParser = require('./filters-parser');
1+
import Interface from 'forest-express';
2+
import _ from 'lodash';
3+
import utils from '../utils/schema';
4+
import getScopedParams from '../utils/scopes';
5+
import FiltersParser from './filters-parser';
6+
import SearchBuilder from './search-builder';
67

78
const OBJECTID_REGEXP = /^[0-9a-fA-F]{24}$/;
89

910
class HasManyGetter {
10-
constructor(parentModel, childModel, opts, params) {
11+
constructor(parentModel, model, opts, params, user) {
1112
this._parentModel = parentModel;
12-
this._childModel = childModel;
13+
this._model = model;
1314
this._params = params;
14-
this._opts = opts;
15-
this._searchBuilder = new SearchBuilder(childModel, opts, params);
15+
this._opts = { Mongoose: model.base, connections: model.base.connections };
16+
this._user = user;
17+
this._searchBuilder = new SearchBuilder(model, this._opts, params);
1618
}
1719

1820
_hasPagination() {
@@ -42,7 +44,7 @@ class HasManyGetter {
4244
}
4345

4446
_handlePopulate(query) {
45-
const schema = Interface.Schemas.schemas[utils.getModelName(this._childModel)];
47+
const schema = Interface.Schemas.schemas[utils.getModelName(this._model)];
4648

4749
_.each(schema.fields, (field) => {
4850
if (field.reference) {
@@ -54,18 +56,17 @@ class HasManyGetter {
5456
}
5557

5658
async _buildConditions(recordIds) {
57-
const conditions = {
58-
$and: [{ _id: { $in: recordIds } }],
59-
};
59+
const conditions = { $and: [{ _id: { $in: recordIds } }] };
6060

61-
if (this._params.search) {
61+
const params = await getScopedParams(this._params, this._model, this._user);
62+
if (params.search) {
6263
const conditionsSearch = await this._searchBuilder.getConditions();
6364
conditions.$and.push(conditionsSearch);
6465
}
6566

66-
if (this._params.filters) {
67-
const filtersParser = new FiltersParser(this._childModel, this._params.timezone, this._opts);
68-
const newFilters = await filtersParser.replaceAllReferences(this._params.filters);
67+
if (params.filters) {
68+
const filtersParser = new FiltersParser(this._model, params.timezone, this._opts);
69+
const newFilters = await filtersParser.replaceAllReferences(params.filters);
6970
const newFiltersString = JSON.stringify(newFilters);
7071
conditions.$and.push(await filtersParser.perform(newFiltersString));
7172
}
@@ -88,7 +89,7 @@ class HasManyGetter {
8889

8990
const childRecordIds = _.map(parentRecords, (record) => record[this._params.associationName]);
9091
const conditions = await this._buildConditions(childRecordIds);
91-
const query = this._childModel.find(conditions);
92+
const query = this._model.find(conditions);
9293
this._handlePopulate(query);
9394

9495
const childRecords = await query;

src/services/line-stat-getter.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import Interface from 'forest-express';
12
import _ from 'lodash';
23
import moment from 'moment-timezone';
3-
import Interface from 'forest-express';
4-
import QueryBuilder from './query-builder';
54
import utils from '../utils/schema';
5+
import getScopedParams from '../utils/scopes';
6+
import QueryBuilder from './query-builder';
67

78
class LineStatGetter {
8-
constructor(model, params, opts) {
9+
constructor(model, params, opts, user) {
910
this._model = model;
1011
this._params = params;
11-
this._opts = opts;
12+
this._opts = { Mongoose: this._model.base, connections: this._model.base.connections };
13+
this._user = user;
1214
}
1315

1416
_getReference(fieldName) {
@@ -98,13 +100,14 @@ class LineStatGetter {
98100
}
99101

100102
async perform() {
101-
const timezone = -parseInt(moment().tz(this._params.timezone).format('Z'), 10);
103+
const params = await getScopedParams(this._params, this._model, this._user);
104+
const timezone = -parseInt(moment().tz(params.timezone).format('Z'), 10);
102105
const timezoneOffset = timezone * 60 * 60 * 1000;
103-
const queryBuilder = new QueryBuilder(this._model, this._params, this._opts);
106+
const queryBuilder = new QueryBuilder(this._model, params, this._opts);
104107

105-
const populateGroupByField = this._getReference(this._params.group_by_field);
108+
const populateGroupByField = this._getReference(params.group_by_field);
106109
const groupByFieldName = populateGroupByField
107-
? this._params.group_by_field.replace(':', '.') : this._params.group_by_field;
110+
? params.group_by_field.replace(':', '.') : params.group_by_field;
108111

109112
const jsonQuery = await queryBuilder.getQueryWithFiltersAndJoins(null);
110113
if (populateGroupByField) {
@@ -118,68 +121,68 @@ class LineStatGetter {
118121
groupBy._id = `$${groupByFieldName}`;
119122
}
120123

121-
if (this._params.group_by_date_field) {
122-
switch (this._params.time_range) {
124+
if (params.group_by_date_field) {
125+
switch (params.time_range) {
123126
case 'Day':
124127
groupBy.year = {
125128
$year: [{
126-
$subtract: [`$${this._params.group_by_date_field}`, timezoneOffset],
129+
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
127130
}],
128131
};
129132
groupBy.month = {
130133
$month: [{
131-
$subtract: [`$${this._params.group_by_date_field}`, timezoneOffset],
134+
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
132135
}],
133136
};
134137
groupBy.day = {
135138
$dayOfMonth: [{
136-
$subtract: [`$${this._params.group_by_date_field}`, timezoneOffset],
139+
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
137140
}],
138141
};
139142
break;
140143
case 'Week':
141144
groupBy.week = {
142145
$week: [{
143-
$subtract: [`$${this._params.group_by_date_field}`, timezoneOffset],
146+
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
144147
}],
145148
};
146149
groupBy.year = {
147150
$year: [{
148-
$subtract: [`$${this._params.group_by_date_field}`, timezoneOffset],
151+
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
149152
}],
150153
};
151154
break;
152155
case 'Year':
153156
groupBy.year = {
154157
$year: [{
155-
$subtract: [`$${this._params.group_by_date_field}`, timezoneOffset],
158+
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
156159
}],
157160
};
158161
break;
159162
default: // Month
160163
groupBy.month = {
161164
$month: [{
162-
$subtract: [`$${this._params.group_by_date_field}`, timezoneOffset],
165+
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
163166
}],
164167
};
165168
groupBy.year = {
166169
$year: [{
167-
$subtract: [`$${this._params.group_by_date_field}`, timezoneOffset],
170+
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
168171
}],
169172
};
170173
}
171-
sort[this._params.group_by_date_field] = 1;
174+
sort[params.group_by_date_field] = 1;
172175
}
173176

174177
let sum = 1;
175-
if (this._params.aggregate_field) {
176-
sum = `$${this._params.aggregate_field}`;
178+
if (params.aggregate_field) {
179+
sum = `$${params.aggregate_field}`;
177180
}
178181

179-
if (this._params.group_by_date_field) {
182+
if (params.group_by_date_field) {
180183
jsonQuery.push({
181184
$match: {
182-
[this._params.group_by_date_field]: { $ne: null },
185+
[params.group_by_date_field]: { $ne: null },
183186
},
184187
});
185188
}
@@ -188,7 +191,7 @@ class LineStatGetter {
188191
jsonQuery.push({
189192
$group: {
190193
_id: groupBy,
191-
[this._params.group_by_date_field]: { $first: `$${this._params.group_by_date_field}` },
194+
[params.group_by_date_field]: { $first: `$${params.group_by_date_field}` },
192195
count: { $sum: sum },
193196
},
194197
});
@@ -201,7 +204,7 @@ class LineStatGetter {
201204
.exec();
202205

203206
if (!records.length) { return { value: [] }; }
204-
const momentRange = this._params.time_range.toLowerCase();
207+
const momentRange = params.time_range.toLowerCase();
205208
const firstDate = LineStatGetter._setDate(records[0], momentRange);
206209
const lastDate = LineStatGetter._setDate(records[records.length - 1], momentRange);
207210

0 commit comments

Comments
 (0)