Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/baserproject/ucmitz into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Mar 27, 2023
2 parents 20b324f + d3ffca9 commit dc6193f
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 722 deletions.
Binary file modified plugins/baser-core/resources/locales/en_US/baser_core.mo
Binary file not shown.
1,030 changes: 318 additions & 712 deletions plugins/baser-core/resources/locales/en_US/baser_core.po

Large diffs are not rendered by default.

38 changes: 36 additions & 2 deletions plugins/bc-blog/src/Controller/Api/BlogContentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use BaserCore\Utility\BcUtil;
use BcBlog\Service\BlogContentsServiceInterface;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Exception\ForbiddenException;
use Cake\ORM\Exception\PersistenceFailedException;

/**
Expand All @@ -25,6 +26,19 @@
class BlogContentsController extends BcApiController
{

/**
* initialize
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function initialize(): void
{
parent::initialize();
$this->Authentication->allowUnauthenticated(['index', 'view']);
}

/**
* [API] ブログコンテンツー一覧取得
*
Expand All @@ -36,8 +50,18 @@ class BlogContentsController extends BcApiController
public function index(BlogContentsServiceInterface $blogContentsService)
{
$this->request->allowMethod(['get']);

$queryParams = $this->getRequest()->getQueryParams();
if (isset($queryParams['status'])) {
if (!$this->isAdminApiEnabled()) throw new ForbiddenException();
}

$queryParams = array_merge([
'status' => 'publish'
], $queryParams);

$this->set([
'blogContents' => $this->paginate($blogContentsService->getIndex($this->request->getQueryParams()))
'blogContents' => $this->paginate($blogContentsService->getIndex($queryParams))
]);
$this->viewBuilder()->setOption('serialize', ['blogContents']);
}
Expand All @@ -54,9 +78,19 @@ public function index(BlogContentsServiceInterface $blogContentsService)
public function view(BlogContentsServiceInterface $service, $blogContentId)
{
$this->request->allowMethod(['get']);

$queryParams = $this->getRequest()->getQueryParams();
if (isset($queryParams['status'])) {
if (!$this->isAdminApiEnabled()) throw new ForbiddenException();
}

$queryParams = array_merge([
'status' => 'publish'
], $queryParams);

$blogContent = $message = null;
try {
$blogContent = $service->get($blogContentId);
$blogContent = $service->get($blogContentId, $queryParams);
} catch (RecordNotFoundException $e) {
$this->setResponse($this->response->withStatus(404));
$message = __d('baser_core', 'データが見つかりません。');
Expand Down
13 changes: 13 additions & 0 deletions plugins/bc-blog/src/Controller/Api/BlogTagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
class BlogTagsController extends BcApiController
{

/**
* initialize
* @return void
* @checked
* @unitTest
* @unitTest
*/
public function initialize(): void
{
parent::initialize();
$this->Authentication->allowUnauthenticated(['index', 'view']);
}

/**
* [API] ブログタグ一覧取得
*
Expand Down
10 changes: 10 additions & 0 deletions plugins/bc-blog/src/Service/BlogContentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public function __construct()
*/
public function getIndex(array $queryParams = []): Query
{
$queryParams = array_merge([
'status' => ''
], $queryParams);

$query = $this->BlogContents->find()->order([
'BlogContents.id'
]);
Expand All @@ -73,6 +77,12 @@ public function getIndex(array $queryParams = []): Query
$query->where(['description LIKE' => '%' . $queryParams['description'] . '%']);
}

if ($queryParams['status'] === 'publish') {
$fields = $this->BlogContents->getSchema()->columns();
$query = $query->contain(['Contents'])->select($fields);
$query->where($this->BlogContents->Contents->getConditionAllowPublish());
}

return $query;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use BaserCore\TestSuite\BcTestCase;
use BcBlog\Controller\Api\BlogContentsController;
use BcBlog\Test\Factory\BlogContentFactory;
use BcBlog\Test\Scenario\BlogContentScenario;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
use Cake\TestSuite\IntegrationTestTrait;

Expand Down Expand Up @@ -86,15 +87,22 @@ public function tearDown(): void
parent::tearDown();
}

/**
* test initialize
*/
public function test_initialize()
{
$controller = new BlogContentsController($this->getRequest());
$this->assertEquals($controller->Authentication->unauthenticatedActions, ['index', 'view']);
}

