Skip to content

Commit

Permalink
Add improvements for better compatibility with different applications
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaboncukcu committed Oct 2, 2018
1 parent f21e778 commit b1d23aa
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 82 deletions.
19 changes: 12 additions & 7 deletions config/routes.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?php
use Cake\Routing\Router;

Router::plugin(
'Stories',
['path' => '/stories'],
function ($routes) {
$routes->fallbacks('DashedRoute');
}
);

$allowTemplates = \Cake\Core\Configure::read('AllowTemplates');
if($allowTemplates) {
Router::plugin(
'Stories',
['path' => '/stories'],
function ($routes) {
$routes->fallbacks('DashedRoute');
}
);
}

10 changes: 8 additions & 2 deletions config/stories.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
return [
'Stories' => [
'Users' => [
'table' => 'Users',
'table' => 'Cms.Users',
'id' => 'id'
],
'DontLog' => [
Expand All @@ -13,6 +13,12 @@
'password'
]
],
'DataLogger' => true
'DataLogger' => true,
'AllowTemplates' => [
'forField' => 'role',
'rule' => function ($fieldValue) {
return $fieldValue === 'superadmin' || $fieldValue === 'admin';
}
]
]
];
13 changes: 13 additions & 0 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@
namespace Stories\Controller;

use App\Controller\AppController as BaseController;
use Cake\Core\Configure;

class AppController extends BaseController
{
/**
* @param $user
* @return bool|void
*/
public function isAuthorized($user)
{
if($this->Auth->user('id')) {
$fieldValue = $this->Auth->user(Configure::read('Stories.AllowTemplates.forField'));
$checker = Configure::read('Stories.AllowTemplates.rule');
return $checker($fieldValue);
}
}

}
3 changes: 2 additions & 1 deletion src/Controller/StoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class StoriesController extends AppController
public function index()
{
$this->paginate = [
'contain' => ['Users']
'contain' => ['Users'],
'order' => ['created' => 'DESC']
];
$stories = $this->paginate($this->Stories);

Expand Down
123 changes: 51 additions & 72 deletions src/Template/Stories/index.ctp
Original file line number Diff line number Diff line change
@@ -1,84 +1,63 @@
<?php
$this->layout = 'default';



?>

<?= $this->fetch('top-menu') ?>
<?= $this->element('General/flashbar') ?>


<?= $this->element('General/PageTitle', [
'pageTitle' => __('Role'),

]); ?>

<div class="gr-container">
<div class="row">
<div class="col-xs-12">

<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Html->link(__('New Story'), ['action' => 'add']) ?></li>
<li><?= $this->Html->link(__('List Users'), ['controller' => 'Users', 'action' => 'index']) ?></li>
<li><?= $this->Html->link(__('New User'), ['controller' => 'Users', 'action' => 'add']) ?></li>
<li><?= $this->Html->link(__('List Phinxlog'), ['controller' => 'Phinxlog', 'action' => 'index']) ?></li>
<li><?= $this->Html->link(__('New Phinxlog'), ['controller' => 'Phinxlog', 'action' => 'add']) ?></li>
</ul>
</nav>
<div class="stories index large-9 medium-8 columns content">
<h3><?= __('Stories') ?></h3>
<table class="table">
<thead>
<tr>
<th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('controller') ?></th>
<th><?= $this->Paginator->sort('action') ?></th>
<th><?= $this->Paginator->sort('ip') ?></th>
<th><?= $this->Paginator->sort('user_id') ?></th>
<th><?= $this->Paginator->sort('level') ?></th>
<th><?= $this->Paginator->sort('webroot') ?></th>
<th><?= $this->Paginator->sort('currentpath') ?></th>
<th><?= $this->Paginator->sort('data_load') ?></th>
<th><?= $this->Paginator->sort('plugin') ?></th>
<th><?= $this->Paginator->sort('created') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($stories as $story): ?>
<tr>
<td><?= $this->Number->format($story->id) ?></td>
<td><?= h($story->controller) ?></td>
<td><?= h($story->action) ?></td>
<td><?= $story->convertedIp ?></td>
<td><?= $story->has('user') ? $this->Html->link($story->user->fullname, ['controller' => 'Users', 'action' => 'view', $story->user->id]) : '' ?></td>
<td><?= h($story->level) ?></td>
<td><?= h($story->webroot) ?></td>
<td><?= h($story->currentpath) ?></td>
<td><?= h($story->plugin) ?></td>
<td><?= h($story->data_load) ?></td>
<td><?= h($story->created) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $story->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $story->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $story->id], ['confirm' => __('Are you sure you want to delete # {0}?', $story->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
</ul>
<p><?= $this->Paginator->counter() ?></p>
</div>
</div>
<div class="stories index large-9 medium-8 columns content">
<h3><?= __('Stories') ?></h3>
<table class="table">
<thead>
<tr>
<th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('controller') ?></th>
<th><?= $this->Paginator->sort('action') ?></th>
<th><?= $this->Paginator->sort('ip') ?></th>
<th><?= $this->Paginator->sort('user_id') ?></th>
<th><?= $this->Paginator->sort('level') ?></th>
<th><?= $this->Paginator->sort('webroot') ?></th>
<th><?= $this->Paginator->sort('currentpath') ?></th>
<th><?= $this->Paginator->sort('plugin') ?></th>
<th><?= $this->Paginator->sort('data_load') ?></th>
<th><?= $this->Paginator->sort('created') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($stories as $story): ?>
<tr>
<td><?= $this->Number->format($story->id) ?></td>
<td><?= h($story->controller) ?></td>
<td><?= h($story->action) ?></td>
<td><?= $story->convertedIp ?></td>
<td><?= $story->has('user') ? $this->Html->link($story->user->id, ['controller' => 'Users', 'action' => 'view', $story->user->id]) : '' ?></td>
<td><?= h($story->level) ?></td>
<td><?= h($story->webroot) ?></td>
<td><?= h($story->currentpath) ?></td>
<td><?= h($story->plugin) ?></td>
<td><?php dump($story->data_load); ?></td>
<td><?= h($story->created) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $story->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $story->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $story->id], ['confirm' => __('Are you sure you want to delete # {0}?', $story->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
</ul>
<p><?= $this->Paginator->counter() ?></p>
</div>
</div>

</div>
</div>
Expand Down

0 comments on commit b1d23aa

Please sign in to comment.