Page 1 of 1

How to create new admin role and permission

Posted: Mon Jul 07, 2014 10:23 am
by prabhat.kataria
I want to create new admin role by which any admin user mapped to this new role can manage products uploaded by him/her only. I want this type of role so as to create a separate ui for users, say traders, who can manage their store/portfolio of products on their own keeping the default demosite admin users in place for website management purpose.

I checked the roles available but each have some features less or more according to my requirements. Just wanted to know how to proceed towards customizing BLC with my requirements?

Re: How to create new admin role and permission

Posted: Mon Jul 07, 2014 11:12 pm
by bpolster
Assuming you've extended the domain to include the owning user, you'll need to create a custom persistence handler to intercept the fetch from the database to add your query restriction.

Enterprise Broadleaf provides support for role level security which provides a bit more out of box support for what you are trying to accomplish. But creating customer persistence handlers is a useful thing to know so take a look http://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/admin/custom-persistence-handlers.

Re: How to create new admin role and permission

Posted: Tue Jul 08, 2014 12:17 am
by prabhat.kataria
Brian, thanks for the information. I understood the use of custom persistence handler but don't know what did you exactly mean by "extended the domain to include the owning user". Also did you mean to say that after having custom persistence handler I will not have to create new type of role and permission? Moreover can you please tell me moniker of one of the implementation of CustomPersistenceHandler in BLC, if any.

Re: How to create new admin role and permission

Posted: Tue Jul 08, 2014 2:52 am
by phillipuniverse
Rather than use a CustomPersistenceHandler, your requirement sounds more appropriate for row level security: http://www.broadleafcommerce.com/docs/c ... l-security.

The comment from @bpolster about extending the domain to include the owning user meant that you would've extended ProductImpl to include something like an Auditable field that denoted which admin user created that product.

Re: How to create new admin role and permission

Posted: Tue Jul 08, 2014 2:41 pm
by prabhat.kataria
Phillip thanks for the reply. Your suggestion looks like the perfect match to what I was looking for. But I have some questions around it:
1. In the tutorial, 2 new entity are mentioned, MyAdminUser and MyProduct, do i need to have a mapping of them in any xml file to use them in admin application?
2. From where will I be able create a user(of type MyAdminUser) and input user's store details?
3. On looking into blc_store table, I can see that store_id is not referenced by any other table. So just wondering how will I map a user to its store? And how will fetch work?
4. In which xml file I need to write "blCustomRowSecurityProviders" bean?

Re: How to create new admin role and permission

Posted: Sun Jul 13, 2014 2:49 pm
by prabhat.kataria
Sometimes waiting for an answer to a query makes you impatient and you read lot of articles/documentations which forces you to try different options(mostly hit and trial :P) and in the process you may find answer to your questions yourself. And this is what happened with me :D.

Thoughts apart, I found answer to most of the questions I raised in my previous comments. Will post about them point by point
1. BLC documentation which guided me to create custom entity http://www.broadleafcommerce.com/docs/core/current/tutorials/getting-started-tutorials/extending-customer-for-heat-clinic-tutorial

2. Once the above step was done, I ran admin application with "blPU.hibernate.hbm2ddl.auto=update" in admin and to my amusement I could see the two entity(MyAdminUser and MyProduct) created in DB. Now when i clicked "add user" inside "Security>Users" I could see option to create normal user or user of type MyAdminUser. I created MyAdminUser and value of column "store_id" was set to "null" which I think happened because I did not map any store. Then in hunt to look for a way to input Store value, I got to know about multi-tenant feature which is available in enterprise edition.

Now for storing Store related info I am not sure whether I will need to write code as I could see StoreServiceImpl available to read store data from DB.

3. I was able to see blc_store table being referenced by previously mentioned new entities. But I am still not clear how will I map user to their store. Will i need to code it? But for fetch I assume StoreServiceImpl will suffice.

4. Created beans mapping in applicationContext-servlet-admin.xml but not sure whether this is the right place to do so !!!. Also not clear when these beans will be called?

Re: How to create new admin role and permission

Posted: Sat Jul 26, 2014 6:59 am
by prabhat.kataria
still not able to figure out whether i will have to code logic to map a Store to a User or is that work already done in BLC framework !!!

Re: How to create new admin role and permission

Posted: Tue Jul 29, 2014 3:09 pm
by phillipuniverse
You will have to code logic to map a store to a user.

Code: Select all

@Entity
@Table("MYCOMPANY_ADMIN_USER")
public class 
MyCompanyAdminUser extends AdminUser {
    
    @
ManyToOne(targetEntity StoreImpl.class)
    protected 
Store store;

}