app/models/decidim/initiative.rb in decidim-initiatives-0.24.3 vs app/models/decidim/initiative.rb in decidim-initiatives-0.25.0.rc1
- old
+ new
@@ -19,10 +19,11 @@
include Decidim::HasReference
include Decidim::Randomable
include Decidim::Searchable
include Decidim::Initiatives::HasArea
include Decidim::TranslatableResource
+ include Decidim::HasResourcePermission
translatable_fields :title, :description, :answer
belongs_to :organization,
foreign_key: "decidim_organization_id",
@@ -122,19 +123,22 @@
def self.log_presenter_class_for(_log)
Decidim::Initiatives::AdminLog::InitiativePresenter
end
+ delegate :document_number_authorization_handler, :promoting_committee_enabled?, to: :type
+ delegate :type, :scope, :scope_name, to: :scoped_type, allow_nil: true
+
# PUBLIC banner image
#
# Overrides participatory space's banner image with the banner image defined
# for the initiative type.
#
- # RETURNS string
- delegate :banner_image, to: :type
- delegate :document_number_authorization_handler, :promoting_committee_enabled?, to: :type
- delegate :type, :scope, :scope_name, to: :scoped_type, allow_nil: true
+ # RETURNS Decidim::BannerImageUploader
+ def banner_image
+ type.attached_uploader(:banner_image)
+ end
# PUBLIC
#
# Returns true when an initiative has been created by an individual person.
# False in case it has been created by an authorized organization.
@@ -175,21 +179,10 @@
# RETURN string
def author_name
user_group&.name || author.name
end
- # PUBLIC author_avatar_url
- #
- # Returns the author's avatar URL. In case it is not defined the method
- # falls back to decidim/default-avatar.svg
- #
- # RETURNS STRING
- def author_avatar_url
- author.avatar&.url ||
- ActionController::Base.helpers.asset_path("decidim/default-avatar.svg")
- end
-
def votes_enabled?
published? &&
signature_start_date <= Date.current &&
signature_end_date >= Date.current
end
@@ -408,10 +401,14 @@
def enough_committee_members?
committee_members.approved.count >= minimum_committee_members
end
+ def component
+ nil
+ end
+
# PUBLIC
#
# Checks if the type the initiative belongs to enables SMS code
# verification step. Tis configuration is ignored if the organization
# doesn't have the sms authorization available
@@ -424,9 +421,18 @@
# Public: Returns an empty object. This method should be implemented by
# `ParticipatorySpaceResourceable`, but for some reason this model does not
# implement this interface.
def user_role_config_for(_user, _role_name)
Decidim::ParticipatorySpaceRoleConfig::Base.new(:empty_role_name)
+ end
+
+ # Public: Overrides the `allow_resource_permissions?` Resourceable concern method.
+ def allow_resource_permissions?
+ true
+ end
+
+ def user_allowed_to_comment?(user)
+ ActionAuthorizer.new(user, "comment", self, nil).authorize.ok?
end
private
# Private: This is just an alias because the naming on InitiativeTypeScope