strapi-plugin-comments 2.0.0-beta.4 → 2.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/admin/src/components/DiscussionThread/index.js +1 -0
- package/admin/src/components/DiscussionThreadItem/index.js +3 -3
- package/admin/src/components/DiscussionThreadItemActions/index.js +22 -38
- package/admin/src/components/DiscussionThreadItemActions/styles.js +0 -4
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +72 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +6 -0
- package/admin/src/components/DiscussionThreadItemWarnings/index.js +1 -1
- package/admin/src/components/Nav/index.js +5 -1
- package/admin/src/components/icons/review.js +2 -2
- package/admin/src/pages/Details/components/DetailsEntity/index.js +66 -0
- package/admin/src/pages/Details/components/DetailsFilters/index.js +36 -0
- package/admin/src/pages/Details/components/DetailsFilters/styles.js +8 -0
- package/admin/src/pages/Details/index.js +40 -13
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +33 -39
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +8 -0
- package/admin/src/pages/Discover/index.js +6 -3
- package/admin/src/pages/{Details/utils → utils}/api.js +15 -3
- package/admin/src/translations/en.json +15 -4
- package/admin/src/utils/constants.js +3 -6
- package/admin/src/utils/getMessage.js +1 -1
- package/admin/src/utils/getRelatedGroups.js +1 -3
- package/admin/src/utils/index.js +3 -1
- package/admin/src/utils/renderEntryTitle.js +14 -0
- package/admin/src/utils/resolveCommentStatus.js +30 -0
- package/admin/src/utils/resolveCommentStatusColor.js +22 -0
- package/package.json +7 -3
- package/server/config/index.js +2 -1
- package/server/controllers/admin.js +3 -3
- package/server/controllers/client.js +1 -0
- package/server/services/admin.js +33 -7
- package/server/services/client.js +21 -13
- package/server/services/common.js +30 -65
- package/server/services/utils/functions.js +7 -14
- package/server/utils/constants.js +3 -3
- package/admin/src/components/EntityDetails/index.js +0 -53
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { isArray,
|
|
3
|
+
const { isArray, uniq, first } = require('lodash');
|
|
4
4
|
// const { sanitizeEntity } = require('strapi-utils');
|
|
5
5
|
const PluginError = require('./../utils/error');
|
|
6
6
|
const {
|
|
7
|
-
extractMeta,
|
|
8
7
|
getModelUid,
|
|
9
8
|
getRelatedGroups,
|
|
10
9
|
buildNestedStructure,
|
|
@@ -16,62 +15,17 @@ const {
|
|
|
16
15
|
*/
|
|
17
16
|
|
|
18
17
|
module.exports = ({ strapi }) => ({
|
|
19
|
-
getAssociationModel(ormModel, related) {
|
|
20
|
-
const relatedAssociation = ormModel.associations.find(_ => _.alias === 'related');
|
|
21
|
-
if (relatedAssociation) {
|
|
22
|
-
return relatedAssociation.related.find(rel => rel.collectionName === related);
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
},
|
|
26
18
|
|
|
27
|
-
|
|
28
|
-
const ormModel = strapi.query(getModelUid('comment'));
|
|
29
|
-
return ormModel.model.morph;
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
isMongoDB(){
|
|
33
|
-
return strapi.query(getModelUid('comment'))?.model?.orm === 'mongoose';
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
getMorphData(query) {
|
|
37
|
-
return this
|
|
38
|
-
.getMorphModel()
|
|
39
|
-
.query(function () {
|
|
40
|
-
this.where(query);
|
|
41
|
-
})
|
|
42
|
-
.fetchAll()
|
|
43
|
-
.then((entities) => entities.map(entity => entity.toJSON()));
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
checkEntityRelation(uid, entityId) {
|
|
47
|
-
const result = parsedRelation.some(ref => {
|
|
48
|
-
const model = strapi.query(ref);
|
|
49
|
-
return model && model.associations.length &&
|
|
50
|
-
model.associations.some(_ => _.plugin === 'comments' && _.collection === 'comment');
|
|
51
|
-
});
|
|
52
|
-
if (!result) {
|
|
53
|
-
throw new PluginError(400, 'Comment not have relation to this type content type.');
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
getConfig(prop) {
|
|
19
|
+
getConfig(prop, defaultValue) {
|
|
58
20
|
let queryProp = prop;
|
|
59
21
|
if (prop && isArray(prop)) {
|
|
60
22
|
queryProp = prop.join('.');
|
|
61
23
|
}
|
|
62
|
-
return strapi.config.get(`plugin.comments${ queryProp ? '.' + queryProp : ''}`);
|
|
24
|
+
return strapi.config.get(`plugin.comments${ queryProp ? '.' + queryProp : ''}`) || defaultValue;
|
|
63
25
|
},
|
|
64
26
|
|
|
65
27
|
// Find comments in the flat structure
|
|
66
|
-
async findAllFlat({ query, populate = {} },
|
|
67
|
-
const criteria = {
|
|
68
|
-
...query,
|
|
69
|
-
$or: [{ removed: { $null: true } }, { removed: false }],
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (isAdmin){
|
|
73
|
-
delete criteria.$or;
|
|
74
|
-
}
|
|
28
|
+
async findAllFlat({ query = {}, populate = {} }, relatedEntity = null) {
|
|
75
29
|
|
|
76
30
|
const defaultPopulate = {
|
|
77
31
|
authorUser: true,
|
|
@@ -80,7 +34,7 @@ module.exports = ({ strapi }) => ({
|
|
|
80
34
|
const entries = await strapi.db.query(getModelUid('comment'))
|
|
81
35
|
.findMany({
|
|
82
36
|
where: {
|
|
83
|
-
...
|
|
37
|
+
...query,
|
|
84
38
|
},
|
|
85
39
|
populate: {
|
|
86
40
|
...defaultPopulate,
|
|
@@ -122,9 +76,8 @@ module.exports = ({ strapi }) => ({
|
|
|
122
76
|
populate = {},
|
|
123
77
|
startingFromId = null,
|
|
124
78
|
dropBlockedThreads = false,
|
|
125
|
-
isAdmin = false,
|
|
126
79
|
}, relatedEntity) {
|
|
127
|
-
const entities = await this.findAllFlat({ query, populate },
|
|
80
|
+
const entities = await this.findAllFlat({ query, populate }, relatedEntity);
|
|
128
81
|
return buildNestedStructure(entities, startingFromId, 'threadOf', dropBlockedThreads, false);
|
|
129
82
|
},
|
|
130
83
|
|
|
@@ -135,24 +88,36 @@ module.exports = ({ strapi }) => ({
|
|
|
135
88
|
where: criteria
|
|
136
89
|
}, ['related', 'reports']);
|
|
137
90
|
if (!entity){
|
|
138
|
-
throw
|
|
91
|
+
throw new PluginError(404, 'Not found');
|
|
139
92
|
}
|
|
140
93
|
return filterOurResolvedReports(this.sanitizeCommentEntity(entity));
|
|
141
94
|
},
|
|
142
95
|
|
|
143
96
|
// Find all related entiries
|
|
144
97
|
async findRelatedEntitiesFor(entities = []) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
98
|
+
const data = entities.reduce((acc, cur) => {
|
|
99
|
+
const [relatedUid, relatedStringId] = getRelatedGroups(cur.related);
|
|
100
|
+
return {
|
|
101
|
+
...acc,
|
|
102
|
+
[relatedUid]: [...(acc[relatedUid] || []), parseInt(relatedStringId, 10)]
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
{}
|
|
106
|
+
);
|
|
107
|
+
return Promise.all(
|
|
108
|
+
Object.entries(data)
|
|
109
|
+
.map(async ([relatedUid, relatedStringIds]) =>
|
|
110
|
+
strapi.db.query(relatedUid).findMany({
|
|
111
|
+
where: { id: Array.from(new Set(relatedStringIds)) }
|
|
112
|
+
}).then(relatedEntities => relatedEntities.map(_ =>
|
|
113
|
+
({
|
|
114
|
+
..._,
|
|
115
|
+
uid: relatedUid,
|
|
116
|
+
})
|
|
117
|
+
))
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
.then(result => result.flat(2));
|
|
156
121
|
},
|
|
157
122
|
|
|
158
123
|
// Merge related entity with comment
|
|
@@ -34,9 +34,14 @@ const buildNestedStructure = (
|
|
|
34
34
|
module.exports = {
|
|
35
35
|
isEqualEntity: (existing, data, user) => {
|
|
36
36
|
const { authorUser, authorId } = existing;
|
|
37
|
-
console.log('data', data);
|
|
38
|
-
console.log(existing);
|
|
39
37
|
const { author } = data;
|
|
38
|
+
|
|
39
|
+
// Disallow approval status change by Client
|
|
40
|
+
if (data.approvalStatus && (existing.approvalStatus !== data.approvalStatus)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Make sure that author is exact the same
|
|
40
45
|
if (authorUser) {
|
|
41
46
|
const existingUserId = authorUser?.id || authorUser;
|
|
42
47
|
const receivedUserId = user?.id || author;
|
|
@@ -45,18 +50,6 @@ module.exports = {
|
|
|
45
50
|
return authorId === author?.id;
|
|
46
51
|
},
|
|
47
52
|
|
|
48
|
-
extractMeta: plugins => {
|
|
49
|
-
const { comments: plugin } = plugins;
|
|
50
|
-
const { comments: service } = plugin.services;
|
|
51
|
-
const { comment: model} = plugin.models;
|
|
52
|
-
return {
|
|
53
|
-
model,
|
|
54
|
-
service,
|
|
55
|
-
plugin,
|
|
56
|
-
pluginName: plugin.package.strapi.name.toLowerCase()
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
|
|
60
53
|
getRelatedGroups: related => related.split(REGEX.relatedUid).filter(s => s && s.length > 0),
|
|
61
54
|
|
|
62
55
|
getModelUid: name => {
|
|
@@ -5,9 +5,9 @@ const APPROVAL_STATUS = {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
const REGEX = {
|
|
8
|
-
uid:
|
|
9
|
-
relatedUid:
|
|
10
|
-
email:
|
|
8
|
+
uid: /^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,
|
|
9
|
+
relatedUid: /^(?<uid>[a-z0-9-]+\:{2}[a-z0-9-]+\.[a-z0-9-]+)\:{1}(?<id>[a-z0-9-]+)$/i,
|
|
10
|
+
email: /\S+@\S+\.\S+/,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
module.exports = {
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Entity Details
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import PropTypes from 'prop-types';
|
|
9
|
-
import { isNil } from 'lodash';
|
|
10
|
-
import { Box } from '@strapi/design-system/Box';
|
|
11
|
-
import { Divider } from '@strapi/design-system/Divider';
|
|
12
|
-
import { Flex } from '@strapi/design-system/Flex';
|
|
13
|
-
import { Stack } from '@strapi/design-system/Stack';
|
|
14
|
-
import { Typography } from '@strapi/design-system/Typography';
|
|
15
|
-
import { getMessage } from '../../utils';
|
|
16
|
-
|
|
17
|
-
const EntityDetails = ({ data = {}, schema = {} }) => {
|
|
18
|
-
const { attributes = {} } = schema;
|
|
19
|
-
const keys = Object.keys(attributes);
|
|
20
|
-
|
|
21
|
-
if (keys.length === 0) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const itemKeys = keys.filter(_ => (attributes[_].type === 'string') && !isNil(data[_]));
|
|
26
|
-
|
|
27
|
-
return (<Box padding={4}>
|
|
28
|
-
<Typography variant="sigma" textColor="neutral600" id="entity-details">
|
|
29
|
-
{ getMessage('page.details.panel.entity', 'Details') }
|
|
30
|
-
</Typography>
|
|
31
|
-
<Box paddingTop={2} paddingBottom={6}>
|
|
32
|
-
<Divider />
|
|
33
|
-
</Box>
|
|
34
|
-
<Stack size={itemKeys.length}>
|
|
35
|
-
{ itemKeys.map(_ =>
|
|
36
|
-
(<Flex justifyContent="space-between">
|
|
37
|
-
<Typography fontWeight="bold">
|
|
38
|
-
{ _ }
|
|
39
|
-
</Typography>
|
|
40
|
-
<Typography>{ data[_] }</Typography>
|
|
41
|
-
</Flex>))
|
|
42
|
-
}
|
|
43
|
-
</Stack>
|
|
44
|
-
</Box>);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
EntityDetails.propTypes = {
|
|
48
|
-
data: PropTypes.object.isRequired,
|
|
49
|
-
schema: PropTypes.object.isRequired,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default EntityDetails;
|
|
53
|
-
|