Unverified Commit 91a20564 authored by Nicolas Widart's avatar Nicolas Widart

Merge branch '2.0'

* 2.0:
  Preparing 2.4.0 release
  Publish the new workshop configuration key
  CS: PSR1/2
  Adding changelog item
  Trigger an event before a user is created, allowing customising its data via listeners
  Adding workshop changelog
  Testing the feature of overwriting stub views.
  Testing the feature of overwriting stub views. Using realpath instead of base_path, leaving more options open
  Create a stub route files to overwrite default routes stub
  Add custom stubs folder (#344)
parents 987981c9 23e2e981
...@@ -5,8 +5,8 @@ namespace Modules\Core\Console; ...@@ -5,8 +5,8 @@ namespace Modules\Core\Console;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Modules\User\Permissions\PermissionsRemover; use Modules\User\Permissions\PermissionsRemover;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class DeleteModuleCommand extends Command class DeleteModuleCommand extends Command
{ {
...@@ -50,6 +50,7 @@ class DeleteModuleCommand extends Command ...@@ -50,6 +50,7 @@ class DeleteModuleCommand extends Command
} }
if ($this->confirm("Are you sure you wish to delete the [$module] module{$extra}?") === false) { if ($this->confirm("Are you sure you wish to delete the [$module] module{$extra}?") === false) {
$this->info('Nothing was deleted'); $this->info('Nothing was deleted');
return; return;
} }
...@@ -57,11 +58,13 @@ class DeleteModuleCommand extends Command ...@@ -57,11 +58,13 @@ class DeleteModuleCommand extends Command
if ($this->finder->exists($modulePath) === false) { if ($this->finder->exists($modulePath) === false) {
$this->error('This module does not exist'); $this->error('This module does not exist');
return; return;
} }
if (is_core_module($module) === true) { if (is_core_module($module) === true) {
$this->error('You cannot remove a core module.'); $this->error('You cannot remove a core module.');
return; return;
} }
......
...@@ -4,8 +4,8 @@ namespace Modules\Core\Console; ...@@ -4,8 +4,8 @@ namespace Modules\Core\Console;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Modules\Core\Downloader\Downloader; use Modules\Core\Downloader\Downloader;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
class DownloadModuleCommand extends Command class DownloadModuleCommand extends Command
...@@ -39,6 +39,7 @@ class DownloadModuleCommand extends Command ...@@ -39,6 +39,7 @@ class DownloadModuleCommand extends Command
$downloader->download($this->argument('name')); $downloader->download($this->argument('name'));
} catch (\Exception $e) { } catch (\Exception $e) {
$this->output->writeln("<error>{$e->getMessage()}</error>"); $this->output->writeln("<error>{$e->getMessage()}</error>");
return; return;
} }
...@@ -46,7 +47,7 @@ class DownloadModuleCommand extends Command ...@@ -46,7 +47,7 @@ class DownloadModuleCommand extends Command
$composer = $this->findComposer(); $composer = $this->findComposer();
$commands = [ $commands = [
$composer.' dump-autoload', $composer . ' dump-autoload',
]; ];
if ($this->option('migrations') === true || $this->option('demo') === true) { if ($this->option('migrations') === true || $this->option('demo') === true) {
$commands[] = "php artisan module:migrate $name"; $commands[] = "php artisan module:migrate $name";
...@@ -100,6 +101,7 @@ class DownloadModuleCommand extends Command ...@@ -100,6 +101,7 @@ class DownloadModuleCommand extends Command
if (str_contains($package, '/') === false) { if (str_contains($package, '/') === false) {
throw new \Exception('You need to use vendor/name structure'); throw new \Exception('You need to use vendor/name structure');
} }
return studly_case(substr(strrchr($package, '/'), 1)); return studly_case(substr(strrchr($package, '/'), 1));
} }
...@@ -110,9 +112,10 @@ class DownloadModuleCommand extends Command ...@@ -110,9 +112,10 @@ class DownloadModuleCommand extends Command
*/ */
protected function findComposer() protected function findComposer()
{ {
if (file_exists(getcwd().'/composer.phar')) { if (file_exists(getcwd() . '/composer.phar')) {
return '"'.PHP_BINARY.'" composer.phar'; return '"' . PHP_BINARY . '" composer.phar';
} }
return 'composer'; return 'composer';
} }
} }
...@@ -53,6 +53,7 @@ class Downloader ...@@ -53,6 +53,7 @@ class Downloader
if ($this->finder->isDirectory($directory) === true) { if ($this->finder->isDirectory($directory) === true) {
$this->output->writeln("<error>The folder [Modules/{$this->extractPackageNameFrom($package)}] already exists.</error>"); $this->output->writeln("<error>The folder [Modules/{$this->extractPackageNameFrom($package)}] already exists.</error>");
return; return;
} }
...@@ -99,7 +100,7 @@ class Downloader ...@@ -99,7 +100,7 @@ class Downloader
$progress->setFormat('[%bar%] %elapsed:6s%'); $progress->setFormat('[%bar%] %elapsed:6s%');
$response = (new Client)->get($latestVersionUrl, [ $response = (new Client)->get($latestVersionUrl, [
'progress' => function($downloadTotal, $downloadedBytes, $uploadTotal, $uploadedBytes) use ($progress) { 'progress' => function ($downloadTotal, $downloadedBytes, $uploadTotal, $uploadedBytes) use ($progress) {
$progress->advance(); $progress->advance();
}, },
]); ]);
...@@ -159,6 +160,7 @@ class Downloader ...@@ -159,6 +160,7 @@ class Downloader
if (str_contains($package, '/') === false) { if (str_contains($package, '/') === false) {
throw new \Exception('You need to use vendor/name structure'); throw new \Exception('You need to use vendor/name structure');
} }
return studly_case(substr(strrchr($package, '/'), 1)); return studly_case(substr(strrchr($package, '/'), 1));
} }
......
url: https://github.com/AsgardCms/Platform url: https://github.com/AsgardCms/Platform
versions: versions:
"2.4.0@unreleased": "2.4.0":
added: added:
- new blade directive for thumbnails <code>@thumbnail('path', 'thumbnailName')</code> - new blade directive for thumbnails <code>@thumbnail('path', 'thumbnailName')</code>
changed: changed:
......
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
namespace Modules\Page\Sidebar; namespace Modules\Page\Sidebar;
use Maatwebsite\Sidebar\Badge;
use Maatwebsite\Sidebar\Group; use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item; use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu; use Maatwebsite\Sidebar\Menu;
use Modules\Page\Repositories\PageRepository;
use Modules\User\Contracts\Authentication; use Modules\User\Contracts\Authentication;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace Modules\Translation\Http\Controllers\Api; namespace Modules\Translation\Http\Controllers\Api;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel; use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request; use Illuminate\Http\Request;
......
<?php
namespace Modules\User\Events;
final class UserIsCreating
{
/**
* @var array
*/
private $attributes;
public $original;
public function __construct(array $attributes)
{
$this->attributes = $attributes;
$this->original = $attributes;
}
/**
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @param array $attributes
*/
public function setAttributes(array $attributes)
{
$this->attributes = array_merge($this->attributes, $attributes);
}
}
...@@ -7,6 +7,7 @@ use Cartalyst\Sentinel\Laravel\Facades\Sentinel; ...@@ -7,6 +7,7 @@ use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Modules\User\Entities\Sentinel\User; use Modules\User\Entities\Sentinel\User;
use Modules\User\Events\UserHasRegistered; use Modules\User\Events\UserHasRegistered;
use Modules\User\Events\UserIsCreating;
use Modules\User\Events\UserIsUpdating; use Modules\User\Events\UserIsUpdating;
use Modules\User\Events\UserWasCreated; use Modules\User\Events\UserWasCreated;
use Modules\User\Events\UserWasUpdated; use Modules\User\Events\UserWasUpdated;
...@@ -48,7 +49,9 @@ class SentinelUserRepository implements UserRepository ...@@ -48,7 +49,9 @@ class SentinelUserRepository implements UserRepository
public function create(array $data, $activated = false) public function create(array $data, $activated = false)
{ {
$this->hashPassword($data); $this->hashPassword($data);
$user = $this->user->create((array) $data);
event($event = new UserIsCreating($data));
$user = $this->user->create($event->getAttributes());
if ($activated) { if ($activated) {
$this->activateUser($user); $this->activateUser($user);
......
...@@ -28,7 +28,7 @@ class PermissionsRemoverTest extends BaseUserTestCase ...@@ -28,7 +28,7 @@ class PermissionsRemoverTest extends BaseUserTestCase
$this->user->create([ $this->user->create([
'email' => 'n.widart@gmail.com', 'email' => 'n.widart@gmail.com',
'password' => 'demo1234', 'password' => 'demo1234',
'permissions' => ['dashboard.index' => true, 'user.users.index' => true, 'user.users.create' => true,] 'permissions' => ['dashboard.index' => true, 'user.users.index' => true, 'user.users.create' => true,],
]); ]);
$this->app->config->set('asgard.user.permissions', [ $this->app->config->set('asgard.user.permissions', [
'user.users' => [ 'user.users' => [
......
...@@ -5,6 +5,7 @@ namespace Modules\User\Tests; ...@@ -5,6 +5,7 @@ namespace Modules\User\Tests;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Modules\User\Entities\Sentinel\User; use Modules\User\Entities\Sentinel\User;
use Modules\User\Events\UserHasRegistered; use Modules\User\Events\UserHasRegistered;
use Modules\User\Events\UserIsCreating;
use Modules\User\Events\UserIsUpdating; use Modules\User\Events\UserIsUpdating;
use Modules\User\Events\UserWasCreated; use Modules\User\Events\UserWasCreated;
use Modules\User\Events\UserWasUpdated; use Modules\User\Events\UserWasUpdated;
...@@ -44,6 +45,69 @@ class SentinelUserRepositoryTest extends BaseUserTestCase ...@@ -44,6 +45,69 @@ class SentinelUserRepositoryTest extends BaseUserTestCase
$this->assertCount(1, $this->user->all()); $this->assertCount(1, $this->user->all());
} }
/** @test */
public function it_fires_event_when_user_is_creating()
{
Event::fake();
$user = $this->user->create([
'email' => 'n.widart@gmail.com',
'password' => 'demo1234',
]);
Event::assertDispatched(UserIsCreating::class, function ($e) use ($user) {
return $e->getAttributes()['email'] === $user->email;
});
}
/** @test */
public function it_can_change_data_when_it_is_creating_event()
{
Event::listen(UserIsCreating::class, function (UserIsCreating $event) {
$event->setAttributes(['email' => 'john@doe.com']);
});
$user = $this->user->create([
'email' => 'n.widart@gmail.com',
'password' => 'demo1234',
]);
$this->assertEquals('john@doe.com', $user->email);
}
/** @test */
public function it_can_change_the_data_multiple_times()
{
Event::listen(UserIsCreating::class, function (UserIsCreating $event) {
$event->setAttributes(['email' => 'john@doe.com']);
});
Event::listen(UserIsCreating::class, function (UserIsCreating $event) {
$event->setAttributes(['email' => 'jane@doe.com']);
});
$user = $this->user->create([
'email' => 'n.widart@gmail.com',
'password' => 'demo1234',
]);
$this->assertEquals('jane@doe.com', $user->email);
}
/** @test */
public function it_makes_sure_the_event_contains_original_attributes()
{
Event::fake();
$this->user->create([
'email' => 'n.widart@gmail.com',
'password' => 'demo1234',
]);
Event::assertDispatched(UserIsCreating::class, function ($e) {
return $e->original['email'] === 'n.widart@gmail.com';
});
}
/** @test */ /** @test */
public function it_fires_event_when_user_created() public function it_fires_event_when_user_created()
{ {
...@@ -92,7 +156,6 @@ class SentinelUserRepositoryTest extends BaseUserTestCase ...@@ -92,7 +156,6 @@ class SentinelUserRepositoryTest extends BaseUserTestCase
'password' => 'demo1234', 'password' => 'demo1234',
], ['User']); ], ['User']);
$hasher = app('sentinel.hasher'); $hasher = app('sentinel.hasher');
$this->assertTrue($hasher->check('demo1234', $userOne->password)); $this->assertTrue($hasher->check('demo1234', $userOne->password));
......
url: https://github.com/AsgardCms/Platform url: https://github.com/AsgardCms/Platform
versions: versions:
"2.4.0@unreleased": "2.4.0":
added:
- Trigger an event (<code>UserIsCreating</code>) before a user is created, allowing customising its data via listeners
changed: changed:
- Testing password hashing - Testing password hashing
- Moved the <code>CanFindUserWithBearerToken</code> to the <code>Trait</code> namespace - Moved the <code>CanFindUserWithBearerToken</code> to the <code>Trait</code> namespace
......
<?php <?php
return [ return [
/*
|--------------------------------------------------------------------------
| Custom Stubs Folder
|--------------------------------------------------------------------------
| You can specify place from which you would like to use stubs.
| e.g. "Modules/<module-name>/Resources/views/stubs"
| Only the customized stubs need to be in this folder.
| All other stubs will be loaded from Workshop Module folder.
| No custom stubs folder: null
*/
'custom-stubs-folder' => null,
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Custom Sidebar Class | Custom Sidebar Class
......
...@@ -83,6 +83,15 @@ abstract class Generator ...@@ -83,6 +83,15 @@ abstract class Generator
*/ */
protected function getStubPath($filename) protected function getStubPath($filename)
{ {
$folder = $this->config->get('asgard.workshop.config.custom-stubs-folder');
if ($folder !== null) {
$file = realpath($folder . '/' . $filename);
if ($file !== false) {
return $file;
}
}
return __DIR__ . "/../stubs/$filename"; return __DIR__ . "/../stubs/$filename";
} }
......
...@@ -488,6 +488,21 @@ class ModuleScaffoldTest extends BaseTestCase ...@@ -488,6 +488,21 @@ class ModuleScaffoldTest extends BaseTestCase
$this->cleanUp(); $this->cleanUp();
} }
/** @test */
public function it_can_overwrite_stub_files_with_custom_ones()
{
config()->set('asgard.workshop.config.custom-stubs-folder', __DIR__ . '/stubs');
$this->scaffoldModuleWithEloquent();
$path = $this->testModulePath . '/Http/backendRoutes.php';
$file = $this->finder->get($path);
$this->assertTrue($this->finder->isFile($path));
$this->assertContains('overwritten by custom config', $file);
$this->cleanUp();
}
/** /**
* Get the contents of composer.json file * Get the contents of composer.json file
* @return string * @return string
......
<?php
use Illuminate\Routing\Router;
/** @var Router $router */
// overwritten by custom config
$router->group(['prefix' =>'/$LOWERCASE_MODULE$'], function (Router $router) {
// append
});
url: https://github.com/AsgardCms/Platform url: https://github.com/AsgardCms/Platform
versions: versions:
"2.4.0":
added:
- Add the ability to set custom stubs folder used by generated modules
"2.0.0": "2.0.0":
added: added:
- Laravel 5.4 compatibility - Laravel 5.4 compatibility
......
url: https://github.com/AsgardCms/Platform url: https://github.com/AsgardCms/Platform
versions: versions:
"2.4.0@unreleased": "2.4.0":
changed: changed:
- Moved to using laravel.mix - Moved to using laravel.mix
- Dependencies are now handled by NPM instead of Bower - Dependencies are now handled by NPM instead of Bower
......
url: https://github.com/AsgardCms/Platform url: https://github.com/AsgardCms/Platform
versions: versions:
"2.4.0@unreleased": "2.4.0":
added: added:
- Moved to using laravel.mix - Moved to using laravel.mix
"2.0.0": "2.0.0":
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"laravel", "laravel",
"laravel5" "laravel5"
], ],
"version": "2.3.0", "version": "2.4.0",
"license": "MIT", "license": "MIT",
"type": "project", "type": "project",
"require": { "require": {
......
<?php <?php
return [ return [
/*
|--------------------------------------------------------------------------
| Custom Stubs Folder
|--------------------------------------------------------------------------
| You can specify place from which you would like to use stubs.
| e.g. "Modules/<module-name>/Resources/views/stubs"
| Only the customized stubs need to be in this folder.
| All other stubs will be loaded from Workshop Module folder.
| No custom stubs folder: null
*/
'custom-stubs-folder' => null,
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Custom Sidebar Class | Custom Sidebar Class
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment