Skip to content

Commit

Permalink
Use new plugin show route
Browse files Browse the repository at this point in the history
  • Loading branch information
romanrizzi committed Jul 1, 2024
1 parent 67c08ef commit f8050be
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import DiscourseRoute from "discourse/routes/discourse";

Check failure on line 1 in admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-antivirus-stats.js

View workflow job for this annotation

GitHub Actions / ci / linting

Run autofix to sort these imports!
import { ajax } from "discourse/lib/ajax";

export default class DiscourseAntivirusStatsRoute extends DiscourseRoute {
model() {
return ajax("/admin/plugins/discourse-antivirus/stats");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<section class="antivirus-stats admin-detail pull-left">
<div class="antivirus-stats__header">
<h3>{{i18n "antivirus.stats.title"}}</h3>
</div>

<table>
<thead>
<tr>
<th>{{i18n "antivirus.version"}}</th>
<th>{{i18n "antivirus.database_version"}}</th>
<th>{{i18n "antivirus.database_updated_at"}}</th>
</tr>
</thead>
<tbody>
{{#each this.model.versions as |version|}}
<tr>
<td>{{version.antivirus}}</td>
<td>{{version.database}}</td>
<td>{{version.updated_at}}</td>
</tr>
{{/each}}
</tbody>
</table>

<table>
<thead>
<tr>
<th>{{i18n "antivirus.stats.total_scans"}}</th>
<th>{{i18n "antivirus.stats.recently_scanned"}}</th>
<th>{{i18n "antivirus.stats.quarantined"}}</th>
<th>{{i18n "antivirus.stats.found"}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{this.model.stats.scans}}</td>
<td>{{this.model.stats.recently_scanned}}</td>
<td>{{this.model.stats.quarantined}}</td>
<td>{{this.model.stats.found}}</td>
</tr>
</tbody>
</table>

</section>
15 changes: 15 additions & 0 deletions app/controllers/discourse_antivirus/admin/antivirus_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module DiscourseAntivirus
module Admin
class AntivirusController < ::Admin::AdminController
requires_plugin ::DiscourseAntivirus::PLUGIN_NAME

def index
antivirus = DiscourseAntivirus::ClamAv.instance

render json: DiscourseAntivirus::BackgroundScan.new(antivirus).stats
end
end
end
end
13 changes: 0 additions & 13 deletions app/controllers/discourse_antivirus/antivirus_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
resource: "admin.adminPlugins.show",
path: "/plugins",

map() {
this.route("discourse-antivirus-stats", { path: "stats" });

Check failure on line 6 in assets/javascripts/discourse/admin-discourse-antivirus-plugin-route-map.js

View workflow job for this annotation

GitHub Actions / ci / linting

Trailing spaces not allowed
}
};
8 changes: 0 additions & 8 deletions assets/javascripts/discourse/antivirus-route-map.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { PLUGIN_NAV_MODE_TOP } from "discourse/lib/admin-plugin-config-nav";
import { withPluginApi } from "discourse/lib/plugin-api";

export default {
name: "discourse-antivirus-admin-plugin-configuration-nav",

initialize(container) {
const currentUser = container.lookup("service:current-user");
if (!currentUser || !currentUser.admin) {
return;
}

withPluginApi("1.1.0", (api) => {
api.addAdminPluginConfigurationNav("discourse-antivirus", PLUGIN_NAV_MODE_TOP, [
{
label: "antivirus.stats.title",
route: "adminPlugins.show.discourse-antivirus-stats",
},
]);
});
},
};
17 changes: 0 additions & 17 deletions assets/javascripts/discourse/routes/admin-plugins-antivirus.js

This file was deleted.

43 changes: 0 additions & 43 deletions assets/javascripts/discourse/templates/admin/plugins-antivirus.hbs

This file was deleted.

1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ en:
clamav_unavailable: We cannot establish a connection with the antivirus software. File scanning will be temporarily disabled.

stats:
title: Stats
total_scans: Scanned Files
recently_scanned: Recently Scanned
quarantined: Quarantined
Expand Down
9 changes: 2 additions & 7 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# frozen_string_literal: true

#DiscourseAntivirus::Engine.routes.draw do
# root to: "antivirus#index"
# get "/stats" => "antivirus#index"
#end

Discourse::Application.routes.draw do
scope "/admin/plugins/antivirus", constraints: AdminConstraint.new do
get "/stats" => "antivirus#index"
scope "/admin/plugins/discourse-antivirus", constraints: AdminConstraint.new do
get "/stats" => "discourse_antivirus/admin/antivirus#index"
end
end
2 changes: 1 addition & 1 deletion lib/discourse_antivirus/background_scan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def stats

{
versions: @antivirus.versions,
background_scan_stats: {
stats: {
scans: scanned_upload_stats[0] || 0,
recently_scanned: scanned_upload_stats[1] || 0,
quarantined: scanned_upload_stats[2] || 0,
Expand Down
4 changes: 2 additions & 2 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# name: discourse-antivirus
# about: Scan uploads
# about: Scan your Discourse uploads using ClamAV
# version: 0.1
# authors: romanrizzi
# url: https://github.com/discourse/discourse-antivirus
Expand All @@ -18,7 +18,7 @@ module ::DiscourseAntivirus

require_relative "lib/discourse_antivirus/engine"

add_admin_route "antivirus.title", "antivirus"
add_admin_route("antivirus.title", "antivirus", { use_new_show_route: true })

after_initialize do
register_reviewable_type ReviewableUpload
Expand Down

0 comments on commit f8050be

Please sign in to comment.