留言板

How to auto assign new user to organization?

thumbnail
Ay Kay,修改在11 年前。

How to auto assign new user to organization?

Junior Member 帖子: 52 加入日期: 11-11-17 最近的帖子
Hi there,

I need to manually assign each and every new user to my default organization for there is no auto-assign mechanism? Eerrr..... Really?

That means you guys really want me to hire an additional secretary?



Shaking my head in disbelief over Liferay's status of stone age or alternatively over the fact how well hidden the concering switch is....
thumbnail
Hitoshi Ozawa,修改在11 年前。

RE: How to auto assign new user to organization?

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
That means you guys really want me to hire an additional secretary?


Well, that'll help the economy. :-)

That aside, go to "Control Panel" -> "Users and Organization" -> select "Action" button to the right of the default organization -> "Assign Users" -> Select "Available" tab -> select the top checkbox to check all users -> select "Update Associations"
thumbnail
Ay Kay,修改在11 年前。

RE: How to auto assign new user to organization?

Junior Member 帖子: 52 加入日期: 11-11-17 最近的帖子
No. Just no.

That means, Liferay forces us to e-mail or phone up each and every newly registered user to ask from what page he or she was actually registering from in order to correctly assign them one by one to the appropriate organisation? Are you serious on that?

I try to make the scenario clear once again. Hopefully.
On monday morning I see 200 newly registered users in my list. 120 Americans, 30 Italians, 30 French guys, 20 Germans. All of them registered from their specific country based "location site". All of them end up in that long list of 200 new users you mention. Unrecognizable in terms of interest in language branch. Now you tell me, I mark all of them to assign them to an organisation? You see your loophole?!

I need to automatically assign them to their appropriate organisation depending on from what location site they were registering. See?!
thumbnail
Hitoshi Ozawa,修改在11 年前。

RE: How to auto assign new user to organization?

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
Should have written your question fully beforehand. Seems like you didn't design your portal property.
thumbnail
Ay Kay,修改在11 年前。

RE: How to auto assign new user to organization?

Junior Member 帖子: 52 加入日期: 11-11-17 最近的帖子
Just for clearance, I put it another way.
QUESTION: How do you automatically assign a newly registered user to the organisation whose location site he or she happened to be on when registering?
Hitoshi Ozawa:
Seems like you didn't design your portal property.

When all this is closely related to how the portal is set up, then what portal property missing or falsely set up prevents this basic behaviour from fireing?

Sorry for loosing my temper, but this sort of stuff (programming basics) heavily eats into our budget.
thumbnail
Ay Kay,修改在11 年前。

RE: How to auto assign new user to organization?

Junior Member 帖子: 52 加入日期: 11-11-17 最近的帖子
Ay Kay:
Hitoshi Ozawa:
Seems like you didn't design your portal property.

When all this is closely related to how the portal is set up, then what portal property missing or falsely set up prevents this basic behaviour from fireing?

I am afraid I won't get an answer to this. Since this is fundamental function that simply needs to work, I spend the last couple of hours writing a solution myself.

Really can't believe this is true. This is the first programming I do in Liferay and it's something that is so elementary that I (and the whole team here) expected it to be an out-of-the-box feature. I cannot believe all Liferay administrators cheerfully assign newly registered users to their relevant organisation by hand. So even if I invented a solution meanwhile, please someone point me to the official approach.

Just in case such official approach does not exist, I would happily share my solution with all those poor souls out there that administrate this by hand.
[indent]I finally sketch my approach.
It's a hook (called it AutoAssigner-hook) that you simply deploy with your portal instance. After that you can simply use standard login portlet on any organisations "location's site". (Sorry if I use wrong terms, still new to this.) That leads to any user signing up being assigned to his or her correct organization. (That one he or she was coming from.) Tested it, does fly.
[/indent]
thumbnail
Luis Mas,修改在11 年前。

RE: How to auto assign new user to organization?

Regular Member 帖子: 146 加入日期: 09-5-18 最近的帖子
You could open an issue in http://issues.liferay.com and contribute your solution.
thumbnail
Ay Kay,修改在11 年前。

RE: How to auto assign new user to organization?

Junior Member 帖子: 52 加入日期: 11-11-17 最近的帖子
Luis Mas:
You could open an issue in http://issues.liferay.com and contribute your solution.

