Commit Graph

15065 Commits

Author SHA1 Message Date
Javi Martín
58befabde5 Bump puma from 4.2.1 to 4.3.0 2019-11-12 20:20:45 +01:00
Javier Martín
e7842adb67 Merge pull request #3846 from consul/redirects
Avoid redirects with unprotected query params
2019-11-12 20:12:24 +01:00
Javi Martín
31c21ddd42 Keep current host in links to current path
This way we avoid a possible unprotected redirect.
2019-11-12 19:28:35 +01:00
Javi Martín
9065683216 Redirect to referer after destroying an image
The same way we do for documents. This way we avoid a possible
unprotected redirect.
2019-11-12 19:28:35 +01:00
Javi Martín
50bdfd5488 Avoid redirects with unprotected query params
In theory it's possible to add a `host` parameter to a URL, and we could
end up redirecting to that host if we just redirect using query
parameters.

Generating the path using `url_for` with `only_path` solves the issue.

Note in the tests I'm using the `get` method because the `patch` method
wouldn't send query parameters. This doesn't mean the action can be
accessed through GET requests, since controller tests don't check route
verbs. Using feature specs doesn't seem to work because `controller` and
`host` parameters are filtered automatically in feature specs.

Also note I'm not testing every hidden/moderation controller because
they basically use the same code.
2019-11-12 19:27:58 +01:00
Javi Martín
667797161b Extract method to redirect keeping query params 2019-11-12 19:27:58 +01:00
Javi Martín
941fc76884 Remove unused query parameters in redirect
These actions are never called with query parameters in our application,
so there's no need to use these parameters in a redirect.

Note in the test I'm using the `get` method because the `patch` method
wouldn't send query parameters. This doesn't mean the action can be
accessed through GET requests, since controller tests don't check route
verbs.
2019-11-12 19:27:58 +01:00
Javier Martín
aef4651f0d Merge pull request #3849 from consul/puma_socket
Make puma restarts work with systemd
2019-11-12 16:31:05 +01:00
Javi Martín
c4a97a3cf7 Clarify our puma.rb file is only used locally 2019-11-12 16:05:43 +01:00
Javi Martín
95d395343b Use two puma workers
This is the same configuration we had with unicorn.

With several workers, we've got two basic configuration options:

* Preload the application and use a hot restart
* Don't preload the application and use a phased restart

I've decided to preload the application because using a hot restart
changes are available immediately, while with a phased restart there are
a few seconds when both workers for the old code and workers for the new
code exist.

Using a phased restart also has advantages, so some forks might want to
disable the `puma_preload_app` setting in order to use it.
2019-11-12 15:32:04 +01:00
Javi Martín
d17b2523cf Make puma restarts work with systemd
Just like mentioned in puma's documentation:

https://github.com/puma/puma/blob/master/docs/systemd.md#socket-activation
2019-11-12 15:32:04 +01:00
Javier Martín
e9b9512254 Merge pull request #3695 from consul/smtp_secrets
Define SMTP settings in secrets file
2019-11-12 15:28:26 +01:00
Javi Martín
d7aab4c929 Check permissions for secrets file
Old versions of the installer created this file as root, making it
impossible to change it as a regular user.

So for old installations we need to make sure we've got write access to
this file.

We're using `sudo` because in these applications the installer gives
`sudo` access to the deploy user, so everything works fine with the
default configuration.
2019-11-12 14:58:35 +01:00
Javi Martín
a08d42d3f8 Enable/disable delayed jobs in the secrets file
While this is not a secret and in theory should be in a file under
version control, currently the CONSUL installer disables delayed jobs by
default, meaning we were keeping two versions of the delayed jobs
configuration file, and some existing configurations have their settings
defined in a file in capistrano's `shared` folder.

So we're moving existing settings to the secrets file.
2019-11-12 14:58:35 +01:00
Javi Martín
6ecd9e59dc Update secrets based on the previous release
We were copying the current SMTP and SSL settings to the secrets file
after overwriting them, but we need to copy them before overwriting
them.

