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
@@ -7,19 +7,22 @@ module Decidim
7
7
  class AuthorizationsController < ApplicationController
8
8
  helper_method :handler, :handlers
9
9
  before_action :valid_handler, only: [:new, :create]
10
- before_action :only_one_handler?, only: [:index]
11
10
 
12
- def new
13
- authorize! current_user, Authorization
14
- end
11
+ include Decidim::UserProfile
12
+
13
+ layout "layouts/decidim/user_profile", only: [:index]
14
+
15
+ def new; end
15
16
 
16
17
  def index
17
- authorize! current_user, Authorization
18
+ @authorizations = current_user.authorizations
18
19
  end
19
20
 
20
- def create
21
- authorize! current_user, Authorization
21
+ def first_login
22
+ redirect_to(action: :new, handler: handlers.first.handler_name) if handlers.length == 1
23
+ end
22
24
 
25
+ def create
23
26
  AuthorizeUser.call(handler) do
24
27
  on(:ok) do
25
28
  flash[:notice] = t("authorizations.create.success", scope: "decidim")
@@ -35,7 +38,7 @@ module Decidim
35
38
 
36
39
  def destroy
37
40
  @authorization = current_user.authorizations.find(params[:id])
38
- authorize! current_user, @authorization
41
+ authorize! :destroy, @authorization
39
42
 
40
43
  @authorization.destroy
41
44
  flash[:notice] = t("authorizations.destroy.success", scope: "decidim")
@@ -72,5 +75,15 @@ module Decidim
72
75
  def only_one_handler?
73
76
  redirect_to(action: :new, handler: handlers.first.handler_name) && return if handlers.length == 1
74
77
  end
78
+
79
+ def handlers
80
+ @handlers ||= available_authorization_handlers.reject do |handler|
81
+ authorized_handlers.include?(handler.handler_name)
82
+ end
83
+ end
84
+
85
+ def authorized_handlers
86
+ current_user.authorizations.map(&:name)
87
+ end
75
88
  end
76
89
  end
@@ -7,6 +7,8 @@ module Decidim
7
7
  include Decidim::LocaleSwitcher
8
8
  helper Decidim::TranslationsHelper
9
9
 
10
+ layout "layouts/decidim/application"
11
+
10
12
  # We don't users to create invitations, so we just redirect them to the
11
13
  # homepage.
12
14
  def authenticate_inviter!
@@ -12,7 +12,7 @@ module Decidim
12
12
 
13
13
  def after_sign_in_path_for(user)
14
14
  if !pending_redirect?(user) && first_login_and_not_authorized?(user)
15
- authorizations_path
15
+ first_login_authorizations_path
16
16
  else
17
17
  super
18
18
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require_dependency "decidim/application_controller"
3
+
4
+ module Decidim
5
+ # The controller to handle managing the current user's
6
+ # UserGroups.
7
+ class OwnUserGroupsController < ApplicationController
8
+ include Decidim::UserProfile
9
+
10
+ def index
11
+ @user_groups = current_user.user_groups
12
+ end
13
+ end
14
+ end
@@ -11,7 +11,7 @@ module Decidim
11
11
 
12
12
  helper_method :participatory_processes, :promoted_processes
13
13
 
14
- skip_after_action :verify_participatory_process , only: [:index]
14
+ skip_after_action :verify_participatory_process, only: [:index]
15
15
 
16
16
  def index
