Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tenancy for all objects in model, except for specific conditions #291

Open
darylpdavies opened this issue Jul 26, 2022 · 5 comments
Open

Comments

@darylpdavies
Copy link

I have a model called Post. Posts require tenancy and are only accessible by their owners.

However - if a Post is set to "global" (or created by a site admin), it will be accessible by everyone.

acts_as_tenant :account, has_global_records: true

In my controller:
@post = Post.find(params[:id])

if @post.global? || @post.account.admin?
     // Accessible by everyone
end
@pruzicka
Copy link

I don't believe it's possible to do something like this now. There was some work here #86, but again I don't think it's possible now to share objects between tenants.

@darylpdavies
Copy link
Author

Thanks @pruzicka – that definitely points me in the right direction. My platform allows users to see only their own posts, but I wanted to add the ability for the admins to create "shared posts" that everyone can see but not edit.

@pruzicka
Copy link

Thanks @pruzicka – that definitely points me in the right direction. My platform allows users to see only their own posts, but I wanted to add the ability for the admins to create "shared posts" that everyone can see but not edit.

Well I would use it as well. I have libraries that are owned by tenants yet I would like to have "shared" library that each tenant could use. One option would be to always create copy for each tenant but that is "brute force" way, not smart at all. If I remember there was an option to have "nil" in tenant_id field, that record would be "shared" record. But it doesn't work anymore

@darylpdavies
Copy link
Author

Thanks @pruzicka – that definitely points me in the right direction. My platform allows users to see only their own posts, but I wanted to add the ability for the admins to create "shared posts" that everyone can see but not edit.

Well I would use it as well. I have libraries that are owned by tenants yet I would like to have "shared" library that each tenant could use. One option would be to always create copy for each tenant but that is "brute force" way, not smart at all. If I remember there was an option to have "nil" in tenant_id field, that record would be "shared" record. But it doesn't work anymore

That sounds very much like my use case – I was thinking of adding a "global" setting, so that it requires a little more confirmation on the admin side. Could be a bad situation if a post were to accidentally have a "nil" tenant to suddenly be viewable by everyone.

Something like:
acts_as_tenant :account, allow_global_tenant: "is_global"

"is_global" would be a customizable column with a boolean value - if true, then the object is shared for all users. Then you can use something like pundit to allow users to view these "global" posts but not edit/delete them. I'm hoping to use these objects as templates and allow users to "clone" and edit them without having to start a new post from scratch.

Would that work for your libraries?

@pruzicka
Copy link

Thanks @pruzicka – that definitely points me in the right direction. My platform allows users to see only their own posts, but I wanted to add the ability for the admins to create "shared posts" that everyone can see but not edit.

Well I would use it as well. I have libraries that are owned by tenants yet I would like to have "shared" library that each tenant could use. One option would be to always create copy for each tenant but that is "brute force" way, not smart at all. If I remember there was an option to have "nil" in tenant_id field, that record would be "shared" record. But it doesn't work anymore

That sounds very much like my use case – I was thinking of adding a "global" setting, so that it requires a little more confirmation on the admin side. Could be a bad situation if a post were to accidentally have a "nil" tenant to suddenly be viewable by everyone.

Something like: acts_as_tenant :account, allow_global_tenant: "is_global"

"is_global" would be a customizable column with a boolean value - if true, then the object is shared for all users. Then you can use something like pundit to allow users to view these "global" posts but not edit/delete them. I'm hoping to use these objects as templates and allow users to "clone" and edit them without having to start a new post from scratch.

Would that work for your libraries?

Yes, that would be perfect. so some records would be visible to everyone, or better say could be visibile for everyone. first would be is_global: true and second condition would be cancancan or pundit. Not all tenants could see everything, let't say it would be additional service to sell to them, if they can have global library as a start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants