decidim-core 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim.js.es6 +2 -4
  3. data/app/assets/javascripts/decidim/append_elements.js.es6 +1 -1
  4. data/app/assets/javascripts/decidim/editor.js.es6 +33 -35
  5. data/app/assets/javascripts/decidim/filters.js.es6 +9 -15
  6. data/app/assets/javascripts/decidim/form_filter.component.js.es6 +5 -5
  7. data/app/assets/javascripts/decidim/form_filter.component.test.js +1 -1
  8. data/app/assets/javascripts/decidim/foundation.js.es6 +17 -0
  9. data/app/assets/javascripts/decidim/user_registrations.js.es6 +2 -3
  10. data/app/assets/stylesheets/decidim/_decidim.scss +9 -0
  11. data/app/assets/stylesheets/decidim/_variables.scss +5 -11
  12. data/app/assets/stylesheets/decidim/application.scss.erb +6 -0
  13. data/app/assets/stylesheets/decidim/extras/_leaflet.scss +13 -0
  14. data/app/assets/stylesheets/decidim/modules/_buttons.scss +8 -2
  15. data/app/assets/stylesheets/decidim/modules/_cards.scss +0 -2
  16. data/app/assets/stylesheets/decidim/modules/_comments.scss +33 -8
  17. data/app/assets/stylesheets/decidim/modules/{_defintion-data.scss → _definition-data.scss} +0 -0
  18. data/app/assets/stylesheets/decidim/modules/_filter-tags.scss +24 -0
  19. data/app/assets/stylesheets/decidim/modules/_layout.scss +1 -9
  20. data/app/assets/stylesheets/decidim/modules/_list-docs.scss +1 -1
  21. data/app/assets/stylesheets/decidim/modules/_margins.scss +15 -0
  22. data/app/assets/stylesheets/decidim/modules/_modules.scss +56 -0
  23. data/app/assets/stylesheets/decidim/modules/_opinion-toggle.scss +25 -5
  24. data/app/assets/stylesheets/decidim/modules/_order-by.scss +1 -0
  25. data/app/assets/stylesheets/decidim/modules/_process-header.scss +2 -1
  26. data/app/assets/stylesheets/decidim/modules/_process-phase.scss +0 -4
  27. data/app/assets/stylesheets/decidim/modules/_status-labels.scss +7 -1
  28. data/app/assets/stylesheets/decidim/modules/_typography.scss +17 -0
  29. data/app/assets/stylesheets/decidim/utils/_fontface.scss +3 -3
  30. data/app/assets/stylesheets/decidim/utils/_settings.scss +10 -7
  31. data/app/commands/decidim/invite_user.rb +2 -2
  32. data/app/commands/decidim/update_account.rb +48 -0
  33. data/app/controllers/concerns/decidim/form_factory.rb +1 -1
  34. data/app/controllers/concerns/decidim/needs_authorization.rb +12 -1
  35. data/app/controllers/concerns/decidim/user_profile.rb +30 -0
  36. data/app/controllers/decidim/account_controller.rb +28 -10
  37. data/app/controllers/decidim/authorizations_controller.rb +21 -8
  38. data/app/controllers/decidim/devise/invitations_controller.rb +2 -0
  39. data/app/controllers/decidim/devise/sessions_controller.rb +1 -1
  40. data/app/controllers/decidim/own_user_groups_controller.rb +14 -0
  41. data/app/controllers/decidim/participatory_processes_controller.rb +1 -1
  42. data/app/forms/decidim/account_form.rb +41 -0
  43. data/app/helpers/decidim/aria_selected_link_to_helper.rb +26 -0
  44. data/app/helpers/decidim/attachments_helper.rb +15 -0
  45. data/app/helpers/decidim/filters_helper.rb +2 -3
  46. data/app/helpers/decidim/layout_helper.rb +29 -6
  47. data/app/helpers/decidim/resource_helper.rb +64 -0
  48. data/app/helpers/decidim/user_profile_helper.rb +23 -0
  49. data/app/mailers/decidim/decidim_devise_mailer.rb +1 -0
  50. data/app/models/decidim/abilities/everyone.rb +5 -1
  51. data/app/models/decidim/ability.rb +3 -4
  52. data/app/models/decidim/{participatory_process_attachment.rb → attachment.rb} +5 -5
  53. data/app/models/decidim/feature.rb +2 -0
  54. data/app/models/decidim/organization.rb +1 -0
  55. data/app/models/decidim/participatory_process.rb +2 -5
  56. data/app/models/decidim/resource_link.rb +28 -0
  57. data/app/models/decidim/user.rb +6 -0
  58. data/app/models/decidim/user_group.rb +10 -1
  59. data/app/services/decidim/resource_search.rb +1 -4
  60. data/app/types/decidim/session_type.rb +16 -0
  61. data/app/types/decidim/user_group_type.rb +20 -0
  62. data/app/types/decidim/user_type.rb +5 -1
  63. data/app/uploaders/decidim/attachment_uploader.rb +4 -1
  64. data/app/uploaders/decidim/avatar_uploader.rb +8 -0
  65. data/app/uploaders/decidim/banner_image_uploader.rb +1 -0
  66. data/app/uploaders/decidim/hero_image_uploader.rb +1 -0
  67. data/app/uploaders/decidim/homepage_image_uploader.rb +5 -1
  68. data/app/uploaders/decidim/image_uploader.rb +1 -1
  69. data/app/uploaders/decidim/organization_favicon_uploader.rb +17 -0
  70. data/app/uploaders/decidim/organization_logo_uploader.rb +2 -2
  71. data/app/validators/feature_validator.rb +23 -0
  72. data/app/views/decidim/account/_password_fields.html.erb +2 -0
  73. data/app/views/decidim/account/_user_groups.html.erb +0 -0
  74. data/app/views/decidim/account/show.html.erb +24 -29
  75. data/app/views/decidim/application/_attachments.html.erb +8 -0
  76. data/app/views/decidim/{participatory_processes → application}/_documents.html.erb +0 -0
  77. data/app/views/decidim/{participatory_processes → application}/_photos.html.erb +0 -0
  78. data/app/views/decidim/authorizations/first_login.html.erb +22 -0
  79. data/app/views/decidim/authorizations/index.html.erb +46 -19
  80. data/app/views/decidim/devise/omniauth_registrations/new.html.erb +1 -1
  81. data/app/views/decidim/devise/registrations/new.html.erb +1 -1
  82. data/app/views/decidim/own_user_groups/index.html.erb +24 -0
  83. data/app/views/decidim/participatory_process_steps/_participatory_process_step.html.erb +1 -1
  84. data/app/views/decidim/participatory_process_steps/index.html.erb +3 -1
  85. data/app/views/decidim/participatory_processes/_participatory_process.html.erb +2 -2
  86. data/app/views/decidim/participatory_processes/_promoted_process.html.erb +1 -1
  87. data/app/views/decidim/participatory_processes/index.html.erb +2 -0
  88. data/app/views/decidim/participatory_processes/show.html.erb +37 -8
  89. data/app/views/decidim/shared/_comments.html.erb +0 -0
  90. data/app/views/layouts/decidim/_application.html.erb +5 -3
  91. data/app/views/layouts/decidim/_header.html.erb +4 -4
  92. data/app/views/layouts/decidim/_logo.html.erb +29 -17
  93. data/app/views/layouts/decidim/_process_header.html.erb +15 -3
  94. data/app/views/layouts/decidim/_process_header_steps.html.erb +1 -1
  95. data/app/views/layouts/decidim/_user_menu.html.erb +3 -0
  96. data/app/views/layouts/decidim/mailer.html.erb +1 -1
  97. data/app/views/layouts/decidim/user_profile.html.erb +35 -0
  98. data/app/views/pages/home.html.erb +5 -139
  99. data/app/views/pages/home/_extended.html.erb +48 -0
  100. data/app/views/pages/home/_hero.html.erb +20 -0
  101. data/app/views/pages/home/_highlighted_processes.html.erb +37 -0
  102. data/app/views/pages/home/_statistics.html.erb +22 -0
  103. data/app/views/pages/home/_sub_hero.html.erb +11 -0
  104. data/config/i18n-tasks.yml +1 -0
  105. data/config/initializers/foundation_rails_helper.rb +2 -0
  106. data/config/locales/ca.yml +69 -33
  107. data/config/locales/en.yml +86 -29
  108. data/config/locales/es.yml +68 -32
  109. data/config/routes.rb +8 -3
  110. data/db/migrate/20161116115156_create_attachments.rb +0 -2
  111. data/db/migrate/20170113150627_create_resource_links.rb +10 -0
  112. data/db/migrate/20170123134023_make_attachments_polymorphic.rb +18 -0
  113. data/db/migrate/20170123140857_add_avatar_to_user_groups.rb +5 -0
  114. data/db/migrate/20170125135937_rename_attachable_to_attached_to.rb +11 -0
  115. data/db/migrate/20170125152026_add_weight_to_features.rb +5 -0
  116. data/db/migrate/20170126151123_add_extra_info_to_processes.rb +8 -0
  117. data/db/migrate/20170128140553_add_timestamps_to_identities.rb +5 -0
  118. data/db/migrate/20170130132833_add_favicon_to_decidim_organizations.rb +5 -0
  119. data/db/seeds.rb +38 -6
  120. data/lib/decidim/authorable.rb +32 -0
  121. data/lib/decidim/core.rb +37 -0
  122. data/lib/decidim/core/engine.rb +2 -3
  123. data/lib/decidim/core/test.rb +6 -0
  124. data/lib/decidim/core/test/factories.rb +24 -3
  125. data/lib/decidim/core/test/shared_examples/authorable.rb +31 -0
  126. data/lib/decidim/core/test/shared_examples/has_attachments.rb +29 -0
  127. data/lib/decidim/core/test/shared_examples/has_category.rb +10 -0
  128. data/lib/decidim/core/test/shared_examples/has_feature.rb +20 -0
  129. data/lib/decidim/core/test/shared_examples/has_scope.rb +10 -0
  130. data/lib/decidim/core/version.rb +1 -1
  131. data/lib/decidim/feature_manifest.rb +31 -1
  132. data/lib/decidim/features/base_controller.rb +10 -0
  133. data/lib/decidim/features/settings_manifest.rb +1 -0
  134. data/lib/decidim/has_attachment.rb +32 -0
  135. data/lib/decidim/has_attachments.rb +32 -0
  136. data/lib/decidim/has_category.rb +21 -0
  137. data/lib/decidim/has_feature.rb +20 -0
  138. data/lib/decidim/has_scope.rb +21 -0
  139. data/lib/decidim/query_extensions.rb +2 -2
  140. data/lib/decidim/resource_manifest.rb +80 -0
  141. data/lib/decidim/resourceable.rb +85 -0
  142. metadata +67 -40
  143. data/app/assets/javascripts/decidim/inline_svg.js.es6 +0 -12
  144. data/app/assets/stylesheets/decidim/application.sass +0 -12
  145. data/app/assets/stylesheets/decidim/extras/_turbolinks.scss +0 -3
  146. data/app/assets/stylesheets/decidim/modules/_popularity.scss +0 -74
  147. data/app/assets/stylesheets/decidim/utils/_variables.scss +0 -22
  148. data/app/views/decidim/account/_authorizations.html.erb +0 -52
  149. data/vendor/assets/javascripts/owl.carousel.min.js +0 -47
  150. data/vendor/assets/javascripts/svg-injector.js +0 -464
@@ -10,7 +10,6 @@ require "devise-i18n"
10
10
  require "devise_invitable"
11
11
  require "jquery-rails"
12
12
  require "sassc-rails"
13
- require "turbolinks"
14
13
  require "foundation-rails"
15
14
  require "foundation_rails_helper"
16
15
  require "active_link_to"
@@ -42,7 +41,7 @@ module Decidim
42
41
 
43
42
  initializer "decidim.action_controller" do |_app|
44
43
  ActiveSupport.on_load :action_controller do
45
- helper Decidim::LayoutHelper
44
+ helper Decidim::LayoutHelper if respond_to?(:helper)
46
45
  end
47
46
  end
48
47
 
@@ -74,7 +73,7 @@ module Decidim
74
73
 
75
74
  initializer "decidim_admin.inject_abilities_to_user" do |_app|
76
75
  Decidim.configure do |config|
77
- config.abilities << Abilities::Everyone
76
+ config.abilities << "Decidim::Abilities::Everyone"
78
77
  end
79
78
  end
80
79
 
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ require "decidim/core/test/shared_examples/authorable"
3
+ require "decidim/core/test/shared_examples/has_attachments"
4
+ require "decidim/core/test/shared_examples/has_feature"
5
+ require "decidim/core/test/shared_examples/has_scope"
6
+ require "decidim/core/test/shared_examples/has_category"
@@ -36,6 +36,7 @@ FactoryGirl.define do
36
36
  description { Decidim::Faker::Localized.wrapped("<p>", "</p>") { Decidim::Faker::Localized.sentence(2) } }
37
37
  welcome_text { Decidim::Faker::Localized.wrapped("<p>", "</p>") { Decidim::Faker::Localized.sentence(2) } }
38
38
  homepage_image { test_file("city.jpeg", "image/jpeg") }
39
+ favicon { test_file("icon.png", "image/png") }
39
40
  default_locale I18n.default_locale
40
41
  available_locales Decidim.available_locales
41
42
  end
@@ -50,6 +51,10 @@ FactoryGirl.define do
50
51
  banner_image { test_file("city2.jpeg", "image/jpeg") }
51
52
  published_at { Time.current }
52
53
  organization
54
+ scope { Decidim::Faker::Localized.word }
55
+ domain { Decidim::Faker::Localized.word }
56
+ developer_group { Faker::Company.name }
57
+ end_date 2.month.from_now.at_midnight
53
58
 
54
59
  trait :promoted do
55
60
  promoted true
@@ -94,7 +99,7 @@ FactoryGirl.define do
94
99
  organization
95
100
  locale { organization.default_locale }
96
101
  tos_agreement "1"
97
- avatar { test_file("avatar.svg", "image/svg+xml") }
102
+ avatar { test_file("avatar.jpg", "image/jpeg") }
98
103
 
99
104
  trait :confirmed do
100
105
  confirmed_at { Time.current }
