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

Make it possible to disable tenants #5050

Merged
merged 4 commits into from
Dec 28, 2022
Merged

Make it possible to disable tenants #5050

merged 4 commits into from
Dec 28, 2022

Conversation

javierm
Copy link
Member

@javierm javierm commented Dec 16, 2022

References

Background

We don't allow removing a tenant because it would remove all its data, which would be a dangerous operation. However, there might be cases where we don't want a tenant to be accessible, and there's currently no way to do so.

Objectives

  • Make it possible to make a tenant unaccessible

Visual Changes

Before these changes

There's no way to disable a tenant

After these changes

In the tenants index, there's a switch to enable/disable a tenant

@javierm javierm self-assigned this Dec 16, 2022
@javierm javierm added this to Doing in Consul Democracy Dec 16, 2022
app/models/tenant.rb Outdated Show resolved Hide resolved
@javierm javierm force-pushed the hide_tenants branch 3 times, most recently from 04e5804 to 6afe487 Compare December 19, 2022 15:32
@javierm javierm moved this from Doing to Reviewing in Consul Democracy Dec 19, 2022
@javierm javierm marked this pull request as ready for review December 19, 2022 15:33
@Senen Senen self-assigned this Dec 20, 2022
Copy link
Member

@Senen Senen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @javierm, I left just a single comment. Let me know what you think!

app/models/tenant.rb Outdated Show resolved Hide resolved
@Senen
Copy link
Member

Senen commented Dec 20, 2022

Hi again @javierm,

While testing locally, I found disabling subdomains tenants works fine but disabling domain tenants is not working.

I tested it in the development environment by adding the domain I gave to the tenant in my machine /etc/hosts file, so the domain resolves to 127.0.0.1. After that, the tenant is always accessible even when disabled.

After digging, I found the cause could be in the resolve_host methods call to the find_by_domain method, which finds even within the hidden records and returns the host. Probably we want to search only over the not hidden records. 🤔

@javierm javierm moved this from Reviewing to Doing in Consul Democracy Dec 21, 2022
@javierm
Copy link
Member Author

javierm commented Dec 21, 2022

@Senen Great! I've updated the pull request so we raise an exception when accessing a hidden tenant with a domain, just like we do when accessing a hidden tenant with a subdomain.

@javierm javierm moved this from Doing to Reviewing in Consul Democracy Dec 21, 2022
Consul Democracy automation moved this from Reviewing to Testing Dec 27, 2022
This is consistent with the way we use separate actions to hide and
restore records, which is similar to enabling and disabling a record. We
might do something similar with the `toggle_selection` actions in the
future. For now, we're only doing it with budget phases because we're
going to add a similar switch control to hide and restore tenants.

We're also making these actions idempotent, so sending many requests to
the same action will get the same result, which wasn't the case with the
`toggle` action. Although it's a low probability case, the `toggle`
action could result in disabling a phase when trying to enable it if
someone else has enabled it between the time the page loaded and the
time the admin clicked on the "enable" button.
We're going to use it in other places.
We were returning `nil` in this case, meaning we would be accessing the
main tenant in this situation instead of returning "Not Found".
Note we could use `acts_as_paranoid` with the `without_default_scope`
option, but we aren't doing so because it isn't possible to consider
deleted records in uniqueness validations with the paranoia gem [1].
I've added tests for these cases so we don't accidentally add
`acts_as_paranoid` in the future.

Also note we're extracting a `RowComponent` because, when
enabling/disabling a tenant, we're also enabling/disabling the link
pointing to its URL, and so we need to update the URL column after the
AJAX call.

[1] See issues 285 and 319 in https://github.com/rubysherpas/paranoia/
@javierm javierm merged commit 171cf4e into master Dec 28, 2022
Consul Democracy automation moved this from Testing to Release 2.0.0 Dec 28, 2022
@javierm javierm deleted the hide_tenants branch December 28, 2022 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants