added clickable users on posts

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@163123 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2018-02-09 14:27:37 +00:00
parent 6a2dd96752
commit f6d583c8da
4 changed files with 62 additions and 14 deletions

View File

@ -395,12 +395,13 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
String baseUrl = "url of the record here";
String fullName = "Andrea Rossi";
String usernameCurrent = "andrea.rossi";
String uuid = UUID.randomUUID().toString();
String adminInUrl = "costantino.perciante";
String adminInUrlFullName = "Costantino Perciante";
long timestamp = System.currentTimeMillis() - 1000 * ((long)(Math.random() * 10 * 60 * 60));
return new RevertableOperationInfo(
baseUrl, fullName, uuid, adminInUrlFullName, adminInUrl, timestamp, RevertableOperations.MERGE);
baseUrl, fullName, usernameCurrent, uuid, adminInUrlFullName, adminInUrl, timestamp, RevertableOperations.MERGE);
}
PortalContext pContext = PortalContext.getConfiguration();
@ -445,14 +446,14 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
// check if it is a reviewer, than he can do what he wants (no matter the admin)
if(isReviewer){
return new RevertableOperationInfo(recordUrl,
fullName, uuid, fullNameadminInUrl, userNameadminInUrl, decryptedUrl.getTimestamp(), decryptedUrl.getOperation());
fullName, username, uuid, fullNameadminInUrl, userNameadminInUrl, decryptedUrl.getTimestamp(), decryptedUrl.getOperation());
}else{
if(!username.equals(userNameadminInUrl))
throw new Exception("You are not the editor allowed to perform this operation!");
else
return new RevertableOperationInfo(recordUrl,
fullName, uuid, fullNameadminInUrl, userNameadminInUrl, decryptedUrl.getTimestamp(), decryptedUrl.getOperation());
fullName, username, uuid, fullNameadminInUrl, userNameadminInUrl, decryptedUrl.getTimestamp(), decryptedUrl.getOperation());
}
}

View File

