Skip to content

Commit

Permalink
Merge branch 'develop' into wip/vite-mix-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxwilko committed Jul 14, 2024
2 parents 72f1e29 + cb51ce9 commit 9b252d6
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 94 deletions.
2 changes: 1 addition & 1 deletion modules/backend/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function registerConsole()
$this->registerConsoleCommand('create.controller', \Backend\Console\CreateController::class);
$this->registerConsoleCommand('create.formwidget', \Backend\Console\CreateFormWidget::class);
$this->registerConsoleCommand('create.reportwidget', \Backend\Console\CreateReportWidget::class);

$this->registerConsoleCommand('user.create', \Backend\Console\UserCreate::class);
$this->registerConsoleCommand('winter.passwd', \Backend\Console\WinterPasswd::class);
}

Expand Down
6 changes: 3 additions & 3 deletions modules/backend/classes/Controller.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php namespace Backend\Classes;
<?php

namespace Backend\Classes;

use Lang;
use View;
use Flash;
use Config;
use Closure;
use Request;
use Backend;
use Session;
use Redirect;
use Response;
use Exception;
Expand Down
87 changes: 87 additions & 0 deletions modules/backend/console/UserCreate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Backend\Console;

use Backend\Models\User;
use Backend\Models\UserRole;
use Illuminate\Support\Facades\Config;
use Winter\Storm\Console\Command;

class UserCreate extends Command
{
use \Winter\Storm\Console\Traits\ConfirmsWithInput;

/**
* @var string The console command name.
*/
protected static $defaultName = 'user:create';

/**
* @var string The name and signature of this command.
*/
protected $signature = 'user:create email
{email : The email address of the user to create.}
{--password= : The password for the user.}
{--fname= : The first name of the user.}
{--lname= : The last name of the user.}
{--role= : The role to assign the user to. <info>Use the role\'s code</info>}
{--f|force : Force the operation to run and ignore production warnings and confirmation questions.}';

/**
* @var string The console command description.
*/
protected $description = 'Creates a backend user.';

/**
* Execute the console command.
*/
public function handle(): int
{
$email = $this->argument('email');

if (
Config::get('app.env', 'production') !== 'local'
&& !$this->option('force')
&& !$this->confirmWithInput("CAUTION, currently working with non-local data. Please confirm the user email address", $email)
) {
return 1;
}

if (User::where('email', $email)->exists()) {
$this->error('A user with that email already exists.');
return 1;
}

$data = [
'email' => $email,
'password' => $this->option('password') ?: $this->secret('Password'),
'first_name' => $this->option('fname') ?: $this->ask('First name', ''),
'last_name' => $this->option('lname') ?: $this->ask('Last name', ''),
'role_id' => (
$role = UserRole::where(
'code',
$this->option('role') ?: $this->choice(
'Role',
UserRole::lists('name', 'code')
)
)->firstOrFail()
)->id,
];

$data['password_confirmation'] = $data['password'];

$user = User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'login' => $data['email'],
'email' => $data['email'],
'role_id' => $data['role_id'],
'password' => $data['password'],
'password_confirmation' => $data['password'],
]);

$this->info("User {$user->email} created successfully with the {$role->name} role.");

return 0;
}
}
24 changes: 12 additions & 12 deletions modules/backend/layouts/_head.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
<?= e(trans($this->pageTitle)) ?> | <?= e(Backend\Models\BrandSetting::get('app_name')) ?>
</title>
<?php
$coreBuild = System\Models\Parameter::get('system::core.build', 1);

// Styles
$styles = [
Url::asset('modules/system/assets/ui/storm.css'),
Url::asset('modules/system/assets/ui/icons.css'),
Backend::skinAsset('assets/css/winter.css'),
];
foreach ($styles as $style) {
$this->addCss($style, [
'build' => 'core',
'order' => 1,
]);
}

// Scripts
$scripts = [
Expand Down Expand Up @@ -49,18 +53,14 @@
Backend::skinAsset('assets/js/winter.flyout.js'),
Backend::skinAsset('assets/js/winter.tabformexpandcontrols.js'),
]);
foreach ($scripts as $script) {
$this->addJs($script, [
'build' => 'core',
'order' => 1,
]);
}
?>

<?php foreach ($styles as $style): ?>
<link href="<?= $style . '?v=' . $coreBuild; ?>" rel="stylesheet" importance="high">
<link href="<?= $style . '?v=' . $coreBuild; ?>" rel="preload" as="style" importance="high">
<?php endforeach; ?>

<?php foreach ($scripts as $script): ?>
<script data-cfasync="false" src="<?= $script . '?v=' . $coreBuild; ?>" importance="high"></script>
<link href="<?= $script . '?v=' . $coreBuild; ?>" rel="preload" as="script" importance="high">
<?php endforeach; ?>

<?php if (!Config::get('cms.enableBackendServiceWorkers', false)): ?>
<script>
"use strict";
Expand Down
22 changes: 12 additions & 10 deletions modules/backend/layouts/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
Url::asset('modules/system/assets/ui/icons.css'),
Backend::skinAsset('assets/css/winter.css'),
];
foreach ($styles as $style) {
$this->addCss($style, [
'build' => 'core',
'order' => 1,
]);
}
$scripts = [
Backend::skinAsset('assets/js/vendor/jquery.min.js'),
Backend::skinAsset('assets/js/vendor/jquery-migrate.min.js'),
Expand All @@ -26,18 +32,14 @@
Url::asset('modules/backend/assets/js/auth/auth.js'),
Url::asset('modules/system/assets/js/lang/lang.'.App::getLocale().'.js'),
];
foreach ($scripts as $script) {
$this->addJs($script, [
'build' => 'core',
'order' => 1,
]);
}
?>

<?php foreach ($styles as $style): ?>
<link href="<?= $style . '?v=' . $coreBuild; ?>" rel="stylesheet" importance="high">
<link href="<?= $style . '?v=' . $coreBuild; ?>" rel="preload" as="style" importance="high">
<?php endforeach; ?>

<?php foreach ($scripts as $script): ?>
<script data-cfasync="false" src="<?= $script . '?v=' . $coreBuild; ?>" importance="high"></script>
<link href="<?= $script . '?v=' . $coreBuild; ?>" rel="preload" as="script" importance="high">
<?php endforeach; ?>

<?php if (!Config::get('cms.enableBackendServiceWorkers', false)): ?>
<script>
"use strict";
Expand Down
4 changes: 2 additions & 2 deletions modules/cms/lang/ru/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
'not_found' => 'Тема для редактирования не найдена.',
'not_match' => 'Объект, который вы пытаетесь открыть, не принадлежит редактируемой теме. Пожалуйста, обновите страницу.',
],
'settings_menu' => 'Фронтенд темы',
'settings_menu_description' => 'Управление темой интерфейса',
'settings_menu' => 'Фронтенд тема',
'settings_menu_description' => 'Управление и настройка параметров темы.',
'default_tab' => 'Свойства',
'name_label' => 'Название',
'name_create_placeholder' => 'Название новой темы',
Expand Down
8 changes: 7 additions & 1 deletion modules/system/lang/ru/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
'menu_description' => 'Просмотр системного журнала событий.',
'empty_link' => 'Очистить журнал событий',
'empty_loading'=> 'Очищение журнала событий...',
'empty_success'=> 'Успешное очищение журнала событий.',
'empty_success'=> 'Журнал событий очищен',
'return_link'=> 'Вернуться в журнал событий',
'id' => 'ID',
'id_label' => 'ID события',
Expand Down Expand Up @@ -465,4 +465,10 @@
'previous' => 'Предыдущий',
'next' => 'Следующий',
],
'datetime' => [
'today' => 'Сегодня',
'yesterday' => 'Вчера',
'tomorrow' => 'Завтра',
'at' => ':date в :time',
],
];
62 changes: 53 additions & 9 deletions modules/system/tests/traits/AssetMakerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

