Commit Graph

17784 Commits

Author SHA1 Message Date
Javi Martín
5983006657 Use a custom method to detect the current tenant
The subdomain elevator we were using, which is included in apartment,
didn't work on hosts already including a subdomain (like
demo.consul.dev, for instance). In those cases, we would manually add
the subdomain to the list of excluded subdomains. Since these subdomains
will be different for different CONSUL installations, it meant each
installation had to customize the code. Furthermore, existing
installations using subdomains would stop working.

So we're using a custom method to find the current tenant, based on the
host defined in `default_url_options`.

In order to avoid any side-effects on single-tenant applications, we're
adding a new configuration option to enable multitenancy

We're enabling two ways to handle this configuration option:

a) Change the application_custom.rb file, which is under version control
b) Change the secrets.yml file, which is not under version control

This way people prefering to handle configuration options through
version control can do so, while people who prefer handling
configuration options through te secrets.yml file can do so as well.

We're also disabling the super-annoying warnings mentioning there are no
tenants which we got every time we run migrations on single-tenant
applications. These messages will only be enabled when the multitenancy
feature is enabled too. For this reason, we're also disabling the
multitenancy feature in the development environment by default.
2022-11-09 18:19:20 +01:00
Javi Martín
d77cf77761 Validate format of subdomains / schema names
Note we're using the `:HOST` regular expression since subdomains can
contain the same characters as domains do. This isn't 100% precise,
though, since subdomains have a maximum length of 63 characters, but is
good enough for our purposes.
2022-11-09 18:19:01 +01:00
Javi Martín
c483c6036a Install extensions in a shared schema
This way all tenants will be able to access them instead of just the
default one.

The apartment gem recommends using a rake task instead of a migration,
but that's a solution which is primarily meant for new installations.
Migrations are easier to execute on existing installations.

However, since this migration doesn't affect the `schema.rb` file, we
still need to make sure the shared schema is created in tasks which do
not execute migrations, like `db:schema:load` or `db:test:prepare`, just
like the apartment gem recommends. That's why we're enhancing these
tasks so they execute this migration.