17
17
  authorize! :read, ParticipatoryProcess
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # The form object that handles the data behind updating a user's
5
+ # account in her profile page.
6
+ class AccountForm < Form
7
+ mimic :user
8
+
9
+ attribute :name
10
+ attribute :email
11
+ attribute :password
12
+ attribute :password_confirmation
13
+ attribute :avatar
14
+ attribute :remove_avatar
15
+
16
+ validates :name, presence: true
17
+ validates :email, presence: true
18
+
19
+ validates :password, confirmation: true
20
+ validates :password, length: { in: Decidim::User.password_length, allow_blank: true }
21
+ validates :password_confirmation, presence: true, if: :password_present
22
+
23
+ validate :unique_email
24
+
25
+ private
26
+
27
+ def password_present
28
+ !password.blank?
29
+ end
30
+
31
+ def unique_email
32
+ return true if Decidim::User.where(
33
+ organization: context.current_organization,
34
+ email: email
35
+ ).where.not(id: context.current_user.id).empty?
36
+
37
+ errors.add :email, :taken
38
+ false
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # Module to add the attribute `aria-selected` to links when they are
4
+ # pointing to the current path. Uses the `active_link_to` gem to calculate
5
+ # this.
6
+ #
7
+ module AriaSelectedLinkToHelper
8
+ # Adds the `aria-selected` attribute to a link when it's pointing to the
9
+ # current path. The API is the same than the `link_to` one, and uses this
10
+ # helper internally.
11
+ #
12
+ # text - a String with the link text
13
+ # link - Where the link should point to. Accepts the same value than
14
+ # `link_to` helper.
15
+ # options - An options Hash that will be passed to `link_to`.
16
+ def aria_selected_link_to(text, link, options = {})
17
+ link_to(
18
+ text,
19
+ link,
20
+ options.merge(
21
+ "aria-selected": is_active_link?(link, options[:aria_link_type] || :inclusive)
22
+ )
23
+ )
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # A Helper to render and link to resources.
4
+ module AttachmentsHelper
5
+ # Renders a the attachments of a model that includes the
6
+ # HasAttachments concern.
7
+ #
8
+ # attached_to - The model to render the attachments from.
9
+ #
10
+ # Returns nothing.
11
+ def attachments_for(attached_to)
12
+ render partial: "attachments", locals: { attached_to: attached_to }
13
+ end
14
+ end
15
+ end
@@ -10,12 +10,11 @@ module Decidim
10
10
  #
11
11
  # Returns the filter resource form wrapped in a div
12
12
  def filter_form_for(filter)
13
- filters_container = content_tag :div, class: "filters" do
14
- form_for filter, builder: FilterFormBuilder, url: url_for, as: :filter, method: :get, remote: true do |form|
13
+ content_tag :div, class: "filters" do
14
+ form_for filter, builder: FilterFormBuilder, url: url_for, as: :filter, method: :get, remote: true, html: { id: nil } do |form|
15
15
  yield form
16
16
  end
17
17
  end
18
- filters_container + javascript_include_tag("decidim/filters")
19
18
  end
20
19
  end
21
20
  end
@@ -3,10 +3,22 @@ module Decidim
3
3
  # View helpers related to the layout.
4
4
  module LayoutHelper
5
5
  def decidim_page_title
6
- title = content_for(:title)
6
+ title = content_for(:meta_title)
7
7
  title ? "#{title} - #{current_organization.name}" : current_organization.name
8
8
  end
9
9
 
10
+ # Public: Generates a set of meta tags that generate the different favicon
11
+ # versions for an organization.
12
+ #
13
+ # Returns a safe String with the versions.
14
+ def favicon
15
+ return unless current_organization.favicon.present?
16
+
17
+ safe_join(Decidim::OrganizationFaviconUploader::SIZES.map do |version, size|
18
+ favicon_link_tag(current_organization.favicon.send(version).url, sizes: "#{size}x#{size}")
19
+ end)
20
+ end
21
+
10
22
  # Outputs an SVG-based icon.
11
23
  #
12
24
  # name - The String with the icon name.
@@ -34,8 +46,7 @@ module Decidim
34
46
  html_properties["role"] = options[:role]
35
47
  html_properties["aria-hidden"] = options[:aria_hidden]
36
48
 
37
- icon_class = (options[:remove_icon_class] ? "" : "icon")
38
- html_properties["class"] = "icon--#{name} #{icon_class} #{options[:class]}"
49
+ html_properties["class"] = (["icon--#{name}"] + _icon_classes(options)).join(" ")
39
50
 
40
51
  content_tag :svg, html_properties do
