Skip to content

Commit dceaba4

Browse files
committed
Feature: Check for updates every 24 hours
1 parent 6727873 commit dceaba4

File tree

11 files changed

+152
-8
lines changed

11 files changed

+152
-8
lines changed

.env.example

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ LOCKBOX_MASTER_KEY=replace_with_encryption_key
44

55
SECRET_KEY_BASE=replace_with_secret_key_base
66

7+
# Checks every 24 hours to see if a new version of ToolJet is available
8+
CHECK_FOR_UPDATES=check_if_updates_are_available
9+
710
GOOGLE_CLIENT_ID=
811
GOOGLE_CLIENT_SECRET=
912

@@ -14,5 +17,5 @@ SMTP_PASSWORD=
1417
SMTP_DOMAIN=
1518
SMTP_ADDRESS=
1619

17-
# DISABLE USER SIGNUPS (true or false)
18-
DISABLE_SIGNUPS=
20+
# DISABLE USER SIGNUPS (true or false). Default: true
21+
DISABLE_SIGNUPS=
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class MetadataController < ApplicationController
2+
def index
3+
4+
unless ENV.fetch('CHECK_FOR_UPDATES', true)
5+
return
6+
end
7+
8+
installed_version = TOOLJET_VERSION
9+
10+
metadata = Metadatum.first
11+
if metadata
12+
data = metadata.data
13+
else
14+
metadata = Metadatum.create(data: { last_checked: Time.now - 2.days })
15+
data = metadata.data
16+
end
17+
18+
if Time.now - data["last_checked"].to_time > 86400
19+
check_for_updates(data, installed_version)
20+
data = metadata.data
21+
end
22+
23+
render json: {
24+
latest_version: data["latest_version"],
25+
installed_version: installed_version,
26+
version_ignored: data["version_ignored"]
27+
}
28+
end
29+
30+
def skip_version
31+
data = Metadatum.first&.data
32+
data["version_ignored"] = true
33+
data["ignored_version"] = data["latest_version"]
34+
Metadatum.first.update(data: data)
35+
end
36+
37+
private
38+
def check_for_updates(current_data, installed_version)
39+
40+
response = HTTParty.post('https://hub.tooljet.io/updates',
41+
verify: false,
42+
body: { installed_version: installed_version }.to_json,
43+
headers: { "Content-Type" => "application/json" })
44+
45+
data = JSON.parse(response.body)
46+
latest_version = data["latest_version"]
47+
48+
if latest_version > '0.5.3' && latest_version != current_data["ignored_version"]
49+
current_data["latest_version"] = latest_version
50+
current_data["version_ignored"] = false
51+
end
52+
53+
current_data["last_checked"] = Time.now
54+
Metadatum.first.update(data: current_data)
55+
end
56+
end

app/models/metadatum.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Metadatum < ApplicationRecord
2+
end

config/routes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
post 'authenticate', to: 'authentication#authenticate'
4343
post 'signup', to: 'authentication#signup'
4444

45+
resources :metadata, only: [:index] do
46+
collection do
47+
post '/skip_version', to: 'metadata#skip_version'
48+
end
49+
end
50+
4551
get '/health', to: 'probe#health_check'
4652

4753
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class CreateMetadata < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :metadata, id: :uuid do |t|
4+
t.json :data
5+
6+
t.timestamps
7+
end
8+
end
9+
end

db/schema.rb

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/App/App.jsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Router, Route } from 'react-router-dom';
33
import { history } from '@/_helpers';
4-
import { authenticationService } from '@/_services';
4+
import { authenticationService, tooljetService } from '@/_services';
55
import { PrivateRoute } from '@/_components';
66
import { HomePage } from '@/HomePage';
77
import { LoginPage } from '@/LoginPage';
@@ -19,12 +19,15 @@ class App extends React.Component {
1919
super(props);
2020

2121
this.state = {
22-
currentUser: null
22+
currentUser: null,
23+
fetchedMetadata: false
2324
};
2425
}
2526

2627
componentDidMount() {
27-
authenticationService.currentUser.subscribe((x) => this.setState({ currentUser: x }));
28+
authenticationService.currentUser.subscribe((x) => {
29+
this.setState({ currentUser: x });
30+
});
2831
}
2932

3033
logout = () => {
@@ -33,11 +36,29 @@ class App extends React.Component {
3336
}
3437

3538
render() {
36-
const { currentUser } = this.state;
39+
const { currentUser, fetchedMetadata, updateAvailable } = this.state;
40+
41+
if(currentUser && fetchedMetadata === false) {
42+
tooljetService.fetchMetaData().then((data) => {
43+
this.setState({ fetchedMetadata: true });
44+
45+
if(data.installed_version < data.latest_version && data.version_ignored === false) {
46+
this.setState({ updateAvailable: true });
47+
}
48+
})
49+
}
50+
3751
return (
3852
<Router history={history}>
3953
<div>
40-
{currentUser && <div></div>}
54+
{updateAvailable && <div class="alert alert-info alert-dismissible" role="alert">
55+
<h3 class="mb-1">Update available</h3>
56+
<p>A new version of ToolJet has been released.</p>
57+
<div class="btn-list">
58+
<a href="https://docs.tooljet.io/docs/setup/updating" target="_blank" class="btn btn-info">Read release notes & update</a>
59+
<a onClick={() => { tooljetService.skipVersion(); this.setState({ updateAvailable: false }); }} class="btn">Skip this version</a>
60+
</div>
61+
</div>}
4162

4263
<ToastContainer />
4364

frontend/src/_services/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ export * from './appVersion.service';
88
export * from './organization_user.service';
99
export * from './openapi.service';
1010
export * from './folder.service';
11+
export * from './tooljet.service';
12+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import config from 'config';
2+
import { authHeader, handleResponse } from '@/_helpers';
3+
4+
export const tooljetService = {
5+
fetchMetaData,
6+
skipVersion
7+
};
8+
9+
function fetchMetaData() {
10+
const requestOptions = {
11+
method: 'GET',
12+
headers: authHeader()
13+
};
14+
15+
return fetch(`${config.apiUrl}/metadata`, requestOptions).then(handleResponse);
16+
}
17+
18+
function skipVersion() {
19+
const requestOptions = {
20+
method: 'POST',
21+
headers: authHeader()
22+
};
23+
24+
return fetch(`${config.apiUrl}/metadata/skip_version`, requestOptions).then(handleResponse);
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "test_helper"
2+
3+
class MetadataControllerTest < ActionDispatch::IntegrationTest
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

test/models/metadatum_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "test_helper"
2+
3+
class MetadatumTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)