Skip to content

Commit

Permalink
Merge branch 'develop-NetCommons3/NetCommons3#863'
Browse files Browse the repository at this point in the history
  • Loading branch information
kteraguchi committed May 26, 2017
2 parents fc9153c + fb6340f commit a6ec04a
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Controller/BbsArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ public function edit() {
)
));

//掲示板の場合は、削除権限と同じ条件とする
if (! $this->BbsArticle->canDeleteWorkflowContent($bbsArticle)) {
// WorkflowBehavior::canEditWorkflowContentをBbsArticle::canEditWorkflowContentでoverride
if (! $this->BbsArticle->canEditWorkflowContent($bbsArticle)) {
return $this->throwBadRequest();
}

Expand Down
34 changes: 33 additions & 1 deletion Model/BbsArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,36 @@ public function deleteBbsArticle($data) {
return true;
}

}
/**
* コンテンツの編集権限があるかどうかのチェック
*
* WorkflowBehavior::canEditWorkflowContent をoverride
* - 編集権限あり(content_editable)
* - 子記事がない
* - 自分自身のコンテンツ
*
* @param array $data BbsArticle data
* @return bool true:編集可、false:編集不可
*/
public function canEditWorkflowContent($data) {
if (Current::permission('content_editable')) {
return true;
}
if (! isset($data['BbsArticle']['created_user'])) {
return false;
}

$childArticle = $this->BbsArticleTree->findByParentId(
$data['BbsArticleTree']['id'],
'id',
null,
-1
);
if ($childArticle) {
return false;
}

return ((int)$data['BbsArticle']['created_user'] === (int)Current::read('User.id'));
}

}
11 changes: 11 additions & 0 deletions Test/Case/Controller/BbsArticlesController/EditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ public function dataProviderEditGetByCreatable() {
$results[3] = Hash::merge($results[2], array(
'assert' => array('method' => 'assertInput', 'type' => 'button', 'name' => 'delete', 'value' => null),
));
// 一般の記事に返信がつくと編集できない
$results[4] = array(
'urlOptions' => array('frame_id' => '6', 'block_id' => '2', 'key' => 'bbs_article_14'),
'assert' => null,
'exception' => 'BadRequestException',
);

return $results;
}
Expand Down Expand Up @@ -232,6 +238,11 @@ public function dataProviderEditGetByEditable() {
'assert' => array('method' => 'assertEquals', 'expected' => 'emptyRender'),
'exception' => null, 'return' => 'viewFile'
);
// 一般の記事に返信があっても、編集権限あれば可能
$results[count($results)] = array(
'urlOptions' => array('frame_id' => '6', 'block_id' => '2', 'key' => 'bbs_article_14'),
'assert' => array('method' => 'assertInput', 'type' => 'textarea', 'name' => 'data[BbsArticle][content]', 'value' => null),
);

return $results;
}
Expand Down
17 changes: 14 additions & 3 deletions Test/Case/Controller/BbsArticlesController/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function dataProviderViewByCreatable() {
'assert' => array('method' => 'assertNotEmpty'),
);
$results[1] = Hash::merge($results[0], array( //(承認済み記事は編集不可)
'assert' => array('method' => 'assertActionLink', 'action' => 'edit', 'linkExist' => false, 'url' => array()),
'assert' => array('method' => 'assertActionLink', 'action' => 'edit', 'linkExist' => true, 'url' => array()),
));
//作成権限のみ(一般が書いた記事&公開前)
$results[2] = array(
Expand Down Expand Up @@ -176,6 +176,12 @@ public function dataProviderViewByCreatable() {
'exception' => 'BadRequestException',
'return' => 'json'
);
// 一般の記事に返信がつくと編集できない
$results[16] = array(
'urlOptions' => array('frame_id' => '6', 'block_id' => '2', 'key' => 'bbs_article_14'),
'assert' => array('method' => 'assertActionLink', 'action' => 'edit', 'linkExist' => false, 'url' => array()),
);

return $results;
}