@ -4,6 +4,7 @@ import static org.gcube.resources.discovery.icclient.ICFactory.client;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -12,6 +13,7 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
@ -57,6 +59,8 @@ public class SocialCommunications {
private static final String serviceName = "SocialNetworking";
private static final String serviceClass = "Portal";
public static final String USER_PROFILE_OID = "userIdentificationParameter";
// social operations
private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "2/tokens/generate-application-token";
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "2/posts/write-post-app";
@ -150,8 +154,6 @@ public class SocialCommunications {
String currentScope = ScopeProvider.instance.get();
String tokenUser = SecurityTokenProvider.instance.get();
//return "b159b50c-c0f8-4a4c-bac9-b6149d6b81fc-98187548";
logger.info("Current scope for requireApplicationToken is " + currentScope + " and token is " + tokenUser.substring(0, 10) + "***************");
String basePath = serviceUrl;
@ -212,7 +214,7 @@ public class SocialCommunications {
* @throws Exception
*/
@SuppressWarnings("unchecked")
public static void writePostOnRevert(String serviceUrl, RevertableOperationInfo rInfo, boolean enablePostNotification) throws Exception{
public static void writePostOnRevert(String serviceUrl, RevertableOperationInfo rInfo, boolean enablePostNotification, String userCurrentUrl) throws Exception{
// discover service endpoint for the social networking library
String currentScope = ScopeProvider.instance.get();
@ -235,8 +237,20 @@ public class SocialCommunications {
// require url
String applicationToken = requireApplicationToken(serviceUrl);
final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(userCurrentUrl) + GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
String userFullNameHighlightedCurrent = "<a class=\"link\" href=\"" + profilePageURL + "?"+
Base64.getEncoder().encodeToString(USER_PROFILE_OID.getBytes())+"="+
Base64.getEncoder().encodeToString(rInfo.getUserNameCurrentAdmin().getBytes())+"\">"+rInfo.getFullNameCurrentAdmin()+
"</a> ";
String userFullNameHighlightedOriginal = "<a class=\"link\" href=\"" + profilePageURL + "?"+
Base64.getEncoder().encodeToString(USER_PROFILE_OID.getBytes())+"="+
Base64.getEncoder().encodeToString(rInfo.getUserNameOriginalAdmin().getBytes())+"\">"+rInfo.getFullNameOriginalAdmin()+
"</a> ";
// replace
String message = POST_ON_REVERT.replace("RECORD_URL", rInfo.getRecordUrl()).replace("ADMIN_WHO_CHANGED", rInfo.getFullNameCurrentAdmin()).replace("ORIGINAL_USER", rInfo.getFullNameOriginalAdmin());
String message = POST_ON_REVERT.replace("RECORD_URL", rInfo.getRecordUrl()).replace("ADMIN_WHO_CHANGED", userFullNameHighlightedCurrent).replace("ORIGINAL_USER",userFullNameHighlightedOriginal);
// add hashtag
message +="<br><br>";
@ -275,7 +289,7 @@ public class SocialCommunications {
* @throws Exception
*/
@SuppressWarnings("unchecked")
public static void writeProductPost(String serviceUrl, ManageProductBean bean, String username, String fullName, boolean enablePostNotification) throws Exception{
public static void writeProductPost(String serviceUrl, ManageProductBean bean, String username, String fullName, boolean enablePostNotification, String userCurrentUrl) throws Exception{
// discover service endpoint for the social networking library
String currentScope = ScopeProvider.instance.get();
@ -298,9 +312,15 @@ public class SocialCommunications {
// require url
String applicationToken = requireApplicationToken(serviceUrl);
final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(userCurrentUrl) + GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
String userFullNameHighlighted = "<a class=\"link\" href=\"" + profilePageURL + "?"+
Base64.getEncoder().encodeToString(USER_PROFILE_OID.getBytes())+"="+
Base64.getEncoder().encodeToString(username.getBytes())+"\">"+fullName+
"</a> ";
// replace
String message = POST_MESSAGE.replace("PRODUCT_TITLE", bean.getTitle()).replace("LINK_RECORD", bean.getUrl()).
replace("USER_FULLNAME", fullName);
replace("USER_FULLNAME", userFullNameHighlighted);
if(bean.getReport() != null && !bean.getReport().isEmpty())
message += ADD_REPORT.replace("REPORT_UPDATE", bean.getReport());
@ -335,6 +355,21 @@ public class SocialCommunications {
}
}
private static String extractOrgFriendlyURL(String portalURL) {
String groupRegEx = "/group/";
if (portalURL.contains(groupRegEx)) {
String[] splits = portalURL.split(groupRegEx);
String friendlyURL = splits[1];
if (friendlyURL.contains("/")) {
friendlyURL = friendlyURL.split("/")[0];
} else {
friendlyURL = friendlyURL.split("\\?")[0].split("\\#")[0];
}
return "/"+friendlyURL;
}
return null;
}
/**
* Send an email to the administrator as well as the
* @param bean
@ -527,7 +562,7 @@ public class SocialCommunications {
String messageToReviewer = EMAIL_REVIEWER_REVERT.replace("ADMIN_WHO_CHANGED", rInfo.getFullNameCurrentAdmin()).replace("RECORD_URL", rInfo.getRecordUrl()).
replace("ORIGINAL_USER", rInfo.getFullNameOriginalAdmin());
String subject = "Revert merge request on GRSF Record";
messageToEditor = messageToEditor.replace("<br>", "\n");
messageToReviewer = messageToReviewer.replace("<br>", "\n");

View File

@ -222,7 +222,7 @@ public class Utils {
groupId, currentBrowserUrl, bean.isMergesInvolved());
// create a post about the operation
SocialCommunications.writeProductPost(baseUrlSocial, bean, username, fullName, false);
SocialCommunications.writeProductPost(baseUrlSocial, bean, username, fullName, false, currentBrowserUrl);
}catch(Exception e){
logger.error("Something failed while alerting editors/reviewers", e);
@ -256,6 +256,9 @@ public class Utils {
// require social networking url
final String baseUrlSocial = SocialCommunications.getBaseUrlSocialService(httpServletRequest);
// and the user current browser url
final String currentBrowserUrl = Utils.getCurrentClientUrl(httpServletRequest).split("\\?")[0]; // ignore other parameters
// manage interactions through a separated thread but set there security token and context (and then reset them)
Thread t = new Thread(new Runnable() {
@ -266,7 +269,7 @@ public class Utils {
try{
// write post about this
SocialCommunications.writePostOnRevert(baseUrlSocial, rInfo, false);
SocialCommunications.writePostOnRevert(baseUrlSocial, rInfo, false, currentBrowserUrl);
// alert who's involved
SocialCommunications.sendEmailAdministratorsOnOperationReverted(baseUrlSocial, rInfo, groupId);

View File

@ -7,6 +7,7 @@ public class RevertableOperationInfo implements Serializable{
private static final long serialVersionUID = 5274434342849474800L;
private String recordUrl;
private String fullNameCurrentAdmin; // the one who is thinking to revert it
private String userNameCurrentAdmin;
private String uuid;
private String fullNameOriginalAdmin; // the original admin in the link (his/her Full Name)
private String userNameOriginalAdmin; // the original admin's username
@ -19,6 +20,7 @@ public class RevertableOperationInfo implements Serializable{
public RevertableOperationInfo(
String recordUrl,
String fullNameCurrentAdmin,
String userNameCurrentAdmin,
String uuid,
String fullNameOriginalAdmin,
String userNameOriginalAdmin,
@ -27,12 +29,12 @@ public class RevertableOperationInfo implements Serializable{
super();
this.recordUrl = recordUrl;
this.fullNameCurrentAdmin = fullNameCurrentAdmin;
this.userNameCurrentAdmin = userNameCurrentAdmin;
this.uuid = uuid;
this.fullNameOriginalAdmin = fullNameOriginalAdmin;
this.userNameOriginalAdmin = userNameOriginalAdmin;
this.timestamp = timestamp;
this.operation = operation;
}
public long getTimestamp() {
@ -82,6 +84,12 @@ public class RevertableOperationInfo implements Serializable{
this.userNameOriginalAdmin = userNameOriginalAdmin;
}
public String getUserNameCurrentAdmin() {
return userNameCurrentAdmin;
}
public void setUserNameCurrentAdmin(String userNameCurrentAdmin) {
this.userNameCurrentAdmin = userNameCurrentAdmin;
}
public String getUuid() {
return uuid;
}
@ -91,7 +99,8 @@ public class RevertableOperationInfo implements Serializable{
@Override
public String toString() {
return "RevertableOperationInfo [recordUrl=" + recordUrl
+ ", fullNameCurrentAdmin=" + fullNameCurrentAdmin + ", uuid="
+ ", fullNameCurrentAdmin=" + fullNameCurrentAdmin
+ ", userNameCurrentAdmin=" + userNameCurrentAdmin + ", uuid="
+ uuid + ", fullNameOriginalAdmin=" + fullNameOriginalAdmin
+ ", userNameOriginalAdmin=" + userNameOriginalAdmin
+ ", timestamp=" + timestamp + ", operation=" + operation + "]";