diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 296f1aa8..cc354420 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -171,4 +171,8 @@ module ApplicationHelper def list_title(list) generate_title list.name end + + def rails_admin_path_for_resource(resource) + [rails_admin_path, resource.model_name.param_key, resource.id].join('/') + end end diff --git a/app/views/answerbox/_actions.haml b/app/views/answerbox/_actions.haml index f6f99c12..133a3521 100644 --- a/app/views/answerbox/_actions.haml +++ b/app/views/answerbox/_actions.haml @@ -38,3 +38,7 @@ %a.dropdown-item{ href: '#', data: { a_id: a.id, action: 'ab-report' } } %i.fa.fa-exclamation-triangle = t 'views.actions.report' + - if current_user.has_role? :administrator + %a.dropdown-item{ href: rails_admin_path_for_resource(a), target: '_blank' } + %i.fa.fa-gears + View in Kontrollzentrum diff --git a/app/views/answerbox/_header.haml b/app/views/answerbox/_header.haml index 5b262bb4..b33387eb 100644 --- a/app/views/answerbox/_header.haml +++ b/app/views/answerbox/_header.haml @@ -18,6 +18,10 @@ %a.dropdown-item{ href: '#', tabindex: -1, data: { action: 'ab-question-report', q_id: a.question.id } } %i.fa.fa-exclamation-triangle = t 'views.actions.report' + - if current_user.has_role? :administrator + %a.dropdown-item{ href: rails_admin_path_for_resource(a.question), target: '_blank' } + %i.fa.fa-gears + View in Kontrollzentrum %h6.text-muted.media-heading.answerbox__question-user = raw t('views.answerbox.asked', user: user_screen_name(a.question.user, anonymous: a.question.author_is_anonymous), time: time_tooltip(a.question)) - if !a.question.author_is_anonymous && a.question.answer_count > 1 diff --git a/app/views/user/_actions.haml b/app/views/user/_actions.haml index ceea4584..b22cfdba 100644 --- a/app/views/user/_actions.haml +++ b/app/views/user/_actions.haml @@ -28,3 +28,7 @@ %a.dropdown-item{ href: '#', data: { target: '#modal-ban', toggle: :modal } } %i.fa.fa-ban = t 'views.actions.ban' + - if current_user.has_role? :administrator + %a.dropdown-item{ href: rails_admin_path_for_resource(user), target: '_blank' } + %i.fa.fa-cogs + "View in Kontrollzentrum" diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 58a2ff69..6bdc4702 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -87,4 +87,15 @@ EOS end end end + + describe "#rails_admin_path_for_resource" do + context "user resource" do + let(:resource) { FactoryBot.create(:user) } + subject { rails_admin_path_for_resource(resource) } + + it "should return a URL to the given resource within rails admin" do + expect(subject).to eq("/justask_admin/user/#{resource.id}") + end + end + end end