Commit Graph

168 Commits

Author SHA1 Message Date
Javi Martín
a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00
Javi Martín
5b6de96241 Add and apply MultilineMethodCallIndentation rule 2023-08-18 14:56:16 +02:00
Javi Martín
629e208e9d Add and apply ArgumentAlignment rubocop rule
We're choosing the default `with_first_argument` style because it's the
one we use the most.
2023-08-18 14:56:16 +02:00
Javi Martín
1cb6268d4e Add and apply Layout/ClosingHeredocIndentation rule 2023-08-18 14:56:16 +02:00
Javi Martín
286a128a71 Merge pull request #5106 from consul/fix_budget_background_image
Render background images with brackets in their names
2023-06-30 17:20:56 +02:00
Karim Semmoud
3faaa8521d Render markdown tables in legislation draft
* Add Tables option to Redcarpet in Legislation draft

* Allow table tags in Admin Legislation Sanitizer

* Add Test to render markdown tables in Legislation drafts

* Add Test for Admin Legislation Sanitizer

We include test for image, table and h1 to h6 tags and additional tests to strengthen the allowed and disallowed parameters

* Add Table from markdown test in System and Factories

* Add test to render  tables for admin user

* Remove comment line about Redcarpet options

* Edit custom css for legislation draft table to make it responsive
2023-06-29 20:48:01 +02:00
karim-semmoud
3a623c070f Add tests for budget images with brackets / quotes 2023-06-27 13:57:51 +02:00
karim-semmoud
f4973498be Add budget image to Budget and image factories and model 2023-06-26 19:40:42 +02:00
Matheus Miranda
de13e789dd Add polygon geographies to Budgets' map
Note that in the budgets wizard test we now create district with no
associated geozone, so the text "all city" will appear in the districts
table too, meaning we can't use `within "section", text: "All city" do`
anymore since it would result in an ambiguous match.

Co-Authored-By: Julian Herrero <microweb10@gmail.com>
Co-Authored-By: Javi Martín <javim@elretirao.net>
2023-05-31 16:56:15 +02:00
Javi Martín
65ed778226 Avoid removing other proposals map locations
It was possible to remove a map location from a different proposal (even
one created by a different author) by modifying the hidden `id`
parameter in the form.

So we're making sure the map location we destroy is the one associated
to the proposal we're updating.

Since we're now using the `@proposal` instance variable in the
`destroy_map_location_association` method, we're calling that method
after loading the resource with cancancan.
2023-04-28 17:11:59 +02:00
Javi Martín
4954038076 Only re-render my ballot after voting
We were rendering the whole sidebar again, which wasn't necessary since
most of it remains unchanged. This resulted in complicated code to pass
the necessary information to render the same map that was already
rendered. Furthermore, when users had been moving the map around or
zooming out, we were resetting the map to its default settings after
voting, which was potentially annoying.

This also fixes the wrong investments being displayed in the map after
voting; only the investments on the current page were displayed in this
case while the index displayed all of them.
2023-04-27 17:39:56 +02:00
Javi Martín
e1e16d21c3 Allow having tenants with different domains
Some institutions using CONSUL have expressed interest in this feature
since some of their tenants might already have their own domains.

We've considered many options for the user interface to select whether
we're using a subdomain or a domain, like having two separate fields,
using a check box, ... In the end we've chosen radio buttons because
they make it easier to follow a logical sequence: first you decide
whether you're introducing a domain or subdomain, and then you enter it.

We've also considered hiding this option and assuming "if it's got a
dot, it's a domain". However, this wouldn't work with nested subdomains
and it wouldn't work with domains which are simply machine names.

Note that a group of radio buttons (or check boxes) is difficult to
style when the text of the label might expand over more than one line
(as is the case here on small screens); in this case, most solutions
result in the second line of the label appearing immediately under the
radio button, instead of being aligned with the first line of the label.
That's why I've added a container for the input+label combination.
2022-12-13 13:10:02 +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
decabeza
a25629951c Update poll factories 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
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
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
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
decabeza
80e64590b7 Allow enable 'hide_money' check on admin budget form
Add new 'hide_money' field to admin budget form.

Only display new field 'hide_money' when voting style is 'approval'
2022-03-29 14:49:25 +02:00
Javi Martín
8eea6f585a Remove hack to allow IO files in Active Storage
We were using this hack in order to allow `File.new` attachments in
tests files. However, we can use the `fixture_file_upload` helper
instead.

