Commit 20a75b9a authored by Jim Laurie's avatar Jim Laurie
Browse files

Change relation type

parent bfc4e580
......@@ -55,4 +55,4 @@
"npm": ">= 5.3.0"
},
"license": "MIT"
}
}
\ No newline at end of file
......@@ -110,4 +110,4 @@
"webpack-hot-middleware": "^2.18.2",
"whatwg-fetch": "^2.0.3"
}
}
}
\ No newline at end of file
......@@ -14,13 +14,13 @@ module.exports = async (ctx, next) => {
if (ctx.params._id) {
const data = await (plugin ? strapi.plugins[plugin] : strapi.api[model]).services[model].fetch(ctx.params);
if (data.created_by.id == ctx.state.user.id || data.created_by._id == ctx.state.user._id) {
if (data.owner.id == ctx.state.user.id || data.owner._id == ctx.state.user._id) {
return await next();
} else {
return ctx.unauthorized();
}
} else {
// Update query with create_by user._id
ctx.query.owner = ctx.state.user._id;
}
await next();
......
......@@ -27,7 +27,7 @@ module.exports = async (ctx, next) => {
role = ctx.state.user.role;
if (!ctx.request.admin && strapi.plugins['users-permissions'].config.createdBy && (ctx.request.method === 'POST' || ctx.request.method === 'PUT')) {
ctx.request.body.created_by = (ctx.state.user.id || ctx.state.user._id).toString();
ctx.request.body.owner = (ctx.state.user.id || ctx.state.user._id).toString();
}
if (role.type === 'root') {
......
......@@ -6,6 +6,7 @@
// Public node modules.
const _ = require('lodash');
const pluralize = require('pluralize');
module.exports = strapi => {
return {
......@@ -32,19 +33,20 @@ module.exports = strapi => {
if (_.get(strapi.plugins['users-permissions'], 'config.createdBy')) {
for (const model in strapi.models) {
strapi.models[model].attributes['created_by'] = {
strapi.models[model].attributes['owner'] = {
model: 'user',
via: 'owned',
via: pluralize.plural(model.toLowerCase()),
plugin: 'users-permissions',
configurable: false,
}
configurable: false
};
strapi.plugins['users-permissions'].models.user.attributes[pluralize.plural(model.toLowerCase())] = {
collection: model.toLowerCase(),
via: 'owner',
configurable: false
};
}
strapi.plugins['users-permissions'].models.user.attributes.owned = {
collection: '*',
filter: 'field',
configurable: false
}
}
cb();
......
......@@ -27,6 +27,7 @@
"grant-koa": "^3.8.1",
"jsonwebtoken": "^8.1.0",
"koa": "^2.1.0",
"pluralize": "^7.0.0",
"purest": "^2.0.1",
"request": "^2.83.0",
"uuid": "^3.1.0"
......@@ -55,4 +56,4 @@
"npm": ">= 3.0.0"
},
"license": "MIT"
}
\ No newline at end of file
}
{
"name": "strapi-upload-cloudinary",
"version": "3.0.0-alpha.11.1",
"version": "3.0.0-alpha.11.2",
"description": "Cloudinary provider for strapi upload",
"homepage": "http://strapi.io",
"keywords": [
......@@ -43,4 +43,4 @@
"npm": ">= 5.3.0"
},
"license": "MIT"
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment