Re-add and apply MDL rule MD040
We were following it about half of the time and we even added it to our former `.mdlrc` file. However, for some reason, MDL doesn't detect this rule when specified in the `.mdlrc` file, so we didn't notice we weren't following it in many cases. Now that we're using a style file to configure MDL, we can enable this rule again and apply it, since now MDL correctly includes it in its report.
This commit is contained in:
@@ -38,7 +38,7 @@ The information to be filled in is divided into three sections:
|
||||
|
||||
To help you understand how to fill in each of the fields, we will rely on a supposed WebService that receives a method called `:get_habita_datos` with the following structure:
|
||||
|
||||
```
|
||||
```ruby
|
||||
{
|
||||
request: {
|
||||
codigo_institucion: 12, # Static Value
|
||||
@@ -98,7 +98,7 @@ The information to be filled in is divided into three sections:
|
||||
|
||||
As in the previous section we will define an example answer, to help you understand how to fill in each of the fields in this section.
|
||||
|
||||
```
|
||||
```ruby
|
||||
{
|
||||
get_habita_datos_response: {
|
||||
get_habita_datos_return: {
|
||||
|
||||
@@ -8,7 +8,7 @@ We should add in the model the attributes that are going to be translated. To do
|
||||
|
||||
We also need to add the option `globalize_accessors` to include all the locales we want to support. This gem generates all the methods needed by the application (`title_en`, `title_es`, etc.). If you want to include **all** the translated fields in **all** the defined languages in your application, just call `globalize_accessors` without any option (as the [documentation](https://github.com/globalize/globalize-accessors#example) says).
|
||||
|
||||
```
|
||||
```ruby
|
||||
# Supposing a model Post with title and text attributes
|
||||
|
||||
class Post < ActiveRecord::Base
|
||||
@@ -21,7 +21,7 @@ end
|
||||
|
||||
We must create a migration to generate the table where the translations are going to be stored. The table must have a column for each attribute we want to translate. To migrate the stored data in the original table, add the option `:migrate_data => true` in the migration.
|
||||
|
||||
```
|
||||
```ruby
|
||||
class AddTranslatePost < ActiveRecord::Migration
|
||||
def self.up
|
||||
Post.create_translation_table!({
|
||||
@@ -42,7 +42,7 @@ end
|
||||
|
||||
Add the `Translatable` module in the controller that will handle the translations.
|
||||
|
||||
```
|
||||
```ruby
|
||||
class PostController < Admin::BaseController
|
||||
include Translatable
|
||||
...
|
||||
@@ -50,7 +50,7 @@ class PostController < Admin::BaseController
|
||||
|
||||
Make sure that the controller has the functions `resource_model` and `resource`, which return the name of the model and the object we want to save the translations for, respectively.
|
||||
|
||||
```
|
||||
```ruby
|
||||
...
|
||||
def resource_model
|
||||
Post
|
||||
@@ -66,7 +66,7 @@ Make sure that the controller has the functions `resource_model` and `resource`,
|
||||
|
||||
Add as permitted params those dedicated to translations. To do that, the module `Translatable` owns a function called `translation_params(params)`, which will receive the object param and will return those keys with a value. It takes into account the languages defined for that model.
|
||||
|
||||
```
|
||||
```ruby
|
||||
# Following the example, we pass the params[:post] because is the one that has the information.
|
||||
|
||||
attributes = [:title, :description]
|
||||
@@ -85,7 +85,7 @@ Remember that, to avoid errors when using locales like `pt-BR`, `es-ES`, etc. (t
|
||||
|
||||
Add the hidden parameters to the form to delete translations:
|
||||
|
||||
```
|
||||
```erb
|
||||
<%= hidden_field_tag "delete_translations[#{locale}]", 0 %>
|
||||
```
|
||||
|
||||
@@ -95,7 +95,7 @@ We must add the link "Remove translation" to delete translations, which should h
|
||||
- an attribute `data-locale` with the value of `neutral_locale(locale)`.
|
||||
- the class `delete-language`.
|
||||
|
||||
```
|
||||
```erb
|
||||
<%= link_to t("admin.milestones.form.remove_language"), "#",
|
||||
id: "delete-#{neutral_locale(locale)}",
|
||||
class: 'delete-language',
|
||||
@@ -108,7 +108,7 @@ The CSS styles and the rest of the classes will depend on the designed UI for th
|
||||
|
||||
So that they will be generated when the DB is restored. For example, to create a post whose description is translated.
|
||||
|
||||
```
|
||||
```ruby
|
||||
section "Creating post with translations" do
|
||||
post = Post.new(title: title)
|
||||
I18n.available_locales.map do |locale|
|
||||
|
||||
@@ -36,7 +36,7 @@ One of the characteristics that differentiates a REST API from a GraphQL one is
|
||||
|
||||
GraphQL queries are written following a standard which resembles to JSON, for example:
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
proposal(id: 1) {
|
||||
id,
|
||||
@@ -140,7 +140,7 @@ The models are the following:
|
||||
|
||||
### Request a single record from a collection
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
proposal(id: 2) {
|
||||
id,
|
||||
@@ -166,7 +166,7 @@ Response:
|
||||
|
||||
### Request a complete collection
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
proposals {
|
||||
edges {
|
||||
@@ -205,7 +205,7 @@ Response:
|
||||
|
||||
The maximum (and default) number of records that each page contains is set to 25. For navigating through the different pages it's necessary to request also information relative to the `endCursor`:
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
proposals(first: 25) {
|
||||
pageInfo {
|
||||
@@ -242,7 +242,7 @@ The response:
|
||||
|
||||
To retrieve the next page, you have to pass as a parameter the cursor received in the previous request, and so on:
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
proposals(first: 25, after: "NQ==") {
|
||||
pageInfo {
|
||||
@@ -262,7 +262,7 @@ To retrieve the next page, you have to pass as a parameter the cursor received i
|
||||
|
||||
This query requests information about several models in a single request: `Proposal`, `User`, `Geozone` and `Comment`:
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
proposal(id: 15262) {
|
||||
id,
|
||||
@@ -298,7 +298,7 @@ There are three main mechanisms to prevent such abuses:
|
||||
|
||||
The maximum depth of queries is currently set at 8. Deeper queries (such as the following) will be rejected:
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
user(id: 1) {
|
||||
public_proposals {
|
||||
@@ -339,7 +339,7 @@ The response will look something like this:
|
||||
|
||||
The main risk factor is when multiple collections of resources are requested in the same query. The maximum number of collections that can appear in the same query is limited to 2. The following query requests information from the `users`, `debates` and `proposals` collections, so it will be rejected:
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
users {
|
||||
edges {
|
||||
@@ -384,7 +384,7 @@ The response will look something like this:
|
||||
|
||||
However, it is possible to request information belonging to more than two models in a single query, as long as you do not try to access the entire collection. For example, the following query that accesses the `User`, `Proposal` and `Geozone` models is valid:
|
||||
|
||||
```
|
||||
```graphql
|
||||
{
|
||||
user(id: 468501) {
|
||||
id
|
||||
|
||||
@@ -14,7 +14,7 @@ If you're upgrading a Consul Democracy installation to version 2.0.0 from versio
|
||||
|
||||
First, after deploying version 2.0.0 to your production server, execute the release tasks:
|
||||
|
||||
```
|
||||
```bash
|
||||
RAILS_ENV=production bin/rails consul:execute_release_tasks
|
||||
```
|
||||
|
||||
@@ -26,13 +26,13 @@ If that's the case, restart the application. If not, make sure the `config/datab
|
||||
|
||||
Next, open a database console with a user having permission to create and manage database extensions:
|
||||
|
||||
```
|
||||
```bash
|
||||
sudo -u postgres psql -d consul_production
|
||||
```
|
||||
|
||||
If you didn't use the [installer](https://github.com/consuldemocracy/installer/) to install Consul Democracy, you might need to execute a couple of queries to make sure the Rails database user has permission to create schemas and the shared extensions schema has the right permissions:
|
||||
|
||||
```
|
||||
```sql
|
||||
CREATE SCHEMA shared_extensions AUTHORIZATION <replace_with_rails_database_username>;
|
||||
GRANT CREATE ON DATABASE consul_production TO <replace_with_rails_database_username>;
|
||||
GRANT usage ON SCHEMA shared_extensions TO public;
|
||||
@@ -40,7 +40,7 @@ GRANT usage ON SCHEMA shared_extensions TO public;
|
||||
|
||||
Whether or not you installed Consul Democracy with the installer, run:
|
||||
|
||||
```
|
||||
```sql
|
||||
ALTER EXTENSION pg_trgm SET SCHEMA shared_extensions;
|
||||
ALTER EXTENSION unaccent SET SCHEMA shared_extensions;
|
||||
```
|
||||
@@ -88,13 +88,13 @@ If you've installed Consul Democracy using the installer and are using Certbot t
|
||||
|
||||
One option would be adding each certificate manually every time you create a tenant. For example, in orer to add a tenant using the `mars` subdomain in the `solarsystemexample.org` domain, run:
|
||||
|
||||
```
|
||||
```bash
|
||||
sudo certbot certonly --nginx --noninteractive --agree-tos --expand -d solarsystemexample.org,mars.solarsystemexample.org
|
||||
```
|
||||
|
||||
If you're going to add many subdomains at different times, this task can be tedious. Another option is enabling any subdomain. In order to achieve this goal, you need access to your DNS configuration in order to follow the instructions you'll get by either using one of the [Certbot DNS plugins](https://eff-certbot.readthedocs.io/en/stable/using.html#dns-plugins) or the [manual generation of the certificate](https://eff-certbot.readthedocs.io/en/stable/using.html#manual) with the following command:
|
||||
|
||||
```
|
||||
```bash
|
||||
sudo certbot certonly --manual --agree-tos --expand -d solarsystemexample.org,*.solarsystemexample.org
|
||||
```
|
||||
|
||||
@@ -110,7 +110,7 @@ In order to reduce the chance your application sends emails which are erronously
|
||||
|
||||
If you'd like to use a different mail configuration for the new tenant, like one for a hypothetical `jupiter` subdomain, edit the `config/secrets.yml` file this way:
|
||||
|
||||
```
|
||||
```yaml
|
||||
production:
|
||||
# (...) Other secrets
|
||||
multitenancy: true
|
||||
@@ -138,7 +138,7 @@ The first option is changing your existing application using the Twitter/Google/
|
||||
|
||||
The other option is creating a new Twitter/Google/Facebook/Wordpress application and configuring it so it can be used from the new tenant. In this case, you'll have to add the configuration of this application to the `config/secrets.yml` file. For example, if you've added a tenant using the `saturn` subdomain, edit the file this way, filling in the keys and secrets of the services you're using:
|
||||
|
||||
```
|
||||
```yaml
|
||||
production:
|
||||
# (...) Other secrets
|
||||
multitenancy: true
|
||||
@@ -172,7 +172,7 @@ When the multitenancy feature is enabled, Consul Democracy adds a class to the `
|
||||
|
||||
This way, it'll be possible to overwrite the default styles for just this tenant by creating a new stylesheet in the `app/assets/stylesheets/custom/` folder:
|
||||
|
||||
```
|
||||
```css
|
||||
.tenant-uranus {
|
||||
// Styles that will only be applied to the Uranus tenant
|
||||
}
|
||||
@@ -180,7 +180,7 @@ This way, it'll be possible to overwrite the default styles for just this tenant
|
||||
|
||||
To easily change the default colors on a specific tenant, you can use CSS variables; their usage is documented in the [app/assets/stylesheets/custom/tenants.scss](https://github.com/consuldemocracy/consuldemocracy/blob/master/app/assets/stylesheets/custom/tenants.scss) file. For example, to make the brand colors green on the tenant with the `uranus` subdomain, write:
|
||||
|
||||
```
|
||||
```css
|
||||
.tenant-uranus {
|
||||
--brand: #350;
|
||||
--brand-secondary: #173a00;
|
||||
|
||||
Reference in New Issue
Block a user