Skip to content

Commit

Permalink
Merge pull request #120 from NetCommons3/issue-Netcommons3/Netcommons…
Browse files Browse the repository at this point in the history
  • Loading branch information
kteraguchi committed Jul 11, 2017
2 parents f9dfc49 + 88d72b6 commit 2d0c264
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 135 deletions.
92 changes: 92 additions & 0 deletions Config/Migration/1499309604_delete_publishable_permission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* DeletePublishablePermission
*
*/

/**
* DeletePublishablePermission
*
*/
class DeletePublishablePermission extends CakeMigration {

/**
* Migration description
*
* @var string
*/
public $description = 'delete_publishable_permission';

/**
* Actions to be performed
*
* @var array $migration
*/
public $migration = array(
'up' => array(),
'down' => array(),
);

/**
* Before migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction) {
if ($direction === 'down') {
return true;
}

/* @var $DefaultRolePermission AppModel */
/* @var $RolesRoom AppModel */
/* @var $Block AppModel */
$DefaultRolePermission = $this->generateModel('DefaultRolePermission');
$RolesRoom = $this->generateModel('RolesRoom');
$Block = $this->generateModel('BlockRolePermission');

$query = [
'fields' => 'role_key',
'conditions' => [
'permission' => 'content_comment_publishable',
'fixed' => '1'
],
'recursive' => -1
];
$roleKeyList = $DefaultRolePermission->find('list', $query);

$query = [
'fields' => 'id',
'conditions' => [
'role_key' => $roleKeyList,
],
'recursive' => -1
];
$roleRoomIdList = $RolesRoom->find('list', $query);

$conditions = [
'OR' => [
'permission' => 'content_publishable',
[
'permission' => 'content_comment_publishable',
'roles_room_id' => $roleRoomIdList
]
]
];
if (!$Block->deleteAll($conditions, false)) {
return false;
}

return true;
}
}
62 changes: 0 additions & 62 deletions Model/Behavior/BlockRolePermissionBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,68 +103,6 @@ public function beforeValidate(Model $model, $options = array()) {
return true;
}

/**
* beforeSave is called before a model is saved. Returning false from a beforeSave callback
* will abort the save operation.
*
* @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
* @return mixed False if the operation should abort. Any other result will continue.
* @see Model::save()
*/
public function beforeSave(Model $model, $options = array()) {
if (! isset($model->data['BlockRolePermission'])) {
return true;
}

if (! isset($model->data[$model->alias]['approval_type'])) {
return true;
}
$approvalType = $model->data[$model->alias]['approval_type'];

$approvalTypes = [Block::NOT_NEED_APPROVAL, Block::NEED_APPROVAL, Block::NEED_COMMENT_APPROVAL];
if (! in_array($approvalType, $approvalTypes, true)) {
return true;
}

$permission = Hash::get($model->data['BlockRolePermission'], 'content_publishable', array());
foreach ($permission as $roleKey => $role) {
if (in_array($approvalType, [Block::NOT_NEED_APPROVAL, Block::NEED_COMMENT_APPROVAL])) {
$value = Hash::get(
$model->data['BlockRolePermission'], 'content_creatable.' . $roleKey . '.value', true
);
} else {
$value = false;
}
$model->data['BlockRolePermission'] = Hash::insert(
$model->data['BlockRolePermission'], 'content_publishable.' . $roleKey . '.value', $value
);
}

$permission = Hash::get(
$model->data['BlockRolePermission'], 'content_comment_publishable', array()
);
foreach ($permission as $roleKey => $role) {
if ($approvalType === Block::NOT_NEED_APPROVAL) {
$pathKey = 'content_comment_creatable.' . $roleKey . '.value';
$value = Hash::get($model->data['BlockRolePermission'], $pathKey, true);

} elseif ($approvalType === Block::NEED_COMMENT_APPROVAL) {
$pathKey = 'content_comment_publishable.' . $roleKey . '.value';
$value = Hash::get($model->data['BlockRolePermission'], $pathKey, false);

} else {
$value = false;
}
$pathKey = 'content_comment_publishable.' . $roleKey . '.value';
$model->data['BlockRolePermission'] = Hash::insert(
$model->data['BlockRolePermission'], $pathKey, $value
);
}

return true;
}

