decidim 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim might be problematic. Click here for more details.

Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile.lock +74 -63
  3. data/README.md +33 -37
  4. data/Rakefile +40 -33
  5. data/docs/getting_started.md +0 -14
  6. data/docs/managing_translations_i18n.md +24 -0
  7. data/docs/testing.md +1 -1
  8. data/docs/view_hooks.md +74 -0
  9. data/lib/decidim.rb +2 -0
  10. data/lib/decidim/version.rb +1 -1
  11. data/lib/generators/decidim/app_generator.rb +9 -15
  12. data/lib/generators/decidim/docker_generator.rb +12 -14
  13. data/lib/generators/decidim/install_generator.rb +1 -1
  14. data/lib/generators/decidim/templates/Dockerfile.erb +1 -1
  15. data/lib/generators/decidim/templates/docker-compose.yml.erb +2 -23
  16. metadata +57 -79
  17. data/.babelrc +0 -17
  18. data/.circleci/config.yml +0 -387
  19. data/.codeclimate.yml +0 -57
  20. data/.csslintrc +0 -2
  21. data/.decidim-version +0 -1
  22. data/.dockerignore +0 -5
  23. data/.editorconfig +0 -9
  24. data/.eslintignore +0 -15
  25. data/.eslintrc.json +0 -277
  26. data/.gitattributes +0 -3
  27. data/.github/ISSUE_TEMPLATE.md +0 -31
  28. data/.github/PULL_REQUEST_TEMPLATE.md +0 -16
  29. data/.gitignore +0 -15
  30. data/.inch.yml +0 -5
  31. data/.rubocop.yml +0 -1278
  32. data/.ruby-version +0 -1
  33. data/.simplecov +0 -12
  34. data/.yardopts +0 -8
  35. data/CHANGELOG.md +0 -1875
  36. data/CODE_OF_CONDUCT.md +0 -49
  37. data/Dockerfile.ci +0 -28
  38. data/codecov.yml +0 -104
  39. data/config/i18n-tasks.yml +0 -135
  40. data/crowdin.yaml +0 -3
  41. data/decidim.gemspec +0 -44
  42. data/docker-compose.yml +0 -27
  43. data/jsconfig.json +0 -3
  44. data/lib/generators/decidim/templates/Dockerfile.dev.erb +0 -21
  45. data/lib/generators/decidim/templates/decidim/dummy_authorization_handler.rb +0 -27
  46. data/logo.svg +0 -62
  47. data/package-lock.json +0 -11607
  48. data/package.json +0 -108
  49. data/spec/generator_spec.rb +0 -51
  50. data/spec/i18n_spec.rb +0 -37
  51. data/tsconfig.json +0 -21
  52. data/tslint.json +0 -11
  53. data/webpack.config.js +0 -82
  54. data/webpack.d.ts +0 -5
data/Rakefile CHANGED
@@ -4,11 +4,8 @@ require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
5
  require "generators/decidim/app_generator"
6
6
  require "generators/decidim/docker_generator"
7
- require "decidim/dev"
8
7
 
9
- load "decidim-dev/lib/tasks/test_app.rake"
10
-
11
- DECIDIM_GEMS = %w(core system admin api participatory_processes assemblies pages meetings proposals comments accountability budgets surveys dev).freeze
8
+ DECIDIM_GEMS = %w(core system admin api participatory_processes assemblies pages meetings proposals comments accountability budgets surveys verifications dev).freeze
12
9
 
13
10
  RSpec::Core::RakeTask.new(:spec)
14
11
 
@@ -35,25 +32,21 @@ def replace_file(name, regexp, replacement)
35
32
  File.open(name, "w") { |f| f.write(new_content) }
36
33
  end
37
34
 
35
+ def version
36
+ File.read("#{__dir__}/.decidim-version").strip
37
+ end
38
+
38
39
  desc "Update version in all gems to the one set in the `.decidim-version` file"
39
40
  task :update_versions do
40
- version = File.read("#{__dir__}/.decidim-version").strip
41
-
42
41
  replace_file(
43
42
  "#{__dir__}/package.json",
44
43
  /^ "version": "[^"]*"/,
