From 17600fd6794c7763ae14537a8b7a345b1120b378 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Jun 02 2020 19:27:43 +0000 Subject: ✨ — Fix #174 — Show latest tag and commit of the instance It’s showed in about page and config API endpoint --- diff --git a/CHANGELOG b/CHANGELOG index 320c077..d046cfa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ Revision history for Lufi - Notifications when uploading and downloading files (#181) - Use Weblate instead of Zanata for translations (https://weblate.framasoft.org/projects/lufi/development/) - Add config API endpoint (#183) + - Show latest tag and commit of the instance in about page and config API endpoint (#174) 0.04.6 2019-11-07 - Now can send large files (>2Gio) while using a DB other than SQLite (#165) diff --git a/lib/Lufi/Controller/Misc.pm b/lib/Lufi/Controller/Misc.pm index fef0ea7..be2b9a1 100644 --- a/lib/Lufi/Controller/Misc.pm +++ b/lib/Lufi/Controller/Misc.pm @@ -32,7 +32,12 @@ sub change_lang { } sub about { - shift->render(template => 'about'); + my $c = shift; + + $c->render( + template => 'about', + version => $c->git_version + ); } sub config_infos { @@ -52,6 +57,7 @@ sub config_infos { keep_ip_during => $c->config('keep_ip_during'), stop_upload => (-f 'stop-upload' || -f 'stop-upload.manual') ? true : false, need_authentication => (defined($c->config('ldap')) || defined($c->config('htpasswd'))) ? true : false, + version => $c->git_version } ); } diff --git a/lib/Lufi/Plugin/Helpers.pm b/lib/Lufi/Plugin/Helpers.pm index b06fda0..293fb05 100644 --- a/lib/Lufi/Plugin/Helpers.pm +++ b/lib/Lufi/Plugin/Helpers.pm @@ -69,14 +69,15 @@ sub register { $app->helper(create_invitation_token => \&_create_invitation_token); $app->helper(is_guest => \&_is_guest); $app->helper(get_date_lang => \&_get_date_lang); + $app->helper(git_version => \&_git_version); } sub _pg { my $c = shift; - my $pgdb = $c->config('pgdb'); - my $port = (defined $pgdb->{port}) ? $pgdb->{port}: 5432; - my $addr = $c->pg_url({ + my $pgdb = $c->config('pgdb'); + my $port = (defined $pgdb->{port}) ? $pgdb->{port}: 5432; + my $addr = $c->pg_url({ host => $pgdb->{host}, port => $port, database => $pgdb->{database}, user => $pgdb->{user}, pwd => $pgdb->{pwd} }); state $pg = Mojo::Pg->new($addr); @@ -85,11 +86,11 @@ sub _pg { } sub _mysql { - my $c = shift; + my $c = shift; - my $mysqldb = $c->config('mysqldb'); - my $port = (defined $mysqldb->{port}) ? $mysqldb->{port}: 3306; - my $addr = $c->pg_url({ + my $mysqldb = $c->config('mysqldb'); + my $port = (defined $mysqldb->{port}) ? $mysqldb->{port}: 3306; + my $addr = $c->pg_url({ host => $mysqldb->{host}, port => $port, database => $mysqldb->{database}, user => $mysqldb->{user}, pwd => $mysqldb->{pwd} }); $addr =~ s/postgresql/mysql/; @@ -123,7 +124,7 @@ sub _provisioning { } sub _get_empty { - my $c = shift; + my $c = shift; my $ldfile = Lufi::DB::File->new(app => $c->app)->get_empty; @@ -219,7 +220,7 @@ my %date_langs = ( ); sub _get_date_lang { - my $c = shift; + my $c = shift; my $l = $c->languages(); @@ -231,4 +232,18 @@ sub _get_date_lang { return Date::Language->new('English'); } +sub _git_version { + my $c = shift; + + my $last_tag = `git describe --abbrev=0`; + my $last_commit = `git rev-parse HEAD`; + chomp $last_tag; + chomp $last_commit; + + return { + tag => $last_tag, + commit => $last_commit + } +} + 1; diff --git a/themes/default/lib/Lufi/I18N/en.po b/themes/default/lib/Lufi/I18N/en.po index 51b3c8d..cf37d06 100644 --- a/themes/default/lib/Lufi/I18N/en.po +++ b/themes/default/lib/Lufi/I18N/en.po @@ -94,7 +94,7 @@ msgstr "As Lufi is a free software licensed under of the terms of the %s', stash('version') +#: themes/default/templates/about.html.ep:22 +msgid "Latest commit of this instance: %1" +msgstr "Latest commit of this instance: %1" + +#. (sprintf('%s', stash('version') +#: themes/default/templates/about.html.ep:21 +msgid "Latest tag of this instance: %1" +msgstr "Latest tag of this instance: %1" + #: themes/default/templates/login.html.ep:15 msgid "Login" msgstr "Login" @@ -694,6 +704,10 @@ msgstr "Uploaded at" msgid "Uploaded files" msgstr "Uploaded files" +#: themes/default/templates/about.html.ep:20 +msgid "Version" +msgstr "Version" + #: themes/default/templates/partial/index.js.ep:31 msgid "Websocket communication error" msgstr "Websocket communication error" diff --git a/themes/default/lib/Lufi/I18N/fr.po b/themes/default/lib/Lufi/I18N/fr.po index d9a11b7..f8b3ed3 100644 --- a/themes/default/lib/Lufi/I18N/fr.po +++ b/themes/default/lib/Lufi/I18N/fr.po @@ -441,6 +441,16 @@ msgstr "Javascript est désactivé. Lufi ne fonctionnera pas." msgid "Language" msgstr "Langue" +#. (sprintf('%s', stash('version') +#: themes/default/templates/about.html.ep:22 +msgid "Latest commit of this instance: %1" +msgstr "Dernier commit de cette instance : %1" + +#. (sprintf('%s', stash('version') +#: themes/default/templates/about.html.ep:21 +msgid "Latest tag of this instance: %1" +msgstr "Dernière étiquette de cette instance : %1" + #: themes/default/templates/login.html.ep:15 msgid "Login" msgstr "Identifiant" @@ -833,6 +843,10 @@ msgstr "Envoyé le" msgid "Uploaded files" msgstr "Fichiers envoyés" +#: themes/default/templates/about.html.ep:20 +msgid "Version" +msgstr "Version" + #: themes/default/templates/partial/index.js.ep:30 msgid "Websocket communication error" msgstr "Erreur de communication WebSocket" diff --git a/themes/default/lib/Lufi/I18N/lufi.pot b/themes/default/lib/Lufi/I18N/lufi.pot index fa78471..c55bda4 100644 --- a/themes/default/lib/Lufi/I18N/lufi.pot +++ b/themes/default/lib/Lufi/I18N/lufi.pot @@ -94,7 +94,7 @@ msgstr "" msgid "Asking for file part XX1 of %1" msgstr "" -#: themes/default/templates/about.html.ep:20 +#: themes/default/templates/about.html.ep:23 msgid "Back to homepage" msgstr "" @@ -389,6 +389,16 @@ msgstr "" msgid "Language" msgstr "" +#. (sprintf('%s', stash('version') +#: themes/default/templates/about.html.ep:22 +msgid "Latest commit of this instance: %1" +msgstr "" + +#. (sprintf('%s', stash('version') +#: themes/default/templates/about.html.ep:21 +msgid "Latest tag of this instance: %1" +msgstr "" + #: themes/default/templates/login.html.ep:15 msgid "Login" msgstr "" @@ -694,6 +704,10 @@ msgstr "" msgid "Uploaded files" msgstr "" +#: themes/default/templates/about.html.ep:20 +msgid "Version" +msgstr "" + #: themes/default/templates/partial/index.js.ep:31 msgid "Websocket communication error" msgstr "" diff --git a/themes/default/templates/about.html.ep b/themes/default/templates/about.html.ep index 27c4854..bf491d5 100644 --- a/themes/default/templates/about.html.ep +++ b/themes/default/templates/about.html.ep @@ -17,5 +17,8 @@

<%== l('As Lufi is a free software licensed under of the terms of the AGPLv3, you can install it on you own server. Have a look on the Wiki for the procedure.') %>
<%== l('Get the source code on the official repository or on its Github mirror') %>

+

<%= l('Version') %>

+

<%== l('Latest tag of this instance: %1', sprintf('%s', stash('version')->{tag}, stash('version')->{tag})) %>

+

<%== l('Latest commit of this instance: %1', sprintf('%s', stash('version')->{commit}, stash('version')->{commit})) %>

<%= link_to url_for('/') => ( class => "btn waves-effect waves-light cyan" ) => begin %><%= l('Back to homepage') %><% end%>