I've successfully added a custom field to the User Sign-up page (create_account.jsp) by creating an expando column via Hook plugin. However, the field is not visible until I enable Guest permissions on it through the admin UI.
I need to be able to do this programmatically, through the Hook plugin. Exhaustive research leads me to believe that the following code should do the trick:
Role guest = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST);
ResourcePermissionLocalServiceUtil.setResourcePermissions(
companyId,
ExpandoColumn.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(expandoColumn.getColumnId()),
guest.getRoleId(),
new String[] { ActionKeys.VIEW, ActionKeys.UPDATE });
But it doesn't.
Anyone got any ideas?
I tried same code as yours and it worked for me. In my opinion the problem is in "expandoColumn.getColumnId()". How do you retreive object ExpandoColumn? I tried with with table id and name:
ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(21806, "Menu");
For this try i retreive the table id directly from DataBase, from table "expandocolumn"
Related
I'm attempting to integrate AdColony into an app. I'd like to set a custom ID for each user that gets passed back in the server to server callback I can setup in their dashboard. Right now the custom ID field returns null because it isn't set.
From what I can tell in their new java docs, they seem to have removed the setCustomID call from the AdColony class - or just overlooked it.
Their old docs for 2.3.6 have a built in method that makes it easy to do.
Apparently the name has changed to setUserID() and is now located on the AppOptions object. So you can do it like this:
AdColonyAppOptions options = new AdColonyAppOptions();
options.setUserID("MY USER ID");
AdColony.configure(this, options, "MY APP ID", "MY ZONE ID");
When I'm changing role programmatically then updated role is not taking place immediately until run clean up permissions from control panel.
Is there any way to call some APIs to do the same through program itself?
the method doing it is CleanUpPermissionsUtil.cleanUpAddToPagePermissions(ActionRequest)
but the problem that it is a internal utility and is not possible to call in a plugin. It execute in the PortalContext.
You can see the source of the class at the link and try to replicate the code maybe in your logic
https://github.com/liferay/liferay-portal/blob/6.2.x/portal-impl/src/com/liferay/portlet/admin/util/CleanUpPermissionsUtil.java
This is the way that you should use to reload permission from update role:
Role role = RoleLocalServiceUtil.getRole(companyId, RoleConstants.USER);
List<ResourcePermission> roleResourcePermissions = ResourcePermissionLocalServiceUtil.getRoleResourcePermissions(role.getRoleId());
for(ResourcePermission permission : roleResourcePermissions )
ResourcePermissionLocalServiceUtil.reassignPermissions(permission.getResourcePermissionId(),role.getRoleId());
I need to know how to take info from the user in one page using a label and textfield and displaying that in a grid in another page.
For example, Im getting the name of the user and displaying their name in following page in a grid. I'm using eclipse and working with vaadin, if that helps.
if what you need is an info from connected user, I suggest you to set the User object as Session Attribute.
IE:
User connectedUser = new User();
VaadinSession.getCurrent().setAttribute(User.class, connectedUser);
Then, if you need to pick this information, you just have to call
User currentUser = (User) VaadinSession.getCurrent().getAttribute(User.class);
Then, you can pick with all your getter all the required infos, like
String username = currentUser.getUsername();
In my opinion the best approach is to set the user attribute after his login, so you can have it everywhere you need to pick it from any class of your Vaadin application.
Hope this helps.
Bye
I am currently trying to enhance the To-Do List tutorial from Play framework's website. I've added a login form, (and of course a User class acting as a model), and it works perfectly well. I also made a small "dashboard" in which the logged user is able to change his password and his email address. But when I submit the form, I get a "Datasource user is null ?" error (RuntimeException).
The whole problem came when I wanted to restrict the edition possibilities (I first used a whole User form, which is quite over the top (User do not need to edit their ID). So I made a small inner class in my Application file called UpdateUser which gathers the required informations, just as I did for the login system.
Searching this error gave me many results but people saw their problem fixed by uncommenting the ebean.default line in the conf file, which I already did.
Here is the method I used to update user's informations :
Firstly, I made a small class in my Application to hold the form (exactly like I did for the login thing).
Then I made a update function as found here in my user class :
public static String update(String id, User newuser) {
newuser.update(id);
return("Your profile has been updated");
}
which returns the String that will be in my flash and which is according to my compiler the problem function.
This function is called in my Application like this :
public static Result updateUser(String id)
{
Form<UpdateUser> filledForm = updateUserForm.bindFromRequest();
System.out.println("Updated User : "+filledForm.get().id);
if(filledForm.hasErrors())
{
flash("success","Error while updating");
}else{
User user = new User(filledForm.get().id, filledForm.get().email, User.find.byId(filledForm.get().id).name, User.find.byId(filledForm.get().id).surname, filledForm.get().password);
flash("success", User.update(id,user));
}
return redirect(routes.Application.dashboard());
}
I tracked the data in the Form and it is not null (I mean I can get everything from the form). But I wonder if I have to create another ebean or if it's my function which is wrong. I also wonder if it's not my User creation that fail. Or maybe I should take the updateUser function and put it in my inner UpdateUser class ?
I have to admit that I worked on that all of yesterday (and probably today too), and I can't find anything on the internet except the ebean.default thing.
------EDIT
I continued to search, so here's what I tried :
1) Getting the form result into an instance of UpdateUser in order to use it
2) Use this instance instead of getting the data from the form
But it failed too. What's really weird is that I've added a toString() method for User class, and calling it on the user I want to insert (as an update) gives me the full stuff. I think it must be a configuration problem, but I can't see it.
Another thing : when I come to the error page and when I try to come back to the application by modifying the URL, I am disconnected. Is it my ebean that closes himself ?
Last edit for the day, I'm getting tired of this. I tried to delay the action (i.e. making it happen after the user has logged out), the new data are correctly saved but I still get the error when calling the update function.
Alright, I finally found it, but totally by chance.
I just had to write this :
public static String update(String id, User user) {
user.update((Object)id);
return ("Your profile has been updated");
}
Because for some reason that I don't really understand, The id String needs to be cast to Object. The rest of the code was correct. But apparently, when using update() on this particular case (is it because my id is a String or because I get the informations from another class before using it as my Model), the parameter which is supposed to be a String (even in the documentation) HAS to be cast.
That's it.
I have been trying to debug why my DropDownChoice in a simple form with just the DropDown and a Submit Button hasn't been working correctly for hours now.
It has a very weird behaviour. Where the first value selected in the drop down choice is sent successfully to the server after which any other choice select is not updated by the model. ie if I have a List persons, and I select the 2nd person, it submits this successfully. However, on select of another person and trying to submit it again it keeps showing the first selected option.
Snippets of code here:
ChoiceRenderer<Empowerment> empowermentChoiceRenderer = new ChoiceRenderer<>("name", "id");
final DropDownChoice<Empowerment> empowermentDropDownChoice =
new DropDownChoice<>("empowerment", new PropertyModel<Empowerment>(this, "empowerment"), empowermentList, empowermentChoiceRenderer);
empowermentDropDownChoice.setRequired(true);
add(empowermentDropDownChoice);
Only way I am able to get a decent behaviour is if I set the empowerment variable above to null. In this case, on submit the empowerment is reinitialised to null and then a new submit works correctly.
empowerment is just a JPA entity.
I'll be glad to know if this is a known issue. I experienced it in wicket 6.9.1 and wicket 6.12
Finally, found the solution to the problem. Above code is correct, but problem lied in the entity class itself - Empowerment needs to implement Equals and Hashcode correctly.
The DropDownChoice works just fine after this.
Add an OnChangeAjaxBehavior to your DropDownChoice. This will update the model value on every selection change you make on the drop down:
empowermentDropDownChoice .add(new OnChangeAjaxBehavior() {
#Override
protected void onUpdate(AjaxRequestTarget art) {
//just model update
}
});