简体   繁体   English

如何转移管理员和管理员的SonataAdminBundle

[英]How to divert the SonataAdminBundle for both admin and manager

I would like to know the basic idea guideline. 我想知道基本的想法指南。

I am managing entity by SonataAdminBundle for now and get used to it. 我现在由SonataAdminBundle管理实体,并习惯了它。 I would like to make progress step forward. 我想取得进步。

I want to make both admin and user edit the entity by sonataadminbundle 我想让管理员和用户通过sonataadminbundle编辑实体

[For example] [例如]

I have table/entity like this. 我有这样的表/实体。

Id |User  | data
1  |bear  | sarmon
2  |dog   | meat
3  |monkey| banana
4  |bear  | peanuts
5  |dog   | corn 

Of course I(admin) can edit entity from admin_dashboard of SonataAdminBundle. 当然,我(管理员)可以从SonataAdminBundle的admin_dashboard编辑实体。

However I want to let user 'bear' edit only 1 and 4 rows. 但是我想让用户“熊”只编辑1和4行。

If I make edit/update/list script from the scratch in Controller. 如果我从头开始在Controller中进行编辑/更新/列出脚本。 It is easy to accomplish. 这很容易实现。

However, I think it is like useless work because SonataAdminBundle has better UI than I make from scratch. 但是,我认为这就像无用的工作,因为SonataAdminBundle具有比我从头开始更好的UI。

So, Does anyone know the appropriate way for this kind of ideas?? 那么,有人知道这种想法的合适方法吗? or it is bad idea to use SonataAdminBundle for both user and admin?? 还是对用户和管理员同时使用SonataAdminBundle是个坏主意?


I want let user bear see only bear related tables like. 我想让用户忍受只看到熊相关的表。

Id |User  | data
1  |bear  | sarmon
4  |bear  | peanuts

At first I am struggling with public function configureListFields(ListMapper $listMapper) however this code is only called one time. 起初,我在使用public function configureListFields(ListMapper $listMapper)挣扎,但是此代码仅被调用一次。 I can't find the right answer. 我找不到正确的答案。

So I guess I need to put this kind of code somewhere else. 所以我想我需要将这种代码放在其他地方。

if ($user == bear){
array_push($table,$line);
}
else {
}

It's completely fine to use the AdminBundle for an user and a privileged-user at the same time. 同时为用户和特权用户使用AdminBundle是完全可以的。 You can easily ask the Admin if the current logged in user has been granted to edit the rows 1 or 4. 您可以轻松询问管理员,是否已授予当前登录用户编辑第1行或第4行的权限。

For example you could use: 例如,您可以使用:

protected function configureFormFields(FormMapper $mapper)
{
    /* either identify your custom rows here or via ACL/ROLES */
    if (!$this->isGranted('EDIT')) {
      // not allowed
    }
}

For security concerns (and depending on your use-case), please note that this won't prevent your non-privileged users to show/list those entities (since the above example only overrides the form/edit mask). 出于安全方面的考虑(并取决于您的用例),请注意,这不会阻止您的非特权用户显示/列出这些实体(因为上面的示例仅覆盖了表单/编辑掩码)。 Of course, you can add you logic to those methods too. 当然,您也可以将逻辑添加到这些方法中。

Depending on your security-handler, you can use everything that's supported by symfony (Roles, ACL, ...). 根据您的安全处理程序,您可以使用symfony支持的所有功能(Roles,ACL等)。 Please take a look on how to configure it to your needs here: https://sonata-project.org/bundles/admin/3-x/doc/reference/security.html 请在此处查看如何根据您的需要配置它: https : //sonata-project.org/bundles/admin/3-x/doc/reference/security.html

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

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