ivanamat / cakephp3-aclmanager

CakePHP 3.x - Acl Manager
MIT License
27 stars 27 forks source link

Images in view #2

Closed stagistabm closed 8 years ago

stagistabm commented 8 years ago

change your permissions.ctp to this


<?php 

/**
 * CakePHP 3.x - Acl Manager
 * 
 * PHP version 5
 * 
 * permissions.ctp
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @category CakePHP3
 * 
 * @author Ivan Amat <dev@ivanamat.es>
 * @copyright Copyright 2016, Iván Amat
 * @license MIT http://opensource.org/licenses/MIT
 * @link https://github.com/ivanamat/cakephp3-aclmanager
 */

use Cake\Core\Configure; 
use Cake\Utility\Inflector;

echo $this->Html->css('AclManager/img/default',['inline' => false]);

?>

<div class="row">
    <div class="columns large-12">
        <h1><?php echo $this->Html->link(__('CakePHP 3.x - Acl Manager'),['action' => 'index']); ?></h1>
        <p class="subtitle"><?php echo sprintf(__("Managing %s"), strtolower($model)); ?></p>
    </div>
</div>

<div class="row panel">
    <div class="columns large-4">
        <h3><?php echo __('Manage'); ?></h3>
        <ul class="options">
            <?php if($this->request->session()->check('Auth.User.role_id') && $this->request->session()->read('Auth.User.role_id') == 1) { ?>
                <li><?php echo $this->Html->link(__('Manage groups'), ['controller' => 'Acl', 'action' => 'Permissions', 'Groups']); ?></li>
            <?php } ?>
            <li><?php echo $this->Html->link(__('Manage roles'), ['controller' => 'Acl', 'action' => 'Permissions', 'Roles']); ?></li>
            <li><?php echo $this->Html->link(__('Manage users'), ['controller' => 'Acl', 'action' => 'Permissions', 'Users']); ?></li>
        </ul>
    </div>
    <?php if($this->request->session()->check('Auth.User.role_id') && $this->request->session()->read('Auth.User.role_id') == 1) { ?>
    <div class="columns large-4">
        <h3><?php echo __('Update'); ?></h3>
        <ul class="options">
            <li><?php echo $this->Html->link(__('Update ACOs'), ['controller' => 'Acl', 'action' => 'UpdateAcos']); ?></li>
            <li><?php echo $this->Html->link(__('Update AROs'), ['controller' => 'Acl', 'action' => 'UpdateAros']); ?></li>
        </ul>
    </div>
    <div class="columns large-4">
        <h3><?php echo __('Drop and restore'); ?></h3>
        <ul class="options">
            <li><?php echo $this->Html->link(__('Drop permissions'), ['controller' => 'Acl', 'action' => 'RevokePerms'], ['confirm' => __('Do you really want to delete all permissions? After removing all permissions, only root users can access.')]); ?></li>
            <li><?php echo $this->Html->link(__('Drop ACOs/AROs'), ['controller' => 'Acl', 'action' => 'drop'], ['confirm' => __('Do you really want to delete ACOs and AROs? This too will remove all permissions. Make sure the method isAuthorized returns true if you want update ACOs and AROs after remove all them, otherwise you can\'t get acces to manage ACOs and AROs.')]); ?></li>
            <li><?php echo $this->Html->link(__('Restore to default'), ['controller' => 'Acl', 'action' => 'defaults'], ['confirm' => __('Do you want restore all permissions? This will override all above assigned permissions. Only root users can access after reset to defaults.')]); ?></li>
        </ul>
    </div>
    <?php } ?>
</div>

