Skip to content

Commit

Permalink
B #3167: Fix upgrade banner (#3950)
Browse files Browse the repository at this point in the history
Was triggering false positives.
  • Loading branch information
jloboescalona2 authored and Tino Vázquez committed Nov 18, 2019
1 parent 6cd81d3 commit 704f944
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 61 deletions.
93 changes: 57 additions & 36 deletions src/sunstone/public/app/tabs/official-support-tab/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,6 @@ define(function(require) {
var RESOURCE = "official-support";
var TAB_ID = require("./tabId");

var majorVersion = function(version){
var r = 0;
if(version && version.length){
var major = version.substring(0, version.lastIndexOf("."));
if(major && major.length){
r = parseFloat(major);
}
}
return r;
};

var minorVersion = function(version){
var r = 0;
if(version && version.length){
var minor = version.substring(version.lastIndexOf(".")+1);
if(minor && minor.length){
r = parseFloat(minor);
}
}
return r;
};

var _actions = {
"Support.check":{
type: "list",
Expand All @@ -66,25 +44,68 @@ define(function(require) {
if($("#footer>a").length){
var localVersion = $("#footer>a").text().replace("OpenNebula ", "");
if(req && req.version && req.version!=="0" && localVersion.length){
var version = req.version;
var remoteMajorVersion = majorVersion(version);
var remoteMinorVersion = minorVersion(version);
var localMajorVersion = majorVersion(localVersion);
var localMinorVersion = minorVersion(localVersion);
var link = $("<a/>", {href:"https://opennebula.org/software/"}).text(
"(new version available: " + version + ")"
);
if(remoteMajorVersion > localMajorVersion){
$("#latest_version").show().empty().append(link);
return;
}
if(remoteMajorVersion === localMajorVersion && remoteMinorVersion > localMinorVersion){
var gitVersion = req.version;
var splitGitVersion = gitVersion.split(".");
var splitGitLocalVersion = localVersion.split(".");

var major = false;
var minor = false;
var message = false;

splitGitVersion.forEach(function(position, index){
var numberPosition = parseInt(position);
var numberLocalPosition = parseInt(splitGitLocalVersion[index]);

switch (index) {
case 0:
if(numberPosition > numberLocalPosition){
message = true;
return;
}
break;
case 1:
if(numberPosition > numberLocalPosition && major){
message = true;
return;
}
break;
case 2:
if(numberPosition > numberLocalPosition && major && minor){
message = true;
return;
}
break;
default:
break;
}

if(numberPosition === numberLocalPosition){
switch (index) {
case 0:
major = true;
break;
case 1:
minor = true;
break;
default:
break;
}
}

});

if (message){
var link = $("<a/>", {href:"https://opennebula.org/software/"}).text(
"(new version available: " + gitVersion + ")"
);
$("#latest_version").show().empty().append(link);
$("#li_upgrade-top-tab").show();
return;
}

}
}
$("#latest_version").hide().empty();

},
error: function(request){
if (request && request.status && request.status >= 400) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ define(function(require) {
}

function _check_last_version_support(){
$("#li_upgrade-top-tab").hide();
Sunstone.runAction("Support.checkversion");
}

Expand Down
43 changes: 19 additions & 24 deletions src/sunstone/routes/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,17 @@ def check_zendesk_api_gem
get '/support/check/version' do
$conf[:one_version_time] = 0 if $conf[:one_version_time].nil?
$conf[:one_last_version] = '0' if $conf[:one_last_version].nil?

def returnRoute(version,httpCode=200)
return [httpCode, JSON.pretty_generate(:version => version )]
end

find = 'release-'
validate_time = Time.now.to_i - $conf[:one_version_time]

if validate_time < 86400
return [200, JSON.pretty_generate(:version => $conf[:one_last_version])]
return returnRoute($conf[:one_last_version])
end

begin
http = Curl.get(GITHUB_TAGS_URL) do |request|
if !$conf[:proxy].nil? && !$conf[:proxy].empty?
Expand All @@ -266,7 +271,7 @@ def check_zendesk_api_gem
request.headers['User-Agent'] = 'OpenNebula Version Validation'
end
rescue StandardError
return [400, JSON.pretty_generate(:version => 0)]
return returnRoute(0, 400)
end

if !http.nil? && http.response_code == 200
Expand All @@ -277,35 +282,25 @@ def check_zendesk_api_gem
!tag['name'].empty? &&
tag['name'].start_with?(find)

version = tag['name'].tr(find, '')
split_version = version.split('.')
git_version = tag['name'].tr(find, '')
split_version = git_version.split('.')

gem_git_version = Gem::Version.new(git_version)
gem_local_version = Gem::Version.new($conf[:one_last_version])

next unless split_version &&
split_version[1] &&
split_version[1].to_i &&
split_version[1].to_i.even?

memory_version = $conf[:one_last_version]
minor_version =
version.slice(version.rindex('.').to_i + 1..-1).to_i

if version.to_f > memory_version.to_f
$conf[:one_last_version] = version
end

memory_version_index = memory_version.rindex('.').to_i
minor_memory_version =
memory_version.slice(memory_version_index.to_i + 1..-1).to_i

if version.to_f == memory_version.to_f &&
minor_version >= minor_memory_version
$conf[:one_last_version] = version
if gem_git_version > gem_local_version
$conf[:one_last_version] = git_version
$conf[:one_version_time] = Time.now.to_i
end
return returnRoute($conf[:one_last_version])
end
$conf[:one_version_time] = Time.now.to_i
[200, JSON.pretty_generate(:version => $conf[:one_last_version])]
else
[400, JSON.pretty_generate(:version => 0)]
end
return returnRoute(0, 400)
end

post '/support/request/:id/action' do
Expand Down
2 changes: 1 addition & 1 deletion src/sunstone/sunstone-server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
}

UPGRADE = {
:upgrade => "<span style='color: #0098c3'>Upgrade Available</span>&nbsp;<span style='color:#DC7D24'><i class='fas fa-exclamation-circle'></i></span>",
:upgrade => "<span style='color: #0098c3' id='itemUpdate' style='display:none;'>Upgrade Available</span>&nbsp;<span style='color:#DC7D24'><i class='fas fa-exclamation-circle'></i></span>",
:no_upgrade => "",
:url => "http://opennebula.org/software/"
}
Expand Down

0 comments on commit 704f944

Please sign in to comment.