diff --git a/Changelog.md b/Changelog.md index 780a11514..c998cda1d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -30,6 +30,7 @@ * Add OpenGraph video support [#7043](https://github.com/diaspora/diaspora/pull/7043) * You'll now get redirected to the invites page if you follow an invitation but you're already logged inĀ [#7061](https://github.com/diaspora/diaspora/pull/7061) * Add support for setting BOSH access protocol via chat configuration [#7100](https://github.com/diaspora/diaspora/pull/7100) +* Add number of unreviewed reports to admin dashboard and admin sidebar [#7109](https://github.com/diaspora/diaspora/pull/7109) # 0.6.0.0 diff --git a/app/assets/javascripts/app/pages/admin_dashboard.js b/app/assets/javascripts/app/pages/admin_dashboard.js index 4826c12ea..96ebf6c00 100644 --- a/app/assets/javascripts/app/pages/admin_dashboard.js +++ b/app/assets/javascripts/app/pages/admin_dashboard.js @@ -2,6 +2,7 @@ app.pages.AdminDashboard = Backbone.View.extend({ initialize: function() { + this.podVersionAlert = $("#pod-status .alert.pod-version"); this.updatePodStatus(); }, @@ -38,15 +39,15 @@ app.pages.AdminDashboard = Backbone.View.extend({ }, updatePodStatusSuccess: function() { - $("#pod-status .alert").removeClass("alert-info"); + this.podVersionAlert.removeClass("alert-info"); var podStatusMessage = Diaspora.I18n.t("admins.dashboard.up_to_date"); if(this.podUpToDate()) { - $("#pod-status .alert").addClass("alert-success"); + this.podVersionAlert.addClass("alert-success"); } else { podStatusMessage = Diaspora.I18n.t("admins.dashboard.outdated"); - $("#pod-status .alert").addClass("alert-danger"); + this.podVersionAlert.addClass("alert-danger"); } - $("#pod-status .alert") + this.podVersionAlert .html("" + podStatusMessage + "") .append(" ") .append(Diaspora.I18n.t("admins.dashboard.compare_versions", { @@ -56,7 +57,7 @@ app.pages.AdminDashboard = Backbone.View.extend({ }, updatePodStatusFail: function() { - $("#pod-status .alert") + this.podVersionAlert .removeClass("alert-info") .addClass("alert-warning") .text(Diaspora.I18n.t("admins.dashboard.error")); diff --git a/app/helpers/report_helper.rb b/app/helpers/report_helper.rb index 5a6f1e0e3..022ef1bb7 100644 --- a/app/helpers/report_helper.rb +++ b/app/helpers/report_helper.rb @@ -16,4 +16,8 @@ module ReportHelper raw t("report.not_found") end end + + def unreviewed_reports_count + @unreviewed_reports_count ||= Report.where(reviewed: false).size + end end diff --git a/app/views/admins/_admin_bar.haml b/app/views/admins/_admin_bar.haml index c2187bf4e..43ab0a8a4 100644 --- a/app/views/admins/_admin_bar.haml +++ b/app/views/admins/_admin_bar.haml @@ -13,7 +13,11 @@ %li{role: "presentation", class: current_page?(pod_stats_path) && "active"} = link_to t(".pod_stats"), pod_stats_path %li{role: "presentation", class: current_page?(report_index_path) && "active"} - = link_to t(".report"), report_index_path + %a{href: report_index_path} + - if unreviewed_reports_count > 0 + .pull-right.badge + = unreviewed_reports_count + = t(".report") %li{role: "presentation", class: current_page?(admin_pods_path) && "active"} = link_to t(".pod_network"), admin_pods_path %li{role: "presentation", class: current_page?(sidekiq_path) && "active"} diff --git a/app/views/admins/dashboard.html.haml b/app/views/admins/dashboard.html.haml index bf7fd1089..326758301 100644 --- a/app/views/admins/dashboard.html.haml +++ b/app/views/admins/dashboard.html.haml @@ -6,5 +6,8 @@ #pod-status %h2 = t(".pod_status") - .alert.alert-info{role: "alert"} + .alert.alert-info.pod-version{role: "alert"} = t(".fetching_diaspora_version") + - if unreviewed_reports_count > 0 + .alert.alert-warning.reports-warning{role: "alert"} + = t("report.unreviewed_reports", count: unreviewed_reports_count) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index eab3953a0..0f94fa9fc 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -940,6 +940,10 @@ en: status: destroyed: "The post was destroyed" failed: "Something went wrong" + unreviewed_reports: + zero: "There are no unreviewed reports." + one: "There is one unreviewed report." + other: "There are %{count} unreviewed reports." profiles: edit: diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb index e56fc5fb7..bf4763a47 100644 --- a/spec/controllers/admins_controller_spec.rb +++ b/spec/controllers/admins_controller_spec.rb @@ -10,6 +10,43 @@ describe AdminsController, :type => :controller do sign_in @user, scope: :user end + describe "#dashboard" do + context "admin not signed in" do + it "is behind redirect_unless_admin" do + get :dashboard + expect(response).to redirect_to stream_path + end + end + + context "admin signed in" do + before do + Role.add_admin(@user.person) + @post = bob.post(:status_message, text: "hello", to: bob.aspects.first.id) + @post_report = alice.reports.create( + item_id: @post.id, item_type: "Post", + text: "offensive content" + ) + end + + it "succeeds" do + get :dashboard + expect(response).to be_success + end + + it "warns the user about unreviewed reports" do + get :dashboard + expect(response.body).to match("reports-warning") + expect(response.body).to include(I18n.t("report.unreviewed_reports", count: 1)) + end + + it "doesn't show a report warning if there are no unreviewed reports" do + @post_report.mark_as_reviewed + get :dashboard + expect(response.body).not_to match("reports-warning") + end + end + end + describe '#user_search' do context 'admin not signed in' do it 'is behind redirect_unless_admin' do diff --git a/spec/helpers/report_helper_spec.rb b/spec/helpers/report_helper_spec.rb index 3bdaf8670..0eb854639 100644 --- a/spec/helpers/report_helper_spec.rb +++ b/spec/helpers/report_helper_spec.rb @@ -26,4 +26,11 @@ describe ReportHelper, type: :helper do .to include %(href="#{post_path(@post, anchor: @comment.guid)}") end end + + describe "#unreviewed_reports_count" do + it "returns the number of unreviewed reports" do + @comment_report.mark_as_reviewed + expect(helper.unreviewed_reports_count).to be(1) + end + end end diff --git a/spec/javascripts/app/pages/admin_dashboard_spec.js b/spec/javascripts/app/pages/admin_dashboard_spec.js index 3b97a3fab..4ff323739 100644 --- a/spec/javascripts/app/pages/admin_dashboard_spec.js +++ b/spec/javascripts/app/pages/admin_dashboard_spec.js @@ -139,28 +139,28 @@ describe("app.pages.AdminDashboard", function(){ spyOn(this.view, "podUpToDate").and.returnValue(true); this.view.latestVersion = [0, 5, 1, 1]; this.view.updatePodStatusSuccess(); - expect($("#pod-status .alert")).toHaveClass("alert-success"); - expect($("#pod-status .alert").text()).toContain("up to date"); - expect($("#pod-status .alert").text()).toContain("release is v0.5.1.1"); - expect($("#pod-status .alert").text()).toContain("pod is running v0.5.1.2"); + expect($("#pod-status .alert.pod-version")).toHaveClass("alert-success"); + expect($("#pod-status .alert.pod-version").text()).toContain("up to date"); + expect($("#pod-status .alert.pod-version").text()).toContain("release is v0.5.1.1"); + expect($("#pod-status .alert.pod-version").text()).toContain("pod is running v0.5.1.2"); }); it("adds a 'danger' alert if the pod is up to date", function() { spyOn(this.view, "podUpToDate").and.returnValue(false); this.view.latestVersion = [0, 5, 1, 3]; this.view.updatePodStatusSuccess(); - expect($("#pod-status .alert")).toHaveClass("alert-danger"); - expect($("#pod-status .alert").text()).toContain("outdated"); - expect($("#pod-status .alert").text()).toContain("release is v0.5.1.3"); - expect($("#pod-status .alert").text()).toContain("pod is running v0.5.1.2"); + expect($("#pod-status .alert.pod-version")).toHaveClass("alert-danger"); + expect($("#pod-status .alert.pod-version").text()).toContain("outdated"); + expect($("#pod-status .alert.pod-version").text()).toContain("release is v0.5.1.3"); + expect($("#pod-status .alert.pod-version").text()).toContain("pod is running v0.5.1.2"); }); }); describe("updatePodStatusFail", function() { it("adds a 'warning' alert", function() { this.view.updatePodStatusFail(); - expect($("#pod-status .alert")).toHaveClass("alert-warning"); - expect($("#pod-status .alert").text()).toContain("Unable to determine"); + expect($("#pod-status .alert.pod-version")).toHaveClass("alert-warning"); + expect($("#pod-status .alert.pod-version").text()).toContain("Unable to determine"); }); }); });