Expand Down Expand Up @@ -217,7 +223,7 @@ public function dataProviderViewByEditable() {
//チェック
//--編集ボタン
$results[4] = Hash::merge($results[3], array( //なし(公開すると編集不可)
'assert' => array('method' => 'assertActionLink', 'action' => 'edit', 'linkExist' => false, 'url' => array()),
'assert' => array('method' => 'assertActionLink', 'action' => 'edit', 'linkExist' => true, 'url' => array()),
));
//--コメントボタン
$results[5] = Hash::merge($results[3], array(
Expand All @@ -235,7 +241,7 @@ public function dataProviderViewByEditable() {
'assert' => array('method' => 'assertNotEmpty'),
);
$results[8] = Hash::merge($results[3], array(
'assert' => array('method' => 'assertActionLink', 'action' => 'edit', 'linkExist' => false, 'url' => array()),
'assert' => array('method' => 'assertActionLink', 'action' => 'edit', 'linkExist' => true, 'url' => array()),
));
//根記事が取得できない
$results[9] = array(
Expand All @@ -261,6 +267,11 @@ public function dataProviderViewByEditable() {
'exception' => 'BadRequestException',
'return' => 'json'
);
// 一般の記事に返信があっても、編集権限あれば可能
$results[16] = array(
'urlOptions' => array('frame_id' => '6', 'block_id' => '2', 'key' => 'bbs_article_14'),
'assert' => array('method' => 'assertActionLink', 'action' => 'edit', 'linkExist' => true, 'url' => array()),
);

return $results;
}
Expand Down
4 changes: 2 additions & 2 deletions Test/Case/Model/BbsArticle/SaveBbsArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ public function testSave($data) {

$before['BbsArticleTree'] = $data['BbsArticleTree'];
$before['BbsArticleTree']['id'] = (string)$maxId;
$before['BbsArticleTree']['lft'] = '27';
$before['BbsArticleTree']['rght'] = '28';
$before['BbsArticleTree']['lft'] = '31';
$before['BbsArticleTree']['rght'] = '32';
$before['BbsArticleTree']['article_no'] = '1';
$before['BbsArticleTree']['bbs_article_child_count'] = '0';
}
Expand Down
32 changes: 32 additions & 0 deletions Test/Fixture/BbsArticleFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,38 @@ class BbsArticleFixture extends CakeTestFixture {
'modified_user' => 4,
'modified' => '2015-05-14 07:09:55'
),
//一般が書いた記事(子記事あり)
array(
'id' => '14',
'bbs_key' => 'bbs_1',
'language_id' => '2',
'status' => '1',
'is_active' => true,
'is_latest' => '1',
'key' => 'bbs_article_14',
'title' => 'Lorem ipsum dolor sit amet',
'content' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.',
'created_user' => 4,
'created' => '2015-05-14 07:09:55',
'modified_user' => 1,
'modified' => '2015-05-14 07:09:55'
),
//親記事が一般の記事
array(
'id' => '15',
'bbs_key' => 'bbs_1',
'language_id' => '2',
'status' => '2',
'is_active' => false,
'is_latest' => '1',
'key' => 'bbs_article_15',
'title' => 'Lorem ipsum dolor sit amet',
'content' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.',
'created_user' => 4,
'created' => '2015-05-14 07:09:55',
'modified_user' => 4,
'modified' => '2015-05-14 07:09:55'
),
);

/**
Expand Down
30 changes: 30 additions & 0 deletions Test/Fixture/BbsArticleTreeFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,36 @@ class BbsArticleTreeFixture extends CakeTestFixture {
'modified_user' => 4,
'modified' => '2015-05-14 07:09:02'
),
array( //一般が書いた記事(子記事あり)
'id' => 14,
'bbs_key' => 'bbs_1',
'bbs_article_key' => 'bbs_article_14',
'root_id' => 0,
'parent_id' => 0,
'lft' => 27,
'rght' => 30,
'article_no' => 1,
'bbs_article_child_count' => 1,
'created_user' => 4,
'created' => '2015-05-14 07:09:02',
'modified_user' => 1,
'modified' => '2015-05-14 07:09:02'
),
array( //親記事が一般の記事
'id' => 15,
'bbs_key' => 'bbs_1',
'bbs_article_key' => 'bbs_article_15',
'root_id' => 14,
'parent_id' => 14,
'lft' => 28,
'rght' => 29,
'article_no' => 2,
'bbs_article_child_count' => 0,
'created_user' => 4,
'created' => '2015-05-14 07:09:02',
'modified_user' => 4,
'modified' => '2015-05-14 07:09:02'
),
);

/**
Expand Down
4 changes: 2 additions & 2 deletions View/Elements/BbsArticles/view_bbs_article.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ $linkFormatId = BbsArticlesController::LINK_ID_FORMAT;
}
?>

<?php //根記事編集は、削除権限と同じ条件とする ?>
<?php if ($this->Workflow->canDelete('BbsArticle', $bbsArticle)) : ?>
<?php // WorkflowBehavior::canEditWorkflowContentをBbsArticle::canEditWorkflowContentでoverride ?>
<?php if ($this->Workflow->canEdit('BbsArticle', $bbsArticle)) : ?>
<div class="nc-bbs-edit-link">
<?php echo $this->Button->editLink('', array('key' => $bbsArticle['BbsArticle']['key']), array(
'tooltip' => true,
Expand Down

0 comments on commit a6ec04a

Please sign in to comment.