Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ユーザーのステータス機能を追加 #2644

Open
wants to merge 3 commits into
base: dev-4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/webroot/theme/admin-third/Users/admin/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ class="helptext"><?php echo sprintf(__d('baser', 'ユーザーグループごと
</div>
</td>
</tr>

<?php if($this->request->action == 'admin_add' || $deletable): ?>
<tr>
<th class="col-head bca-form-table__label">
<?php echo $this->BcForm->label('status', __d('baser_core', '利用状態')) ?>
</th>
<td class="col-input bca-form-table__input">
<?php echo $this->BcForm->input('status', ['type' => 'checkbox', 'label' => __d('baser_core', '有効')]) ?>
<?php echo $this->BcForm->error('status') ?>
</td>
</tr>
<?php endif ?>

<?php echo $this->BcForm->dispatchAfterForm() ?>
</table>
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/Baser/Config/Schema/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
37 changes: 37 additions & 0 deletions lib/Baser/Config/update/4.8.0/alter_users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/* Users schema generated on: 2013-03-23 00:03:52 : 1363966852 */

class UsersSchema extends CakeSchema {

public $name = 'Users';

public $file = 'users.php';

public $connection = 'default';

public function before($event = []) {
return true;
}

public function after($event = []) {
}

public $users = [
'id' => ['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]],
];

}
41 changes: 41 additions & 0 deletions lib/Baser/Config/update/4.8.0/updater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* baserCMS : Based Website Development Project <http://basercms.net>
* Copyright (c) baserCMS Users Community <http://basercms.net/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);
}
3 changes: 2 additions & 1 deletion lib/Baser/Controller/BcAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 4 additions & 1 deletion lib/Baser/Controller/Component/BcAuthConfigureComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down
1 change: 1 addition & 0 deletions lib/Baser/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}

// 判定
Expand Down
5 changes: 4 additions & 1 deletion lib/Baser/Test/Case/Model/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, 'フォームの初期値が正しくありません');
}

Expand Down