Just like it happened with `file_fixture`, this helper method doesn't
work in fixtures, so in this case we're using `Rack::Test::UploadedFile`
instead.
2022-02-23 19:00:33 +01:00
Javi Martín
76555495f6 Hide legislation proposals when blocking a user
We're also updating the notice messages to specify all contents have
been hidden (not just debates).
2021-12-30 15:50:03 +01:00
rgarcia
68a2281203 Refactor segment constant into a class method
We're going to make it dynamic using the geozones. Besides, class
methods can be overwritten using custom models, while constants can't be
overwritten without getting a warning [1].

Makes the definition of segments with geozones a little cleaner. I
think it’s worth it, compared to the slight memory gain of using a
constant [2].

[1] warning: already initialized constant UserSegments::SEGMENTS

[2] https://stackoverflow.com/questions/15903835/class-method-vs-constant-in-ruby-rails#answer-15903970
2021-12-20 15:07:25 +01:00
Senén Rodero Rodríguez
30afb64bac Do not consider attributes using the :unless option as required
Remove some of the factories introduced in commit 66334b5 as now we do
not need them anymore.

Co-Authored-By: Javi Martín <35156+javierm@users.noreply.github.com>
2021-11-05 16:40:36 +01:00
Javi Martín
7d818e24ca Fix condition to show the "see results" link
This condition was obsolete since we introduced the `results_enabled`
field in commit 4f4dc2c2a.
2021-10-25 18:01:47 +02:00
Javi Martín
6d26ce57cb Show answers with attachments in additional info
We weren't showing the details of answers without a description, even if
they had images, videos or documents. Some users found that behavior
unexpected since the description isn't a mandatory field and so they
left it blank, but they added images to that answer and they didn't
appear on the poll page.

Note we had a condition not to show the title of an answer when it had
no description. I think that condition was redundant because answers
without a description weren't loaded in the first place. Anyway, that
condition doesn't make sense anymore because we're displaying answers
with images but no description.
2021-10-06 16:52:23 +02:00
Javi Martín
480bb8cd55 Remove link column in dashboard actions
This column wasn't used in any released Consul version since it was only
used during development. For the same reason, the task to migrate the
information in the `link` column to the `links` table isn't needed
either.
2021-10-06 14:13:44 +02:00
Javi Martín
5c1a7044cd Hide comments when features are disabled
We were already doing so for debates and investments.

We probably never noticed because this is an edge case that requires
enabling a feature, people adding comments, and then disabling the
feature.
2021-10-05 14:43:47 +02:00
Javi Martín
be9c272ce4 Remove default Active Storage direct upload action
We're already using a custom controller to handle direct uploads.

Besides, as mentioned by one of Active Storage co-authors [1], the
Active Storage DirectUploadsController doesn't provide any
authentication or validation at all, meaning anyone could create blobs
in our database by posting to `/rails/active_storage/direct_uploads`.
The response there could be then used to upload any file (again, without
validation) to `/rails/active_storage/disk/`.

For now, we're monkey-patching the controllers in order to send
unauthorized responses, since we aren't using these routes. If we ever
enable direct uploads with Active Storage, we'll have to add some sort
of authentication.

Similar upload solutions like CKEditor don't have this issue since their
controllers inherit from `ApplicationController` (which includes
authorization rules), while Active Storage controllers inherit from
`ActionController::Base`.

[1] https://discuss.rubyonrails.org/t/activestorage-direct-uploads-safe-by-default-how-to-make-it-safe/74863/2
2021-09-24 13:39:15 +02:00
Javi Martín
9b61945ee4 Add and apply Lint/EmptyBlock rubocop rule
It was introduced in Rubocop 1.1.0.
2021-09-03 11:49:53 +02:00
Machine Learning
4d27bbebad Add experimental machine learning 2021-08-16 16:31:04 +02:00
Javi Martín
102cf74b3d Bump faker from 1.8.7 to 2.0
Since version 2.0 introduced many breaking changes, we're upgrading to
it first.

The changes have been done by installing the rubocop-faker gem and
running:

```
rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
```
2021-08-13 04:39:44 +02:00
Javi Martín
701378d02c Add padding to the whole header
Instead of adding the padding to each individual element inside the
container, why not adding padding to the container itself? The answer is
"because we want the background of the children elements to take the
width of the whole screen". But this generates either HTML cluttered
with elements to add padding or repetitive padding definitions in the
CSS.

So now we only define the padding once, and when an element requires a
full width background or border, we use the `full-width-background`
mixin.

In this case the code is a bit more complex because the header is also
used in the dashboard and admin layouts:

* In the public layout, the body has a margin, so we include the mixin
  to take margin into account
* In the dashboard layout, the header itself has a margin, so we include
  the same mixin
* In the admin layout, the headet doesn't have a margin but gets the
  whole width, so in this case we include the mixin which dosen't take
  the margin into account

In the future, the idea is to apply this principle to the <body>
element and remove the `@include grid-column-gutter` in the CSS as well
as the `small-12 column` classes in the HTML.

Note we use the `calc()` function inside the mixin instead of using it
in the `$full-width-margin` variable. That way we avoid nested `calc()`
operations, which don't work in Internet Explorer.

Also note we're using `flex-grow: 1` to make one element appear on the
left of the screen and the other one on the right. It would be easier to
use `justify-content: space-between` (which is actually the default for
the top-bar element). However, there's a bug in Internet Explorer and
old versions of Firefox; they include the absolutely-positioned
`::before` element we use to set the full width background when
calculating where to position the elements. The bug was fixed in Firefox
52 (released in 2017).

Finally, we're removing the padding from our logo. In order to allow
logos like the new one and at the same time provide backwards
compatibility to logos in existing CONSUL installations, we're relaxing
the validation rule for the logo width.
2021-07-09 03:45:55 +02:00
Melvin Lammerts
c34aa54122 Remove skip map checkbox 2021-06-03 11:13:52 +02:00
Javi Martín
b196e83121 Fix header card factory
It was using methods which don't exist.
2021-05-29 14:18:31 +02:00
Carlos Iniesta
67d61699b6 Restore all related content when a user is restored 2021-04-09 17:54:56 +02:00
taitus
85611a5103 Adding consistency for post_started_at and post_ended_at on specs
These two fields are of type Date and in some specs they are being
filled as Time or DateTime.
2021-04-08 17:23:33 +02:00
Julian Herrero
28caabecdf Refactor participatory budgets in draft mode
Previously the draft mode was a phase of the PB, but that had some
limitations.

Now the phase drafting disappears and therefore the PB can have the
status published or not published (in draft mode).

That will give more flexibility in order to navigate through the
different phases and see how it looks for administrators before
publishing the PB and everybody can see.

By default, the PB is always created in draft mode, so it gives you
the flexibility to adjust and modify anything before publishing it.
2021-02-23 17:05:24 +01:00
taitus
0a3de68206 Add relation between Goal and LocalTarget
This is similar to what we do with investments, which belong to a heading
but also belong to a budget. In our case, the reason is we've been asked
to add local targets which belong to a goal but are not related to any
existing target.
Even though we're not implementing that case right now, we're adding the
relation so we don't have to add data migrations in the future.
2021-01-26 19:10:12 +01:00
Senén Rodero Rodríguez
0368aa459f Add SDG::Review model
and its relation with relatables

Note about sdg_review factory: Cannot use the constantize method on
the relatable_type as long as the relatable classes will be loaded and
this will throw an exception because the database is not available at
factiry definition time.
2021-01-18 13:17:37 +01:00
Javi Martín
13f95e9419 Add SDG phase model
The purpose of this model will be to have different sections in the SDG
index.
2021-01-14 17:38:01 +01:00
taitus
cd7185f317 Create sdg manager 2020-12-16 11:43:15 +01:00
Senén Rodero Rodríguez
2ad66409e2 Add SDG LocalTarget model 2020-12-08 11:30:46 +01:00
Senén Rodero Rodríguez
c39c7213c7 Add SDG target model
and its relation with the SDG goal model.

Add comparable module be able to sort collections of targets
by code attribute.

Co-Authored-By: Javi Martín <35156+javierm@users.noreply.github.com>
2020-12-04 15:15:32 +01:00
Javi Martín
428644cd3e Add SDG goal model
Since data for this model (title and description) is not generated in
CONSUL but by the United Nations, we aren't storing it in the database
but in our YAML translation files.

The reasoning is as follows. Suppose that, a few months after CONSUL
gets SDG support, a new language is added to CONSUL.

With YAML files, getting the texts in the new language would mean
updating CONSUL to include the new language.

But if we store these texts in the database, it means we have to update
the databases of all existing CONSUL installations, either each
installation by themselves (duplicating efforts) or running a rake task
(which we would have to write each time).

So we believe using translations works better in this case.

We're still storing records in the database with the code, so they can
be easily referenced via `has_many` or `has_many :through` associations.
2020-12-02 12:13:02 +01:00
Javi Martín
40244d6411 Add and apply FactoryBot/FactoryClassName rule
This rule is available since rubocop-rspec 1.37.0. We were already
applying the same principle in the models since commit 234a5108.
2020-10-25 14:23:53 +01:00
Ziyan Junaideen
1e3e8c1304 Add approval voting to budgets
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-08-06 12:38:18 +02:00
Javi Martín
014ccd8374 Use shared specs to flag comments 2020-07-07 23:39:21 +02:00
Andrew Sims
95c82d8777 Changes following PR review
* Internationalisation for admin fields
* Correct typos
* Additional tests
* Replace ternary with if-then statement
2020-04-09 07:11:53 +10:00