use System\Tests\Bootstrap\TestCase;
use System\Traits\AssetMaker;
use System\Traits\EventEmitter;
use System\Traits\ViewMaker;
use Winter\Storm\Support\Facades\Url;

class AssetMakerStub
{
use AssetMaker;
use ViewMaker; // Needed for guessViewPath(), which is used to set default assetPath
use ViewMaker; // Needed for `guessViewPath()`, which is used to set default assetPath
use EventEmitter; // Needed for `addAsset()`
}

class AssetMakerTest extends TestCase
{
private $stub;
private AssetMakerStub $stub;

public function setUp() : void
{
Expand All @@ -26,7 +29,7 @@ public function setUp() : void
// Tests
//

public function testGetLocalPath()
public function testGetLocalPath(): void
{
$basePath = base_path();

Expand All @@ -50,28 +53,69 @@ public function testGetLocalPath()
$this->assertEquals(realpath($basePath.'/some/wild/absolute/path/'), realpath($resolvedPath));
}

public function testGetAssetPath()
public function testGetAssetPath(): void
{
$assetPath = 'my/path/assets';

$hostUrl = Url::to('/');

// assetPath is ignored since we use pathSymbol for plugins
$path = $this->stub->getAssetPath('$/author/plugin/assets/js/myAsset.js', $assetPath);
$this->assertEquals('http://localhost/plugins/author/plugin/assets/js/myAsset.js', $path);
$this->assertEquals($hostUrl . 'plugins/author/plugin/assets/js/myAsset.js', $path);

// assetPath is ignored since we use pathSymbol for theme
$path = $this->stub->getAssetPath('#/mytheme/assets/js/myAsset.js', $assetPath);
$this->assertEquals('http://localhost/themes/mytheme/assets/js/myAsset.js', $path);
$this->assertEquals($hostUrl . 'themes/mytheme/assets/js/myAsset.js', $path);

// assetPath is ignored since we use pathSymbol for app root
$path = $this->stub->getAssetPath('~/plugins/author/plugin/assets/js/myAsset.js', $assetPath);
$this->assertEquals('http://localhost/plugins/author/plugin/assets/js/myAsset.js', $path);
$this->assertEquals($hostUrl . 'plugins/author/plugin/assets/js/myAsset.js', $path);

// assetPath is used since we use a relative path without pathSymbol
$path = $this->stub->getAssetPath('js/myAsset.js', $assetPath);
$this->assertEquals('http://localhost/' . $assetPath . '/js/myAsset.js', $path);
$this->assertEquals($hostUrl . $assetPath . '/js/myAsset.js', $path);

// assetPath is ignored since we use an absolute path
$path = $this->stub->getAssetPath('/js/myAsset.js', $assetPath);
$this->assertEquals('http://localhost/js/myAsset.js', $path);
$this->assertEquals($hostUrl . 'js/myAsset.js', $path);
}

public function testAssetOrdering(): void
{
$hostUrl = Url::to('/');

// Test specified priorities
$this->stub->addCss('mySecond.css', [
'order' => 2,
]);
$this->stub->addCss('myThird.css', [
'order' => 3,
]);
$this->stub->addCss('myFirst.css', [
'order' => 1,
]);

$assets = $this->stub->getAssetPaths();

$this->assertEquals([
$hostUrl . 'myFirst.css',
$hostUrl . 'mySecond.css',
$hostUrl . 'myThird.css',
], $assets['css']);

// Test first-come, first-served - these assets will be prioritised the default 100.
$this->stub->flushAssets();

$this->stub->addCss('myFirst.css');
$this->stub->addCss('mySecond.css');
$this->stub->addCss('myThird.css');

$assets = $this->stub->getAssetPaths();

$this->assertEquals([
$hostUrl . 'myFirst.css',
$hostUrl . 'mySecond.css',
$hostUrl . 'myThird.css',
], $assets['css']);
}
}
Loading

0 comments on commit 9b252d6

Please sign in to comment.