The workaround I've found is to copy the tasks to the folder of the
previous release and execute them there.
2019-11-12 14:58:06 +01:00
Julian Herrero
d6130cf6e2 Add task to move force_ssl settings to secrets.yml
Existing installations having their configuration settings in the
capistrano shared folder needed this migration.
2019-11-12 14:58:05 +01:00
Julian Herrero
df4f8810c5 Define force_ssl configuration in secrets file
this is usually configured in the production.rb file (which is under
version control), the natural place to configure it is the secrets.yml
file.

Until now we were using the capistrano shared folder, but that's a bit
inconvenient since changes we've done to the production.rb file (like
changing eager_load_paths when we upgraded to Rails 5) won't take effect
after a deployment.
2019-11-12 14:47:28 +01:00
Javi Martín
03c4275525 Add task to move SMTP settings to secrets.yml
Existing installations having their configuration settings in the
capistrano shared folder needed this migration.

Note we can't just use `YAML.load` because we'd lose the anchors defined
in the file. So we have to parse the file the hard way.
2019-11-12 14:47:27 +01:00
dependabot-preview[bot]
18f8c96073 Bump sitemap_generator from 6.0.1 to 6.0.2
Bumps [sitemap_generator](https://github.com/kjvarga/sitemap_generator) from 6.0.1 to 6.0.2.
- [Release notes](https://github.com/kjvarga/sitemap_generator/releases)
- [Changelog](https://github.com/kjvarga/sitemap_generator/blob/master/CHANGES.md)
- [Commits](https://github.com/kjvarga/sitemap_generator/compare/v6.0.1...v6.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-11 14:12:26 +00:00
Javi Martín
bc9471b49e Define SMTP configuration in the secrets file
Since SMTP passwords should not be in a file under version control, and
they're usually configured in the production.rb file (which is under
version control), the natural place to configure it is the secrets.yml
file.

Until now we were using the capistrano shared folder, but that's a bit
inconvenient since changes we've done to the production.rb file (like
changing eager_load_paths when we upgraded to Rails 5) won't take effect
after a deployment.
2019-11-11 12:11:20 +01:00
Javier Martín
4b41ccf75d Merge pull request #3845 from consul/pagination_tests
Reduce number of records in pagination tests
2019-11-10 16:58:57 +01:00
Javi Martín
bd03e249ce Reduce number of records in pagination tests
Creating more than 25 records isn't necessary to test pagination; we can
stub the number of records per page in a test.

On my machine we save about one second per test with these changes.
2019-11-10 14:12:21 +01:00
Javier Martín
2228ac3781 Merge pull request #3844 from consul/hidden_tests
Split comments and debates admin tests
2019-11-10 13:00:47 +01:00
Javi Martín
a84cf54c73 Add tests for debates and comments admin index 2019-11-10 12:32:25 +01:00
Javi Martín
940f099505 Move tests for moderated content to their own files
When we renamed hidden controllers in the admin section in commit
85722eb7 we forgot to rename the test files as well.
2019-11-10 12:32:25 +01:00
Javier Martín
83e97cba55 Merge pull request #3843 from consul/remove_unused_code
Remove unused code
2019-11-10 01:04:42 +01:00
Javi Martín
216d9e61dc Remove unused Voter methods
AFAIK these methods were never used. In any case, the similar method
`set_demographic_info` was added in commit 6c34599e.
2019-11-10 00:34:45 +01:00
Javi Martín
497b087072 Remove obsolete model
It was replaced by Dashboard::AdministratorTask in commit e5f9cf67.
2019-11-10 00:34:45 +01:00
Javi Martín
3eda2de2d5 Remove unused helper methods
They aren't used since commits a6585361, 3752f3a5, 88a7a29d, eef8ad1b,
f67f058b, 04910fea and 9181610d. The method `image_bytes_to_megabytes`
was never used and is a duplicate of the method `bytes_to_megabytes`.
2019-11-10 00:34:45 +01:00
Javi Martín
23d132c3d3 Remove obsolete controller concern
It isn't used since commit 18f0697e.
2019-11-10 00:34:40 +01:00
Javi Martín
e0cb2047e6 Remove unused controller
It was probably added by accident in commit 85c08da7.
2019-11-09 23:24:54 +01:00
Javier Martín
b22ba4aff3 Merge pull request #3838 from PierreMesure/replace-spanish-text-with-app-name
Replace old Spanish text with org name
2019-11-09 21:39:35 +01:00
Javier Martín
dbe67edcdf Merge pull request #3839 from consul/generate_stats
Improve restrictions for poll stats
2019-11-09 19:58:08 +01:00
Pierre Mesure
232e6c7f11 Replace old Spanish text with org name 2019-11-09 19:38:13 +01:00
Javi Martín
ed6a4a1b95 Don't generate stats for budget polls
The link to show stats for these polls is nowhere to be seen in the
application, and these stats are included in the budget stats, so it
makes sense to restrict access to them.
2019-11-09 19:34:24 +01:00
Javi Martín
01a01c834d Only generate stats if we can access them
There's no point generating stats nobody can access.

Note with this change we're automatically excluding polls created in the
dashboard, since these polls don't have stats enabled.
2019-11-09 19:34:24 +01:00
Javi Martín
f8e6e98d3a Define stats and result permissions with scopes
When defining abilities, scopes cover more cases because they can be
used to check permissions for a record and to filter a collection. Ruby
blocks can only be used to check permissions for a record.

Note the `Budget::Phase.kind_or_later` name sounds funny, probably
because we use the word "phase" for both an an attribute in the budgets
table and an object associated with the budget, and so naming methods
for a budget phase is a bit tricky.
2019-11-09 19:34:21 +01:00
Javi Martín
9e27027f56 Remove duplicate scope
The scopes `created_by_admin` and `public_polls` were very similar. I'm
using `created_by_admin` because `Poll.public_polls` feels redundant,
and the reason for that name is we should not name the scope `public`
because `public` is a ruby access modifier.
2019-11-09 19:33:02 +01:00
Javi Martín
864f750d92 Remove duplication in poll permissions
We were checking for `expired?` and `results_enabled?` in views and
helpers, when we've already defined a rule for accessing stats and
results for a poll.

This way we also fix a bug when stats were enabled but the poll wasn't
finished. In this scenario, the link pointed to the stats page, but when
clicking it we'd get a "you don't have permission" message.

Now the link doesn't point to the stats page anymore.
2019-11-09 19:33:02 +01:00
Javi Martín
2029d7baa5 Limit admin access to poll stats and results
There's no reason to allow administrators to check stats and results for
a poll when it isn't finished or when results and stats are not enabled.

Now admins have the same permissions as everyone else.
2019-11-09 19:32:54 +01:00
Javi Martín
8dbad5c3d2 Simplify tests for stats and results permissions
Now these tests look like the other ability tests.
2019-11-09 15:18:58 +01:00
Javier Martín
6778bdb204 Merge pull request #3834 from consul/find_by_everywhere
Apply rubocop Rails/FindBy rule everywhere
2019-11-08 20:32:31 +01:00
Javier Martín
82c0e9650d Merge pull request #3833 from consul/remove_obsolete_milestone_tables
Remove old milestone tables
2019-11-08 19:37:51 +01:00
Javi Martín
9ff285b9cc Use find_by_slug_or_id! to find a poll
We were manually doing a similar thing - only we weren't raising an
exception when we should.
2019-11-08 19:22:11 +01:00
Javi Martín
ea2aeab383 Apply rubocop Rails/FindBy rule everywhere
We didn't detect these cases because by default the rule only searches
for offenses in `app/models/`.
2019-11-08 19:15:04 +01:00
Javier Martín
84bbd81d95 Merge pull request #3832 from consul/test_logger
Don't add log info messages when running tests
2019-11-08 19:10:55 +01:00
Javi Martín
56c797348c Remove old milestone tables
These tables are obsolete since commit c0f6fa18, and their content was
migrated in version 0.18 with the task added in commit 4c3dadf1.
2019-11-08 18:57:54 +01:00
Javier Martín
fcb2e2fb54 Merge pull request #3831 from consul/fix_action_title
Fix random title with trailing spaces
2019-11-08 18:41:18 +01:00
Javier Martín
0f646c67f1 Merge pull request #3828 from consul/remove_obsolete_translatable_columns
Bring back removal of translatable columns
2019-11-08 18:20:54 +01:00
Javi Martín
a1b89094be Don't add log info messages when running tests
We use these messages in rake tasks, but when we run the test suite they
only add noise.
2019-11-08 18:06:18 +01:00