Note that there might be cases where the database user isn't a superuser
(as it's usually the case on production environments), meaning commands
to create, alter or drop extensions will fail. There's also the case
where users don't have permissions to create schemas, which is needed in
order to create the shared extensions schema and the schemas used by the
tenants. For these reasons, we're minimizing the number of commands, and
so we only alter or create extensions when it is really necessary.

When users don't have permission, we aren't running the commands but
showing a warning with the steps needed to run the migration manually.
This is only necessary on installations which are going to use
multitenancy; single-tenant applications upgrading don't need to run
this migration, and that's why we aren't raising exceptions when we
can't run it.

For new installations, we'll change the CONSUL installer so extensions
are automatically created in the shared schema.

Also note the plpgsql extension is not handled here. This is a special
extension which must be installed on the pg_catalog schema, which is
always in the search path and so is shared by all tenants.

Finally, we also need to change the `database.yml` file in order to
search for shared extensions while running migrations or model tests,
since none of our enabled extensions are executed during migrations;
we're also adding a rake task for existing installations. Quoting the
apartment documentation:

> your database.yml file must mimic what you've set for your default and
> persistent schemas in Apartment. When you run migrations with Rails,
> it won't know about the extensions schema because Apartment isn't
> injected into the default connection, it's done on a per-request
> basis.
2022-11-09 17:53:31 +01:00
Eduardo Vilar
382abb3666 Add multitenancy with apartment
Co-Authored-By: Javi Martín <javim@elretirao.net>
2022-11-09 17:52:05 +01:00
Javi Martín
fcd8466ddf Allow using the lvh.me URL in development
Rails 6.0 introduced a `hosts` option which, in the development
environment, defaults to all IP addresses and the `localhost` domain.

However, we can't work with subdomains using `localhost`. For that
purpose, the `lvh.me` domain was created [1].

So we're allowing this domain and its subdomains so we can use them
while working with multitenancy in the development environment.

[1] http://railscasts.com/episodes/123-subdomains-revised
2022-10-28 14:44:57 +02:00
Javi Martín
9057264373 Merge pull request #5020 from consul/unify_color_variables
Unify duplicate SCSS color variables
2022-10-28 14:44:28 +02:00
Javi Martín
7b4e7c6e9c Merge pull request #5019 from consul/automatic_color_contrast
Base text color on background color when possible
2022-10-28 14:23:53 +02:00
Javi Martín
9ac8ddb6bf Unify dark and brand-secondary SCSS variables
We were using each one half the time, while they both had the same value
by default. It was impossible to know when me meant "use a dark color
here" or "use the secondary brand color" here.

So now we're only using one variable, so it's easy it'll be easy to add
CSS custom properties to overwrite this variable. We're choosing
`brand-secondary` because its name makes it less problematic to use a
light color.
2022-10-28 14:07:33 +02:00
Javi Martín
b96d745e0e Use $body-font-color instead of $text
This is consistent with the usage of `$body-background`. This way
Foundation elements using `$body-font-color`, like the `<body>` tag,
will be changed when changing this variable, which wouldn't happen when
using `$text`.
2022-10-28 14:07:33 +02:00
Javi Martín
ea3ae4d262 Use $anchor-color instead of $link
The variables `$anchor-color` and `$anchor-color-hover` are the ones
Foundation uses internally; by using them, we make sure every link will
use the colors we define.

Now we can simplify the default styles for the `<a>` tags, since by
default they already use these variables.
2022-10-28 14:07:33 +02:00
Javi Martín
7c740f1daa Remove duplicate HTML in dashboard mail preview
We noticed this while editing the styles for this class in the previous
commits.
2022-10-28 13:58:04 +02:00
Javi Martín
6cb4f4acde Extract mixin to get a background with text contrast
This way we simplify the code a bit.

Note we're only using this function when variables for background colors
are already defined, since that means customizing the variable using the
background color will automatically change the color of the text.
Customization isn't easier when using raw colors.
2022-10-28 13:58:04 +02:00
Javi Martín
1b1b5b5755 Use color-pick-contrast to get text colors
We were defining (for instance) white text against the `$brand`
background. That meant that, if somebody customized the `$brand` color
so it used a light color, they had to customize the text color as well
in order to guarantee proper contrast between text and background
colors.

So we're using `color-pick-contrast` instead, which means we don't have
to manually calculate whether white or black will be the color which
makes the text more readable.
2022-10-28 13:58:04 +02:00
Javi Martín
025d7bf9f8 Remove duplication in sidebar color definition
We're going to change that code so it uses color-pick-contrast, so we're
refactoring it first.
2022-10-28 13:57:18 +02:00
Javi Martín
48391eb668 Merge pull request #5016 from consul/dependabot/bundler/nokogiri-1.13.9
Bump nokogiri from 1.13.8 to 1.13.9
2022-10-28 02:26:25 +02:00
dependabot[bot]
43b0fd7b7b Bump nokogiri from 1.13.8 to 1.13.9
Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.13.8 to 1.13.9.
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.13.8...v1.13.9)

---
updated-dependencies:
- dependency-name: nokogiri
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-28 02:06:44 +02:00
Javi Martín
5845dd46d9 Extract variable for SDG text color
We were using `#fff` in some places and `$white` in others. We're
choosing `#fff` because it has a better contrast against the lighter SDG
colors and because it's the one officially used by the United Nations.
2022-10-27 15:35:27 +02:00
Javi Martín
3aa73110c5 Use foundation variables to set caption color
This way we can simplify the code a bit since Foundation automatically
chooses the text color of the caption so there's enough contrast with
the background color defined in `$orbit-caption-background`.
2022-10-27 15:35:27 +02:00
Javi Martín
0f7637f7e2 Merge pull request #5018 from consul/simplify_main_colors
Remove redundant color definitions
2022-10-27 15:34:33 +02:00
Javi Martín
0be0f459ab Extract mixin to use links with the text color 2022-10-27 15:14:48 +02:00
Javi Martín
33eea0b21a Extract mixin to use body background and text color
This way we reduce the usages of the `$body-background` and `$text`
variables, making it easier to replace them with CSS variables in the
future.
2022-10-27 15:14:48 +02:00
Javi Martín
3c8d97fc57 Simplify hover color in link to delete comments
Since we were using the default color, we can do so without overwriting
it twice.
2022-10-27 15:09:13 +02:00
Javi Martín
335f0d8bde Inherit text color instead of defining it again
This way it's easier to customize colors, particularly when links use
the same colors as the text surrounding them.

Note that the `markdown-editor-header` isn't displayed since commit
76b7f66fb, which was probably an unintended side-effect. So we're
modifying the colors here as well instead of removing the element; we
might display it again in the future.

Also note the change in `.supported` only affects the proposals section;
budget investments use a different color for the `.supported` sucess
message. Not sure whether this was originally intended or done by
accident.
2022-10-27 15:07:53 +02:00
Javi Martín
09471c1432 Remove redundant background definitions
These elements didn't need a background because their parent elements
already defined the same background.
2022-10-27 01:10:46 +02:00
Javi Martín
590f557aaa Remove redundant link colors definitions
These elements already used these colors because their parent elements
already used these colors for links.
2022-10-27 01:10:36 +02:00
Javi Martín
e050e5cc70 Remove redundant text color definitions
These elements were already using these colors because they inherited
them from their parent elements or Foundation already defined them.

Note that the only contents of `.comment-info` are: `.user-name` and
`.is-author`, `.is-association`, `.level-1`, ... and the link to the
comment. All of these elements were overwriting the `$text-medium`
color, so there's no need to set it. That means we can use the default
text color for `.user-name` without specifically setting it.
2022-10-27 01:10:31 +02:00
Javi Martín
6f75069cb3 Remove unused style for table header labels
This style was added in commit 92f4c26fa. However, we don't have any
labels inside <th> elements, so we don't need it.
2022-10-26 16:23:50 +02:00
Javi Martín
4e7b0dad99 Merge pull request #5017 from consul/fix_colors
Fix and adjust the colors of some elements
2022-10-26 16:23:18 +02:00
Javi Martín
7ed0dbfd9a Use the same colors for admin top-links
Doing so will help to immediately identify which administration you're
managing when using multitenant applications.

We might revert this change if we detect it causes usability issues in
the admin section.
2022-10-25 21:23:52 +02:00
Javi Martín
5dbd694861 Use the same color for solid and hollow buttons
Should hollow buttons use the same color as links do or the same color
as solid buttons do? In the default scenario, it doesn't matter, since
links and solid buttons use the same color. However, it matters when
people customize the application so links and solid buttons don't use
the same color.

I'm choosing to use the same color for solid and hollow buttons because
these elements are usually isolated and so from the UX perspective they
are similar; links, on the other hand, are often in the middle of some
text.

Note we're talking about links and buttons while many of the "buttons"
we use in the application are actually links styled as buttons. Here,
"buttons" means "things that look like buttons".
2022-10-24 20:38:16 +02:00
Javi Martín
a16247b258 Respect hover color in leaflet and author links
We were overwriting the color of the links, but not the color of the
links on hover.

