Commit Graph

1457 Commits

Author SHA1 Message Date
Senén Rodero Rodríguez
7df0e9a961 Allow to remove poll answers 2022-10-18 11:04:40 +02:00
decabeza
48d7ec75d0 Do not allow to create more answers than the maximum defined
In case we receive consecutive requests we are locking the poll author record
until the first request transaction ends, so the author answers count during
subsequent requests validations is up to date.
2022-10-18 10:39:00 +02:00
decabeza
4fba76f64f Do not show answers without additional information 2022-10-18 10:38:59 +02:00
decabeza
d1c1aa6691 Add VotationType model 2022-10-18 10:38:59 +02:00
Senén Rodero Rodríguez
64676be246 Remove token column from poll_voters table
As it is no longer used as originally pretended [1][2].

[1] Check consul/consul pull request 1994
[2] Check consul/consul pull request 3539
2022-09-22 10:34:07 +02:00
Julian Herrero
4c8f247de7 Don't allow to modify answer's documents for started polls 2022-09-20 17:50:49 +02:00
Julian Herrero
245594f32b Don't allow to modify answer's images for started polls
Note that the `create` action doesn't create an image but updates an
answer instead. We're removing the references to `:create` in the
abilities since it isn't used.

In the future we might change the form to add an image to an answer
because it's been broken for ages since it shows all the attached
images.
2022-09-20 17:50:49 +02:00
Julian Herrero
5fe86264ca Don't allow to modify answer's videos for started polls
Same rules that will apply for the answer itself should apply for the
attachments like videos, images, and/or documents.
2022-09-20 17:50:49 +02:00
Julian Herrero
14542df0de Allow to delete answers if the poll has not started yet
Deleting answers was not even possible. But it was possible to delete
questions. So we implemented the same behavior.
2022-09-20 17:50:49 +02:00
Julian Herrero
3a6e99cb8c Don't allow changing answers if the poll has started
Just like we did with questions.
2022-09-20 17:50:49 +02:00
Julian Herrero
8a26954bc5 Don't allow to modify questions for started polls
Adding, modifiying, and/or deleting questions for an already started
poll is far away from being democratic and can lead to unwanted side
effects like missing votes in the results or stats.

So, from now on, only modifiying questions will be possible only if
the poll has not started yet.
2022-09-20 17:50:35 +02:00
Julian Herrero
ecd22131f1 Disallow to modify the end date for an ended poll 2022-09-20 17:29:01 +02:00
Julian Herrero
8b5c315eb0 Allow to modify the end date as long as it is not to the past 2022-09-20 17:21:39 +02:00
Julian Herrero
471096c698 Disallow to modify the start date for an already started poll
We need to update a couple of tests because a poll is created in the
tests with a timestamp that includes nanoseconds and in the form to edit
the time of the poll the nanoseconds are not sent, meaning it was
detected as a change.
2022-09-20 17:21:36 +02:00
Julian Herrero
855fedc025 Allow only creation of polls with dates that are not in the past 2022-09-20 13:37:56 +02:00
taitus
d0359d584e Remove trait :current for poll on factories
When we create a poll with "create(:poll)" it is already a current poll.
2022-09-14 15:14:23 +02:00
Javi Martín
5a0fde4048 Allow selecting the time when a poll starts/ends
We were already saving it as a time, but we didn't offer an interface to
select the time due to lack of decent browser support for this field
back when this feature was added.

However, nowadays all major browsers support this field type and, at the
time of writing, at least 86.5% of the browsers support it [1]. This
percentage could be much higher, since support in 11.25% of the browsers
is unknown.

Note we still need to support the case where this field isn't supported,
and so we offer a fallback and on the server side we don't assume we're
always getting a time. We're doing a strange hack so we set the field
type to text before changing its value; otherwise old Firefox browsers
crashed.

Also note that, until now, we were storing end dates in the database as
a date with 00:00 as its time, but we were considering the poll to be
open until 23:59 that day. So, in order to keep backwards compatibility,
we're adding a task to update the dates of existing polls so we get the
same behavior we had until now.

This also means budget polls are now created so they end at the
beginning of the day when the balloting phase ends. This is consistent
with the dates we display in the budget phases table.

Finally, there's one test where we're using `beginning_of_minute` when
creating a poll. That's because Chrome provides an interface to enter a
time in a `%H:%M` format when the "seconds" value of the provided time
is zero. However, when the "seconds" value isn't zero, Chrome provides
an interface to enter a time in a `%H:%M:%S` format. Since Capybara
doesn't enter the seconds when using `fill_in` with a time, the test
failed when Capybara tried to enter a time in the `%H:%M` format when
Chrome expected a time in the `%H:%M:%S` format.

To solve this last point, an alternative would be to manually provide
the format when using `fill_in` so it includes the seconds.

[1] https://caniuse.com/mdn-html_elements_input_type_datetime-local
2022-09-14 15:14:23 +02:00
Javi Martín
3543767951 Don't include current polls in recounting polls
On the day when a poll ends, it was considered both current and
recounting.
2022-09-14 15:14:23 +02:00
Javi Martín
2153bd9e98 Add tests for current/expired/recounting polls
We didn't have model tests for some of these scopes, and neither scope
tests nor instance method tests covered edge cases like the current
date.
2022-09-14 15:14:23 +02:00
Javi Martín
bd85a09d32 Group poll scopes tests together
We're also using the convention of using a `.` to describe class
methods.
2022-09-14 15:14:23 +02:00
taitus
83e0d4c6b7 Add load_and_authorize_resource to images controller 2022-09-14 14:45:37 +02:00
taitus
99495a21d2 Add load_and_authorize_resource to videos controller 2022-09-14 14:45:36 +02:00
taitus
cb2958e1b0 Add load_and_authorize_resource to answers controller 2022-09-14 14:45:34 +02:00
Javi Martín
3a7a5b2346 Merge pull request #4920 from consul/budget_results_tests
Fix flaky budget results tests
2022-08-25 15:32:39 +02:00
Javi Martín
969e0014e5 Move budget result test to the model
We were testing that the `calculate_winners` method does not take the
price into account; we can do the same in a model test. We already have
a different system test to check that the price isn't displayed in the
view.
2022-08-25 14:31:51 +02:00
Javi Martín
c8270d58bd Add and apply Rails/DurationArithmetic rubocop rule
This rule was added in rubocop-rails 2.13.0. We were already applying it
most of the time.
2022-08-24 23:24:36 +02:00
Javi Martín
5b844bf231 Use index_with to simplify hash generation
This method was introduced in Rails 6.0. It can be used to take an array
and create a hash where the elements of the array are the indexes of the
hash.
2022-08-24 18:19:02 +02:00
Javi Martín
c97e7852a4 Use "excluding" instead of "reject"
This method was already available as #without, but we didn't know about
it.
2022-08-24 18:11:56 +02:00
Javi Martín
b59e2b31d3 Use unfreeze_time instead of travel_back
This is consistent with `with_frozen_time`.
2022-08-24 18:11:56 +02:00
Jacek Skrzypacz
2af7e32415 Add search form for hidden content
Added search for comments and proposal_notifications, added tsv column
for search and rake tasks to update/create tsv vector.
2022-08-23 14:30:38 +02:00
Javi Martín
e66b9687a2 Fix calculating tsvector on hidden records
We introduced this bug in commit 55d339572, since we didn't take hidden
records into consideration.

I've tried to use `update_column` to simplify the code, but got a syntax
error `unnamed portal parameter` and didn't find how to fix it.
2022-08-23 14:30:38 +02:00
Javi Martín
11bed74678 Extract constant to configure valid mime types
This way it'll be possible to overwrite the valid mime types in a custom
model.
2022-08-17 12:56:55 +02:00
Javi Martín
7e663f8bcf Fix spacing issues after removing lines
Rubocop was complaining about a Layout/ExtraSpacing in a couple of
places.

These issues weren't detected by Pronto because they didn't affect lines
changed in the pull request. These lines were fine until we removed the
lines next to them in commits 4b42a68b6 and 00f0c4410.
2022-06-13 17:39:53 +02:00
Javi Martín
d776923ffe Use "withdraw" instead of "retire"
We used "retire" because we translated it literally from the Spanish
verb "retirar" which can mean both "retire" and "withdraw".

Note we're still using "retire" in database fields and method names;
changing that might make it harder to upgrade from a previous version of
CONSUL.
2022-06-01 14:27:33 +02:00
Senén Rodero Rodríguez
c6190d0199 Remove roles when block or delete users
After a user assigned as a budget admin deletes their account or gets blocked by
a moderator, the application throws an exception while loading the admin
investment index page.

As an erased user is not really deleted and neither its associated roles, the
application was failing when trying to sort and administration without a
username. In this case, the application was throwing an `ArgumentError:
comparison of NilClass with String failed` exception.

