Giter VIP home page Giter VIP logo

strapi-plugin-multi-tenant's People

Contributors

anetaj avatar eubash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

strapi-plugin-multi-tenant's Issues

Multi-tenancy for Strapi admins?

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?

error: children?.includes is not a function

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

hierarchy of UserGroups doen't work

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

Rename Organization to Tenant

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 :)

Does it work with GraphQL?

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?

To fix a error: children?.includes is not a function

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.

inversedBy attribute cars not found target plugin::multi-tenant.user-group

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 :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.