Well, yeah. I don't see that Liferay, Inc. has an issue with this at all. So I rather don't. But I'll post it in my blog as soon as I can spare some time.
thumbnail
Ay Kay,修改在11 年前。

RE: How to auto assign new user to organization?

Junior Member 帖子: 52 加入日期: 11-11-17 最近的帖子
Okay, my solution to this 2002 juggernaut piece a shhoftware.

/AutoAssigner-hook/docroot/WEB-INF/liferay-hook.xml
<!--?xml version="1.0"?-->


<hook>
    <portal-properties>portal.properties</portal-properties>
</hook>

/AutoAssigner-hook/docroot/WEB-INF/src/portal.properties
value.object.listener.com.liferay.portal.model.User=<your-package>.NewUserListener</your-package>

/AutoAssigner-hook/docroot/WEB-INF/src/<YOUR-PACKAGE>/NewUserListener.java
Code can be improved. (Proper exception handling, Logging, additionally handling web sites, not only organizations, etc. ...)

package YOUR-PACKAGE;

import com.liferay.portal.ModelListenerException;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.BaseModelListener;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.User;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.ServiceContextThreadLocal;
import com.liferay.portal.service.UserLocalServiceUtil;

public class NewUserListener extends BaseModelListener<user>
{
	@Override
	public void onAfterCreate(User model) throws ModelListenerException
	{
		System.out.println("********************************************************************************");
		System.out.println("NEW USER");
		System.out.println("********************************************************************************");

		String portalUrl = ServiceContextThreadLocal.getServiceContext().getPortalURL();
		String layoutUrl = ServiceContextThreadLocal.getServiceContext().getLayoutURL();
		layoutUrl = layoutUrl.substring(portalUrl.length()); // Consume prefix such as "http://localhost:8080" 

		int slashPos = layoutUrl.indexOf('/', 1); // Get position of slash after servlet context path such as "/web/"
		String friendlyUrl = layoutUrl.substring(slashPos);
		slashPos = friendlyUrl.indexOf('/', 1); // Try to get next slash position
		if (slashPos != -1) // User is deeper inside navigation structure
			friendlyUrl = friendlyUrl.substring(0, slashPos); // Chop off suffixing navigation structure

		Long companyId = ServiceContextThreadLocal.getServiceContext().getCompanyId();

		try
		{
			Group group = GroupLocalServiceUtil.getFriendlyURLGroup(companyId, friendlyUrl);
			long organizationId = group.getClassPK();
			long[] userIds = new long[] { model.getUserId() };
			UserLocalServiceUtil.addOrganizationUsers(organizationId, userIds);

			System.out.println("Added user " + model.getLogin() + " (id " + model.getUserId()
					+ ") to organisation (friendly URL: " + friendlyUrl + ", Id: " + organizationId + ")");
		}
		catch (PortalException exception)
		{
			exception.printStackTrace();
		}
		catch (SystemException exception)
		{
			exception.printStackTrace();
		}
	}
}
</user>


Again, it's a 4-liner doing a job that's delivering most basic stuff that should have shipped with version 0.1.

With all due respect, I'd firmly like to stress how astonishingly poor the whole documentation here is for a 2002 state of the art software. The book "LIFERAY in Action" is a joke with code that doens't run. "ActionUtil"? Are you kidding me? Most basic stuff is simply NOT explained. People need to refer to Youtube. Poor job, ....
thumbnail
Aritz Galdos,修改在9 年前。

RE: How to auto assign new user to organization?

Expert 帖子: 416 加入日期: 07-5-15 最近的帖子
Easy mate!

Liferay staff and community members do their best with documentation.

Sometimes we find some lack of documentation but it is an Opencource and free to use project in which you will be welcome to contribute, Just as you did in your last post. It's been helpfull to me.

By the way, you get the portalURL and layoutURL from ServiceContext to "calculate" the friendly to get the group where the user is taking action.

I think it is easier to ask directly for ServiceContextThreadLocal.getServiceContext().getScopeGroup()

And guess what? I read it in the online doc.

https://docs.liferay.com/portal/6.2/javadocs-all/com/liferay/portal/service/ServiceContext.html

Regards,
Aritz