diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a1d989e25..722bb5d9c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -75,7 +75,7 @@ module ApplicationHelper end css_classes += " #{options[:class]}" if css_classes && options[:class].present? - url ? link_to(name, url, :class => css_classes) : name + url ? link_to(name, url, :class => css_classes, :data => options[:data]) : name end # Displays a link to edit group page if current user is admin @@ -1275,7 +1275,10 @@ module ApplicationHelper elsif sep == "@" name = remove_double_quotes(identifier) u = User.visible.find_by("LOWER(login) = :s AND type = 'User'", :s => name.downcase) - link = link_to_user(u, :only_path => only_path, :class => 'user-mention', :mention => true) if u + if u && obj && !obj.visible?(u) + data = {warning_tooltip: l(:error_not_mentioned)} + end + link = link_to_user(u, :only_path => only_path, :class => 'user-mention', :mention => true, :data => data) if u end end (leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}")) diff --git a/config/locales/en.yml b/config/locales/en.yml index 3f60e9e73..d79bf486f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -244,6 +244,7 @@ en: error_invalid_size_parameter: "Invalid size parameter" error_attachment_not_found: "Attachment %{name} not found" error_invalid_authenticity_token: "Invalid form authenticity token." + error_not_mentioned: "You cannot mention this user because they do not have access rights." error_query_statement_invalid: "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." mail_subject_lost_password: "Your %{value} password" diff --git a/public/javascripts/application.js b/public/javascripts/application.js index a183a2777..97b24cbb9 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1121,6 +1121,21 @@ $(function () { at: "center top" } }); + + $("[data-warning-tooltip]:not(.no-tooltip)").tooltip({ + items: '[data-warning-tooltip]', + content: function() { + return $(this).data('warning-tooltip'); + }, + tooltipClass: 'warning', + show: { + delay: 400 + }, + position: { + my: "center bottom-5", + at: "center top" + } + }); }); function inlineAutoComplete(element) { diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index f8e11b050..20a629d12 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1573,6 +1573,11 @@ td.gantt_selected_column .gantt_hdr,.gantt_selected_column_container { box-shadow: none; white-space: pre-wrap; } +.ui-tooltip.warning { + background-color: #F3EDD1; + border-color: #eadbbc; + color: #A6750C; +} /***** Icons *****/ .icon { diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 180066b17..99ff26f06 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -580,6 +580,18 @@ class ApplicationHelperTest < Redmine::HelperTest end end + def test_mention_link_to_users_who_are_not_authorised_to_view_the_object + set_language_if_valid 'en' + with_settings :text_formatting => 'textile' do + issue = Issue.find(4) + assert_not issue.visible?(User.find(3)) + assert_equal "

#{link_to_user(User.find(3), only_path: true, class: 'user-mention', mention: true, data: {warning_tooltip: 'You cannot mention this user because they do not have access rights.'})}

", textilizable("@#{User.find(3).login}", :object => issue) + + journal = Journal.find(2) + assert_equal '

#note-2

', textilizable('#note-2', :object => journal) + end + end + def test_link_to_note_within_the_same_page with_settings :text_formatting => 'textile' do issue = Issue.find(1)