Commit Graph

2109 Commits

Author SHA1 Message Date
Javi Martín
dbcc5fb724 Use AR relations when merging comments
Using arrays made it difficult to order by more than one field (like the
`most_voted` scope does), and so we were ordering by `confidence_score`
and ignoring the `created_at` column.

Using an AR relation makes it easy to reuse the existing `most_voted`
scope.

This change has one side effect: now comments with equal votes are
ordered in descending order instead of having no specific order. That
means flaky specs which failed sometimes because they assumed comments
were ordered by date are now always green.

I've also re-added the `oldest` scope removed in 792b15b thinking it was
removed because using it with arrays was too hard.
2019-05-29 20:50:53 +02:00
Javier Martín
14a5ea87a1 Merge pull request #3562 from consul/prepare_for_rails_5.1
Add Rails 5.1 compatibility
2019-05-29 19:11:19 +02:00
Javi Martín
e445e14d65 Use ActiveSupport::HashWithIndifferentAccess
Using `HashWithIndifferentAccess` directly will be deprecated in Rails
5.1.
2019-05-28 14:23:54 +02:00
voodoorai2000
29f5268e42 Display polls for current booth
Polls that were not votable by a user were not being displayed in the officing interface. Creating a confusing situation for officers.

With this commit polls that are not votable by a user will be displayed, with the corresponding message explaining that that poll can only be voted by residents of a certain geozone.
2019-05-24 15:20:54 +02:00
Javier Martín
387488aa68 Merge pull request #3520 from consul/backport-refactor_stats_enabled
Add options to show advanced stats
2019-05-23 13:07:19 +02:00
Javi Martín
4f4dc2c2af Add show results and stats form to budgets 2019-05-22 11:50:03 +02:00
Javi Martín
354b183e17 Create reports
This table will store which reports (stats, results, ...) will be shown
for a certain process (polls, budgets, ...).

Note Rails fails to save a poll and its report when both are new records
if we add a `validate :process, presence: true` rule. Since it caused a
lot of trouble when creating records for tests during factories rule
completely. Instead, I've created the `results_enabled=` and
`stats_enabled=` methods, so tests are easier to set up, while also
automatically creating a report if it doesn't already exist. This also
decouples form structure and database implemenation.

Originally I named this table `enabled_reports` and instead of having
`stats` and `results` columns, it had an `enabled` column and a `kind`
column, which would be set to "stats" or "results". However, although
that table would allow us to add arbitrary reports easily, I found the
way we had to handle the `has_many` relationship was a bit too complex.
2019-05-22 11:50:03 +02:00
Alberto
ac1d8195f2 Merge pull request #3488 from consul/basic-yml
Admin basic customization texts
2019-05-21 21:43:07 +02:00
Javier Martín
82e3c41aa9 Merge pull request #3512 from consul/backport-stats
Change stats layout
2019-05-21 17:18:47 +02:00
Javier Martín
d57025696f Merge pull request #3503 from consul/backport-blank_votes
Improve poll stats
2019-05-21 14:23:13 +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
Javi Martín
76c7827cf4 Use stats objects instead of hashes
It will make it far easier to call other methods on the stats object,
and we're already caching the methods.

We had to remove the view fragment caching because the stats object
isn't as easy to cache. The good thing about it is the view will
automatically be updated when we change logic regarding which stats to
show, and the methods taking long to execute are cached in the model.
2019-05-21 13:50:18 +02:00
Javier Martín
cbfa2c1df8 Merge pull request #3504 from consul/backport-poll_slugs
Add slug to polls
2019-05-21 13:42:47 +02:00
Bertocq
b8dbdaf9a7 Move question most voted answer from boolean to a enumerable max by total_votes 2019-05-21 13:26:44 +02:00
Bertocq
dbe404d9ad Fix Officer final recount access without voting shift 2019-05-21 13:26:44 +02:00
Alberto
d845c6e973 Merge pull request #3476 from consul/delete-poll
Allow delete polls with associated questions and answers
2019-05-17 17:38:20 +02:00
Alberto
b3ec2b42d1 Merge pull request #3506 from consul/officers-redirect
Remove redirect for poll officers
2019-05-17 17:27:01 +02:00
Alberto
7c79965547 Merge pull request #3397 from consul/proposals-form
Remove question and external_url fields from proposals and legislation proposals
2019-05-17 17:08:56 +02:00
decabeza
4f1e70ea95 Remove redirect to poll officers 2019-05-17 16:30:33 +02:00
rgarcia
1af472b795 hotfix for polls without slugs 2019-05-16 23:40:50 +02:00
María Checa
e3b16230e6 Added slug to polls for named urls 2019-05-16 23:40:50 +02:00
voodoorai2000
abb6eb18b0 Order headings by name and group
Note that we are relying on the existing `sort_by_name`[1] method in the `Budget::Heading` class.

