Add condition

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-06-29 14:45:41 +02:00
parent 4edad86029
commit 85ea0abdc8
2 changed files with 16 additions and 4 deletions

View File

@ -3,10 +3,24 @@
module.exports = { module.exports = {
conditions: [ conditions: [
{ {
displayName: 'Is Creator', displayName: 'Is creator',
name: 'is-creator', name: 'is-creator',
plugin: 'admin', plugin: 'admin',
handler: user => ({ created_by: user.id }), handler: user => ({ 'created_by.id': user.id }),
},
{
displayName: 'Has same role as creator',
name: 'has-same-role-as-creator',
plugin: 'admin',
handler: user => ({
'created_by.roles': {
$elemMatch: {
id: {
$in: user.roles.map(r => r.id),
},
},
},
}),
}, },
], ],
}; };

View File

@ -117,13 +117,11 @@ module.exports = ({ models, target }, ctx) => {
if (!definition.uid.startsWith('strapi::')) { if (!definition.uid.startsWith('strapi::')) {
definition.attributes['created_by'] = { definition.attributes['created_by'] = {
autoPopulate: false,
model: 'user', model: 'user',
plugin: 'admin', plugin: 'admin',
}; };
definition.attributes['updated_by'] = { definition.attributes['updated_by'] = {
autoPopulate: false,
model: 'user', model: 'user',
plugin: 'admin', plugin: 'admin',
}; };