diff --git a/src/API/HealthcheckController.php b/src/API/HealthcheckController.php index 3f333d65..9cb97aa5 100644 --- a/src/API/HealthcheckController.php +++ b/src/API/HealthcheckController.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace App\API; +use App\Constants; use FOS\RestBundle\Controller\Annotations as Rest; use FOS\RestBundle\View\View; use FOS\RestBundle\View\ViewHandlerInterface; @@ -46,4 +47,25 @@ class HealthcheckController extends Controller return $this->viewHandler->handle($view); } + + /** + * @SWG\Response( + * response=200, + * description="Returns version information about the current release", + * ) + * + * @Rest\Get(path="/version") + */ + public function versionAction() + { + $version = [ + 'version' => Constants::VERSION, + 'candidate' => Constants::STATUS, + 'semver' => Constants::VERSION . '-' . Constants::STATUS, + 'name' => Constants::NAME, + 'copyright' => 'Kimai 2 - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.', + ]; + + return $this->viewHandler->handle(new View($version, 200)); + } } diff --git a/src/Command/VersionCommand.php b/src/Command/VersionCommand.php new file mode 100644 index 00000000..3bdb4b40 --- /dev/null +++ b/src/Command/VersionCommand.php @@ -0,0 +1,73 @@ +setName('kimai:version') + ->setDescription('Receive version information') + ->setHelp('This command allows you to fetch various version information about Kimai.') + ->addOption('name', null, InputOption::VALUE_NONE, 'Display the major release name') + ->addOption('candidate', null, InputOption::VALUE_NONE, 'Display the current version candidate (e.g. "stable" or "dev")') + ->addOption('short', null, InputOption::VALUE_NONE, 'Display the version only') + ->addOption('semver', null, InputOption::VALUE_NONE, 'Semantical versioning (SEMVER) compatible version string') + ; + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new SymfonyStyle($input, $output); + + if ($input->getOption('semver')) { + $io->writeln(Constants::VERSION . '-' . Constants::STATUS); + + return; + } + + if ($input->getOption('short')) { + $io->writeln(Constants::VERSION); + + return; + } + + if ($input->getOption('name')) { + $io->writeln(Constants::NAME); + + return; + } + + if ($input->getOption('candidate')) { + $io->writeln(Constants::STATUS); + + return; + } + + $io->writeln('Kimai 2 - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.'); + } +} diff --git a/src/Constants.php b/src/Constants.php index 1cd45515..0c932be2 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -15,9 +15,17 @@ namespace App; class Constants { /** - * Currently only used for informational purpose in the footer + * The current release version */ - public const VERSION = '2.0 dev'; + public const VERSION = 0.5; + /** + * The release name + */ + public const NAME = 'Ayumi'; + /** + * The current release status + */ + public const STATUS = 'dev'; /** * Used in multiple views */ diff --git a/src/Migrations/Version20180924111853.php b/src/Migrations/Version20180924111853.php index 375c387a..23edc7f1 100644 --- a/src/Migrations/Version20180924111853.php +++ b/src/Migrations/Version20180924111853.php @@ -40,6 +40,7 @@ final class Version20180924111853 extends AbstractMigration $this->addSql('DROP TABLE __temp__' . $invoiceTemplates); $this->addSql('CREATE UNIQUE INDEX UNIQ_1626CFE95E237E06 ON ' . $invoiceTemplates . ' (name)'); } else { + $this->addSql('UPDATE ' . $invoiceTemplates . ' SET name=SUBSTRING(name, 1, 60)'); $this->addSql('ALTER TABLE ' . $invoiceTemplates . ' CHANGE name name VARCHAR(60) NOT NULL, CHANGE vat vat DOUBLE PRECISION DEFAULT 0'); } } diff --git a/templates/sidebar/home.html.twig b/templates/sidebar/home.html.twig index 1b5608fd..919ff7f8 100644 --- a/templates/sidebar/home.html.twig +++ b/templates/sidebar/home.html.twig @@ -1,3 +1,4 @@ +{% set version = constant('App\\Constants::VERSION') ~ ' ' ~ constant('App\\Constants::STATUS') %} -

{{ 'home.title'|trans({}, 'sidebar') }}

+

{{ 'home.title'|trans({'%version%': version}, 'sidebar') }}