@@ -117,6 +122,11 @@ FactoryGirl.define do
117
122
  name { Faker::Educator.course }
118
123
  document_number { Faker::Number.number(8) + "X" }
119
124
  phone { Faker::PhoneNumber.phone_number }
125
+ avatar { test_file("avatar.jpg", "image/jpeg") }
126
+
127
+ trait :verified do
128
+ verified_at { Time.current }
129
+ end
120
130
  end
121
131
 
122
132
  factory :user_group_membership, class: Decidim::UserGroupMembership do
@@ -147,11 +157,11 @@ FactoryGirl.define do
147
157
  end
148
158
  end
149
159
 
150
- factory :participatory_process_attachment, class: Decidim::ParticipatoryProcessAttachment do
160
+ factory :attachment, class: Decidim::Attachment do
151
161
  title { Decidim::Faker::Localized.sentence(3) }
152
162
  description { Decidim::Faker::Localized.wrapped("<p>", "</p>") { Decidim::Faker::Localized.sentence(4) } }
153
163
  file { test_file("city.jpeg", "image/jpeg") }
154
- participatory_process
164
+ attached_to { build(:participatory_process) }
155
165
 
156
166
  trait :with_image do
157
167
  file { test_file("city.jpeg", "image/jpeg") }
@@ -180,6 +190,17 @@ FactoryGirl.define do
180
190
  name { generate(:name) }
181
191
  organization
182
192
  end
193
+
194
+ factory :dummy_resource, class: Decidim::DummyResource do
195
+ title { generate(:name) }
196
+ feature
197
+ end
198
+
199
+ factory :resource_link, class: Decidim::ResourceLink do
200
+ name { generate(:slug) }
201
+ to { build(:dummy_resource) }
202
+ from { build(:dummy_resource, feature: to.feature) }
203
+ end
183
204
  end
184
205
 
185
206
  def test_file(filename, content_type)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ shared_examples_for "authorable" do
