diff --git a/common/config/bootstrap.php b/common/config/bootstrap.php index 278f3db..f53af26 100644 --- a/common/config/bootstrap.php +++ b/common/config/bootstrap.php @@ -2,4 +2,3 @@ Yii::setAlias('@common', dirname(__DIR__)); Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console'); Yii::setAlias('@kcadmin', dirname(dirname(__DIR__)) . '/kcadmin'); -Yii::setAlias('@blobt', dirname(dirname(__DIR__)) . '/vendor/blobt'); diff --git a/common/config/main.php b/common/config/main.php index 9be3e17..0df2e70 100644 --- a/common/config/main.php +++ b/common/config/main.php @@ -1,13 +1,18 @@ [ '@bower' => '@vendor/bower-asset', - '@npm' => '@vendor/npm-asset', + '@npm' => '@vendor/npm-asset', + '@blobt' => '@vendor/blobt' ], 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], + 'authManager' => [ + 'class' => 'yii\rbac\DbManager', + ], ], ]; diff --git a/composer.json b/composer.json index 2f09d88..768fceb 100644 --- a/composer.json +++ b/composer.json @@ -1,34 +1,38 @@ { - "name": "blobt/kcbasic", - "description": "This is a fast template using for small project in KcDev.", - "type": "project", - "license": "MIT", - "authors": [ - { - "name": "blobt", - "email": "380255922@qq.com" - } - ], - "minimum-stability": "dev", - "require": { - "php": ">=7.1.0", - "yiisoft/yii2": "~2.0.14", - "yiisoft/yii2-bootstrap": "^2.0@dev", - "yiisoft/yii2-gii": "^2.0@dev" - }, - "repositories": { - "kc_packagist": { - "type": "composer", - "url": "https://packagist.kcshop.com.cn/" - }, + "name": "blobt/kcbasic", + "description": "This is a fast template using for small project in KcDev.", + "type": "project", + "license": "MIT", + "authors": [ + { + "name": "blobt", + "email": "380255922@qq.com" + } + ], + "minimum-stability": "dev", + "require": { + "php": ">=7.1.0", + "yiisoft/yii2": "~2.0.14", + "yiisoft/yii2-bootstrap": "^2.0@dev" + }, + "repositories": { + "asset_packagist": { + "type": "composer", + "url": "https://asset-packagist.org" + }, + "kc_packagist": { + "type": "composer", + "url": "https://packagist.kcshop.com.cn/" + }, - "packagist": { - "type": "composer", - "url": "https://packagist.phpcomposer.com" - } - }, - "require-dev": { - "yiisoft/yii2-debug": "^2.0@dev", - "kint-php/kint": "dev-master" - } + "packagist": { + "type": "composer", + "url": "https://packagist.phpcomposer.com" + } + }, + "require-dev": { + "yiisoft/yii2-debug": "^2.0@dev", + "kint-php/kint": "dev-master", + "yiisoft/yii2-gii": "^2.0@dev" + } } diff --git a/composer.lock b/composer.lock index 88d69ce..c59a1f7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3a4228dae33737e4c38ff88dd6a56a10", + "content-hash": "f3ddaead9bc7b0924e8f9ccf68c842ff", "packages": [ { "name": "bower-asset/bootstrap", @@ -322,44 +322,6 @@ ], "time": "2018-02-23T01:58:20+00:00" }, - { - "name": "phpspec/php-diff", - "version": "v1.1.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/php-diff.git", - "reference": "0464787bfa7cd13576c5a1e318709768798bec6a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/php-diff/zipball/0464787bfa7cd13576c5a1e318709768798bec6a", - "reference": "0464787bfa7cd13576c5a1e318709768798bec6a", - "shasum": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Diff": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Chris Boulton", - "homepage": "http://github.com/chrisboulton" - } - ], - "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", - "time": "2016-04-07T12:29:16+00:00" - }, { "name": "yiisoft/yii2", "version": "dev-master", @@ -577,57 +539,6 @@ "yii2" ], "time": "2019-05-28T08:14:44+00:00" - }, - { - "name": "yiisoft/yii2-gii", - "version": "2.1.0", - "source": { - "type": "git", - "url": "https://github.com/yiisoft/yii2-gii.git", - "reference": "d1c18f0dcbd72ab285acd320c56b1aa2554e06fa" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/d1c18f0dcbd72ab285acd320c56b1aa2554e06fa", - "reference": "d1c18f0dcbd72ab285acd320c56b1aa2554e06fa", - "shasum": "" - }, - "require": { - "phpspec/php-diff": "^1.1.0", - "yiisoft/yii2": "~2.0.14" - }, - "require-dev": { - "phpunit/phpunit": "<7", - "yiisoft/yii2-coding-standards": "~2.0" - }, - "type": "yii2-extension", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "yii\\gii\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Qiang Xue", - "email": "qiang.xue@gmail.com" - } - ], - "description": "The Gii extension for the Yii framework", - "keywords": [ - "code generator", - "gii", - "yii2" - ], - "time": "2019-03-17T19:23:15+00:00" } ], "packages-dev": [ @@ -701,6 +612,44 @@ ], "time": "2019-07-11T17:29:14+00:00" }, + { + "name": "phpspec/php-diff", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/php-diff.git", + "reference": "0464787bfa7cd13576c5a1e318709768798bec6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/php-diff/zipball/0464787bfa7cd13576c5a1e318709768798bec6a", + "reference": "0464787bfa7cd13576c5a1e318709768798bec6a", + "shasum": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Diff": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Chris Boulton", + "homepage": "http://github.com/chrisboulton" + } + ], + "description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).", + "time": "2016-04-07T12:29:16+00:00" + }, { "name": "yiisoft/yii2-debug", "version": "2.1.5", @@ -757,15 +706,66 @@ "yii2" ], "time": "2019-06-04T14:21:49+00:00" + }, + { + "name": "yiisoft/yii2-gii", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/yiisoft/yii2-gii.git", + "reference": "d1c18f0dcbd72ab285acd320c56b1aa2554e06fa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/d1c18f0dcbd72ab285acd320c56b1aa2554e06fa", + "reference": "d1c18f0dcbd72ab285acd320c56b1aa2554e06fa", + "shasum": "" + }, + "require": { + "phpspec/php-diff": "^1.1.0", + "yiisoft/yii2": "~2.0.14" + }, + "require-dev": { + "phpunit/phpunit": "<7", + "yiisoft/yii2-coding-standards": "~2.0" + }, + "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "yii\\gii\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Qiang Xue", + "email": "qiang.xue@gmail.com" + } + ], + "description": "The Gii extension for the Yii framework", + "keywords": [ + "code generator", + "gii", + "yii2" + ], + "time": "2019-03-17T19:23:15+00:00" } ], "aliases": [], "minimum-stability": "dev", "stability-flags": { "yiisoft/yii2-bootstrap": 20, - "yiisoft/yii2-gii": 20, "yiisoft/yii2-debug": 20, - "kint-php/kint": 20 + "kint-php/kint": 20, + "yiisoft/yii2-gii": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/console/migrations/m140506_102106_rbac_init.php b/console/migrations/m140506_102106_rbac_init.php new file mode 100644 index 0000000..e94afec --- /dev/null +++ b/console/migrations/m140506_102106_rbac_init.php @@ -0,0 +1,170 @@ + + * @since 2.0 + */ +class m140506_102106_rbac_init extends \yii\db\Migration +{ + /** + * @throws yii\base\InvalidConfigException + * @return DbManager + */ + protected function getAuthManager() + { + $authManager = Yii::$app->getAuthManager(); + if (!$authManager instanceof DbManager) { + throw new InvalidConfigException('You should configure "authManager" component to use database before executing this migration.'); + } + + return $authManager; + } + + /** + * @return bool + */ + protected function isMSSQL() + { + return $this->db->driverName === 'mssql' || $this->db->driverName === 'sqlsrv' || $this->db->driverName === 'dblib'; + } + + protected function isOracle() + { + return $this->db->driverName === 'oci'; + } + + /** + * {@inheritdoc} + */ + public function up() + { + $authManager = $this->getAuthManager(); + $this->db = $authManager->db; + $schema = $this->db->getSchema()->defaultSchema; + + $tableOptions = null; + if ($this->db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable($authManager->ruleTable, [ + 'name' => $this->string(64)->notNull(), + 'data' => $this->binary(), + 'created_at' => $this->integer(), + 'updated_at' => $this->integer(), + 'PRIMARY KEY ([[name]])', + ], $tableOptions); + + $this->createTable($authManager->itemTable, [ + 'name' => $this->string(64)->notNull(), + 'type' => $this->smallInteger()->notNull(), + 'description' => $this->text(), + 'rule_name' => $this->string(64), + 'data' => $this->binary(), + 'created_at' => $this->integer(), + 'updated_at' => $this->integer(), + 'PRIMARY KEY ([[name]])', + 'FOREIGN KEY ([[rule_name]]) REFERENCES ' . $authManager->ruleTable . ' ([[name]])' . + $this->buildFkClause('ON DELETE SET NULL', 'ON UPDATE CASCADE'), + ], $tableOptions); + $this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type'); + + $this->createTable($authManager->itemChildTable, [ + 'parent' => $this->string(64)->notNull(), + 'child' => $this->string(64)->notNull(), + 'PRIMARY KEY ([[parent]], [[child]])', + 'FOREIGN KEY ([[parent]]) REFERENCES ' . $authManager->itemTable . ' ([[name]])' . + $this->buildFkClause('ON DELETE CASCADE', 'ON UPDATE CASCADE'), + 'FOREIGN KEY ([[child]]) REFERENCES ' . $authManager->itemTable . ' ([[name]])' . + $this->buildFkClause('ON DELETE CASCADE', 'ON UPDATE CASCADE'), + ], $tableOptions); + + $this->createTable($authManager->assignmentTable, [ + 'item_name' => $this->string(64)->notNull(), + 'user_id' => $this->string(64)->notNull(), + 'created_at' => $this->integer(), + 'PRIMARY KEY ([[item_name]], [[user_id]])', + 'FOREIGN KEY ([[item_name]]) REFERENCES ' . $authManager->itemTable . ' ([[name]])' . + $this->buildFkClause('ON DELETE CASCADE', 'ON UPDATE CASCADE'), + ], $tableOptions); + + if ($this->isMSSQL()) { + $this->execute("CREATE TRIGGER {$schema}.trigger_auth_item_child + ON {$schema}.{$authManager->itemTable} + INSTEAD OF DELETE, UPDATE + AS + DECLARE @old_name VARCHAR (64) = (SELECT name FROM deleted) + DECLARE @new_name VARCHAR (64) = (SELECT name FROM inserted) + BEGIN + IF COLUMNS_UPDATED() > 0 + BEGIN + IF @old_name <> @new_name + BEGIN + ALTER TABLE {$authManager->itemChildTable} NOCHECK CONSTRAINT FK__auth_item__child; + UPDATE {$authManager->itemChildTable} SET child = @new_name WHERE child = @old_name; + END + UPDATE {$authManager->itemTable} + SET name = (SELECT name FROM inserted), + type = (SELECT type FROM inserted), + description = (SELECT description FROM inserted), + rule_name = (SELECT rule_name FROM inserted), + data = (SELECT data FROM inserted), + created_at = (SELECT created_at FROM inserted), + updated_at = (SELECT updated_at FROM inserted) + WHERE name IN (SELECT name FROM deleted) + IF @old_name <> @new_name + BEGIN + ALTER TABLE {$authManager->itemChildTable} CHECK CONSTRAINT FK__auth_item__child; + END + END + ELSE + BEGIN + DELETE FROM {$schema}.{$authManager->itemChildTable} WHERE parent IN (SELECT name FROM deleted) OR child IN (SELECT name FROM deleted); + DELETE FROM {$schema}.{$authManager->itemTable} WHERE name IN (SELECT name FROM deleted); + END + END;"); + } + } + + /** + * {@inheritdoc} + */ + public function down() + { + $authManager = $this->getAuthManager(); + $this->db = $authManager->db; + + if ($this->isMSSQL()) { + $this->execute('DROP TRIGGER {$schema}.trigger_auth_item_child;'); + } + + $this->dropTable($authManager->assignmentTable); + $this->dropTable($authManager->itemChildTable); + $this->dropTable($authManager->itemTable); + $this->dropTable($authManager->ruleTable); + } + + protected function buildFkClause($delete = '', $update = '') + { + if ($this->isMSSQL()) { + return ''; + } + + if ($this->isOracle()) { + return ' ' . $delete; + } + + return implode(' ', ['', $delete, $update]); + } +} diff --git a/console/migrations/m170907_052038_rbac_add_index_on_auth_assignment_user_id.php b/console/migrations/m170907_052038_rbac_add_index_on_auth_assignment_user_id.php new file mode 100644 index 0000000..061da00 --- /dev/null +++ b/console/migrations/m170907_052038_rbac_add_index_on_auth_assignment_user_id.php @@ -0,0 +1,60 @@ + + * @since 2.0.13 + */ +class m170907_052038_rbac_add_index_on_auth_assignment_user_id extends Migration +{ + public $column = 'user_id'; + public $index = 'auth_assignment_user_id_idx'; + + /** + * @throws yii\base\InvalidConfigException + * @return DbManager + */ + protected function getAuthManager() + { + $authManager = Yii::$app->getAuthManager(); + if (!$authManager instanceof DbManager) { + throw new InvalidConfigException('You should configure "authManager" component to use database before executing this migration.'); + } + + return $authManager; + } + + /** + * {@inheritdoc} + */ + public function up() + { + $authManager = $this->getAuthManager(); + $this->db = $authManager->db; + + $this->createIndex($this->index, $authManager->assignmentTable, $this->column); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $authManager = $this->getAuthManager(); + $this->db = $authManager->db; + + $this->dropIndex($this->index, $authManager->assignmentTable); + } +} diff --git a/console/migrations/m180523_151638_rbac_updates_indexes_without_prefix.php b/console/migrations/m180523_151638_rbac_updates_indexes_without_prefix.php new file mode 100644 index 0000000..f5882eb --- /dev/null +++ b/console/migrations/m180523_151638_rbac_updates_indexes_without_prefix.php @@ -0,0 +1,64 @@ + + * @since 2.0.16 + */ +class m180523_151638_rbac_updates_indexes_without_prefix extends Migration +{ + /** + * @throws yii\base\InvalidConfigException + * @return DbManager + */ + protected function getAuthManager() + { + $authManager = Yii::$app->getAuthManager(); + if (!$authManager instanceof DbManager) { + throw new InvalidConfigException('You should configure "authManager" component to use database before executing this migration.'); + } + + return $authManager; + } + + /** + * {@inheritdoc} + */ + public function up() + { + $authManager = $this->getAuthManager(); + + $this->dropIndex('auth_assignment_user_id_idx', $authManager->assignmentTable); + $this->createIndex('{{%idx-auth_assignment-user_id}}', $authManager->assignmentTable, 'user_id'); + + $this->dropIndex('idx-auth_item-type', $authManager->itemTable); + $this->createIndex('{{%idx-auth_item-type}}', $authManager->itemTable, 'type'); + } + + /** + * {@inheritdoc} + */ + public function down() + { + $authManager = $this->getAuthManager(); + + $this->dropIndex('{{%idx-auth_assignment-user_id}}', $authManager->assignmentTable); + $this->createIndex('auth_assignment_user_id_idx', $authManager->assignmentTable, 'user_id'); + + + $this->dropIndex('{{%idx-auth_item-type}}', $authManager->itemTable); + $this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type'); + } +} diff --git a/console/migrations/m190802_072830_add_category.php b/console/migrations/m190802_072830_add_category.php new file mode 100644 index 0000000..a76f38f --- /dev/null +++ b/console/migrations/m190802_072830_add_category.php @@ -0,0 +1,42 @@ + + * @author Alexander Kochetov + * @link http://www.yiiframework.com/ + * @copyright 2008 Yii Software LLC + * @license http://www.yiiframework.com/license/ + * @since 2.0 + */ + +drop table if exists `auth_assignment`; +drop table if exists `auth_item_child`; +drop table if exists `auth_item`; +drop table if exists `auth_rule`; + +create table `auth_rule` +( + `name` varchar(64) not null, + `data` blob, + `created_at` integer, + `updated_at` integer, + primary key (`name`) +) engine InnoDB; + +create table `auth_item` +( + `name` varchar(64) not null, + `type` smallint not null, + `description` text, + `rule_name` varchar(64), + `data` blob, + `created_at` integer, + `updated_at` integer, + primary key (`name`), + foreign key (`rule_name`) references `auth_rule` (`name`) on delete set null on update cascade, + key `type` (`type`) +) engine InnoDB; + +create table `auth_item_child` +( + `parent` varchar(64) not null, + `child` varchar(64) not null, + primary key (`parent`, `child`), + foreign key (`parent`) references `auth_item` (`name`) on delete cascade on update cascade, + foreign key (`child`) references `auth_item` (`name`) on delete cascade on update cascade +) engine InnoDB; + +create table `auth_assignment` +( + `item_name` varchar(64) not null, + `user_id` varchar(64) not null, + `created_at` integer, + primary key (`item_name`, `user_id`), + foreign key (`item_name`) references `auth_item` (`name`) on delete cascade on update cascade, + key `auth_assignment_user_id_idx` (`user_id`) +) engine InnoDB; diff --git a/kcadmin/assets/AppAsset.php b/kcadmin/assets/AppAsset.php index 0a10ea3..63b8e8d 100644 --- a/kcadmin/assets/AppAsset.php +++ b/kcadmin/assets/AppAsset.php @@ -12,7 +12,6 @@ class AppAsset extends AssetBundle public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ - 'css/reset.css', 'css/site.css', ]; public $js = [ diff --git a/kcadmin/config/main.php b/kcadmin/config/main.php index ec2b02c..089261d 100644 --- a/kcadmin/config/main.php +++ b/kcadmin/config/main.php @@ -1,9 +1,7 @@ [ 'class' => VerbFilter::className(), 'actions' => [ - 'logout' => ['post'], +// 'logout' => ['post'], ], ], ]; @@ -98,10 +98,8 @@ class SiteController extends Controller { } public function actionTest() { - $model = new LoginForm(); return $this->render('test', [ - 'name' => 'blobt', - 'model' => $model + 'name' => 'blobt' ]); } diff --git a/kcadmin/views/layouts/breadcrumb.php b/kcadmin/views/layouts/breadcrumb.php new file mode 100644 index 0000000..a159020 --- /dev/null +++ b/kcadmin/views/layouts/breadcrumb.php @@ -0,0 +1,13 @@ + +title)): ?> +

title ?>params['subtitle'])): ?>params['subtitle'] ?>