/**
* test index
*/
public function test_index()
{
$this->truncateTable('blog_contents');
BlogContentFactory::make(['id' => 10, 'description' => 'baserCMS inc. [デモ] の最新の情報をお届けします。'])->persist();
BlogContentFactory::make(['id' => 11, 'description' => 'ディスクリプション'])->persist();

$this->loadFixtureScenario(BlogContentScenario::class, 1, 1, null, 'news1', '/news/');
$this->loadFixtureScenario(BlogContentScenario::class, 2, 1, null, 'news2', '/news/');
$this->get('/baser/api/bc-blog/blog_contents/index.json?token=' . $this->accessToken);
$this->assertResponseOk();
$result = json_decode((string)$this->_response->getBody());
Expand All @@ -106,7 +114,7 @@ public function test_index()
*/
public function test_view()
{
ContentFactory::make(['plugin' => 'BcBlog', 'type' => 'BlogContent', 'entity_id' => 12])->persist();
ContentFactory::make(['plugin' => 'BcBlog', 'type' => 'BlogContent', 'entity_id' => 12, 'status' => true])->persist();
BlogContentFactory::make(['id' => 12, 'description' => 'baserCMS inc. [デモ] の最新の情報をお届けします。'])->persist();

$this->get('/baser/api/bc-blog/blog_contents/view/12.json?token=' . $this->accessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public function tearDown(): void
parent::tearDown();
}

/**
* test initialize
*/
public function test_initialize()
{
$controller = new BlogTagsController($this->getRequest());
$this->assertEquals($controller->Authentication->unauthenticatedActions, ['index', 'view']);
}

/**
* test index
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use BaserCore\Controller\Api\BcApiController;
use BcCustomContent\Service\CustomContentsServiceInterface;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Exception\ForbiddenException;
use Cake\ORM\Exception\PersistenceFailedException;
use BaserCore\Annotation\UnitTest;
use BaserCore\Annotation\NoTodo;
Expand All @@ -24,6 +25,20 @@
*/
class CustomContentsController extends BcApiController
{

/**
* initialize
* @return void
* @checked
* @unitTest
* @unitTest
*/
public function initialize(): void
{
parent::initialize();
$this->Authentication->allowUnauthenticated(['index', 'view']);
}

/**
* 一覧取得API
*
Expand All @@ -35,9 +50,17 @@ class CustomContentsController extends BcApiController
*/
public function index(CustomContentsServiceInterface $service)
{
$this->request->allowMethod(['get']);

$queryParams = $this->getRequest()->getQueryParams();
if (isset($queryParams['status'])) {
if (!$this->isAdminApiEnabled()) throw new ForbiddenException();
}

$queryParams = array_merge([
'contain' => null,
], $this->request->getQueryParams());
'status' => 'publish'
], $queryParams);

$this->set([
'customContents' => $this->paginate($service->getIndex($queryParams))
Expand All @@ -58,9 +81,19 @@ public function index(CustomContentsServiceInterface $service)
public function view(CustomContentsServiceInterface $service, int $id)
{
$this->request->allowMethod(['get']);

$queryParams = $this->getRequest()->getQueryParams();
if (isset($queryParams['status'])) {
if (!$this->isAdminApiEnabled()) throw new ForbiddenException();
}

$queryParams = array_merge([
'status' => 'publish'
], $queryParams);

$customContent = $message = null;
try {
$customContent = $service->get($id, $this->request->getQueryParams());
$customContent = $service->get($id, $queryParams);
} catch (RecordNotFoundException $e) {
$this->setResponse($this->response->withStatus(404));
$message = __d('baser_core', 'データが見つかりません。');
Expand Down
11 changes: 10 additions & 1 deletion plugins/bc-custom-content/src/Service/CustomContentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,21 @@ public function getIndex(array $queryParams = []): Query
'contain' => ['Contents']
], $queryParams);

$query = $this->CustomContents->find()->contain($queryParams['contain']);
if (is_null($queryParams['contain'])) {
$fields = $this->CustomContents->getSchema()->columns();
$query = $this->CustomContents->find()->contain(['Contents'])->select($fields);
} else {
$query = $this->CustomContents->find()->contain($queryParams['contain']);
}

if (!empty($queryParams['limit'])) {
$query->limit($queryParams['limit']);
}

if ($queryParams['status'] === 'publish') {
$query->where($this->CustomContents->Contents->getConditionAllowPublish());
}

if (!empty($queryParams['description'])) {
$query->where(['description LIKE' => '%' . $queryParams['description'] . '%']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BcCustomContent\Controller\Api\CustomContentsController;
use BcCustomContent\Test\Scenario\CustomContentsScenario;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
use Cake\TestSuite\IntegrationTestTrait;
Expand Down Expand Up @@ -78,6 +79,15 @@ public function tearDown(): void
parent::tearDown();
}

/**
* test initialize
*/
public function test_initialize()
{
$controller = new CustomContentsController($this->getRequest());
$this->assertEquals($controller->Authentication->unauthenticatedActions, ['index', 'view']);
}

/**
* test index
*/
Expand Down
3 changes: 3 additions & 0 deletions plugins/bc-mail/src/Model/Table/MailFieldsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,17 @@ public function validationDefault(Validator $validator): Validator
->maxLength('group_valid', 255, __d('baser_core', 'グループ入力チェックは255文字以内で入力してください。'));
$validator
->scalar('size')
->allowEmptyString('size')
->naturalNumber('size', __d('baser_core', '表示サイズは半角数字のみで入力してください。'))
->maxLength('size', 9, __d('baser_core', '表示サイズは9文字以内で入力してください。'));
$validator
->scalar('rows')
->allowEmptyString('rows')
->naturalNumber('rows', __d('baser_core', '行数は半角数字のみで入力してください。'))
->maxLength('rows', 9, __d('baser_core', '行数は9文字以内で入力してください。'));
$validator
->scalar('maxlength')
->allowEmptyString('maxlength')
->naturalNumber('maxlength', __d('baser_core', '最大値は半角数字のみで入力してください。'))
->maxLength('maxlength', 9, __d('baser_core', '最大値は9文字以内で入力してください。'));
return $validator;
Expand Down

0 comments on commit dc6193f

Please sign in to comment.