When the current user is visiting his profile in a vre, an alert message appears and the profile itself is not editable
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/social-profile@130538 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a3f07223b4
commit
9f9f88590b
|
@ -18,6 +18,7 @@ import com.google.gwt.core.client.EntryPoint;
|
|||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.Cookies;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.Window.Location;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
|
@ -57,6 +58,8 @@ public class SocialProfile implements EntryPoint {
|
|||
displayProfile();
|
||||
//result contain the publicProfileLinkedInUrl
|
||||
sendRefreshClientEvent(result);
|
||||
// force refresh to reload updated content
|
||||
setUrlBase();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
|
@ -109,6 +112,17 @@ public class SocialProfile implements EntryPoint {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any get parameter (such as code, state)
|
||||
*/
|
||||
private void setUrlBase() {
|
||||
|
||||
String baseUrl = Window.Location.getHref().split("\\?")[0];
|
||||
GWT.log(baseUrl);
|
||||
Location.assign(baseUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the token if everything goers ok, null otherwise
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.gcube.portlets.user.socialprofile.client.SocialServiceAsync;
|
|||
import org.gcube.portlets.user.socialprofile.shared.UserContext;
|
||||
import org.gcube.portlets.widgets.wsmail.client.forms.MailForm;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Alert;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.RunAsyncCallback;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
|
@ -37,7 +38,7 @@ public class DisplayProfile extends Composite {
|
|||
protected final static String ISTI_ERROR = "Your Company please";
|
||||
private final static String OAUTH2_SERVICE = "https://www.linkedin.com/uas/oauth2/authorization?response_type=code";
|
||||
private final static String D4S_APP_ID = "77n7r4c9nwuwk2";
|
||||
|
||||
|
||||
private static DisplayProfileUiBinder uiBinder = GWT
|
||||
.create(DisplayProfileUiBinder.class);
|
||||
|
||||
|
@ -48,7 +49,7 @@ public class DisplayProfile extends Composite {
|
|||
public static final String savingImage = GWT.getModuleBaseURL() + "../images/saving.gif";
|
||||
public static final String GET_OID_PARAMETER = "oid";
|
||||
public static final String CONTROL_SEQUENCE_COOKIE = "CSRF-check-d4science";
|
||||
|
||||
|
||||
private final SocialServiceAsync socialService = GWT.create(SocialService.class);
|
||||
|
||||
|
||||
|
@ -57,28 +58,29 @@ public class DisplayProfile extends Composite {
|
|||
@UiField HTML userFullName;
|
||||
@UiField TextBox headlineBox;
|
||||
@UiField TextBox institutionBox;
|
||||
|
||||
|
||||
@UiField HTML editHeadline;
|
||||
@UiField HTML editIsti;
|
||||
|
||||
|
||||
@UiField HTML headlineLabel;
|
||||
@UiField HTML institutionLabel;
|
||||
|
||||
|
||||
@UiField Image savingHeadline;
|
||||
@UiField Button saveHead;
|
||||
@UiField Button cancelHead;
|
||||
|
||||
|
||||
@UiField Button saveIsti;
|
||||
@UiField Button cancelIsti;
|
||||
|
||||
|
||||
@UiField Button messageButton;
|
||||
@UiField Button editButton;
|
||||
@UiField Button importButton;
|
||||
|
||||
@UiField Alert ownerSeeingProfileAsVreMemberAlert;
|
||||
|
||||
|
||||
private String currHeadLine;
|
||||
private String currInstitution;
|
||||
|
||||
|
||||
private UserInfo myUserInfo;
|
||||
private DisplaySummary summarySibling;
|
||||
|
||||
|
@ -93,46 +95,52 @@ public class DisplayProfile extends Composite {
|
|||
* @param result
|
||||
*/
|
||||
public void show(UserContext result) {
|
||||
|
||||
|
||||
myUserInfo = result.getUserInfo();
|
||||
avatarImage.setUrl(myUserInfo.getAvatarId());
|
||||
userFullName.setText(myUserInfo.getFullName());
|
||||
|
||||
if (SocialProfile.getUserToShowId() == null || result.isOwner()) { //its him seeing his profile
|
||||
|
||||
|
||||
/*
|
||||
* Here we check that:
|
||||
* 1) the user is the owner of the profile;
|
||||
* 2) if the current user to show is null or not (that is, the parameter GCubeSocialNetworking.USER_PROFILE_OID within the url);
|
||||
* 3) if such parameter is equal to the current user we show the profile as if it belong to someone else
|
||||
*/
|
||||
if (showAsOwner(result)) {
|
||||
|
||||
String head = (result.getHeadline() == null || result.getHeadline().compareTo("") == 0) ? HEADLINE_TEXT : result.getHeadline();
|
||||
String isti = (result.getInstitution() == null ||result.getInstitution().compareTo("") == 0) ? ISTI_TEXT : result.getInstitution();
|
||||
headlineLabel.setText(head);
|
||||
institutionLabel.setText(isti);
|
||||
|
||||
|
||||
editHeadline.setStyleName("editImage");
|
||||
editHeadline.setTitle("Edit your Professional Headline (e.g. Researcher at University of ...");
|
||||
|
||||
|
||||
editIsti.setStyleName("editImage");
|
||||
editIsti.setTitle("Edit location or industry");
|
||||
|
||||
|
||||
headlineBox.setMaxLength(100);
|
||||
institutionBox.setMaxLength(100);
|
||||
|
||||
|
||||
messageButton.removeFromParent();
|
||||
currHeadLine = head;
|
||||
if (result.getHeadline() == null || result.getHeadline().compareTo("") == 0) {
|
||||
headlineLabel.getElement().getStyle().setOpacity(0.5);
|
||||
institutionLabel.getElement().getStyle().setOpacity(0.5);
|
||||
}
|
||||
|
||||
|
||||
editButton.addStyleName("import-edit-buttons-style");
|
||||
editButton.setVisible(true);
|
||||
editButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
|
||||
// enable editing
|
||||
summarySibling.enableEditing();
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
importButton.addStyleName("import-edit-buttons-style");
|
||||
importButton.setVisible(true);
|
||||
importButton.addClickHandler(new ClickHandler() {
|
||||
|
@ -140,30 +148,50 @@ public class DisplayProfile extends Composite {
|
|||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
String controlSequence = getRandomString();
|
||||
|
||||
|
||||
//needed to prevent Cross Site Request Forgery attacks
|
||||
Cookies.setCookie(CONTROL_SEQUENCE_COOKIE, controlSequence);
|
||||
|
||||
|
||||
String url = OAUTH2_SERVICE + ""
|
||||
+ "&client_id="+D4S_APP_ID
|
||||
+ "&state="+controlSequence
|
||||
+ "&redirect_uri="+getRedirectURI();
|
||||
|
||||
|
||||
Location.assign(url);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} else { //its someone else
|
||||
String head = (result.getHeadline() == null || result.getHeadline().compareTo("") == 0) ? "" : result.getHeadline();
|
||||
String isti = (result.getInstitution() == null || result.getInstitution().compareTo("") == 0) ? "" : result.getInstitution();
|
||||
headlineLabel.setText(head);
|
||||
institutionLabel.setText(isti);
|
||||
|
||||
|
||||
avatarImage.getElement().getParentElement().setAttribute("href", "");
|
||||
avatarImage.setTitle(myUserInfo.getFullName());
|
||||
messageButton.setVisible(true);
|
||||
|
||||
// check if the current user is the owner but he is looking at his own profile as if it was the profile of another vre member
|
||||
if(result.isOwner()){
|
||||
// TODO get the address of the My Profile page and add a link to redirect the user
|
||||
ownerSeeingProfileAsVreMemberAlert.setText("You are looking your profile as the other vre members see it.");
|
||||
ownerSeeingProfileAsVreMemberAlert.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the profile must be shown as belonging to the user or not
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
private boolean showAsOwner(UserContext result) {
|
||||
|
||||
if((SocialProfile.getUserToShowId() == null && result.isOwner()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return the redirect uri when authorized (or not) by LinkedIn via oAuth2
|
||||
|
@ -175,7 +203,7 @@ public class DisplayProfile extends Composite {
|
|||
return redirectURI+"?gwt.codesvr=127.0.0.1:9997";
|
||||
return redirectURI;
|
||||
}
|
||||
|
||||
|
||||
@UiHandler("editHeadline")
|
||||
void onEditHeadlineClick(ClickEvent e) {
|
||||
headlineLabel.setVisible(false);
|
||||
|
@ -189,7 +217,7 @@ public class DisplayProfile extends Composite {
|
|||
saveHead.setVisible(true);
|
||||
cancelHead.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@UiHandler("editIsti")
|
||||
void onEditInstitutionClick(ClickEvent e) {
|
||||
institutionLabel.setVisible(false);
|
||||
|
@ -203,18 +231,18 @@ public class DisplayProfile extends Composite {
|
|||
saveIsti.setVisible(true);
|
||||
cancelIsti.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@UiHandler("cancelHead")
|
||||
void onCancelHeadlineClick(ClickEvent e) {
|
||||
cancelHeadline();
|
||||
}
|
||||
|
||||
|
||||
@UiHandler("cancelIsti")
|
||||
void onCancelIstiClick(ClickEvent e) {
|
||||
cancelInsti();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@UiHandler("saveHead")
|
||||
void onSaveHeadlineClick(ClickEvent e) {
|
||||
String toShare = escapeHtml(headlineBox.getText());
|
||||
|
@ -244,10 +272,10 @@ public class DisplayProfile extends Composite {
|
|||
savingHeadline.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@UiHandler("saveIsti")
|
||||
void onSaveInstitutionClick(ClickEvent e) {
|
||||
String toShare = escapeHtml(institutionBox.getText());
|
||||
|
@ -277,10 +305,10 @@ public class DisplayProfile extends Composite {
|
|||
savingHeadline.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@UiHandler("messageButton")
|
||||
void onSendPrivateMessageClick(ClickEvent e) {
|
||||
final List<String> listToLogin = new ArrayList<String>();
|
||||
|
@ -295,7 +323,7 @@ public class DisplayProfile extends Composite {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void cancelHeadline() {
|
||||
editHeadline.setVisible(true);
|
||||
saveHead.setVisible(false);
|
||||
|
@ -303,7 +331,7 @@ public class DisplayProfile extends Composite {
|
|||
headlineBox.setVisible(false);
|
||||
headlineLabel.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void cancelInsti() {
|
||||
editIsti.setVisible(true);
|
||||
saveIsti.setVisible(false);
|
||||
|
@ -311,14 +339,14 @@ public class DisplayProfile extends Composite {
|
|||
institutionBox.setVisible(false);
|
||||
institutionLabel.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
public void showError(String message) {
|
||||
Window.alert("Failure: " + message);
|
||||
avatarImage.setSize("100px", "100px");
|
||||
avatarImage.setUrl(avatar_default);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Escape an html string. Escaping data received from the client helps to
|
||||
* prevent cross-site script vulnerabilities.
|
||||
|
@ -333,15 +361,15 @@ public class DisplayProfile extends Composite {
|
|||
return html.replaceAll("&", "&").replaceAll("<", "<")
|
||||
.replaceAll(">", ">");
|
||||
}
|
||||
|
||||
|
||||
private String getRandomString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i=0;i<20;i++) {
|
||||
sb.append('a'+Random.nextInt(26));
|
||||
sb.append('a'+Random.nextInt(26));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the summary sibling object
|
||||
* @param summary
|
||||
|
@ -349,5 +377,5 @@ public class DisplayProfile extends Composite {
|
|||
public void setDisplaySummarySibling(DisplaySummary summary) {
|
||||
this.summarySibling = summary;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui">
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
|
||||
<g:HTMLPanel ui:field="mainPanel">
|
||||
<b:Alert visible="false" animation="true" ui:field="ownerSeeingProfileAsVreMemberAlert"></b:Alert>
|
||||
<table class="">
|
||||
<tr>
|
||||
<td width="110px;" align="middle">
|
||||
|
|
|
@ -471,9 +471,10 @@ public class SocialServiceImpl extends RemoteServiceServlet implements SocialSer
|
|||
UserLocalServiceUtil.updatePortrait(user.getUserId(), pictureData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//update the location/industry
|
||||
new LiferayUserManager().saveCustomAttr(user.getUserId(), CustomAttributeKeys.USER_LOCATION_INDUSTRY.getKeyName(), locationOrIndustry);
|
||||
if(locationOrIndustry != null)
|
||||
new LiferayUserManager().saveCustomAttr(user.getUserId(), CustomAttributeKeys.USER_LOCATION_INDUSTRY.getKeyName(), locationOrIndustry);
|
||||
if (toReturn)
|
||||
return publicProfileURL;
|
||||
else return null;
|
||||
|
|
|
@ -14,8 +14,10 @@
|
|||
<inherits name="org.jsonmaker.gwt.Gwt_jsonmaker" />
|
||||
<inherits
|
||||
name="net.eliasbalasis.tibcopagebus4gwt.testsubscriber.TestSubscriber" />
|
||||
|
||||
<!-- Bootstrap import -->
|
||||
<inherits name="com.github.gwtbootstrap.Bootstrap" />
|
||||
|
||||
<!-- Specify the app entry point class. -->
|
||||
<entry-point
|
||||
class='org.gcube.portlets.user.socialprofile.client.SocialProfile' />
|
||||
|
|
Loading…
Reference in New Issue