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

fix #3153 【5.1】識別名称:エイリアスに漢字カナひらがなが登録できてしまう【サイト管理>サイト編集】 #3158

Merged
merged 4 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 11 additions & 1 deletion plugins/baser-core/src/Model/Table/SitesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public function validationDefault(Validator $validator): Validator
'provider' => 'bc',
'message' => __d('baser_core', '識別名称は、半角英数・ハイフン(-)・アンダースコア(_)で入力してください。')
]]);
$validator
->scalar('alias')
->maxLength('alias', 50, __d('baser_core', 'エイリアスは50文字以内で入力してください。'))
->notEmptyString('alias', __d('baser_core', 'エイリアスを入力してください。'))
->add('alias', [
'nameAlphaNumericPlus' => [
'rule' => ['alphaNumericPlus'],
'provider' => 'bc',
'message' => __d('baser_core', 'エイリアスは、半角英数・ハイフン(-)・アンダースコア(_)で入力してください。')
]]);
$validator
->scalar('display_name')
->maxLength('display_name', 50, __d('baser_core', 'サイト名は50文字以内で入力してください。'))
Expand Down Expand Up @@ -745,7 +755,7 @@ public function save(
if($request) {
$session = Router::getRequest()->getSession();
$currentSite = $session->read('BcApp.Admin.currentSite');
if ($currentSite && $success->id === $currentSite->id) {
if ($success && $currentSite && $success->id === $currentSite->id) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryuring バリデーションを発生したら$success=falseになったのでWarmingを出てしまいました。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HungDV2022 $success の判定は、755行目に入れてください

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryuring こちらを修正しました。確認お願いします。

$session->write('BcApp.Admin.currentSite', $success);
}
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/baser-core/src/Service/Admin/SitesAdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use BaserCore\Annotation\Checked;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\Paging\PaginatedInterface;
use Cake\Routing\Router;
use Cake\Utility\Inflector;

Expand All @@ -35,7 +36,7 @@ class SitesAdminService extends SitesService implements SitesAdminServiceInterfa

/**
* 一覧画面用のデータを取得する
* @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface $sites
* @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface|PaginatedInterface $sites
* @return array
* @checked
* @noTodo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\Paging\PaginatedInterface;

/**
* SitesAdminServiceInterface
Expand All @@ -23,7 +24,7 @@ interface SitesAdminServiceInterface

/**
* 一覧画面用のデータを取得する
* @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface $sites
* @param \Cake\ORM\ResultSet|\Cake\Datasource\ResultSetInterface|PaginatedInterface $sites
* @return array
* @checked
* @noTodo
Expand Down
4 changes: 2 additions & 2 deletions plugins/baser-core/tests/Factory/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ protected function setDefaultTemplate(): void
$this->setDefaultData(function (Generator $faker) {
return [
'name' => $faker->text(255),
'real_name_1' => $faker->text(50),
'real_name_2' => $faker->text(50),
'real_name_1' => $faker->text(5),
'real_name_2' => $faker->text(5),
'password' => 'password',
'email' => $faker->email(),
'nickname' => '',
Expand Down
26 changes: 26 additions & 0 deletions plugins/baser-core/tests/TestCase/Model/Table/SitesTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ public function tearDown(): void
parent::tearDown();
}

/**
* test validationDefault alias
*/
public function testValidationDefault_alias()
{
//バリデーションを発生した場合
$validator = $this->Sites->getValidator('default');
$errors = $validator->validate([
'alias' => '漢字'
]);
$this->assertEquals('エイリアスは、半角英数・ハイフン(-)・アンダースコア(_)で入力してください。', current($errors['alias']));

$validator = $this->Sites->getValidator('default');
$errors = $validator->validate([
'alias' => str_repeat('a', 51)
]);
$this->assertEquals('エイリアスは50文字以内で入力してください。', current($errors['alias']));

//バリデーションを発生しない場合
$validator = $this->Sites->getValidator('default');
$errors = $validator->validate([
'alias' => 'aaaaaaa'
]);
$this->assertArrayNotHasKey('alias', $errors);
}

/**
* 公開されている全てのサイトを取得する
*/
Expand Down
Loading