I would like to know the basic idea guideline.
I am managing entity by SonataAdminBundle for now and get used to it. I would like to make progress step forward.
I want to make both admin and user edit the entity by 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.
However I want to let user 'bear' edit only 1 and 4 rows.
If I make edit/update/list script from the scratch in Controller. It is easy to accomplish.
However, I think it is like useless work because SonataAdminBundle has better UI than I make from scratch.
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??
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.
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. You can easily ask the Admin if the current logged in user has been granted to edit the rows 1 or 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, ...). 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