# Feature #1: Multi-tenancy

### <mark style="color:blue;">What does it do and what can it be used for?</mark>

<mark style="color:blue;">Non-technical functional description (max. 200 words).</mark>&#x20;

The multitenancy feature allows managing several independent organizations ("tenants") or participation projects using the same Consul Democracy installation. For example, in our case, a user who signs up for one tenants's participation platform will only be able to sign in on that platform, and that user's data won't be available to any other tenant.

Which tenant we're accessing depends on the URL we're using in the browser to access the application. In Consul Democracy, the current tenant is established by the subdomain used in this URL. For example, if we used the domain participative-amsterdam.org to manage the different digital participation platforms in Amsterdam, using the URL <https://south.participative-amsterdam.org> we'd access data from the Southern district's participation platform while using the URL <https://north.participative-amsterdam.org> we'd access data from the Northern district. It's also be possible to use different domains per tenant.

### <mark style="color:blue;">Basic technical setup and what's new in terms of programming and tools used?</mark>&#x20;

<mark style="color:blue;">Technical description (max. 200 words).</mark>

#### Enabling multi-tenancy&#x20;

There are two possible ways to enable multitenancy:

* Adding `config.multitenancy = true` inside the `class Application < Rails::Application` class in the `config/application_custom.rb` file
* Replacing the line `multitenancy: false` with `multitenancy: true` (or adding it if it isn't already there) in the `config/secrets.yml` file

The difference between these options is that the first one uses a file under version control while the second one uses a file which isn't under version control. Choose the first option if you'd like to have this change in your git repository; otherwise, use the second one. After enabling this option, restart the application.

#### Creating different views with Ruby variants

Sometimes it might be convenient to use completely different views for different tenants. For example, a certain tenant might use a footer that has nothing to do with the default one.

In these cases, instead of adding conditions like `case Tenant.current_schema` to the view, using a different file might result in code easier to maintain.

For this purpose, we can use [Ruby Variants](https://guides.rubyonrails.org/layouts_and_rendering.html#the-variants-option) which means that, for example, a tenant named `milky-way` will use a view file ending with `.html+milky-way.erb` if it's available. That is, in order to use a different `application.html.erb` layout for the `milky-way` tenant, add a new file under `app/views/custom/layouts/application.html+milky-way.erb`.

&#x20;<mark style="color:blue;">More detailed technical description</mark> [<mark style="color:blue;">here</mark>](https://docs.consuldemocracy.org/tech_docs/features/multitenancy)

### <mark style="color:blue;">Where can I find the code's repository and user instructions, if any?</mark>

<mark style="color:blue;">(link)</mark>

This featurs is part of the main Consul Democracy 2.0. project, available on Github: <https://github.com/consuldemocracy>

### <mark style="color:blue;">What does the feature look like in practice and what does the new code look like?</mark>

<mark style="color:blue;">Visual example of live version and code (max. 3 images/screenshots)</mark>

<figure><img src="https://1205032186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1j9t2QE6wxiDlSWBJz1e%2Fuploads%2FdUUNxmFBQjtldDsrTGiH%2Fmulti-tenancy_scrngrb_1.png?alt=media&#x26;token=99813edc-66aa-46ae-9aae-369a737127e7" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1205032186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1j9t2QE6wxiDlSWBJz1e%2Fuploads%2Fc9UjYXM4mxqBevZgT5zG%2Fmulti-tenancy_scrngrb_2.png?alt=media&#x26;token=204de9c5-10d1-4a8a-b393-2878b6562935" alt=""><figcaption></figcaption></figure>

### <mark style="color:blue;">Where and by whom was the feature developed, and how to get in touch?</mark>

<mark style="color:blue;">Contacts (max. 50 words, Slack handle/username and/or e-mail address).</mark>&#x20;

The multi-tenancy feature was developed through a collaborative project of [Cabildo de Tenerife](https://www.tenerife.es/portalcabtfe/es/) (municipality of Tenerife) and [Rock\&Ror](https://www.rockandror.com/consul/development-services?locale=en).

Both parties are members of [our community Slack channel](https://join.slack.com/t/consul/shared_invite/zt-27jnqqh2b-WXNesYG8YZrAO4uHJmVi7A).

Slack handle Rock\&Ror: @Javi Martin or @sendero&#x20;

E-mail Rock\&Ror: <info@rockandror.com>

Slack handle Cabildo de Tenerife: @Clemente Barreto
