Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Added latest missing changes from security scanning PR (#1289)
Browse files Browse the repository at this point in the history
- Not showing the flashy message "Unable to fetch newer tags data" for every polling.
- Showing "No vulnerabilities found" on tags#show panel istead of an empty space.
  • Loading branch information
vitoravelino committed Jul 19, 2017
1 parent 539755a commit d3454cf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
7 changes: 6 additions & 1 deletion app/assets/javascripts/modules/repositories/pages/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $(() => {
state: store.state,
isLoading: false,
notLoaded: false,
unableToFetchBefore: false,
tags: [],
};
},
Expand All @@ -51,14 +52,18 @@ $(() => {
RepositoriesService.get(id).then((response) => {
set(this, 'tags', response.body.tags);
set(this, 'notLoaded', false);
set(this, 'unableToFetchBefore', false);
}, () => {
// if the data never came,
// show message instead of table,
// otherwise only the alert
if (this.isLoading) {
set(this, 'notLoaded', true);
} else {
}

if (!this.isLoading && !this.unableToFetchBefore) {
Alert.show('Unable to fetch newer tags data');
set(this, 'unableToFetchBefore', true);
}
}).finally(() => {
setTimeout(() => this.loadData(), POLLING_VALUE);
Expand Down
6 changes: 1 addition & 5 deletions app/assets/javascripts/shared/components/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ const ALERT_ELEMENT = '#float-alert';
const TEXT_ALERT_ELEMENT = '#float-alert p';
const HIDE_TIMEOUT = 5000;

function scheduleHide() {
setTimeout(() => $(ALERT_ELEMENT).fadeOut(), HIDE_TIMEOUT);
}

function show(text, autohide = true) {
$(TEXT_ALERT_ELEMENT).html(text);
$(ALERT_ELEMENT).fadeIn();

if (autohide) {
scheduleHide();
setTimeout(() => $(ALERT_ELEMENT).fadeOut(), HIDE_TIMEOUT);
}
}

Expand Down
6 changes: 6 additions & 0 deletions app/helpers/repositories_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,10 @@ def name_and_link(tr, activity)
def security_vulns_enabled?
::Portus::Security.new(nil, nil).enabled?
end

# Returns true if any vulnerability is found
# Or false otherwise
def vulnerable?(vulnerabilities)
!vulnerabilities.select { |_, vulns| !vulns.empty? }.empty?
end
end
22 changes: 13 additions & 9 deletions app/views/tags/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@

.panel-body
span
- @vulnerabilities.each do |backend, vulns|
- next if vulns.empty?
- if vulnerable?(@vulnerabilities)
- @vulnerabilities.each do |backend, vulns|
- next if vulns.empty?

h5= backend
ul
- vulns.each do |v|
li
a href="#{v['Link']}"
= v["Name"]
| (severity: #{v["Severity"]})
h5= backend
ul
- vulns.each do |v|
li
a href="#{v['Link']}"
= v["Name"]
| (severity: #{v["Severity"]})

- else
p No vulnerabilities found
20 changes: 20 additions & 0 deletions spec/helpers/repositories_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,24 @@ def update_registry!(catalog)
expect(helper.security_vulns_enabled?).to be_falsy
end
end

describe "#vulnerable?" do
it "returns true if any security vulnerability server is configured" do
vulnerabilities = {
one: [[]],
two: []
}

expect(helper.vulnerable?(vulnerabilities)).to be_truthy
end

it "returns false if no security vulnerability server is configured" do
vulnerabilities = {
one: [],
two: []
}

expect(helper.vulnerable?(vulnerabilities)).to be_falsy
end
end
end

0 comments on commit d3454cf

Please sign in to comment.