anetaj / strapi-plugin-multi-tenant Goto Github PK
View Code? Open in Web Editor NEWTurn Strapi into a full-fledged backend for your SaaS.
License: MIT License
Turn Strapi into a full-fledged backend for your SaaS.
License: MIT License
Is there a way to set up multi-tenancy for Strapi admin/editor users, or does it work only with regular users? So that admin that is part of one organization doesn't see content that was created by an admin from a different organization?
A simple question, does it work with Strapi v4?
Thank you for this plugin.
First I added an organization, and then I tried to add new userGroup via Strapi portal but I got this error message:
Issue: error: children?.includes is not a function
TypeError: children?.includes is not a function
at Object.beforeCreate (./node_modules/strapi-plugin-multi-tenant/server/content-types/user-group/lifecycles.js:7:19)
A children variable is undefined when no user group exists in the beginning and that will fail line 7:19
Please review and advise. Thank you
Hello!
Hierarchy of UserGroups doen't work for me. Also not able to find is source code where Hierarchy is realized.
readme.md:
UserGroups can optionally create a hierarchy. For example, Acme HQ could have Acme Engineering and Acme Product as its immediate children. Acme Engineering could contain Frontend, Backend, and DevOps UserGroups. In this scenario, every User assigned to Engineering has access to content from Engineering and Frontend, Backend, and DevOps.
UPD:
Just found hierarchy of UserGroups support in service "userGroup.js" in version of source code, which was not still published to npm package, it supports requests like /api/workspaces/:id. Still have no idea how to support hierarchy of UserGroups in lists, because middleware doesn't support it in /api/workspaces
Perhaps the "Organization" content-type is not the most appropriate name for it. Before installing your plugin, I've had my own "Organisation" content-type that I was using for my Organisation Users. My humble suggestion would be to rename it to "Tenant", it's more appropriate :)
I've noticed it working well with my REST endpoints, but not really well with my GraphQL queries and mutations, so why doesn't it?
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch [email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/strapi-plugin-multi-tenant/server/content-types/user-group/lifecycles.js b/node_modules/strapi-plugin-multi-tenant/server/content-types/user-group/lifecycles.js
index 4a74647..af48222 100644
--- a/node_modules/strapi-plugin-multi-tenant/server/content-types/user-group/lifecycles.js
+++ b/node_modules/strapi-plugin-multi-tenant/server/content-types/user-group/lifecycles.js
@@ -4,7 +4,7 @@ module.exports = {
beforeCreate(event) {
const { parent, children } = event.params.data;
- if (children?.includes(parent)) {
+ if (children?.includes && children?.includes(parent)) {
throw new ValidationError("User group cannot be both child and parent");
}
},
This issue body was partially generated by patch-package.
A userGroup field will be empty if new content has been created. Followed your documentation and also added middleware code to route. But still the same issue.
Please review and advise.
Strapi version: v4.7.0-beta.0
strapi-plugin-multi-tenant version: 1.0.4
Full error message:
[2023-03-13 17:13:07.040] debug: โ๏ธ Server wasn't able to start properly.
[2023-03-13 17:13:07.042] error: Error on attribute userGroup in model car(api::car.car): inversedBy attribute cars not found target plugin::multi-tenant.user-group
Error: Error on attribute userGroup in model car(api::car.car): inversedBy attribute cars not found target plugin::multi-tenant.user-group
at createMetadata (/Users/ibrahimsefer/Local Documents/Clients/seferware/swrc/swrc-api-phoenix/node_modules/@strapi/database/lib/metadata/index.js:83:15)
at new Database (/Users/ibrahimsefer/Local Documents/Clients/seferware/swrc/swrc-api-phoenix/node_modules/@strapi/database/lib/index.js:19:21)
at Function.Database.init (/Users/ibrahimsefer/Local Documents/Clients/seferware/swrc/swrc-api-phoenix/node_modules/@strapi/database/lib/index.js:116:14)
at Strapi.bootstrap (/Users/ibrahimsefer/Local Documents/Clients/seferware/swrc/swrc-api-phoenix/node_modules/@strapi/strapi/lib/Strapi.js:417:30)
at Strapi.load (/Users/ibrahimsefer/Local Documents/Clients/seferware/swrc/swrc-api-phoenix/node_modules/@strapi/strapi/lib/Strapi.js:488:16)
at async Strapi.start (/Users/ibrahimsefer/Local Documents/Clients/seferware/swrc/swrc-api-phoenix/node_modules/@strapi/strapi/lib/Strapi.js:217:9)
I already found a solution, but wanted to share it.
Context:
I have a car content-type schema, and as it's mentioned in the documentation, I've added this to it:
{
"kind": "collectionType",
"collectionName": "cars",
"info": {
"singularName": "car",
"pluralName": "cars",
"displayName": "Car",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
// my other car content-type attributes
"userGroup": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::multi-tenant.user-group",
"inversedBy": "cars"
}
}
}
However, this just gives me the error above. If somehow you don't get the error mentioned, then I guess you are very very lucky or I'm just a silly documentation reader.
My solution:
go to index.js
, and extend the plugin::multi-tenant.user-group
content-type like this:
"use strict";
module.exports = {
/**
* An asynchronous register function that runs before
* your application is initialized.
*
* This gives you an opportunity to extend code.
*/
register({ strapi }) {
strapi.contentType("plugin::multi-tenant.user-group").attributes = {
...strapi.contentType("plugin::multi-tenant.user-group").attributes,
cars: {
type: "relation",
relation: "oneToMany",
target: "api::car.car",
mappedBy: "userGroup",
},
};
},
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
async bootstrap(/*{ strapi }*/) {}
};
Now api::car.car
and plugin::multi-tenant.user-group
have a manyToOne relationship :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.