The `use_helpers` method was added in ViewComponent 3.8.0, and it's included by default in all components since version 3.11.0. Note we sometimes delegated the `can?` method to the controller instead of the helpers, for no particularly reason. We're unifying that code as well.
31 lines
733 B
Ruby
31 lines
733 B
Ruby
class Shared::ParticipationNotAllowedComponent < ApplicationComponent
|
|
attr_reader :votable, :cannot_vote_text
|
|
use_helpers :current_user, :link_to_signin, :link_to_signup
|
|
|
|
def initialize(votable, cannot_vote_text:)
|
|
@votable = votable
|
|
@cannot_vote_text = cannot_vote_text
|
|
end
|
|
|
|
def render?
|
|
body.present?
|
|
end
|
|
|
|
private
|
|
|
|
def body
|
|
@body ||=
|
|
if !current_user
|
|
sanitize(t("users.login_to_continue", signin: link_to_signin, signup: link_to_signup))
|
|
elsif organization?
|
|
tag.p t("votes.organizations")
|
|
elsif cannot_vote_text.present?
|
|
tag.p sanitize(cannot_vote_text)
|
|
end
|
|
end
|
|
|
|
def organization?
|
|
current_user&.organization?
|
|
end
|
|
end
|