Commit Graph

58 Commits

Author SHA1 Message Date
Senén Rodero Rodríguez
f8835debae Move logic from key definition to views
Before this change, two important things depend on the format of each key,
where to render it in the administration panel and which kind of interface
to use for each setting. Following this strategy led us to a very complex
code, very difficult to maintain or modify. So, we do not want to depend
on the setting key structure anymore to decide how or where to render each
setting.

With this commit, we get rid of the key format-based rules. Now we render
each setting explicitly passing to it the type and the tab where it belongs.
2024-01-25 18:29:38 +01:00
Javi Martín
8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00
Javi Martín
11832cc07d Make it easier to customize allowed parameters
When customizing CONSUL, one of the most common actions is adding a new
field to a form.

This requires modifying the permitted/allowed parameters. However, in
most cases, the method returning these parameters returned an instance
of `ActionController::Parameters`, so adding more parameters to it
wasn't easy.

So customizing the code required copying the method returning those
parameters and adding the new ones. For example:

```
def something_params
  params.require(:something).permit(
    :one_consul_attribute,
    :another_consul_attribute,
    :my_custom_attribute
  )
end
```

This meant that, if the `something_params` method changed in CONSUL, the
customization of this method had to be updated as well.

So we're extracting the logic returning the parameters to a method which
returns an array. Now this code can be customized without copying the
original method:

```
alias_method :consul_allowed_params, :allowed_params

def allowed_params
  consul_allowed_params + [:my_custom_attribute]
end
```
2022-04-07 19:35:40 +02:00
Javi Martín
1290e2ecd3 Store files with both Paperclip and ActiveStorage
In order to migrate existing files from Paperclip to ActiveStorage, we
need Paperclip to find out the files associated to existing database
records. So we can't simply replace Paperclip with ActiveStorage.

That's why it's usually recommended [1] to first run the migration and
then replace Paperclip with ActiveStorage using two consecutive
deployments.

However, in our case we can't rely on two consecutive deployments
because we have to make an easy process so existing CONSUL installations
don't run into any issues. We can't just release version 1.4.0 and 1.5.0
and day and ask everyone to upgrade twice on the same day.

Instead, we're following a different plan:

* We're going to provide a Rake task (which will require Paperclip) to
  migrate existing files
* We still use Paperclip to generate link and image tags
* New files are handled using both Paperclip and ActiveStorage; that
  way, when we make the switch, we won't have to migrate them, and in
  the meantime they'll be accessible thanks to Paperclip
* After we make the switch, we'll update the `name` column in the active
  storage attachments tables in order to remove the `storage_` prefix

Regarding our handling of new files, the exception are cached
attachments. Since those attachments are temporary files used while
submitting a form and we have to delete them afterwards, we're only
handling them with Paperclip. We'll handle these ones in version 1.5.0.

Note the task creating the dev seeds was failing after these changes
with an `ActiveStorage::IntegrityError` exception because we were
opening some files without closing them. If the same file was attached
twice, it failed the second time.

We're solving it by closing the files with `File.open` and a block. Even
though we didn't get any errors, we're doing the same thing in the
`Attachable` concern because it's a good practice to close files after
we're done with them.

Also note we have to change the CKEditor Active Storage code so it's
compatible with Paperclip. In this case, I haven't been able to write a
test to confirm the attachment exists; I was getting the same
`ActiveStorage::IntegrityError` mentioned above.

Finally, we're updating the site customization image controller to use
`update` so the image and the attachment are updated within the same
transaction. This is also what we do in most controllers.

[1] https://www.youtube.com/watch?v=tZ_WNUytO9o
2021-09-24 13:39:15 +02:00
Javi Martín
bc47d84a1e Extract method do update I18n contents
This way we can test it properly, which will be helpful when fixing
bugs.
2021-09-08 12:38:27 +02:00
Javi Martín
65c9786db7 Apply Layout/RedundantLineBreak rule to short lines
We're not adding the rule because it would apply the current line length
rule of 110 characters per line. We still haven't decided whether we'll
keep that rule or make lines shorter so they're easier to read,
particularly when vertically splitting the editor window.

So, for now, I'm applying the rule to lines which are about 90
characters long.
2021-09-03 11:49:53 +02:00
Javi Martín
0911b89d16 Add name attribute to heading content blocks
This way we can simplify the code and don't have to rely on `.try`
statements which are confusing and so we don't allow them in the
`Rails/SafeNavigation` Rubocop rule.
2021-02-05 17:46:23 +01:00
Senén Rodero Rodríguez
3aaf5ce151 Add back link to cards form
As we normally do in other places.
2021-01-12 15:34:55 +01:00
Javi Martín
4c0bb894eb Use polymorphic routes to manage cards
We use a different logic to load the card depending on the controller
we're using, and then share the rest of the code. This way we simplify
the code a bit, since we don't have to check for the page_id parameter.
2021-01-12 14:50:37 +01:00
Javi Martín
52d71b8432 Remove unneeded namespace methods
These methods are not necessary since we changed the `namespace` helper
method in commit 13b3d9ceb.
2021-01-12 14:50:36 +01:00
Javi Martín
0762c66855 Don't skip authorization check managing cards
I'm not sure why we were skipping this check.
2021-01-12 14:50:36 +01:00
Javi Martín
ded5a8d468 Use cancancan to load pages and cards
Like we do in most places in the application.
2021-01-12 14:50:33 +01:00
Javi Martín
002e9239d0 Simplify code involving Globalize.locale
We don't need to set this value. In commit f2ef27d3 I made a mistake
thinking `Globalize.locale` and `I18n.locale` should always be in sync,
but they're actually automatically in sync when `Globalize.locale` is
`nil`.

So the best way to avoid any issues is not to assign `Globalize.locale`,
and use `Globalize.with_locale` where necessary instead.
2020-06-25 19:37:57 +02:00
Javi Martín
a727dcc031 Apply Style/SymbolProc rubocop rule
This style is much more concise.
2019-10-26 20:10:32 +02:00
Javi Martín
01fe31c5e3 Apply Style/IdenticalConditionalBranches rule 2019-10-26 13:03:49 +02:00
Javi Martín
db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00
Javi Martín
7ca55c44e0 Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
2019-10-23 14:39:31 +02:00
Javi Martín
6ceca143b4 Remove redundant check deleting content blocks
The `find` method raises an exception if nothing is found, so there's no
need to check if it found something.
2019-10-22 17:37:51 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
decabeza
a2cb7501f7 Create new basic tab for admin information texts 2019-05-21 14:06:58 +02:00
Javi Martín
1135441cbd Simplify getting I18nContent translations
This code might be slightly slower because it performs one query per
field in the form, but I didn't notice any differences on my development
machine, and the code is now much easier to understand.
2019-05-21 13:53:39 +02:00
decabeza
1719a8ed28 Adds styles to admin site customization documents 2019-04-30 12:00:59 +02:00
voodoorai2000
19b7526421 Add document upload from admin section 2019-04-30 11:59:08 +02:00
Angel Perez
ee2b87aedf Use .where clause first when calling .destroy_all method 2019-04-17 17:40:55 +02:00
Julian Herrero
4df9a1a1b4 Move HTML settings to content blocks settings page
- Rename html settings keys
- Show html settings next to content blocks page
- Hide html settings from configuration tab
2019-03-19 19:45:34 +01:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01:00
Manu
7657a0e0b4 added i18n text to custom pages cards 2019-01-18 09:54:43 -05:00
Manu
2dd953bdfd added hound corrections and removed wrong tables form the schema.rb 2019-01-18 09:54:43 -05:00
Manu
722a431b54 Add cards to custom pages 2019-01-18 09:54:43 -05:00
Julian Herrero
2081269a67 fix Hound violations 2019-01-02 10:46:31 +01:00
Milber Champutiz Burbano
9f455b9165 Added feature to add content block to headings in sidebar -- rebase 2018-11-27 09:37:35 -05:00
Javi Martín
08c043425a Remove reference to site customization page locale
We don't use that attribute since we added translations for this model.
2018-10-22 16:36:18 +02:00
Javi Martín
00983200d4 Update information texts translatable fields
This part used the code we deleted in order to make it easier to
refactor the rest of the translatable models. Now we add the code back.
2018-10-22 16:36:12 +02:00
Angel Perez
1835bac7e4 Avoid ternary operator usage when appending/creating I18n keys
When using the OR operator, if the left side of the expression evaluates
to false, its right side is taken into consideration. Since in Ruby nil
is false, we can avoid using conditionals for this particular scenario
2018-10-22 16:35:01 +02:00
Angel Perez
05890602fd Fix Rubocop warnings [ci skip] 2018-10-22 16:34:57 +02:00
Raúl Fuentes
bdf12ebdfb Move flat_hash to I18nContent model
also add unit tests for this function and a description
into the model of the behaviour of the function
2018-10-22 16:33:01 +02:00
Javi Martín
3c170f47d2 Update site customization pages translatable fields 2018-10-22 16:13:48 +02:00
Papaya Labs
914bfa645e Updates translatable custom pages 2018-09-27 13:46:17 +02:00
Marko Lovic
54d0068134 Remove unused code
This method has never been used as far as I've
been able to tell from the git history.
2018-09-10 17:33:50 +02:00
Marko Lovic
3c4f221e04 Change Translatable interface 2018-09-10 17:32:49 +02:00
Marko Lovic
4603a30f95 Change Translatable impl to keep track of enabled locales 2018-09-10 17:18:01 +02:00
rgarcia
ea4f079588 Do not store missing translations in DB
When visiting http://localhost:3000/admin/site_customization/information_texts?locale=fr
and creating a translation, other languages where storing translations in db with
the following values:
"<span class=\"translation_missing\" title=\"translation missing: es.debates.index.search_results.one\">One</span>">

With this commit we are not storing this translations

Note that this only happened when using a param[:locale] in the url at least for french
2018-07-26 21:55:08 -04:00
rgarcia
4c8b174274 Display only translations for the current language
After creating a translation in spanish, it was also displaying it when selecting
the english locale.

This was due to the code picking the first translation available

With this commit, we are checking for an existing translation in the current locale
and displaying it if it exists
2018-07-26 21:55:07 -04:00
Angel Perez
8015596cb8 Replace hardcoded update notice when updating translations with proper I18n 2018-07-26 20:49:12 -04:00
rgarcia
461a172bd2 Refactor translations loading for current locale 2018-07-26 20:49:01 -04:00
rgarcia
feb3df1f93 Initialize I18n.backend translations
We were getting a 500 error because the translations had not been initialized
https://stackoverflow.com/a/4054527
2018-07-26 20:49:00 -04:00
rgarcia
82f496ccfa Fix globalization for information texts
Refactoring and making similar specs to the milestones globalization specs
2018-07-26 20:48:56 -04:00
Angel Perez
5c1e0bd949 Don't use hardcoded locale when appending/creating I18n keys 2018-07-26 19:07:11 -04:00
Angel Perez
a190e3e1e0 Fix exception for undeclared variable on InformationTexts#index action 2018-07-26 19:06:54 -04:00
Angel Perez
f92006b3f3 Extract complex logic from InformationTexts#index into separate private methods 2018-07-26 19:06:37 -04:00