Skip to content

Commit

Permalink
Project user invite improvements
Browse files Browse the repository at this point in the history
For last name, user must choose an entry in the autocomplete.
For email, user can choose an entry in the autocomplete or use what is
in the input field to support inviting someone not in the database.
  • Loading branch information
danjasuw committed Aug 29, 2019
1 parent ec3d9ef commit ddb33bc
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,8 @@ var processChosenUserForAddProjectAccess = function(ui, thisValue) {
$("#invite_user_auto_complete_value").text(item.label);
$("#invite_user_auto_complete_display").show();
$("#invite_user_input_fields").hide();

enableInviteButton();
};

var initInviteUser = function() {
Expand Down Expand Up @@ -1206,15 +1208,102 @@ var initInviteUser = function() {
throw e;
}
});

// Listen for changes to invite_user_last_name and invite_user_email

const invite_user_last_name_DOM = document.getElementById("invite_user_last_name");
if ( ! invite_user_last_name_DOM ) {
throw Error("No DOM element with id 'invite_user_last_name'");
}
const invite_user_email_DOM = document.getElementById("invite_user_email");
if ( ! invite_user_email_DOM ) {
throw Error("No DOM element with id 'invite_user_email'");
}

invite_user_last_name_DOM.addEventListener('input', ( eventObject ) => {
try {
eventObject.preventDefault();
// console.log("'input' fired");
const eventTarget = eventObject.target;
const eventTargetValue = eventTarget.value;
if ( eventTargetValue !== "" ) {

// disable invite button
disableInviteButton();

// has value so clear value in invite_user_email
const invite_user_email_DOM = document.getElementById("invite_user_email");
if ( ! invite_user_email_DOM ) {
throw Error("No DOM element with id 'invite_user_email'");
}
invite_user_email_DOM.value = "";
}
return false;
} catch( e ) {
reportWebErrorToServer.reportErrorObjectToServer( { errorException : e } );
throw e;
}
});

invite_user_email_DOM.addEventListener('input', ( eventObject ) => {
try {
eventObject.preventDefault();
// console.log("'input' fired");
const eventTarget = eventObject.target;
const eventTargetValue = eventTarget.value;
if ( eventTargetValue !== "" ) {

// has value so enable invite button
enableInviteButton();

// has value so clear value in invite_user_last_name_DOM
const invite_user_last_name_DOM = document.getElementById("invite_user_last_name");
if ( ! invite_user_last_name_DOM ) {
throw Error("No DOM element with id 'invite_user_last_name'");
}
invite_user_last_name_DOM.value = "";
} else {
// Not have value so disable invite button
disableInviteButton();
}
return false;
} catch( e ) {
reportWebErrorToServer.reportErrorObjectToServer( { errorException : e } );
throw e;
}
});
};


const enableInviteButton = () => {

// Enable Invite button
const $invite_user_button = $("#invite_user_button");
$invite_user_button.prop("disabled",false);
// Hide cover over Invite Button
const $invite_user_button_disabled_cover = $("#invite_user_button_disabled_cover");
$invite_user_button_disabled_cover.hide();
}

const disableInviteButton = () => {

// Disable Invite button
const $invite_user_button = $("#invite_user_button");
$invite_user_button.prop("disabled",true);
// Show cover over Invite Button
const $invite_user_button_disabled_cover = $("#invite_user_button_disabled_cover");
$invite_user_button_disabled_cover.show();
}

/////////////
var clearInviteUserFieldsAndAutocompleteDisplay = function() {
$("#invite_user_auto_complete_display").hide();
existingUserIdForAddProjectAccess = "";
$("#invite_user_input_fields").show();
$("#invite_user_last_name").val("");
$("#invite_user_email").val("");

disableInviteButton();
};