41
52
  content_tag :use, nil, "xlink:href" => "#{asset_url("decidim/icons.svg")}#icon-#{name}"
@@ -49,11 +60,23 @@ module Decidim
49
60
  # path - The asset's path
50
61
  #
51
62
  # Returns an <img /> tag with the SVG icon.
52
- def external_icon(path)
63
+ def external_icon(path, options = {})
53
64
  # Ugly hack to prevent PhantomJS from freaking out with SVGs.
54
- return content_tag(:span, "?", class: "external-svg", "data-src" => path) if Rails.env.test?
65
+ classes = _icon_classes(options) + ["external-icon"]
66
+ return content_tag(:span, "?", class: classes.join(" "), "data-src" => path) if Rails.env.test?
67
+
68
+ if path.split(".").last == "svg"
69
+ asset = Rails.application.assets_manifest.find_sources(path).first
70
+ asset.gsub("<svg ", "<svg class=\"#{classes.join(" ")}\" ").html_safe
71
+ else
72
+ image_tag(path, class: classes.join(" "), style: "display: none")
73
+ end
74
+ end
55
75
 
56
- image_tag(path, class: "external-svg", style: "display: none")
76
+ def _icon_classes(options = {})
77
+ classes = options[:remove_icon_class] ? [] : ["icon"]
78
+ classes += [options[:class]]
79
+ classes.compact
57
80
  end
58
81
  end