45
44
  " \"version\": \"#{version}\""
46
45
  )
47
46
 
48
- replace_file(
49
- "#{__dir__}/package-lock.json",
50
- /^ "version": "[^"]*"/,
51
- " \"version\": \"#{version}\""
52
- )
53
-
54
- DECIDIM_GEMS.each do |gem_name|
47
+ DECIDIM_GEMS.each do |name|
55
48
  replace_file(
56
- "#{__dir__}/decidim-#{gem_name}/lib/decidim/#{gem_name}/version.rb",
49
+ "#{__dir__}/decidim-#{name}/lib/decidim/#{name}/version.rb",
57
50
  /def self\.version(\s*)"[^"]*"/,
58
51
  "def self.version\\1\"#{version}\""
59
52
  )
@@ -68,19 +61,27 @@ end
68
61
 
69
62
  desc "Installs all gems locally."
70
63
  task :install_all do
71
- sh "rake install", verbose: false
72
- DECIDIM_GEMS.each do |gem_name|
73
- Dir.chdir("#{__dir__}/decidim-#{gem_name}") do
74
- sh "rake install", verbose: false
64
+ system "rake install:local"
65
+ DECIDIM_GEMS.each do |name|
66
+ Dir.chdir("#{__dir__}/decidim-#{name}") do
67
+ system "rake install:local"
75
68
  end
76
69
  end
77
70
  end
78
71
 
72
+ desc "Uninstalls all gems locally."
73
+ task :uninstall_all do
74
+ system("gem uninstall decidim -v #{version} --executables --force")
75
+ DECIDIM_GEMS.each do |name|
76
+ system("gem uninstall decidim-#{name} -v #{version} --executables --force")
77
+ end
78
+ end
79
+
79
80
  desc "Pushes a new build for each gem."
80
81
  task release_all: [:update_versions, :check_locale_completeness, :webpack] do
81
82
  sh "rake release"
82
- DECIDIM_GEMS.each do |gem_name|
83
- Dir.chdir("#{__dir__}/decidim-#{gem_name}") do
83
+ DECIDIM_GEMS.each do |name|
84
+ Dir.chdir("#{__dir__}/decidim-#{name}") do
84
85
  sh "rake release"
85
86
  end
86
87
  end
@@ -91,6 +92,21 @@ task :check_locale_completeness do
91
92
  system({ "ENFORCED_LOCALES" => "en,ca,es" }, "rspec spec/i18n_spec.rb")
92
93
  end
93
94
 
95
+ desc "Generates a dummy app for testing"
96
+ task :test_app do
97
+ dummy_app_path = File.expand_path(File.join(Dir.pwd, "spec", "decidim_dummy_app"))
98
+
99
+ Dir.chdir(__dir__) do
100
+ sh "rm -fR #{dummy_app_path}", verbose: false
101
+ end
102
+
103
+ Bundler.with_clean_env do
104
+ Decidim::Generators::AppGenerator.start(
105
+ [dummy_app_path, "--path", "../..", "--recreate_db", "--demo"]
106
+ )
107
+ end
108
+ end
109
+
94
110
  desc "Generates a development app."
95
111
  task :development_app do
96
112
  Dir.chdir(__dir__) do
@@ -106,25 +122,16 @@ end
106
122
 
107
123
  desc "Generates a development app based on Docker."
108
124
  task :docker_development_app do
109
- Dir.chdir(__dir__) do
110
- sh "rm -fR docker_development_app"
111
- end
112
-
113
- path = __dir__ + "/docker_development_app"
125
+ docker_app_path = __dir__ + "/docker_development_app"
114
126
 
115
127
  Bundler.with_clean_env do
116
128
  Decidim::Generators::DockerGenerator.start(
117
- ["docker_development_app", "--path", path]
129
+ ["docker_development_app", "--docker_app_path", docker_app_path]
118
130
  )
119
131
  end
120
132
  end
121
133
 
122
134
  desc "Build webpack bundle files"