<div class="row panel">
    <div class="columns large-12">
        <?php echo $this->Form->create('Perms'); ?>
        <table>
            <thead>
                <tr>
                    <th>Action</th>
                    <?php foreach ($aros as $aro): ?>
                        <?php $aro = array_shift($aro); ?>
                        <th>
                            <?php
                            if (($model == 'Roles' OR $model == 'Users') && $this->request->session()->read('Auth.User.role_id') == 1) {
                                $gData = $this->AclManager->getName('Groups', $aro['group_id']);
                                echo h($aro[$aroDisplayField]) . ' ( ' . $gData['name'] . ' )';
                            } else {
                                echo h($aro[$aroDisplayField]);
                            }
                            ?>
                        </th>
                    <?php endforeach; ?>
                </tr>
            </thead>
            <tbody>
                <?php
                $uglyIdent = Configure::read('AclManager/img/uglyIdent');
                $lastIdent = null;
                foreach ($acos as $id => $aco) {
                    $action = $aco['Action'];
                    $alias = $aco['Aco']['alias'];
                    $ident = substr_count($action, '/');

                    if ($ident <= $lastIdent && !is_null($lastIdent)) {
                        for ($i = 0; $i <= ($lastIdent - $ident); $i++) {
                            echo "</tr>";
                        }
                    }

                    if ($ident != $lastIdent) {
                        echo "<tr class='aclmanager-ident-" . $ident . "'>";
                    }

                    if ($this->AclManager->Acl->check(['Users' => ['id' => $this->request->session()->read('Auth.User.id')]], $action) ||
                            $this->request->session()->read('Auth.User.Role.id') == 1) {
                        echo "<td>";
                        echo Inflector::humanize(($ident == 1 ? "<strong>" : "" ) . ($uglyIdent ? str_repeat("&nbsp;&nbsp;", $ident) : "") . h($alias) . ($ident == 1 ? "</strong>" : "" ));
                        echo "</td>";

                        foreach ($aros as $aro):
                            $inherit = $this->AclManager->value("Perms." . str_replace("/", ":", $action) . ".{$aroAlias}:{$aro[$aroAlias]['id']}-inherit");
                            $allowed = $this->AclManager->value("Perms." . str_replace("/", ":", $action) . ".{$aroAlias}:{$aro[$aroAlias]['id']}");

                            $mAro = $model;
                            $mAllowed = $this->AclManager->Acl->check($aro, $action);
                            $mAllowedText = ($mAllowed) ? 'Allow' : 'Deny';

                            // Originally based on 'allowed' above 'mAllowed'
                            $icon = ($mAllowed) ? $this->Html->image('AclManager/img/allow_32.png') : $this->Html->image('AclManager/img/deny_32.png');

                            if ($inherit) {
                                $icon = $this->Html->image('AclManager/img/inherit_32.png');
                            }

                            if ($mAllowed && !$inherit) {
                                $icon = $this->Html->image('AclManager/img/allow_32.png');
                                $mAllowedText = 'Allow';
                            }

                            if ($mAllowed && $inherit) {
                                $icon = $this->Html->image('AclManager/img/allow_inherited_32.png');
                                $mAllowedText = 'Inherit';
                            }

                            if (!$mAllowed && $inherit) {
                                $icon = $this->Html->image('AclManager/img/deny_inherited_32.png');
                                $mAllowedText = 'Inherit';
                            }

                            if (!$mAllowed && !$inherit) {
                                $icon = $this->Html->image('AclManager/img/deny_32.png');
                                $mAllowedText = 'Deny';
                            }

                            echo "<td class=\"select-perm\">";
                                    echo $icon . ' ' . $this->Form->select("Perms." . str_replace("/", ":", $action) . ".{$aroAlias}:{$aro[$aroAlias]['id']}", array('inherit' => __('Inherit'), 'allow' => __('Allow'), 'deny' => __('Deny')), array('empty' => __($mAllowedText), 'class' => 'form-control'));
                            echo "</td>";
                        endforeach;

                        $lastIdent = $ident;
                    }
                }

                for ($i = 0; $i <= $lastIdent; $i++) {
                    echo "</tr>";
                }
                ?>
            </tbody>
        </table>

        <div class="row">
            <div class="columns large-12">
                <div class="paginator">
                    <ul class="pagination">
                        <?php echo $this->Paginator->prev('< ' . __('previous')) ?>
                        <?php echo $this->Paginator->numbers() ?>
                        <?php echo $this->Paginator->next(__('next') . ' >') ?>
                    </ul>
                    <p><?php echo $this->Paginator->counter() ?></p>
                </div>
                 <button type="submit" class="btn btn-primary right"><?php echo __("Save"); ?></button>
            </div>
        </div>
        <?php echo $this->Form->end(); ?>

    </div>
</div>