5
+ describe "validations" do
6
+ context "when the user group is not verified" do
7
+ it "is not valid" do
8
+ user_group = create(:user_group)
9
+ create(:user_group_membership, user: subject.author, user_group: user_group)
10
+ subject.user_group = user_group
11
+ expect(subject).not_to be_valid
12
+ end
13
+ end
14
+
15
+ context "when the author doesn't have a membership of the user group" do
16
+ it "is not valid" do
17
+ user_group = create(:user_group, :verified)
18
+ subject.user_group = user_group
19
+ expect(subject).not_to be_valid
20
+ end
21
+ end
22
+
23
+ context "when the author is from another organization" do
24
+ before do
25
+ subject.author = create(:user)
26
+ end
27
+
28
+ it { is_expected.to be_invalid }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ shared_examples_for "has attachments" do
5
+ context "when it has attachments" do
6
+ let!(:document) do
7
+ Decidim::AttachmentUploader.enable_processing = true
8
+ create(:attachment, :with_pdf, attached_to: attached_to)
9
+ end
10
+ let!(:image) do
11
+ Decidim::AttachmentUploader.enable_processing = true
12
+ create(:attachment, attached_to: attached_to)
13
+ end
14
+
15
+ before do
16
+ visit current_path
17
+ end
18
+
19
+ it "shows them" do
20
+ within "div.wrapper .documents" do
21
+ expect(page).to have_content(/#{translated(document.title, locale: :en)}/i)
22
+ end
23
+
24
+ within "div.wrapper .images" do
25
+ expect(page).to have_css("img.thumbnail")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ shared_examples_for "has category" do
3
+ context "when the category is from another organization" do
4
+ before do
5
+ subject.category = create(:category)
6
+ end
7
+
8
+ it { is_expected.not_to be_valid }
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ shared_examples_for "has feature" do
5
+ context "without a feature" do
6
+ before do
7
+ subject.feature = nil
8
+ end
9
+
10
+ it { is_expected.not_to be_valid }
11
+ end
12
+
13
+ context "without a valid feature" do
14
+ before do
15
+ subject.feature = build(:feature, manifest_name: "foo-bar")
16
+ end
17
+
18
+ it { is_expected.not_to be_valid }
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ shared_examples_for "has scope" do
3
+ context "when the scope is from another organization" do
4
+ before do
5
+ subject.scope = create(:scope)
6
+ end
7
+
8
+ it { is_expected.not_to be_valid }
9
+ end
10
+ end
@@ -2,7 +2,7 @@
2
2
  # This holds Decidim's version and the Rails version on which it depends.
3
3
  module Decidim
4
4
  def self.version
5
- "0.0.2"
5
+ "0.0.3"
6
6
  end
7
7
 
8
8
  def self.rails_version
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  require_dependency "decidim/features/settings_manifest"
2
3
 
3
- # frozen_string_literal: true
4
4
  module Decidim
5
5
  # This class handles all the logic associated to configuring a feature
6
6
  # associated to a participatory process.
@@ -17,6 +17,11 @@ module Decidim
17
17
  attribute :name, Symbol
18
18
  attribute :hooks, Hash[Symbol => Array[Proc]], default: {}
19
19
 
20
+ # A path with the `scss` stylesheet this engine provides. It is used to
21
+ # mix this engine's stylesheets with the main app's stylesheets so it can
22
+ # use the scss variables and mixins provided by Decidim::Core.
23
+ attribute :stylesheet, String, default: nil
24
+
20
25
  # A String with the feature's icon. The icon must be stored in the
21
26
  # engine's assets path.
22
27
  attribute :icon, String
@@ -94,5 +99,30 @@ module Decidim
94
99
  yield(settings) if block
95
100
  settings
96
101
  end
102
+
103
+ # Public: Registers a resource inside a feature manifest. Exposes a DSL
104
+ # defined by `Decidim::ResourceManifest`.
105
+ #
106
+ # Resource manifests are a way to expose a resource from one engine to
107
+ # the whole system. This was resoruces can be linked between them.
108
+ #
109
+ # block - A Block that will be called to set the Resource attributes.
110
+ #
111
+ # Returns nothing.
112
+ def register_resource
113
+ manifest = ResourceManifest.new
114
+ manifest.feature_manifest = self
115
+ yield(manifest)
116
+ manifest.validate!
117
+ resource_manifests << manifest
118
+ end
119
+
120
+ # Public: Finds all the registered resource manifest's via the
121
+ # `register_resource` method.
122
+ #
123
+ # Returns an Array[ResourceManifest].
124
+ def resource_manifests
125
+ @resource_manifests ||= []
126
+ end
97
127
  end
98
128
  end
@@ -11,6 +11,7 @@ module Decidim
11
11
  include FeatureSettings
12
12
  helper Decidim::TranslationsHelper
13
13
  helper Decidim::ParticipatoryProcessHelper
14
+ helper Decidim::ResourceHelper
14
15
 
15
16
  helper_method :current_feature,
16
17
  :current_manifest
@@ -32,6 +33,15 @@ module Decidim
32
33
  def current_participatory_process
33
34
  request.env["decidim.current_participatory_process"]
34
35
  end
36
+
37
+ def ability_context
38
+ super.merge(
39
+ current_manifest: current_manifest,
40
+ current_participatory_process: current_participatory_process,
41
+ current_settings: current_settings,
42
+ feature_settings: feature_settings
43
+ )
44
+ end
35
45
  end
36
46
  end
37
47
  end
@@ -73,6 +73,7 @@ module Decidim
73
73
 
74
74
  TYPES = {
75
75
  boolean: { klass: Boolean, default: false },
76
+ integer: { klass: Integer, default: 0 },
76
77
  string: { klass: String, default: nil },
77
78
  text: { klass: String, default: nil }
78
79
  }.freeze
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ require "active_support/concern"
3
+
4
+ module Decidim
5
+ # A concern with the features needed when you want a model to be able to create
6
+ # links from it to another resource.
7
+ module HasAttachments
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ has_many :attachments,
12
+ class_name: Decidim::Attachment,
13
+ dependent: :destroy,
14
+ inverse_of: :attached_to,
15
+ as: :attached_to
16
+
17
+ # All the attachments that are photos for this porcess.
18
+ #
19
+ # Returns an Array<Attachment>
20
+ def photos
21
+ @photos ||= attachments.select(&:photo?)
22
+ end
23
+
24
+ # All the attachments that are documents for this porcess.
25
+ #
26
+ # Returns an Array<Attachment>
27
+ def documents
28
+ @documents ||= attachments.select(&:document?)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ require "active_support/concern"
3
+
4
+ module Decidim
5
+ # A concern with the features needed when you want a model to be able to create
6
+ # links from it to another resource.
7
+ module HasAttachments
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ has_many :attachments,
12
+ class_name: Decidim::Attachment,
13
+ dependent: :destroy,
14
+ inverse_of: :attached_to,
15
+ as: :attached_to
16
+
17
+ # All the attachments that are photos for this porcess.
18
+ #
19
+ # Returns an Array<Attachment>
20
+ def photos
21
+ @photos ||= attachments.select(&:photo?)
22
+ end
23
+
24
+ # All the attachments that are documents for this porcess.
25
+ #
26
+ # Returns an Array<Attachment>
27
+ def documents
28
+ @documents ||= attachments.select(&:document?)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require "active_support/concern"
3
+
4
+ module Decidim
5
+ # A concern with the features needed when you want a model to be have a category.
6
+ module HasCategory
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ belongs_to :category, foreign_key: "decidim_category_id", class_name: Decidim::Category
11
+ validate :category_belongs_to_organization
12
+
13
+ private
14
+
15
+ def category_belongs_to_organization
16
+ return unless category
17
+ errors.add(:category, :invalid) unless feature.categories.where(id: category.id).exists?
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require "active_support/concern"
3
+
4
+ module Decidim
5
+ # A concern with the features needed when you want a model to have a feature.
6
+ module HasFeature
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ belongs_to :feature, foreign_key: "decidim_feature_id", class_name: Decidim::Feature
11
+ has_one :organization, through: :feature
12
+ end
13
+
14
+ class_methods do
15
+ def feature_manifest_name(manifest_name)
16
+ validates :feature, feature: { manifest: manifest_name || name.demodulize.pluralize.downcase }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require "active_support/concern"
3
+
4
+ module Decidim
5
+ # A concern with the features needed when you want a model to be have a scope.
6
+ module HasScope
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ belongs_to :scope, foreign_key: "decidim_scope_id", class_name: Decidim::Scope
11
+ validate :scope_belongs_to_organization
12
+
13
+ private
14
+
15
+ def scope_belongs_to_organization
16
+ return if !scope || !feature
17
+ errors.add(:scope, :invalid) unless feature.scopes.where(id: scope.id).exists?
18
+ end
19
+ end
20
+ end
21
+ end
@@ -19,8 +19,8 @@ module Decidim
19
19
  }
20
20
  end
21
21
 
22
- field :currentUser do
23
- type UserType
22
+ field :session do
23
+ type SessionType
24
24
  description "Return's information about the logged in user"
25
25
 
26
26
  resolve ->(_obj, _args, ctx) {