Note we're removing the `!important` rule from the author link; after
testing it, it looks like it wasn't necessary.
2022-10-24 20:38:16 +02:00
Javi Martín
21faad66c9 Fix color changing on hover on non-link notifications
IMHO it was really strange to change the color on hover when the element
isn't interactive.
2022-10-24 20:38:14 +02:00
Javi Martín
9dfff1864a Fix hover and current datepicker color
We were using the wrong color since commit e2d540d20 because, by using
`@extend`, the compiled CSS had the styles for `.ui-state-hover` appear
before the styles for `.ui-state-default`.
2022-10-23 18:55:38 +02:00
Javi Martín
5d37220282 Fix hover colors on buttons to show/hide content
We were setting the color to be the same as links, but forgot to do the
same on hover. Using the `link` mixin solves the issue.
2022-10-23 18:55:38 +02:00
Javi Martín
f0badb82f2 Merge pull request #4921 from consul/dependabot/bundler/master/rubocop-1.35.1
Bump rubocop from 1.18.4 to 1.35.1
2022-10-19 16:29:25 +02:00
Javi Martín
0d4a032f52 Add and apply Lint/NonAtomicFileOperation rule
This rule was added in Rubocop 1.31.0; it follows the principles
mentioned in the Ruby Style Guide [1].

https://rubystyle.guide/#atomic-file-operations
2022-10-19 14:26:49 +02:00
Javi Martín
4a851c0d82 Add and apply Style/MapToHash rubocop rule
This rule was added in Rubocop 1.24.0. Applying it slightly simplifies
the code.
2022-10-19 14:26:49 +02:00
Javi Martín
5ec7f4a339 Add and apply FileRead and FileWrite rubocop rules
They were added in Rubocop 1.24.0.

Even if we were already applying FileRead everywhere, this is something
we've manually fixed in the past. Another reason to add it is that these
rules are deeply related.
2022-10-19 14:26:49 +02:00
Javi Martín
f800a02a42 Add Layout/LineEndStringConcatenationIndentation rule
This rule was added in Rubocop 1.18.0, but we didn't add it back then.
Since we're applying it most of the time, we might as well be consistent
and apply it everywhere.
2022-10-19 14:26:49 +02:00
dependabot[bot]
0d11f2c66a Bump rubocop from 1.18.4 to 1.35.1
Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.18.4 to 1.35.1.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.18.4...v1.35.1)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-19 14:26:49 +02:00
Javi Martín
0b3bcccf11 Merge pull request #5014 from consul/machine_learning_crash
Fix crash running machine learning with no data dir
2022-10-19 11:56:40 +02:00
Javi Martín
669f190640 Simplify test stubbing machine learning files 2022-10-19 03:20:11 +02:00
Javi Martín
33f7a05d3e Fix crash running machine learning with no data dir
The scripts crashed when the `data` folder wasn't present, which is the
common situation in development environments or production environments
not using Capistrano, since this folder isn't under version control.
2022-10-19 03:02:56 +02:00
Senén Rodero
0b8cd158a9 Merge pull request #5012 from consul/multiple_answers
Add poll questions that accept multiple answers per user
2022-10-18 13:25:02 +02:00
Senén Rodero
760abffde9 Merge pull request #4993 from consul/refactor_public_polls
Refactor and simplify public polls views
2022-10-18 13:24:44 +02:00
decabeza
1eb52fb045 Add read more links to poll question component 2022-10-18 11:04:40 +02:00
decabeza
88007d0c5d Update poll question answer description translation 2022-10-18 11:04:40 +02:00
decabeza
105bb0db31 Add votation_types to development seeds 2022-10-18 11:04:40 +02:00
decabeza
36e452437e Add questions with mutiple answers to polls public interface
The `reload` method added to max_votes validation is needed because the
author gets here with some changes because of the around_action
`switch_locale`, which adds some changes to the current user record and
therefore, the lock method raises an exception when trying to lock it
requiring us to save or discard those record changes.
2022-10-18 11:04:40 +02:00
Senén Rodero Rodríguez
3da4112d94 Remove Poll::Voter record when there is no more user answers
Now we can remove answers we should provide a way of removing voting.
2022-10-18 11:04:40 +02:00