diff --git a/app/webroot/theme/admin-third/Users/admin/form.php b/app/webroot/theme/admin-third/Users/admin/form.php index 69b170523f..930fc11e2f 100755 --- a/app/webroot/theme/admin-third/Users/admin/form.php +++ b/app/webroot/theme/admin-third/Users/admin/form.php @@ -146,6 +146,19 @@ class="helptext"> + +request->action == 'admin_add' || $deletable): ?> + + + BcForm->label('status', __d('baser_core', '利用状態')) ?> + + + BcForm->input('status', ['type' => 'checkbox', 'label' => __d('baser_core', '有効')]) ?> + BcForm->error('status') ?> + + + + BcForm->dispatchAfterForm() ?> diff --git a/lib/Baser/Config/Schema/users.php b/lib/Baser/Config/Schema/users.php index 76307cd2f4..538ab4a58e 100755 --- a/lib/Baser/Config/Schema/users.php +++ b/lib/Baser/Config/Schema/users.php @@ -28,6 +28,7 @@ public function after($event = []) { 'nickname' => ['type' => 'string', 'null' => true, 'default' => null], 'activate_key' => ['type' => 'string', 'null' => true, 'default' => null], 'activate_expire' => ['type' => 'datetime', 'null' => true, 'default' => null], + 'status' => ['type' => 'boolean', 'null' => true, 'default' => true], 'created' => ['type' => 'datetime', 'null' => true, 'default' => null], 'modified' => ['type' => 'datetime', 'null' => true, 'default' => null], 'indexes' => ['PRIMARY' => ['column' => 'id', 'unique' => 1]], diff --git a/lib/Baser/Config/update/4.8.0/alter_users.php b/lib/Baser/Config/update/4.8.0/alter_users.php new file mode 100755 index 0000000000..d6ce8fc5e7 --- /dev/null +++ b/lib/Baser/Config/update/4.8.0/alter_users.php @@ -0,0 +1,37 @@ + ['type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'], + 'name' => ['type' => 'string', 'null' => true, 'default' => null], + 'password' => ['type' => 'string', 'null' => true, 'default' => null], + 'real_name_1' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 50], + 'real_name_2' => ['type' => 'string', 'null' => true, 'default' => null, 'length' => 50], + 'email' => ['type' => 'string', 'null' => true, 'default' => null], + 'user_group_id' => ['type' => 'integer', 'null' => true, 'default' => null, 'length' => 4], + 'nickname' => ['type' => 'string', 'null' => true, 'default' => null], + 'activate_key' => ['type' => 'string', 'null' => true, 'default' => null], + 'activate_expire' => ['type' => 'datetime', 'null' => true, 'default' => null], + 'status' => ['type' => 'boolean', 'null' => true, 'default' => false], + 'created' => ['type' => 'datetime', 'null' => true, 'default' => null], + 'modified' => ['type' => 'datetime', 'null' => true, 'default' => null], + 'indexes' => ['PRIMARY' => ['column' => 'id', 'unique' => 1]], + ]; + +} diff --git a/lib/Baser/Config/update/4.8.0/updater.php b/lib/Baser/Config/update/4.8.0/updater.php new file mode 100644 index 0000000000..668e3eb8a8 --- /dev/null +++ b/lib/Baser/Config/update/4.8.0/updater.php @@ -0,0 +1,41 @@ + + * Copyright (c) baserCMS Users Community + * + * @copyright Copyright (c) baserCMS Users Community + * @link https://basercms.net baserCMS Project + * @package Baser.Config + * @since baserCMS v 4.8.0 + * @license https://basercms.net/license/index.html + */ + +/** + * 4.8.0 バージョン アップデートスクリプト + */ + +/** + * users テーブル構造変更 + */ +if ($this->loadSchema('4.8.0', '', 'users', 'alter')) { + $this->setUpdateLog('users テーブルの構造変更に成功しました。'); +} else { + $this->setUpdateLog('users テーブルの構造変更に失敗しました。', true); +} + +App::uses('User', 'Model'); + +$User = new User(); +$records = $User->find('all', ['recursive' => -1]); +$result = true; +foreach($records as $record) { + $record['User']['status'] = true; + if (!$User->save($record)) { + $result = false; + } +} +if ($result) { + $this->setUpdateLog('users テーブルの変換に成功しました。'); +} else { + $this->setUpdateLog('users テーブルの変換に失敗しました。', true); +} diff --git a/lib/Baser/Controller/BcAppController.php b/lib/Baser/Controller/BcAppController.php index 3837aa4913..585de6db2f 100644 --- a/lib/Baser/Controller/BcAppController.php +++ b/lib/Baser/Controller/BcAppController.php @@ -421,7 +421,8 @@ public function beforeFilter() } $conditions = [ $userModel . '.id' => $user['id'], - $userModel . '.' . $nameField => $user[$nameField] + $userModel . '.' . $nameField => $user[$nameField], + $userModel . '.status' => true ]; if (isset($User->belongsTo['UserGroup'])) { $UserGroup = ClassRegistry::init('UserGroup'); diff --git a/lib/Baser/Controller/Component/BcAuthConfigureComponent.php b/lib/Baser/Controller/Component/BcAuthConfigureComponent.php index b81e79ed10..bc236f2b43 100644 --- a/lib/Baser/Controller/Component/BcAuthConfigureComponent.php +++ b/lib/Baser/Controller/Component/BcAuthConfigureComponent.php @@ -125,7 +125,10 @@ public function setting($config) // 認証プレフィックスによるスコープ設定 $UserModel = ClassRegistry::init($config['userModel']); if (isset($UserModel->belongsTo['UserGroup']) && $config['auth_prefix'] && !$config['userScope']) { - $BcAuth->authenticate['Form']['scope'] = ['UserGroup.auth_prefix LIKE' => '%' . $config['auth_prefix'] . '%']; + $BcAuth->authenticate['Form']['scope'] = [ + 'UserGroup.auth_prefix LIKE' => '%' . $config['auth_prefix'] . '%', + 'User.status' => true + ]; } elseif ($config['userScope']) { $BcAuth->authenticate['Form']['scope'] = $config['userScope']; } diff --git a/lib/Baser/Model/User.php b/lib/Baser/Model/User.php index 04def85137..54deb27a59 100755 --- a/lib/Baser/Model/User.php +++ b/lib/Baser/Model/User.php @@ -158,6 +158,7 @@ public function getUserList($conditions = []) public function getDefaultValue() { $data[$this->alias]['user_group_id'] = Configure::read('BcApp.adminGroupId'); + $data[$this->alias]['status'] = true; return $data; } diff --git a/lib/Baser/Test/Case/Controller/Component/BcAuthConfigureComponentTest.php b/lib/Baser/Test/Case/Controller/Component/BcAuthConfigureComponentTest.php index 3eca63977b..261a7ad7e0 100644 --- a/lib/Baser/Test/Case/Controller/Component/BcAuthConfigureComponentTest.php +++ b/lib/Baser/Test/Case/Controller/Component/BcAuthConfigureComponentTest.php @@ -161,7 +161,10 @@ public function testSettingCheckValue($loginAction, $requestedPrefix, $userScope if (!empty($userScope)) { $expected['authenticate']['Form']['scope'] = $userScope; } else if (!empty($auth_prefix)) { - $expected['authenticate']['Form']['scope'] = ['UserGroup.auth_prefix LIKE' => '%' . $auth_prefix . '%']; + $expected['authenticate']['Form']['scope'] = [ + 'UserGroup.auth_prefix LIKE' => '%' . $auth_prefix . '%', + 'User.status' => true + ]; } // 判定 diff --git a/lib/Baser/Test/Case/Model/UserTest.php b/lib/Baser/Test/Case/Model/UserTest.php index ad9e4ae4af..6ac1517660 100644 --- a/lib/Baser/Test/Case/Model/UserTest.php +++ b/lib/Baser/Test/Case/Model/UserTest.php @@ -277,7 +277,10 @@ public function getUserListDataProvider() public function testGetDefaultValue() { $result = $this->User->getDefaultValue(); - $expected = ['User' => ['user_group_id' => 1]]; + $expected = ['User' => [ + 'user_group_id' => 1, + 'status' => true + ]]; $this->assertEquals($expected, $result, 'フォームの初期値が正しくありません'); }