+ + 'ol', + 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], +]); +?> \ No newline at end of file diff --git a/kcadmin/views/layouts/footer.php b/kcadmin/views/layouts/footer.php new file mode 100644 index 0000000..a0a801d --- /dev/null +++ b/kcadmin/views/layouts/footer.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/kcadmin/views/layouts/header.php b/kcadmin/views/layouts/header.php new file mode 100644 index 0000000..2bbba81 --- /dev/null +++ b/kcadmin/views/layouts/header.php @@ -0,0 +1,88 @@ + +
+ + + + +
\ No newline at end of file diff --git a/kcadmin/views/layouts/main.php b/kcadmin/views/layouts/main.php index a23f7a0..421217b 100644 --- a/kcadmin/views/layouts/main.php +++ b/kcadmin/views/layouts/main.php @@ -7,8 +7,6 @@ use yii\helpers\Html; use yii\bootstrap\Nav; use yii\bootstrap\NavBar; use yii\widgets\Breadcrumbs; -use common\widgets\Alert; -use yii\bootstrap\Dropdown; AppAsset::register($this); ?> @@ -18,61 +16,29 @@ AppAsset::register($this); - + registerCsrfMetaTags() ?> <?= Html::encode($this->title) ?> head() ?> - + beginBody() ?> - -