Login to bookmark this video
Buy Access to Course
26.

Role Hierarchy

|

Share this awesome video!

|

Keep on Learning!

2 Comments

Sort By
Login or Register to join the conversation

Maybe off topic question - how to create hierarchy on Database level too.
I have worker 1 - have similar access that worker 2, but information what worker 1 see about summary report from company 1 and worker 2 summary from company 2. Twig for summary identical. I think i need to create method on DataRepository with argument ? It is correct way?

| Reply |

Hey Mepcuk!

Hmm. I'm not sure if this is really a "role hierarchy" that you need in the database, or just a smart voter system + smart queries.

The most important thing to focus on first is how you want to structure the data and relations in the database. It sounds to me like you have this setup:

A) worker 1 and worker 2 generally have similar access (i.e. they probably have similar or identical roles)
B) BUT, worker 1 can see "company 1" summary report only and worker 2 can see "company 2" summary report only.

If this is the case, then you need to protect the "summary" report with a voter - e.g. $this->denyAccessUnlessGranted('SUMMARY_REPORT', $company).

In the database, you will naturally have some way that "worker 1" and "company 1" are related. This part has nothing do with security, it's just part of your data model. For example, maybe your Worker entity has a ManyToOne to Company, which is how you know that worker 1 works for company 1.

Assuming you have the database all modeled how you want, then in your custom voter, you just use that relationship. For example, you would (in your voter) get the current user object (pretend it is "user 1") and then look at the $company object that was passed as the subject (pretend it is "company 1"). Then, if $user->getCompany() === $company, you know that access is granted. Else, access is denied.

Let me know if this helps!

Cheers!

| Reply |

Delete comment?

Share this comment

astronaut with balloons in space

"Houston: no signs of life"
Start the conversation!