123
- task webpack: ["npm:install"] do
124
- sh "npm run build:prod"
125
- end
126
-
127
- desc "Install npm dependencies"
128
- task "npm:install" do
129
- sh "npm i"
135
+ task :webpack do
136
+ sh "yarn install && yarn build:prod"
130
137
  end
@@ -76,20 +76,6 @@ We also have other guides on how to configure some extra features:
76
76
  - [Analytics](https://github.com/decidim/decidim/blob/master/docs/analytics.md): How to enable analytics
77
77
  - [Geocoding](https://github.com/decidim/decidim/blob/master/docs/geocoding.md): How to enable geocoding for proposals and meetings
78
78
 
79
- ## Creating an Authorization handler
80
-
81
- Authorization handlers are used to validate users following some criteria. The most common use case is validating a user against a census, so that you can differentiate users living in your city from users living outside.
82
-
83
- The generator will have created an `ExampleAuthorizationHandler` so you can learn how to implement your own. You'll usually want to define some fields that you will use to authenticate against a census (for example, an ID and a Postal Code). In this class you'll need to write the logic to validate the user against the census. See the documentation for [the parent class](https://github.com/decidim/decidim/blob/master/decidim-core/app/services/decidim/authorization_handler.rb) and a [live example in Decidim Barcelona](https://github.com/decidim/decidim-barcelona/blob/master/app/services/census_authorization_handler.rb).
84
-
85
- You'll need to reference it from the Decidim initializer:
86
-
87
- ```ruby
88
- # config/initializers/decidim.rb
89
-
90
- config.authorization_handlers = ["<my authorization handler class>"]
91
- ```
92
-
93
79
  ## Deploy
94
80
 
95
81
  Once you've generated the Decidim app you might need to do some changes in order to deploy it. You can check [`codegram/decidim-deploy-heroku`](https://github.com/codegram/decidim-deploy-heroku) for an opinionated example of things to do before deploying to Heroku, for example.
@@ -0,0 +1,24 @@
1
+ # Managing translations (i18n)
2
+
3
+ ## The workflow
4
+
5
+ Decidim uses [Crowdin](https://crowdin.com/) to manage the translations.
6
+
7
+ - Whenever someone [adds a new translation key](https://github.com/decidim/decidim/pull/1814/files#diff-c78c80097da59920d55b3f462ca21afaR177) to _Decidim_, _Crowdin_ gets notified and the new content is available to be translated from [Crowdin's Decidim dashboard](https://crowdin.com/project/decidim).
8
+ - When a translator translates any key from Crowdin, it automatically creates a [PR in Github](https://github.com/decidim/decidim/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Adecidim-bot%20Crowdin), adding the keys in the corresponding _yaml_ files.
9
+ - 🌈
10
+
11
+ ## Adding a new language
12
+
13
+ - Setup the new language in [_Crowdin's Decidim project_](https://crowdin.com/project/decidim) (or open an issue on Github asking an admin to do that).
14
+ - Translate at least one key from every engine, so, your _yaml_ files are not empty. The easiest way to do this is to automatically translate and sync all the content. Later you'll be able to fix the content that wasn't properly translated.
15
+ - Add [Foundation Datepicker](https://github.com/najlepsiwebdesigner/foundation-datepicker/tree/master/js/locales)'s translations ([PR](https://github.com/decidim/decidim/pull/2039)).
16
+ - Add Select2 translations ([PR](https://github.com/decidim/decidim/pull/2214)).
17
+ - Add the new language to `available_locales` ([PR](https://github.com/decidim/decidim/pull/1991)).
18
+ - Announce the new language in the Readme ([PR](https://github.com/decidim/decidim/pull/2125)).
19
+
20
+ ## Test the new language
21
+
22
+ - Generate the development app and `cd` into it.
23
+ - Change the `config/initializer/decidim.rb` file and add your locale to `Decidim.available_locales`.
24
+ - `rake db:drop db:setup` to drop, create, load schema and seed the DB.
data/docs/testing.md CHANGED
@@ -5,7 +5,7 @@
5
5
  You need to create a dummy application to run your tests. Run the following command in the decidim root's folder:
6
6
 
7
7
  ```bash
8
- bundle exec rake decidim:generate_test_app
8
+ bundle exec rake test_app
9
9
  ```
10
10
 
11
11
  ## Running the test suite
@@ -0,0 +1,74 @@
1
+ # View hooks
2
+
3
+ ## General description
4
+
5
+ All engines can define their own view hooks, and register to other engines' ones. This allows engines to add content to views rendered by other engines. This will be clearer with an example.
6
+
7
+ Take the homepage, for example. It is rendered by the `decidim-core`. We want to show there a list of highlighted participatory spaces (processes and assemblies). We cannot be sure the final app has these engines, so we need to check they exist:
8
+
9
+ ```
10
+ <% if defined? Decidim::Processes %>
11
+ <% # iterate through the most important ones %>
12
+ <% end %>
13
+ <% if defined? Decidim::Assemblies %>
14
+ <% # iterate through the most important ones %>
15
+ <% end %>
16
+ ```
17
+
18
+ This raises two important issues:
19
+
20
+ 1. We are linking `decidim-core` with `decidim-assemblies` and `decidim-participatory_processes`. This is not perfect.
21
+ 1. The final app cannot extend this view to add more content in a simple way. The developers could overwrite the view, but this raises maintainability problems, as upgrades will be harder.
22
+
23
+ ## Rendering view hooks
24
+
25
+ Instead of the previous example, we created the concept of "view hooks". Think of them as a registry of views which can be defined by a given engine and extended by others. To follow the previous example, we would register a view hook in `decidim-core`:
26
+
27
+ ```
28
+ <%= Decidim.view_hooks.render(:highlighted_elements, self) %>
29
+ ```
30
+
31
+ We're rendering the view hooks registered as `:highlighted_elements`. The `self` parameter is the view context, we will analyze it later.
32
+
33
+ ## Registering view hooks
34
+
35
+ Other engines would register blocks of Ruby and Rails code from their initializers. For example, in `decidim-participatory_processes`:
36
+
37
+ ```ruby
38
+ # decidim-participatory_processes/lib/decidim/participatory_processes/engine.rb
39
+ initializer "decidim_participatory_processes.view_hooks" do
40
+ Decidim.view_hooks.register(:highlighted_elements) do |view_context|
41
+ view_context.render(partial: "my/partial")
42
+ end
43
+ end
44
+ ```
45
+
46
+ In order to register a view hook we need the hook name and a block of Ruby code. We're registering a view hook as `:highlighted-elements`, following our example. We're passing the view context to the block so that we can use our views helper methods there, and we're rendering a partial. We could write `ActiveRecord` queries and pass the results to the partial as `locals` if we wanted a more complex view:
47
+
48
+ ```ruby
49
+ # decidim-participatory_processes/lib/decidim/participatory_processes/engine.rb
50
+ initializer "decidim_participatory_processes.view_hooks" do
51
+ Decidim.view_hooks.register(:highlighted_elements) do |view_context|
52
+ highlighted_processes =
53
+ OrganizationPublishedParticipatoryProcesses.new(view_context.current_organization) | HighlightedParticipatoryProcesses.new
54
+
55
+ view_context.render(partial: "decidim/participatory_processes/my/partial", locals: { highlighted_processes: highlighted_processes })
56
+ end
57
+ end
58
+ ```
59
+
60
+ When registering a view hook, we can set a priority for each one. By default, all view hooks are registered with low priority, but we can change it:
61
+
62
+ ```ruby
63
+ Decidim.view_hooks.register(:highlighted_elements, priority: Decidim::ViewHooks::HIGH_PRIORITY) do |view_context|
64
+ # ...
65
+ end
66
+ ```
67
+
68
+ ## Enabling view hooks in your engine
69
+
70
+ Ideally, each engine should hold their own instance of `Decidim::ViewHooks`. This means that if `decidim-participatory_processes` wants to allow part of its views to be extended by other engines, it should define `Decidim::ParticipatoryProcesses.view_hooks`, and other engines should register to this instance.
71
+
72
+ ## The engine I want to extend does not support view hooks, what can I do?
73
+
74
+ First of all, send a PR to the engine to add the view hook you need. Expose your needs, so the developers can assess a view hook is the best solution. Sometimes a view hook can be replaced with another abstraction, or another UI. Meanwhile, you can use [`deface`](https://github.com/spree/deface) to extend a view file without replacing it. Be careful, since `deface` is *very* powerful and can be a double-edged sword. We considered adding `deface` to `decidim`, but found that it opened to a code that would be much harder to maintain.
data/lib/decidim.rb CHANGED
@@ -6,6 +6,8 @@ require "decidim/admin"
6
6
  require "decidim/api"
7
7
  require "decidim/version"
8
8
 
9
+ require "decidim/verifications"
10
+
9
11
  require "decidim/participatory_processes"
10
12
 
11
13
  begin
@@ -3,6 +3,6 @@
3
3
  # This holds the decidim version and the faker version it uses.
4
4
  module Decidim
5
5
  def self.version
6
- "0.7.4"
6
+ "0.8.0"
7
7
  end
8
8
  end
@@ -79,9 +79,8 @@ module Decidim
79
79
  def gemfile
80
80
  return if options[:skip_gemfile]
81
81
 
82
- path = File.expand_path(File.join("..", "..", "..", "Gemfile"), __dir__)
83
-
84
- template path, "Gemfile", force: true
82
+ template path_to_root("Gemfile"), "Gemfile", force: true
83
+ template path_to_root("Gemfile.lock"), "Gemfile.lock", force: true
85
84
 
86
85
  gem_modifier = if options[:path]
87
86
  "path: \"#{options[:path]}\""
@@ -94,7 +93,7 @@ module Decidim
94
93
  end
95
94
 
96
95
  gsub_file "Gemfile", /gem "decidim([^"]*)".*/, "gem \"decidim\\1\", #{gem_modifier}"
97
- run "bundle install"
96
+ run "BUNDLE_GEMFILE=Gemfile bundle install"
98
97
  end
99
98
 
100
99
  def add_ignore_uploads
@@ -111,17 +110,8 @@ module Decidim
111
110
  def authorization_handler
112
111
  template "initializer.rb", "config/initializers/decidim.rb"
113
112
 
114
- auth_handler = if options[:demo]
115
- "decidim/dummy_authorization_handler"
116
- else
117
- "example_authorization_handler"
118
- end
119
-
120
- template "#{auth_handler}.rb", "app/services/#{auth_handler}.rb"
121
-
122
- gsub_file "config/initializers/decidim.rb",
123
- /config\.mailer_sender = "change-me@domain\.org"/ do |match|
124
- match << "\n config.authorization_handlers = [\"#{auth_handler.classify}\"]"
113
+ if options[:demo]
114
+ template "example_authorization_handler.rb", "app/services/example_authorization_handler.rb"
125
115
  end
126
116
  end
127
117
 
@@ -137,6 +127,10 @@ module Decidim
137
127
 
138
128
  private
139
129
 
130
+ def path_to_root(file)
131
+ File.expand_path(File.join("..", "..", "..", file), __dir__)
132
+ end
133
+
140
134
  def app_const_base
141
135
  options["app_const_base"] || super
142
136
  end
@@ -9,10 +9,8 @@ module Decidim
9
9
  class DockerGenerator < Rails::Generators::Base
10
10
  desc "Generate a docker app for development purposes"
11
11
 
12
- class_option :path, type: :string,
13
- desc: "The path to generate the docker app"
14
-
15
- source_root File.expand_path("templates", __dir__)
12
+ class_option :docker_app_path, type: :string,
13
+ desc: "The path to generate the docker app"
16
14
 
17
15
  def source_paths
18
16
  [
@@ -25,19 +23,19 @@ module Decidim
25
23
  end
26
24
 
27
25
  def create_rails_app
28
- Decidim::Generators::AppGenerator.start([path, "--demo"])
26
+ Decidim::Generators::AppGenerator.start(
27
+ [docker_app_path, "--path", "..", "--demo"]
28
+ )
29
29
  end
30
30
 
31
31
  def build_docker
32
- remove_file "#{path}/Dockerfile"
33
- template "Dockerfile.dev.erb", "#{path}/Dockerfile"
34
- inside(path) do
32
+ inside(docker_app_path) do
35
33
  gsub_file "Gemfile",
36
- /gem "decidim(.*)"/,
37
- 'gem "decidim", path: "/decidim"'
34
+ /gem "decidim([^"]*)".*/,
35
+ 'gem "decidim\1", path: "/decidim"'
38
36
 
39
37
  run "docker-compose build"
40
- run "docker-compose run --rm app rails db:drop db:create db:migrate db:setup"
38
+ run "docker-compose run --rm app rails db:drop db:create db:migrate db:seed"
41
39
  end
42
40
  end
43
41
 
@@ -50,11 +48,11 @@ module Decidim
50
48
  private
51
49
 
52
50
  def remove_directory_if_exists
53
- remove_dir(path) if File.directory?(path)
51
+ remove_dir(docker_app_path) if File.directory?(docker_app_path)
54
52
  end
55
53
 
56
- def path
57
- options[:path]
54
+ def docker_app_path
55
+ options[:docker_app_path]
58
56
  end
59
57
  end
60
58
  end
@@ -49,7 +49,6 @@ module Decidim
49
49
  def append_assets
50
50
  append_file "app/assets/javascripts/application.js", "//= require decidim"
51
51
  gsub_file "app/assets/javascripts/application.js", %r{//= require turbolinks\n}, ""
52
- gsub_file "app/assets/javascripts/application.js", %r{//= require rails-ujs\n}, "//= require jquery\n//= require jquery_ujs\n"
53
52
  inject_into_file "app/assets/stylesheets/application.css",
54
53
  before: "*= require_tree ." do
55
54
  "*= require decidim\n "
@@ -106,6 +105,7 @@ module Decidim
106
105
  <<~RUBY.gsub(/^ *\|/, "")
107
106
  |
108
107
  | config.action_mailer.delivery_method = :letter_opener_web
108
+ | config.action_mailer.default_url_options = { port: 3000 }
109
109
  RUBY
110
110
  end
111
111
  end
@@ -1 +1 @@
1
- FROM decidim/decidim
1
+ FROM decidim/decidim:<%= Decidim.version %>
@@ -1,7 +1,7 @@
1
- version: '2'
1
+ version: '3'
2
2
  services:
3
3
  app:
4
- image: decidim/decidim:0.7.2-dev
4
+ image: decidim/decidim:<%= Decidim.version %>
5
5
  volumes:
6
6
  - .:/app
7
7
  - bundle:/usr/local/bundle
@@ -11,37 +11,16 @@ services:
11
11
  - DATABASE_HOST=pg
12
12
  - DATABASE_USERNAME=postgres
13
13
  - RAILS_ENV=development
14
- - REDIS_URL=redis://redis:6379
15
14
  ports:
16
15
  - 3000:3000
17
16
  links:
18
17
  - pg
19
- - redis
20
18
  command: bundle exec puma
21
- worker:
22
- image: decidim/decidim:latest-dev
23
- volumes:
24
- - .:/app
25
- - bundle:/usr/local/bundle
26
- environment:
27
- - DATABASE_HOST=pg
28
- - DATABASE_USERNAME=postgres
29
- - RAILS_ENV=development
30
- - REDIS_URL=redis://redis:6379
31
- links:
32
- - pg
33
- - redis
34
- command: bundle exec sidekiq
35
19
  pg:
36
20
  image: postgres
37
21
  volumes:
38
22
  - pg-data:/var/lib/postgresql/data
39
- redis:
40
- image: redis
41
- volumes:
42
- - redis-data:/data
43
23
  volumes:
44
24
  node_modules: {}
45
25
  bundle: {}
46
26
  pg-data: {}
47
- redis-data: {}