59
82
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # A Helper to render and link to resources.
4
+ module ResourceHelper
5
+ # Builds the path to a resource. Useful when linking to a resource from
6
+ # another engine.
7
+ #
8
+ # resource - An object that is a valid resource exposed by some feature.
9
+ #
10
+ # Returns a String.
11
+ def decidim_resource_path(resource)
12
+ _decidim_resource_route(resource, "path")
13
+ end
14
+
15
+ # Builds the url to a resource. Useful when linking to a resource from
16
+ # another engine.
17
+ #
18
+ # resource - An object that is a valid resource exposed by some feature.
19
+ #
20
+ # Returns a String.
21
+ def decidim_resource_url(resource)
22
+ _decidim_resource_route(resource, "url")
23
+ end
24
+
25
+ # Renders a collection of linked resources for a resource.
26
+ #
27
+ # resource - The resource to get the links from.
28
+ # type - The String type fo the resources we want to render.
29
+ # link_name - The String name of the link between the resources.
30
+ #
31
+ # Example to render the proposals in a meeting view:
32
+ #
33
+ # linked_resources_for(:meeting, :proposals, "proposals_from_meeting")
34
+ #
35
+ # Returns nothing.
36
+ def linked_resources_for(resource, type, link_name)
37
+ linked_resources = resource.linked_resources(type, link_name).group_by { |linked_resource| linked_resource.class.name }
38
+
39
+ safe_join(linked_resources.map do |klass, resources|
40
+ resource_manifest = klass.constantize.resource_manifest
41
+ content_tag(:div, class: "section") do
42
+ content_tag(:h3, I18n.t(resource_manifest.name, scope: "decidim.resource_links.#{link_name}"), class: "section-heading") +
43
+ render(partial: resource_manifest.template, locals: { resources: resources })
44
+ end
45
+ end)
46
+ end
47
+
48
+ # Private: Build the route to a given resource.
49
+ #
50
+ # Returns a String.
51
+ def _decidim_resource_route(resource, route_type)
52
+ manifest = resource.class.resource_manifest
53
+ engine = send(manifest.mounted_engine_name)
54
+
55
+ url_params = {
56
+ id: resource.id,
57
+ feature_id: resource.feature.id,
58
+ participatory_process_id: resource.feature.participatory_process.id
59
+ }
60
+
61
+ engine.send("#{manifest.route_name}_#{route_type}", url_params)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # Helpers used in controllers implementing the `Decidim::UserProfile` concern.
4
+ module UserProfileHelper
5
+ # Public: Shows a menu tab with a section. It highlights automatically bye
6
+ # detecting if the current path is a subset of the provided route.
7
+ #
8
+ # text - The text to show in the tab.
9
+ # link - The path to link to.
10
+ # options - Extra options.
11
+ # aria_link_type - :inclusive or :exact, depending on the type of
12
+ # highlighting desired.
13
+ #
14
+ # Returns a String with the menu tab.
15
+ def user_profile_tab(text, link, options = {})
16
+ active = is_active_link?(link, (options[:aria_link_type] || :inclusive))
17
+
18
+ content_tag(:li, class: "tabs-title#{active ? " is-active" : nil}") do
19
+ aria_selected_link_to(text, link, options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -16,6 +16,7 @@ module Decidim
16
16
  def invitation_instructions(user, token, opts = {})
17
17
  with_user(user) do
18
18
  @token = token
19
+ @organization = user.organization
19
20
 
20
21
  if opts[:invitation_instructions]
21
22
  opts[:subject] = I18n.t("devise.mailer.#{opts[:invitation_instructions]}.subject", organization: user.organization.name)
@@ -6,10 +6,14 @@ module Decidim
6
6
  class Everyone
7
7
  include CanCan::Ability
8
8
 
9
- def initialize(_user)
9
+ def initialize(user, _context)
10
10
  can :read, ParticipatoryProcess, &:published?
11
11
  can :read, :public_pages
12
12
  can :manage, :locales
13
+
14
+ can :manage, User do |other|
15
+ other == user
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -17,16 +17,15 @@ module Decidim
17
17
  # every time you change things in your ability classes.
18
18
  #
19
19
  # user - the User that needs its abilities checked.
20
- def initialize(user)
20
+ # context - a Hash with some context related to the current request.
21
+ def initialize(user, context = {})
21
22
  Decidim.abilities.each do |ability|
22
- merge ability.new(user)
23
+ merge ability.constantize.new(user, context)
23
24
  end
24
25
 
25
26
  can :manage, Authorization do |authorization|
26
27
  authorization.user == user
27
28
  end
28
-
29
- can :read, :user_account if user
30
29
  end
31
30
  end
32
31
  end
@@ -2,11 +2,11 @@
2
2
  module Decidim
3
3
  # Attachment can be any type of document or images related to a partcipatory
4
4
  # process.
5
- class ParticipatoryProcessAttachment < ApplicationRecord
6
- belongs_to :participatory_process, foreign_key: "decidim_participatory_process_id", class_name: Decidim::ParticipatoryProcess, inverse_of: :attachments
5
+ class Attachment < ApplicationRecord
6
+ belongs_to :attached_to, polymorphic: true
7
7
 
8
- validates :file, :participatory_process, :content_type, presence: true
9
- validates :file, file_size: { less_than_or_equal_to: 10.megabytes }
8
+ validates :file, :attached_to, :content_type, presence: true
9
+ validates :file, file_size: { less_than_or_equal_to: ->(_attachment) { Decidim.maximum_attachment_size } }
10
10
  mount_uploader :file, Decidim::AttachmentUploader
11
11
 
12
12
  # Whether this attachment is a photo or not.
@@ -27,7 +27,7 @@ module Decidim
27
27
  #
28
28
  # Returns String.
29
29
  def file_type
30
- file.file.extension
30
+ file.url&.split(".")&.last&.downcase
31
31
  end
32
32
 
33
33
  # The URL to download the file.
@@ -11,6 +11,8 @@ module Decidim
11
11
 
12
12
  validates :participatory_process, presence: true
13
13
 
14
+ default_scope { order(arel_table[:weight].asc) }
15
+
14
16
  after_initialize :default_values
15
17
 
16
18
  # Public: Finds the manifest this feature is associated to.
@@ -14,6 +14,7 @@ module Decidim
14
14
 
15
15
  mount_uploader :homepage_image, Decidim::HomepageImageUploader
16
16
  mount_uploader :logo, Decidim::OrganizationLogoUploader
17
+ mount_uploader :favicon, Decidim::OrganizationFaviconUploader
17
18
 
18
19
  def homepage_big_url
19
20
  homepage_image.big.url