This method sorts by DESC group name first and then ASC heading name.

[1] https://github.com/AyuntamientoMadrid/consul/pull/1875
2019-05-16 22:01:42 +02:00
rgarcia
51ab4a430e Load budget in stats controller 2019-05-16 22:01:42 +02:00
Bertocq
e0e02b47c0 Add Budgets Stats Controller, route and ability on reviewing ballots and finished budget 2019-05-16 22:01:42 +02:00
Javier Martín
668b6cfd73 Merge pull request #3499 from consul/backport-admin_stats
Add admin budget stats
2019-05-16 20:41:39 +02:00
Juanjo Bazán
110ee961e3 adds budget stats for final voting to admin stats 2019-05-16 14:45:46 +02:00
Juanjo Bazán
5be54b57da reduces current admin budget stats as supporting phase 2019-05-16 14:45:45 +02:00
rgarcia
11437a1d40 add budget investment stats 2019-05-16 13:41:49 +02:00
rgarcia
a31b62526b removes unused multiple lines per graph 2019-05-16 13:37:47 +02:00
rgarcia
cfe3f95f5c moves graphs to individual views 2019-05-16 13:37:47 +02:00
Javier Martín
c39a3d7525 Merge pull request #3492 from consul/backport-fix_delete_budget_with_polls
Don't destroy budgets with an associated poll
2019-05-16 13:07:18 +02:00
decabeza
e026412389 Add button to delete a poll 2019-05-14 16:46:56 +02:00
Javi Martín
1b323383a8 Don't destroy budgets with an associated poll
We were getting an exception due to foreign key database violations.
2019-05-13 13:44:58 +02:00
Alberto
60c02cc19a Merge pull request #3466 from consul/admin-documents
Add document uploads from admin section
2019-05-10 17:57:22 +02:00
Javi Martín
55c8fa3297 Fix obsolete respond_with_bip usage
Since we removed the `best_in_place` gem, this method doesn't exist
anymore. We're replacing it with what the method actually does.

Note the test doesn't check the poll is correctly updated. We could add
a `visit proposal_dashboard_polls_path(proposal)` before checking the
"Show results" field, but then we would enter a race condition between
this request and the AJAX request. A proper solution would be to provide
actual feedback to the user so they know the poll has been updated, and
then checking that feedback is present in the tests.
2019-05-09 19:41:04 +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
decabeza
5bdac5c4f5 Remove question and external_url fields from legislation proposals 2019-04-30 11:35:47 +02:00
decabeza
0995480b73 Remove question and external_url fields from proposals 2019-04-30 11:35:47 +02:00
voodoorai2000
d1ac727a6b Update release version number to 1.0.0-beta 2019-04-29 18:52:03 -05:00
decabeza
47985df4f3 Fix request_to_administrators checkbox on admin dashboard actions 2019-04-29 15:46:38 +02:00
voodoorai2000
dfbdc0568c Allow actions to be unexecuted
Before actions could be marked as executed. With this commit we are also allowing actions to be marked as unexecuted.
2019-04-29 15:43:53 +02:00
decabeza
51ced318e0 Merge branch 'master' into proposal-dashboard 2019-04-29 13:48:23 +02:00
Javier Martín
e0484e45ec Merge pull request #3459 from consul/backport-fix_cross_origin_exception
Fix InvalidCrossOriginRequest response
2019-04-25 22:01:51 +02:00
Javi Martín
d90efa15e4 Fix InvalidCrossOriginRequest response
When requesting files like `/hackattempt.js`, the pages controller was
responding with 404 status code.

However, since the request was considered a JavaScript request (because
of the `.js` extension), the response was also considered to be a
JavaScript one, and since the request wasn't an AJAX request, our
protection from forgery was preventing a potential security issue by
raising an InvalidCrossOriginRequest exception.

By setting HTML as content type, we correctly respond with a 404 status
code.

More info:

https://die-antwort.eu/techblog/2018-08-avoid-invalid-cross-origin-request-with-catch-all-route/
2019-04-25 20:48:38 +02:00
Javi Martín
286e0ca878 Handle AccessDenied in management sessions
We were raising a `CanCan::AcessDenied` and were getting a 500 Internal
Server Error.

I've chosen to do the same thing we do in the ApplicationController.
There are other options to handle this request, like redirecting to the
login page or returning a 401 Unauthorized HTTP status.
2019-04-25 20:36:50 +02:00
Juanjo Bazán
c63c06b7ec protect_from_forgery is not prepended by default
so it has to appear before devise's auth methods
2019-04-25 14:22:19 +02:00
decabeza
18f0697ef7 Fix proposal dashboard settings 2019-04-24 14:00:48 +02:00
decabeza
19c158f4eb Add pending and done filters to dashboard administrator tasks 2019-04-24 13:58:27 +02:00