<div class="row panel">
    <div class="columns large-12">
        <div class="row">
            <div class="columns medium-4">
                <p><?php echo $this->Html->image('AclManager/img/deny_32.png') . ' ' . __('Denied') ?></p>
                <p><?php echo $this->Html->image('AclManager/img/deny_inherited_32.png') . ' ' . __('Denied by inheritance') ?></p>
            </div>
            <div class="columns medium-4">
                <p><?php echo $this->Html->image('AclManager/img/allow_32.png') . ' ' . __('Allowed') ?></p>
                <p><?php echo $this->Html->image('AclManager/img/allow_inherited_32.png') . ' ' . __('Allowed by inheritance') ?></p>
            </div>
            <div class="columns medium-4">
                <p><?php echo __('All permissions are denied by default. When the permissions are set, this ACO\'s children inherit permissions.'); ?></p>
            </div>
        </div>
    </div>
</div>
ivanamat commented 8 years ago

@stagistabm What is it that you changed in permissions.ctp?

stagistabm commented 8 years ago

every image from example:

$this->Html->image('AclManager.allow_32.png') to

$this->Html->image('AclManager/img/allow_32.png');

because the output html doesn't find the image.

ivanamat commented 8 years ago

Yes, I was reviewing now. I think you have made a search and replace and have replaced other routes in your permissions.ctp.

echo $this->Html->css('AclManager/img/default',['inline' => false]); ...

stagistabm commented 8 years ago

yes!

ivanamat commented 8 years ago

I think it's not right. Just try it and it does not work, I have also read the manual it says CakePHP and routes the images of the plugins must be so 'AclManager.image.png'. http://book.cakephp.org/3.0/en/plugins.html#linking-to-assets-in-plugins

stagistabm commented 8 years ago

yes i know, but as you changed your path to AclManager, the output path from the view output is Acl_Manager and then it doesn't find the image.

ivanamat commented 8 years ago

Both works for me, in a clean installation:

http://caketest.ivanamat.es/users/login

User: demo Pass: demo

Go to http://caketest.ivanamat.es/AclManager/acl/permissions

http://caketest.ivanamat.es/acl_manager/img/allow_inherited_32.png http://caketest.ivanamat.es/AclManager/img/allow_inherited_32.png

stagistabm commented 8 years ago

on my side cake 3.2 the output is <img src="/acl_manager/allow_32.png" alt=""/>

so maybe is a problem with the helper, i don't know where is the problem

ivanamat commented 8 years ago

I also use CakePHP 3.2 and my output as you can see in the demo is:

<img src="/acl_manager/img/allow_inherited_32.png" alt=""/>

Maybe you've created or override some routes?

stagistabm commented 8 years ago

yes but without touching your routes

ivanamat commented 8 years ago

I will create a clean install and will review both the error Acl.Acl as images on http://debug.ivanamat.es.

stagistabm commented 8 years ago

okay, I'll keep in touch!

ivanamat commented 8 years ago

@stagistabm Here a complete clean installation:

http://debug.ivanamat.es/

http://debug.ivanamat.es/users/login

User: demo Password: demo

It's all new, the copy of CakePHP 3.2, models, controllers and database.

No Acl.Acl or image issues.

stagistabm commented 8 years ago

I can't login with those credentials, are you sure you uploaded the latest version to git, is strange, i tried in a second installation

ivanamat commented 8 years ago

you are right, I can't login. :D

stagistabm commented 8 years ago

give a look ahah

ivanamat commented 8 years ago

@stagistabm Try again please! XD

stagistabm commented 8 years ago

can you paste your permissions.ctp here , is like this? = $this->Html->image('AclManager.allow_32.png');

ivanamat commented 8 years ago

permissions.txt

I uploaded it as txt.

stagistabm commented 8 years ago

nothing, don't know what's going on, i'll have to modify it then

ivanamat commented 8 years ago

maybe your baseUrl of app.php or rewrite mod of your hosting?

The default App.php config:

'App' => [
        'namespace' => 'App',
        'encoding' => env('APP_ENCODING', 'UTF-8'),
        'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'),
        'base' => false,
        'dir' => 'src',
        'webroot' => 'webroot',
        'wwwRoot' => WWW_ROOT,
        // 'baseUrl' => env('SCRIPT_NAME'),
        'fullBaseUrl' => false,
        'imageBaseUrl' => 'img/',
        'cssBaseUrl' => 'css/',
        'jsBaseUrl' => 'js/',
        'paths' => [
            'plugins' => [ROOT . DS . 'plugins' . DS],
            'templates' => [APP . 'Template' . DS],
            'locales' => [APP . 'Locale' . DS],
        ],
    ],
stagistabm commented 8 years ago

that was the problem, the imageBaseUrl was empty!

ivanamat commented 8 years ago

I'll prepare the food, it is high time to eat!

stagistabm commented 8 years ago

yes it is, European?

ivanamat commented 8 years ago

Yes! From Spain!

stagistabm commented 8 years ago

Lol bien entonces, se puede hablar espanol, Vivo en italia!

ivanamat commented 8 years ago

Jaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaajajajajaja!! Guten!!

stagistabm commented 8 years ago

hahahahaha, bien bien entonces, buen plugin !! ahora encontre algun otro error quizas mio, vas directamente al AclManager/ y te manda a AclManager/users/login pero veré màs adelante

ivanamat commented 8 years ago

Bien, si sabes Español te podré echar una mano bastante mejor, mi ingles es del tipo https://www.youtube.com/watch?v=6LLSDn3_TfE

¿Eso te pasa habiendo iniciado sesión?

stagistabm commented 8 years ago

sin iniciar sesión y vas directamente al aclmanager, Cafe con leche hahahaha, no lo habia visto, epico jjaaj

ivanamat commented 8 years ago

@stagistabm El error es por esto, que debe estar en el AppController.php:

        ...
        'unauthorizedRedirect' => [
            'controller' => 'Users',
            'action' => 'login',
            'prefix' => false
        ],

Debe ser así:

        ...
        'unauthorizedRedirect' => [
            'plugin' => false,
            'controller' => 'Users',
            'action' => 'login',
            'prefix' => false
        ],

Ya lo he cambiado en el README.md

stagistabm commented 8 years ago

sigue igual!

 $this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => [
                        'username' => 'email',
                        'password' => 'password'
                    ]
                ]
            ],
            'loginAction' => [
                'controller' => 'Users',
                'action' => 'login'
            ],
            'unauthorizedRedirect' => [
                'plugin' => false,
                'controller' => 'Users',
                'action' => 'login',
                'prefix' => false
            ],
        ]);
ivanamat commented 8 years ago

Especifica todos a ver si te pasa lo mismo:

$this->loadComponent('Auth', [
            'authenticate' => [
                'Form' => [
                    'fields' => [
                        'username' => 'email',
                        'password' => 'password'
                    ]
                ]
            ],
        'authorize' => [
            'Acl.Actions' => ['actionPath' => 'controllers/']
        ],
        'loginAction' => [
            'plugin' => false,
            'controller' => 'Users',
            'action' => 'login'
        ],
        'loginRedirect' => [
            'plugin' => false,
            'controller' => 'Posts',
            'action' => 'index'
        ],
        'logoutRedirect' => [
            'plugin' => false,
            'controller' => 'Users',
            'action' => 'login'
        ],
        'unauthorizedRedirect' => [
            'plugin' => false,
            'controller' => 'Users',
            'action' => 'login',
            'prefix' => false
        ],
        'authError' => 'You are not authorized to access that location.',
        'flash' => [
            'element' => 'error'
        ]
    ]);

y pone el 'authorize';

En teoría es lo de 'plugin' => false, pero copia y pega a ver si te va.

stagistabm commented 8 years ago

el problema de antes cuando entro en AclManager, cuando navego normal, no aparece el error, The "Acl" alias has already been loaded with the following config: array ( ) which differs from array ( 'className' => 'Acl.Acl', )

ivanamat commented 8 years ago

M... ¿Me quieres decir que ahora te funciona bien?

stagistabm commented 8 years ago

condicionando el loadComponent

ivanamat commented 8 years ago

@stagistabm Puedo echarte una mano a resolver el problema del loadComponent, mediante correo o hangouts? Para no extender los comentarios de la issue original. Yo utilizo Google + o Hangouts, envíame un mail e intentamos solucionar el problema que tienes.

Un saludo!