Verified Commit bcaec3fb authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

rename profile_link helper and place one with that name that really creates a link

- the profile_link helper was delivering a path, but not a link
- renamed profile_link to profile_url_path (not profile_path to not conflict with path helpers)
- created new method profile_link, that creates a real html link of the user with its full name
  - it also checks for current_user policy credentials, edit? or show? and if none of them, it shows
    the users full_name and email as pure text
parent 65afa788
......@@ -87,13 +87,17 @@ module ApplicationHelper
class: 'pagination-lg text-center hidden-print', 'aria-label': 'Pagination'
end
def profile_url_path(user)
if policy(user.profile_entity).edit?
edit_polymorphic_path(user.profile_entity)
elsif policy(user.profile_entity).show?
polymorphic_path(user.profile_entity)
end
end
def profile_link(user)
if user.volunteer?
edit_volunteer_path(user.volunteer)
elsif user.profile
edit_profile_path(user.profile)
else
edit_user_path(user)
link_to_if(policy(user.profile_entity).show?, user.full_name, profile_url_path(user)) do
"#{user.full_name} - #{user.email}"
end
end
......
......@@ -4,6 +4,8 @@ class Profile < ApplicationRecord
has_one :contact, -> { with_deleted }, as: :contactable, dependent: :destroy
accepts_nested_attributes_for :contact
delegate :full_name, to: :contact
belongs_to :user, -> { with_deleted }
has_attached_file :avatar, styles: { thumb: '100x100#' }
......
......@@ -125,6 +125,16 @@ class User < ApplicationRecord
department.any?
end
def profile_entity
if volunteer?
volunteer
elsif profile
profile
else
self
end
end
def missing_profile?
!volunteer? && !profile
end
......
......@@ -41,7 +41,7 @@ nav.navbar.navbar-top.hidden-print
ul.dropdown-menu
li
- if current_user.volunteer?
= link_to 'Profil bearbeiten', profile_link(current_user)
= link_to 'Profil bearbeiten', profile_url_path(current_user)
- elsif current_user.profile.blank?
= link_to 'Profil erfassen', new_profile_path
- else
......
......@@ -23,11 +23,11 @@ table.table.table-striped.assignment-logs-table
- if assignment.client.involved_authority
= link_to_if policy(User).show?,
assignment.client.involved_authority.full_name,
profile_link(assignment.client.involved_authority)
profile_url_path(assignment.client.involved_authority)
- else
= link_to_if policy(User).show?,
assignment.creator.full_name,
profile_link(assignment.creator)
profile_url_path(assignment.creator)
td= link_to_if(assignment.assignment && policy(assignment.assignment).show?,
t_action(:show), assignment.assignment) { '' }
- if policy(Assignment).show_comments?
......@@ -45,6 +45,6 @@ table.table.table-striped.assignment-logs-table
span
= "Quittiert von "
= link_to_if(policy(Assignment).verify_termination?, assignment.termination_verified_by.full_name,
profile_link(assignment.termination_verified_by)) { '' }
profile_url_path(assignment.termination_verified_by)) { '' }
= " am #{l(assignment.termination_verified_at.to_date)}"
......@@ -18,7 +18,7 @@ table.table.table-striped.assignments-table
td= l(assignment.period_end) if assignment.period_end
td= link_to_if policy(User).show?,
assignment.client.involved_authority&.full_name || assignment.creator.full_name,
profile_link(assignment.client.involved_authority || assignment.creator)
profile_url_path(assignment.client.involved_authority || assignment.creator)
- if policy(Assignment).show_comments?
= td_truncate_content_modal(assignment.comments, 'Bemerkungen')
......@@ -15,7 +15,7 @@ tr
td= l(assignment.period_end) if assignment.period_end
td= link_to_if policy(User).show?,
assignment.client.involved_authority&.full_name || assignment.creator.full_name,
profile_link(assignment.client.involved_authority || assignment.creator)
profile_url_path(assignment.client.involved_authority || assignment.creator)
- if policy(Assignment).show_comments?
= td_truncate_content_modal(assignment.comments, 'Bemerkungen')
- if controller_name == 'volunteers' && !assignment.volunteer.external?
......
......@@ -74,7 +74,7 @@ nav.navbar.section-navigation
td= client.goals
td= client.interests
- if policy(Client).superadmin_privileges?
td= link_to client.involved_authority.full_name, profile_link(client.involved_authority) if client.involved_authority
td= link_to client.involved_authority.full_name, profile_url_path(client.involved_authority) if client.involved_authority
td= client.competent_authority
td.no-wrap= l(client.created_at.to_date)
- if policy(Client).show_comments?
......
......@@ -42,7 +42,7 @@ nav.navbar.section-navigation.hidden-print
verify_termination_assignment_path(assignment), class: 'btn btn-default',
data: { method: 'PATCH' }) do
= "Quittiert von "
= link_to assignment.termination_verified_by.full_name, profile_link(assignment.termination_verified_by)
= link_to assignment.termination_verified_by.full_name, profile_url_path(assignment.termination_verified_by)
= " am #{l(assignment.termination_verified_at.to_date)}"
td= link_to assignment.volunteer.contact.full_name, edit_volunteer_path(assignment.volunteer)
td= link_to assignment.client.contact.full_name, client_path(assignment.client)
......
......@@ -53,5 +53,5 @@ h1
td= format_currency record.final_amount
td= format_hours_period record.hours
- if policy(BillingExpense).superadmin_privileges?
td= link_to record.user, profile_link(record.user)
td= link_to record.user, profile_url_path(record.user)
td= l(record.created_at.to_date)
......@@ -29,7 +29,7 @@ tr id=dom_id(client)
td= client.goals
td= client.interests
- if policy(Client).superadmin_privileges?
td= link_to client.involved_authority.full_name, profile_link(client.involved_authority) if client.involved_authority
td= link_to client.involved_authority.full_name, profile_url_path(client.involved_authority) if client.involved_authority
td= client.competent_authority
td.no-wrap= l(client.created_at.to_date)
- if policy(Client).show_comments?
......
......@@ -53,7 +53,7 @@ h1.m-b-20= @client.contact.full_name
- if policy(Client).superadmin_privileges?
tr
td= t_attr(:involved_authority)
td= link_to @client.involved_authority.full_name, profile_link(@client.involved_authority) if @client.involved_authority
td= link_to @client.involved_authority.full_name, profile_url_path(@client.involved_authority) if @client.involved_authority
tr
td= t_attr(:competent_authority)
......@@ -67,7 +67,7 @@ h1.m-b-20= @client.contact.full_name
tr
td= t_attr(:created_by)
td= link_to @client.user.full_name, profile_link(@client.user)
td= link_to @client.user.full_name, profile_url_path(@client.user)
- if policy(Client).show_comments?
tr
......
......@@ -13,7 +13,7 @@
h2= t_attr(:associated_users)
ul
- @department.user.each do |user|
li= link_to user.full_name, profile_link(user)
li= link_to user.full_name, profile_url_path(user)
- if @department.group_offers.active.any?
h2.m-b-20= t('group_offers', count: 2)
......
......@@ -30,7 +30,7 @@ h2= @event.title if @event.title
td Erstellt von
td
= "Erstellt von "
= link_to @event.creator.full_name, profile_link(@event.creator)
= link_to @event.creator.full_name, profile_url_path(@event.creator)
= " am #{l(@event.created_at.to_date)}"
h3 Teilnehmende
......
......@@ -33,5 +33,5 @@ table.table.table-striped.group-assignments-table
span
= "Quittiert von "
= link_to_if(policy(Assignment).verify_termination?, group_assignment.termination_verified_by.full_name,
profile_link(group_assignment.termination_verified_by)) { '' }
profile_url_path(group_assignment.termination_verified_by)) { '' }
= " am #{l(group_assignment.termination_verified_at.to_date)}"
......@@ -61,5 +61,5 @@ nav.navbar.section-navigation.hidden-print
verify_termination_group_assignment_path(assignment), class: 'btn btn-default',
data: { method: 'PATCH' }) do
= "Quittiert von "
= link_to assignment.termination_verified_by.full_name, profile_link(assignment.termination_verified_by)
= link_to assignment.termination_verified_by.full_name, profile_url_path(assignment.termination_verified_by)
= " am #{l(assignment.termination_verified_at.to_date)}"
......@@ -30,5 +30,5 @@
td= l(ga_log.created_at)
td
= "Quittiert von "
= link_to_if policy(ga_log.termination_verified_by.profile).edit?, ga_log.termination_verified_by.full_name, profile_link(ga_log.termination_verified_by)
= link_to_if policy(ga_log.termination_verified_by.profile).edit?, ga_log.termination_verified_by.full_name, profile_url_path(ga_log.termination_verified_by)
= " am #{l(ga_log.termination_verified_at.to_date)}"
......@@ -68,7 +68,7 @@ table.table.table-striped
= offer.department.contact.last_name
td
- if offer.creator
=link_to offer.creator.full_name, profile_link(offer.creator)
=link_to offer.creator.full_name, profile_url_path(offer.creator)
td
- availability_collection.each do |availability|
- if offer[availability]
......
......@@ -26,7 +26,7 @@ h2= @group_offer.title
= link_to_if policy(@group_offer.department).show?, @group_offer.department, department_path(@group_offer.department.id)
tr
td Verantwortliche/r
td= link_to_if policy(@group_offer.creator.profile).edit?, @group_offer.creator, profile_link(@group_offer.creator) if @group_offer.creator
td= link_to_if policy(@group_offer.creator.profile).edit?, @group_offer.creator, profile_url_path(@group_offer.creator) if @group_offer.creator
tr
td= t_attr(:offer_state)
td= t("offer_state.#{@group_offer.offer_state}") if @group_offer.offer_state?
......
......@@ -5,7 +5,7 @@ tr
= button_link navigation_glyph(:edit), edit_reminder_mailing_path(reminder_mailing),
title: 'Bearbeiten'
td= reminder_mailing.t_enum(:kind)
td= link_to reminder_mailing.creator.full_name, profile_link(reminder_mailing.creator)
td= link_to reminder_mailing.creator.full_name, profile_url_path(reminder_mailing.creator)
td
- if reminder_mailing.sending_triggered
bermittelt am #{l(reminder_mailing.updated_at.to_date)}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment