-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Modernize the Antivirus plugin. (#59)
* DEV: Modernize the Antivirus plugin. Autoload files, and annotate models. * Use new plugin show route * DEV: Fix template If there is only a top level route for the admin show for the plugin, it will not be an `index` route, it will just be the route name itself as the top level. * Fix build and add styles to template --------- Co-authored-by: Martin Brennan <[email protected]>
- Loading branch information
1 parent
6bab8a2
commit 815aed3
Showing
35 changed files
with
237 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
inherit_gem: | ||
rubocop-discourse: stree-compat.yml | ||
rubocop-discourse: stree-compat.yml |
8 changes: 8 additions & 0 deletions
8
admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-antivirus-stats.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ajax } from "discourse/lib/ajax"; | ||
import DiscourseRoute from "discourse/routes/discourse"; | ||
|
||
export default class DiscourseAntivirusStatsRoute extends DiscourseRoute { | ||
model() { | ||
return ajax("/admin/plugins/discourse-antivirus/stats"); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...n/assets/javascripts/discourse/templates/admin-plugins/show/discourse-antivirus-stats.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<section class="antivirus-stats admin-detail pull-left"> | ||
<div class="antivirus-stats__header"> | ||
<h3>{{i18n "antivirus.stats.title"}}</h3> | ||
</div> | ||
|
||
<table class="antivirus-stats__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> | ||
|
||
<div class="antivirus-stats__sub-header"> | ||
<h4>{{i18n "antivirus.stats.data"}}</h4> | ||
</div> | ||
|
||
<table class="antivirus-stats__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
15
app/controllers/discourse_antivirus/admin/antivirus_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
app/controllers/discourse_antivirus/antivirus_controller.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/validators/discourse_antivirus/enable_discourse_antivirus_validator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseAntivirus | ||
class EnableDiscourseAntivirusValidator | ||
def initialize(opts = {}) | ||
@opts = opts | ||
end | ||
|
||
def valid_value?(val) | ||
return true if val == "f" | ||
|
||
DiscourseAntivirus::ClamAv.correctly_configured? | ||
end | ||
|
||
def error_message | ||
I18n.t("site_settings.errors.antivirus_srv_record_required") | ||
end | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
assets/javascripts/discourse/admin-discourse-antivirus-plugin-route-map.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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
17
assets/javascripts/discourse/routes/admin-plugins-antivirus.js
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
assets/javascripts/discourse/templates/admin/plugins-antivirus.hbs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.antivirus-stats { | ||
&__sub-header { | ||
margin-top: 15px; | ||
} | ||
|
||
&__header { | ||
margin-bottom: 5px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
DiscourseAntivirus::Engine.routes.draw do | ||
root to: "antivirus#index" | ||
get "/stats" => "antivirus#index" | ||
Discourse::Application.routes.draw do | ||
scope "/admin/plugins/discourse-antivirus", constraints: AdminConstraint.new do | ||
get "/stats" => "discourse_antivirus/admin/antivirus#index" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/discourse_antivirus/clamav.rb → lib/discourse_antivirus/clam_av.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.