As a blocked user is not deleted or its roles, the application failed when trying
to access the user name through the delegation in the Administrator. In this
case, the application was throwing a `NoMethodError: undefined method `name' for
nil:NilClass` exception.
2022-05-04 16:37:35 +02:00
Senén Rodero Rodríguez
d797ec3ca0 Fix crash deleting admin with assigned budgets
Add missing relation between administrator and budget_administrators, otherwise
we'd get the following exception when deleting and administrator with assigned budgets:

PG::ForeignKeyViolation:
ERROR:  update or delete on table "administrators" violates foreign key constraint "fk_rails_ee7dc33688" on table "budget_administrators"
DETAIL:  Key (id)=(3) is still referenced from table "budget_administrators".
2022-05-03 18:39:42 +02:00
Javi Martín
c25ab8e4a6 Remove unused vote extensions methods
These methods aren't used since commit b98244afd.
2022-05-02 17:16:31 +02:00
Javi Martín
fb99d8cb33 Remove obsolete "pending" test
I'd say this feature is actually tested in the "proposal polls specific
validations"; the empty test was probably added by accident in commit
4b8cc85c4.
2022-04-07 15:34:10 +02:00
Javi Martín
e49c32638d Use if instead of skip to skip tests
This way the tests won't appear as "pending" when running the test
suite, and so we get rid of a lot of noise in the test results. There
doesn't seem to be a way to call `skip` without the test being marked as
"pending".

Note that in the globalizable tests we need to build a factory before
deciding whether an atribute is required or not (particularly for the
milestone factory, since milestone attributes are required depending on
the presence of other attributes). This isn't possible before we're
inside the test, so we can't add an `if:` condition to the test. So
we're adding the condition inside the test instead. A minor
inconvenience of this method is the test still runs even when the
condition is `false`.
2022-04-07 15:34:10 +02:00
Javi Martín
702fc84391 Remove pending reportable tests
These tests are obsolete since commit 5ed308c6f.
2022-04-07 15:34:10 +02:00
Javi Martín
4a8a4eacdd Remove pending tag cloud test for debates
This feature was only enabled for proposals five years ago, and it
hasn't changed since then. The pending test only gets in the way.

Implement. Or implement not. There is no pending.
2022-04-07 15:34:10 +02:00
Javi Martín
0eb666db4d Allow commenting on polls as moderator/admin
So it works the same way as everywhere else.
2022-04-07 15:34:09 +02:00
Javi Martín
3752fef6bf Remove map page in debates
The map feature was never implemented for debates (only for proposals
and budget investments) and it was crashing for debates because the page
didn't load the geozones. And we don't have a "geozone" field in the
debates form either.

So we're removing the map page alongside its (pending implementation)
tests.
2022-04-07 15:34:07 +02:00
Javi Martín
b89c358d03 Remove comments related to code from Madrid
CONSUL doesn't implement blank votes via web; the comment was based on
the code used in Madrid, which was actually very complex.

And the concept of "all city" was also specific to Madrid. Poll
questions aren't associated to a geozone, so the geozone will depend on
the poll they're associated to.
2022-04-07 11:55:35 +02:00
Senén Rodero
3ecf2feb2e Merge pull request #4601 from consul/budgets_hide_money
Add hide money option for approval budgets
2022-03-30 09:58:29 +02:00
decabeza
50e00a096b Update investments order when hide_money is active 2022-03-29 14:49:30 +02:00
decabeza
abc4e9dca1 Manage the render of the price field on public investment section 2022-03-29 14:49:27 +02:00
decabeza
9fb5019f0f Manage the render of the price field on admin budget headings
Avoid displaying the price in admin budget headings section
and avoid fill the field 'price' in admin budget headings form
when the budget has been checked with hide_money field.
2022-03-29 14:49:26 +02:00
Javi Martín
df2b3f2ee7 Avoid model inheritance in skip validation test
One of these tests was failing sometimes on Github Actions. It looked
like the line `custom_banner.save!` was using the validations from the
Banner class sometimes, even if the callbacks had correctly been
removed in the DummyBanner class.

Se we're inheriting from ApplicationRecord instead of inheriting from
Banner. Since I couldn't reproduce the issue locally after running the
test hundreds of times and with the same seed and tests that were
running on Github Actions, there's a change this won't work. I've tested
a few times on Github Actions and it seems to be working, but we'll have
to keep an eye on it.
2022-03-25 20:25:34 +01:00
Javi Martín
b5a4609b56 Make it easier to customize validations
There are CONSUL installations where the validations CONSUL offers by
default don't make sense because they're using a different business
logic. Removing these validations in a custom model was hard, and that's
why in many cases modifying the original CONSUL models was an easier
solution.

Since modifying the original CONSUL models makes the code harder to
maintain, we're now providing a way to easily skip validations in a
custom model. For example, in order to skip the price presence
validation in the Budget::Heading model, we could write a model in
`app/models/custom/budget/heading.rb`:

```
require_dependency Rails.root.join("app", "models", "budget", "heading").to_s

class Budget::Heading
  skip_validation :price, :presence
end
```

In order to skip validation on translatable attributes (defined with
`validates_translation`), we have to use the
`skip_translation_validation` method; for example, to skip the proposal
title presence validation:

```
require_dependency Rails.root.join("app", "models", "proposal").to_s

class Proposal
  skip_translation_validation :title, :presence
end

```

Co-Authored-By: taitus <sebastia.roig@gmail.com>
2022-03-24 17:05:35 +01:00