var inviteUserToProject = function(clickThis) {
Expand All @@ -1239,31 +1328,19 @@ var inviteUserToProject = function(clickThis) {
ajaxParams.invitedPersonUserId = existingUserIdForAddProjectAccess;
requestData.existingUserIdForAddProjectAccess = existingUserIdForAddProjectAccess;
} else {
var $invite_user_last_name = $("#invite_user_last_name");
if ($invite_user_last_name.length === 0) {
throw Error( "Unable to find input field for id 'invite_user_last_name' " );
}
// Remove invite_user_last_name input since user must choose an existing last name which existingUserIdForAddProjectAccess is then populated
var $invite_user_email = $("#invite_user_email");
if ($invite_user_email.length === 0) {
throw Error( "Unable to find input field for id 'invite_user_email' " );
}
var invite_user_last_name = $invite_user_last_name.val();
var invite_user_email = $invite_user_email.val();
if ( invite_user_last_name === "" && invite_user_email === "" ) {
// alert("last name or email must be specified");
var $element = $("#error_message_invite_name_or_email_required");
showErrorMsg( $element );
return false; // !!! EARLY EXIT
}
if ( invite_user_last_name !== "" && invite_user_email !== "" ) {
// alert("last name and email cannot both be specified");
var $element = $("#error_message_invite_name_and_email_have_values");
showErrorMsg( $element );
return false; // !!! EARLY EXIT
}
ajaxParams.invitedPersonLastName = invite_user_last_name;
// // Should never occur since button disabled when field is empty
// if ( invite_user_email === "" ) {
// var $element = $("#error_message_invite_name_or_email_required");
// showErrorMsg( $element );
// return false; // !!! EARLY EXIT
// }
ajaxParams.invitedPersonEmail = invite_user_email;
requestData.invite_user_last_name = invite_user_last_name;
requestData.invite_user_email = invite_user_email;
}
requestData.ajaxParams = ajaxParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class UserInviteService {
@Path("/invite")
public UserInviteResult userInviteService(
@FormParam( "invitedPersonUserId" ) String invitedPersonUserIdString,
@FormParam( "invitedPersonLastName" ) String invitedPersonLastName,
@FormParam( "invitedPersonEmail" ) String invitedPersonEmail,
@FormParam( "invitedPersonAccessLevel" ) String invitedPersonAccessLevelString,
@FormParam( "projectId" ) String projectIdString,
Expand All @@ -77,9 +76,6 @@ public UserInviteResult userInviteService(
// Restricted to users with ACCESS_LEVEL_ASSISTANT_PROJECT_OWNER or better
if ( invitedPersonUserIdString != null ) {
invitedPersonUserIdString = invitedPersonUserIdString.trim();
}
if ( invitedPersonLastName != null ) {
invitedPersonLastName = invitedPersonLastName.trim();
}
if ( invitedPersonEmail != null ) {
invitedPersonEmail = invitedPersonEmail.trim();
Expand All @@ -103,15 +99,8 @@ public UserInviteResult userInviteService(
);
}
} else {
if ( StringUtils.isEmpty( invitedPersonLastName ) && StringUtils.isEmpty( invitedPersonEmail )) {
log.warn( "UserInviteService: invitedPersonLastName and invitedPersonEmail both empty" );
throw new WebApplicationException(
Response.status( WebServiceErrorMessageConstants.INVALID_PARAMETER_STATUS_CODE ) // Send HTTP code
.entity( WebServiceErrorMessageConstants.INVALID_PARAMETER_TEXT ) // This string will be passed to the client
.build()
);
} else if ( StringUtils.isNotEmpty( invitedPersonLastName ) && StringUtils.isNotEmpty( invitedPersonEmail )) {
log.warn( "UserInviteService: invitedPersonLastName and invitedPersonEmail both not empty" );
if ( StringUtils.isEmpty( invitedPersonEmail )) {
log.warn( "UserInviteService: invitedPersonEmail is empty when invitedPersonUserIdString is empty" );
throw new WebApplicationException(
Response.status( WebServiceErrorMessageConstants.INVALID_PARAMETER_STATUS_CODE ) // Send HTTP code
.entity( WebServiceErrorMessageConstants.INVALID_PARAMETER_TEXT ) // This string will be passed to the client
Expand Down Expand Up @@ -260,18 +249,7 @@ public UserInviteResult userInviteService(
}

addExistingUserToProjectUsingProjectId( invitedPersonUserId, invitedPerson_userMgmtUserId, invitedPersonAccessLevel, projectAuthShareableObjectId, userInviteResult );

} else if ( StringUtils.isNotEmpty( invitedPersonLastName ) ) {
// process the last name
if ( projectId == null ) {
log.warn( "UserInviteService: Adding existing user but no project id provided, invitedPersonUserId: " + invitedPersonUserId );
throw new WebApplicationException(
Response.status( WebServiceErrorMessageConstants.INVALID_PARAMETER_STATUS_CODE ) // Send HTTP code
.entity( WebServiceErrorMessageConstants.INVALID_PARAMETER_TEXT ) // This string will be passed to the client
.build()
);
}
addExistingUserToProjectUsingLastName( invitedPersonLastName, invitedPersonAccessLevel, projectAuthShareableObjectId, userInviteResult, sessionKey );

} else {
// Process the email
UserMgmtSearchUserDataRequest userMgmtSearchUserDataRequest = new UserMgmtSearchUserDataRequest();
Expand Down Expand Up @@ -314,15 +292,7 @@ public UserInviteResult userInviteService(
invitedPersonAccessLevel,
projectAuthShareableObjectId,
userInviteResult );

// When get here, need to add an account in Proxl
// This becomes a problem since then unlike when the user is creating their own account
// the person making the invite cannot accept the terms.

// throw new RuntimeException( "Invalid here to pass invitedPerson_userMgmtUserId as invitedPersonUserId" );
// addExistingUserToProjectUsingProjectId( invitedPerson_userMgmtUserId /* invitedPersonUserId */, invitedPersonAccessLevel, projectAuthShareableObjectId, userInviteResult );

// addExistingUserToProjectUsingProjectId( invitedPersonUserIdFromEmail, invitedPersonAccessLevel, projectAuthShareableObjectId, userInviteResult );

} else {
// no account with this email exists
inviteNewUserUsingEmail( invitedPersonEmail, request,
Expand All @@ -344,61 +314,6 @@ public UserInviteResult userInviteService(
}
}

/**
* @param invitedPersonLastName
* @param invitedPersonAccessLevel
* @param projectAuthShareableObjectId
* @param userInviteResult
* @throws Exception
*/
private void addExistingUserToProjectUsingLastName(
String invitedPersonLastName,
int invitedPersonAccessLevel,
int projectAuthShareableObjectId,
UserInviteResult userInviteResult,
String sessionKey ) throws Exception {

UserMgmtSearchUserDataRequest userMgmtSearchUserDataRequest = new UserMgmtSearchUserDataRequest();
userMgmtSearchUserDataRequest.setSessionKey( sessionKey );
userMgmtSearchUserDataRequest.setSearchString( invitedPersonLastName );
userMgmtSearchUserDataRequest.setSearchStringExactMatch(true);

UserMgmtSearchUserDataResponse userMgmtSearchUserDataResponse =
UserMgmtCentralWebappWebserviceAccess.getInstance().searchUserDataByLastName( userMgmtSearchUserDataRequest );

if ( ! userMgmtSearchUserDataResponse.isSuccess() ) {
if ( userMgmtSearchUserDataResponse.isSessionKeyNotValid() ) {
String msg = "Session Key invalid for call to UserMgmtCentralWebappWebserviceAccess.getInstance().searchUserDataByLastName(...)";
log.error( msg );
throw new ProxlWebappInternalErrorException( msg );
}
String msg = "call to UserMgmtCentralWebappWebserviceAccess.getInstance().searchUserDataByLastName(...) not successful, invitedPersonLastName: " + invitedPersonLastName;
log.error( msg );
throw new ProxlWebappInternalErrorException( msg );
}
List<Integer> userIdList = userMgmtSearchUserDataResponse.getUserIdList();
if ( userIdList == null || ( userIdList.isEmpty() ) ) {
userInviteResult.setLastNameNotFoundError(true);
} else if ( userIdList.size() > 1 ) {
userInviteResult.setLastNameDuplicateError(true);
} else {
int invitedPerson_userMgmtUserId = userIdList.get( 0 );

addUser_Using_UserMgmtId_ToProjectUsingProjectId(
invitedPerson_userMgmtUserId,
invitedPersonAccessLevel,
projectAuthShareableObjectId,
userInviteResult );
// When get here, need to add an account in Proxl
// This becomes a problem since then unlike when the user is creating their own account
// the person making the invite cannot accept the terms.

// throw new RuntimeException( "Invalid here to pass invitedPerson_userMgmtUserId as invitedPersonUserId" );
// addExistingUserToProjectUsingProjectId( invitedPerson_userMgmtUserId /* invitedPersonUserId */, invitedPersonAccessLevel, projectAuthShareableObjectId, userInviteResult );
}
}


/**
* @param invitedPerson_Proxl_AuthUserId - Proxl Auth User Id
* @param invitedPersonAccessLevel
Expand Down Expand Up @@ -445,7 +360,6 @@ private void addExistingUserToProjectUsingProjectId(
invitedPerson_Proxl_AuthUserId = authUserId_FromDB;
}
}


// Get full user data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,14 @@
<tr>
<td nowrap>
<input placeholder="Last Name" id="invite_user_last_name" class="autocomplete-entry-field"
title="Last Name" >
title="Last Name. Must choose from list." >
</td>
<td>
or
</td>
<td nowrap>
<input placeholder="Email Address" id="invite_user_email" class="autocomplete-entry-field"
title="Email Address" >
title="Email Address. May choose from list or use what is entered." >
</td>
</tr>
<tr>
Expand Down Expand Up @@ -655,8 +655,15 @@
</c:if>

</select>

<div style="display: inline-block; position: relative;">
<input type="button" value="Invite User" disabled="disabled" id="invite_user_button">
<div id="invite_user_button_disabled_cover"
style="position: absolute; left:0px;right:0px;top:0px;bottom:0px"
title="First enter value for email or choose from selection for email or last name"
></div>
</div>

<input type="button" value="Invite User" id="invite_user_button">
<input type="button" value="Cancel" class="invite_user_cancel_button_jq">
</td>
</tr>
Expand Down

0 comments on commit ddb33bc

Please sign in to comment.