- {{ 'home.betainfo'|trans({'%version%': constant('App\\Constants::VERSION'), '%url%': constant('App\\Constants::GITHUB')}, 'sidebar')|raw|nl2br }} + {{ 'home.betainfo'|trans({'%version%': version, '%url%': constant('App\\Constants::GITHUB')}, 'sidebar')|raw|nl2br }}
{{ 'made.by.license'|trans({}, 'sidebar')|raw }}
diff --git a/tests/API/HealthcheckControllerTest.php b/tests/API/HealthcheckControllerTest.php index 851bf62e..c0a96ef1 100644 --- a/tests/API/HealthcheckControllerTest.php +++ b/tests/API/HealthcheckControllerTest.php @@ -9,6 +9,7 @@ namespace App\Tests\API; +use App\Constants; use App\Entity\User; /** @@ -31,4 +32,28 @@ class HealthcheckControllerTest extends APIControllerBaseTest $this->assertInternalType('array', $result); $this->assertEquals(['message' => 'pong'], $result); } + + public function testVersion() + { + $client = $this->getClientForAuthenticatedUser(User::ROLE_USER); + $this->assertAccessIsGranted($client, '/api/version'); + $result = json_decode($client->getResponse()->getContent(), true); + + $this->assertInternalType('array', $result); + + $this->assertArrayHasKey('version', $result); + $this->assertArrayHasKey('candidate', $result); + $this->assertArrayHasKey('semver', $result); + $this->assertArrayHasKey('name', $result); + $this->assertArrayHasKey('copyright', $result); + + $this->assertSame(Constants::VERSION, $result['version']); + $this->assertEquals(Constants::STATUS, $result['candidate']); + $this->assertEquals(Constants::VERSION . '-' . Constants::STATUS, $result['semver']); + $this->assertEquals(Constants::NAME, $result['name']); + $this->assertEquals( + 'Kimai 2 - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.', + $result['copyright'] + ); + } } diff --git a/tests/Command/VersionCommandTest.php b/tests/Command/VersionCommandTest.php new file mode 100644 index 00000000..229b5efa --- /dev/null +++ b/tests/Command/VersionCommandTest.php @@ -0,0 +1,67 @@ +application = new Application($kernel); + + $this->application->add(new VersionCommand()); + } + + /** + * @dataProvider getTestData + */ + public function testVersion(array $options, $result) + { + $commandTester = $this->getCommandTester($options); + $output = $commandTester->getDisplay(); + $this->assertEquals($result . PHP_EOL, $output); + } + + public function getTestData() + { + return [ + [[], 'Kimai 2 - ' . Constants::VERSION . ' ' . Constants::STATUS . ' (' . Constants::NAME . ') by Kevin Papst and contributors.'], + [['--name' => true], Constants::NAME], + [['--candidate' => true], Constants::STATUS], + [['--short' => true], Constants::VERSION], + [['--semver' => true], Constants::VERSION . '-' . Constants::STATUS], + ]; + } + + protected function getCommandTester(array $options = []) + { + $command = $this->application->find('kimai:version'); + $commandTester = new CommandTester($command); + $inputs = array_merge(['command' => $command->getName()], $options); + $commandTester->execute($inputs); + + return $commandTester; + } +} diff --git a/translations/sidebar.de.xliff b/translations/sidebar.de.xliff index 21c3ca29..1dc5b0e3 100644 --- a/translations/sidebar.de.xliff +++ b/translations/sidebar.de.xliff @@ -4,13 +4,13 @@ home.title - Kimai v2 - Vorab Version + Kimai v2 - %version% home.betainfo Kimai. - Diese neue Version %version% ist aktuell noch in einer frühen Phase der Entwicklung und wurde vorab veröffentlicht, um frühzeitig Rückmeldungen ihrer Benutzer zu sammeln und deren Ideen in die weitere Planung zu integrieren. + Diese neue Version ist aktuell noch in einer frühen Phase der Entwicklung und wurde vorab veröffentlicht, um frühzeitig Rückmeldungen ihrer Benutzer zu sammeln und deren Ideen in die weitere Planung zu integrieren. Um bei der Verbesserung von Kimai zu helfen, schicken Sie mir bitte eine Nachricht auf der verlinkten Webseite. Egal ob Fragen, Fehlermeldungen oder Ideen für Erweiterungen, Ihr Feedback ist wertvoll! ]]> diff --git a/translations/sidebar.en.xliff b/translations/sidebar.en.xliff index 36fa9aee..d526e397 100644 --- a/translations/sidebar.en.xliff +++ b/translations/sidebar.en.xliff @@ -4,13 +4,13 @@ home.title - Kimai v2 - Pre-Version + Kimai v2 - %version% home.betainfo Kimai. - This new version %version% is currently in an early stage of development and has been published in advance to collect feedback from its users and integrate their ideas into further planning. + This new version is currently in an early stage of development and has been published in advance to collect feedback from its users and integrate their ideas into further planning. To help me improve Kimai, please send your message on the linked website. Whether you have questions, error messages or ideas for enhancements, your feedback is valuable! ]]> diff --git a/translations/sidebar.es.xliff b/translations/sidebar.es.xliff index 0ab423cd..ed60b1f7 100644 --- a/translations/sidebar.es.xliff +++ b/translations/sidebar.es.xliff @@ -4,13 +4,13 @@ home.title - Kimai v2 - Pre-Version + Kimai v2 - %version% home.betainfo Kimai. - Esta nueva versión %version% se encuentra en una etapa inicial de desarrollo y ha sido publicada con la intención de recolectar feedback de los usuarios para incluir sus ideas en planes futuros.. + Esta nueva versión se encuentra en una etapa inicial de desarrollo y ha sido publicada con la intención de recolectar feedback de los usuarios para incluir sus ideas en planes futuros.. Para ayudar a mejorar Kimai, por favor enviar sus comentarios al sitio. Sus comentarios, ideas para mejorar o reportes de errores son valiosos y agradezco el tiempo para enviárnoslos! ]]> diff --git a/translations/sidebar.fr.xliff b/translations/sidebar.fr.xliff index e9a1148c..6221f5ee 100644 --- a/translations/sidebar.fr.xliff +++ b/translations/sidebar.fr.xliff @@ -4,13 +4,13 @@ home.title - Kimai v2 - Pré-version + Kimai v2 - %version% home.betainfo Kimai. - Cette nouvelle version %version% est actuellement à un stade précoce de développement et a été publié à l'avance afin de recueillir les commentaires de ses utilisateurs et d'intégrer leurs idées dans la planification à venir. + Cette nouvelle version est actuellement à un stade précoce de développement et a été publié à l'avance afin de recueillir les commentaires de ses utilisateurs et d'intégrer leurs idées dans la planification à venir. Pour m'aider à améliorerKimai, merci de poster votre message sur le site lié. Que vous ayez des questions, des messages ou des idées d'améliorations, vos retours sont précieux ! ]]> diff --git a/translations/sidebar.it.xliff b/translations/sidebar.it.xliff index f03b09e7..c0f48ad9 100755 --- a/translations/sidebar.it.xliff +++ b/translations/sidebar.it.xliff @@ -4,13 +4,13 @@ home.title - Kimai v2 - Pre-Version + Kimai v2 - %version% home.betainfo Kimai. - This new version %version% is currently in an early stage of development and has been published in advance to collect feedback from its users and integrate their ideas into further planning. + This new version is currently in an early stage of development and has been published in advance to collect feedback from its users and integrate their ideas into further planning. To help me improve Kimai, please send your message on the linked website. Whether you have questions, error messages or ideas for enhancements, your feedback is valuable! ]]> diff --git a/translations/sidebar.ru.xliff b/translations/sidebar.ru.xliff index e040f1fb..04e616f7 100644 --- a/translations/sidebar.ru.xliff +++ b/translations/sidebar.ru.xliff @@ -4,7 +4,7 @@ home.title - Kimai v2 - Предварительная версия + Kimai v2 - %version% home.betainfo diff --git a/var/docs/installation.md b/var/docs/installation.md index c2d92453..2bb3eea4 100644 --- a/var/docs/installation.md +++ b/var/docs/installation.md @@ -90,14 +90,14 @@ You just imported demo data, to test the application in its full beauty and with You can now login with these accounts: -| Username | Password | Role | -|---|:---:|---| -| clara_customer | kitten | Customer | -| john_user | kitten | User | -| chris_user | kitten | User (deactivated) | -| tony_teamlead | kitten | Teamlead | -| anna_admin | kitten | Administrator | -| susan_super | kitten | Super-Administrator | +| Username | Password | API Key | Role | +|---|:---:|:---:|---| +| clara_customer| kitten | api_kitten |Customer | +| john_user| kitten | api_kitten |User | +| chris_user| kitten | api_kitten |User (deactivated) | +| tony_teamlead| kitten | api_kitten |Teamlead | +| anna_admin| kitten | api_kitten |Administrator | +| susan_super| kitten | api_kitten |Super-Administrator | Demo data can always be deleted by dropping the schema and re-creating it. The `kimai:reset-dev` command can always be executed later on to reset your dev database and cache. diff --git a/var/docs/internal.md b/var/docs/internal.md index 0da983cc..d9a3da46 100644 --- a/var/docs/internal.md +++ b/var/docs/internal.md @@ -6,8 +6,9 @@ Internal documentation for project maintainers - Prepare a GitHub release-draft - Change .github_changelog_generator config accordingly to new release tag (increase future release) +- Change version constants in `src/Constants.php` - Create CHANGELOG.md with [github-changelog-generator](https://github.com/github-changelog-generator/github-changelog-generator]) by running `github_changelog_generator kevinpapst/kimai2` -- Push a release branch and add it as last PR merge into master +- Push a release branch and merge it as last PR into master - Edit the release-draft and add the "Full changelog" link + everything from CHANGELOG.md related to the new version - Create the release - Post a new issue at [YunoHost tracker for Kimai 2](https://github.com/YunoHost-Apps/kimai2_ynh)