简体   繁体   English

Opencart权限被拒绝-无法添加权限

[英]Opencart Permission Denied - Cannot add permissions

I am extending opencart and I am building a custom controller for catalog for uploading products via CSV. 我正在扩展opencart,并正在构建用于目录的自定义控制器,以便通过CSV上传产品。 I am getting this error when I try and view catalog/upload You do not have permission to access this page, please refer to your system administrator. 尝试查看目录/上载时出现此错误。 You do not have permission to access this page, please refer to your system administrator. .

I figured I would need to change the permissions in the db, and found a function to do so 我认为我需要更改数据库中的权限,并找到一个函数来执行此操作

$this->model_user_user_group->addPermission($this->user->getId(), 'access', 'catalog/upload'); $this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'catalog/upload');

I put this in a module built for the sole purpose of addiing these permissions when it installs 我将其放在一个模块中,该模块的唯一目的是在安装时添加这些权限

<?php
    class ControllerModuleInstl extends Controller {
        public function install() {
            $this->load->model('user/user_group');
            $this->model_user_user_group->addPermission($this->user->getId(), 'access', 'catalog/upload');
            $this->model_user_user_group->addPermission($this->user->getId(), 'modify', 'catalog/upload');

            if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
                $this->model_setting_setting->editSetting('instl', $this->request->post);       

                $this->session->data['success'] = $this->language->get('text_success');

                $this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
            }
        }
    }
?>

I click install, I get a success message (no page redirect however), when I check the DB the permissions have not been changed. 我单击安装,我收到一条成功消息(但是没有页面重定向),当我检查数据库时,权限没有更改。

I find this hard to debug because when usually debugging Ill use echo and such, but obviously you can't do this kind of thing with an application of this size (I usually just write small scripts), what is the best way to debug opencart, step through it, and also can anyone tell me why my permissions are not being changed? 我发现这很难调试,因为通常在调试时我会使用echo等,但是很显然,您无法使用这种大小的应用程序(我通常只是编写小脚本)来进行此类操作,调试opencart的最佳方法是什么,逐步执行,还有谁能告诉我为什么我的权限没有被更改?

Thanks! 谢谢!

Go to your admin dashboard -> system -> user groups 转到管理控制台->系统->用户组

There are two options which are access permissions and modify permissions. 有两个选项,分别是访问权限和修改权限。

You have to access your new permission there. 您必须在那里访问您的新权限。

I hope this will help you. 我希望这能帮到您。

Here is how i fixed this problem when i faced it. 这是我遇到问题时如何解决的。 Opencart stores it permission by serializing a php array to the database. Opencart通过将php数组序列化到数据库来存储它的权限。 write a small utility to grab that record and deserialize it and then add your permissions to it then serialize and write it back. 编写一个小的实用程序来获取该记录并反序列化,然后为其添加权限,然后进行序列化并将其写回。

To answer your simpler question you can use: 要回答更简单的问题,您可以使用:

$this->log->write('message');

in place of echo. 代替echo. It will send the message to the admin panel's error log in Opencart. 它将消息发送到Opencart中管理面板的错误日志。

You know function "addPermission" of Opencart, it set params with "user group id" not about "user id" you set it above. 您知道Opencart的函数“ addPermission”,它使用“用户组ID”设置参数,而不是您在上面设置的“用户ID”。 So: 所以:

You can get user group id with: 您可以通过以下方式获取用户组ID:

$user_group_id = $this->user->getGroupId();

After that, you addPermission "access/modify" for this user group of user. 之后,您为此用户组的用户添加权限“访问/修改”。

$this->model_user_user_group->addPermission($user_group_id, 'access', 'catalog/upload');

$this->model_user_user_group->addPermission($user_group_id, 'modify', 'catalog/upload');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM