问题
I want to customize the Site Administrator Role permissions i.e, I need to enable a feature for creating the users for site administration under respective site. How can I achieve that? Do I need to achieve it with Hook OR need to create EXT? OR any other simpler way to achieve that? I need to enable the user creation and assign permission for Site Administrator under respective site. I don't want to crate users by Super admin.
回答1:
Maybe you can create a custom portlet, put it in control panel, in which only the Site Administrators, filling a form, can create users that you assign directly as members of current site.
PRO: I think you can achieve your task.
CON:
- You have to spend time to develop, it's not a "solution in a few clicks".
- It is not a Permissions customization.
References: "Beginning Liferay Development" It's a usefull guide that explain, using all Liferay best practice, how to develop a complete portlet, the "famous" KnowledgeBasePortlet. I suggest you to read it all, but the important points for your problem are:
- Setting Permissions, to permit only to Site Administrator to create Users
- Adding Portlet to Control Panel
NB: As you will see (Creating Entity Actions), the KnowledgeBasePortlet creates two custom Entities, you don't need to do it: the entities you need already exist. Use that chapter just to learn how call the methods to add/edit/delete that entities, you will have to do the same but with the User entity through the UserLocalServiceUtil.
回答2:
I'm not sure I'm understanding what you need (sorry, I try to hypotesize).
If you already have different websites and you need to create programmatically all site admin users (one shot), you need to create a portlet (and deploy it as control panel portlet). Your portlet should have just an interface to invoke a method... and your method just need to
- get all sites you need (in which admin user doesn't exist yet)
- create a user (using UserLocalServiceUtil)
- assigning to users necessary Roles by RoleLocalServiceUtil and UserGroupRoleLocalServiceUtil A good example of code can be found here: Liferay Forum: How to Programmatically Add Liferay Users in Java
If you prefer your portlet can expose this methos to Liferay not uy UI, but using Liferay cron job. You just need to add a declaration inside your liferay-portlet.xml pointing to your code: watch this simple guide
Differently, if you want an automatic way to add a user everytime you create a site by interface you can use an hook and override the entity creation event on DB.
Websites are in Group table, so you can add a servlet.service.events.post
Event Handler to a Service Event.
There you can call your code: read this useful post
I hope it can be useful for you.
来源:https://stackoverflow.com/questions/28813244/customize-permissions-for-site-administrator-role-in-life-ray