Files
nairobi/app/helpers/users_helper.rb
Javi Martín cb2aebe2c8 Fix current_user usage in management section
In the management section, `current_user` is the user impersonated by
the manager. We were deciding whether to show the admin menu depending
on the privileges of the current user, but this menu should be shown
according to the privileges of the manager who is impersonating the
user.

We're doing a similar (very subtle) change in the login items. We were
rendering the `login_items` partial passing `current_user: user`.
However, inside this method, we were using `user_signed_in`, which
ignored the `current_user` we were passing. The result was always the
same expect in tests where we manually sign in users, but we're changing
it anyway in order to reduce confusion.
2023-01-16 14:22:23 +01:00

53 lines
1.4 KiB
Ruby

module UsersHelper
def humanize_document_type(document_type)
case document_type
when "1"
t "verification.residence.new.document_type.spanish_id"
when "2"
t "verification.residence.new.document_type.passport"
when "3"
t "verification.residence.new.document_type.residence_card"
end
end
def comment_commentable_title(comment)
commentable = comment.commentable
if commentable.nil?
deleted_commentable_text(comment)
elsif commentable.hidden?
tag.del(commentable.title) + " " +
tag.span("(#{deleted_commentable_text(comment)})", class: "small")
else
link_to(commentable.title, comment)
end
end
def deleted_commentable_text(comment)
case comment.commentable_type
when "Proposal"
t("users.show.deleted_proposal")
when "Debate"
t("users.show.deleted_debate")
when "Budget::Investment"
t("users.show.deleted_budget_investment")
else
t("users.show.deleted")
end
end
def show_admin_menu?(user)
unless namespace == "officing"
user&.administrator? || user&.moderator? || user&.valuator? ||
(user&.manager? && namespace != "management") || user&.poll_officer? || user&.sdg_manager?
end
end
def interests_title_text(user)
if current_user == user
t("account.show.public_interests_my_title_list")
else
t("account.show.public_interests_user_title_list")
end
end
end