/**
* afterSave is called after a model is saved.
*
Expand Down
73 changes: 0 additions & 73 deletions View/Helper/BlockRolePermissionFormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,49 +55,6 @@ public function checkboxBlockRolePermission($fieldName, $attributes = array()) {
return $html;
}

/**
* BlockRolePermissionのコンテンツ公開権限
*
* @return string HTML
*/
public function contentPublishablePermission() {
$fieldName = 'BlockRolePermission.content_publishable';
list($model, $permission) = explode('.', $fieldName);
$html = '';

if (! isset($this->_View->request->data[$model][$permission])) {
return $html;
}

foreach ($this->_View->request->data[$model][$permission] as $roleKey => $role) {
if (! $role['default'] && $role['fixed']) {
continue;
}

$pubFieldName = $fieldName . '.' . $roleKey;
if (Hash::get($this->_View->request->data, $pubFieldName . '.id')) {
$outputPublishable = true;
} elseif (! (bool)Hash::get($this->_View->request->data, $pubFieldName . '.roles_room_id')) {
$outputPublishable = false;
} elseif (! (bool)Hash::get($this->_View->request->data, $pubFieldName . '.fixed')) {
$outputPublishable = true;
} else {
//作成権限ON固定で、公開権限がOFFの場合、inputタグを表示する
$outputPublishable = ! Hash::get($this->_View->request->data, $pubFieldName . '.default');
}
if (! $outputPublishable) {
continue;
}

$html .= $this->NetCommonsForm->hidden($pubFieldName . '.id');
$html .= $this->NetCommonsForm->hidden($pubFieldName . '.roles_room_id');
$html .= $this->NetCommonsForm->hidden($pubFieldName . '.block_key');
$html .= $this->NetCommonsForm->hidden($pubFieldName . '.permission');
}

return $html;
}

/**
* BlockRolePermissionのチェックボックス表示
*
Expand All @@ -112,13 +69,6 @@ private function __inputBlockRolePermission($model, $permission, $roleKey, $attr
$html .= '<div class="checkbox checkbox-inline">';

$fieldName = $model . '.' . $permission . '.' . $roleKey;
if ($permission === 'content_creatable') {
$pubFieldName = $model . '.' . 'content_publishable' . '.' . $roleKey;
} elseif ($permission === 'content_comment_creatable') {
$pubFieldName = $model . '.' . 'content_comment_publishable' . '.' . $roleKey;
} else {
$pubFieldName = '';
}

if (! Hash::get($this->_View->request->data, $fieldName . '.fixed')) {
$html .= $this->NetCommonsForm->hidden($fieldName . '.id');
Expand All @@ -143,29 +93,6 @@ private function __inputBlockRolePermission($model, $permission, $roleKey, $attr

$html .= $this->NetCommonsForm->checkbox($fieldName . '.value', $options);

if (! $pubFieldName) {
$html .= '</div>';
return $html;
}
if (Hash::get($this->_View->request->data, $pubFieldName . '.id')) {
$outputPublishable = true;
} elseif (! (bool)Hash::get($this->_View->request->data, $pubFieldName . '.fixed')) {
$outputPublishable = true;
} else {
//作成権限ON固定で、公開権限がOFFの場合、inputタグを表示する
$outputPublishable = ! Hash::get($this->_View->request->data, $pubFieldName . '.default');
}
if (! $outputPublishable) {
$html .= '</div>';
return $html;
}

$html .= $this->NetCommonsForm->hidden($pubFieldName . '.id');
$html .= $this->NetCommonsForm->hidden($pubFieldName . '.roles_room_id');
$html .= $this->NetCommonsForm->hidden($pubFieldName . '.block_key');
$html .= $this->NetCommonsForm->hidden($pubFieldName . '.permission');
$html .= $this->NetCommonsForm->hidden($pubFieldName . '.value');

$html .= '</div>';
return $html;
}
Expand Down

0 comments on commit 2d0c264

Please sign in to comment.