Skip to content

Commit

Permalink
Merge branch 'rkrutak/STR-1331/pair_app_with_invite' into 'main'
Browse files Browse the repository at this point in the history
feat: pair application with invitation

See merge request perun/perun-idm/perun-wui!281
  • Loading branch information
kofzera committed Jul 25, 2024
2 parents 0a75ae3 + 240f278 commit bd866c5
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cz.metacentrum.perun.wui.json.managers;

import com.google.gwt.http.client.Request;
import cz.metacentrum.perun.wui.json.JsonClient;
import cz.metacentrum.perun.wui.json.JsonEvents;

/**
* Manager with standard callbacks to Perun's API (InvitationsManager).
* <p/>
* Each callback returns unique Request used to make call. Such call can be removed
* while processing to prevent any further actions based on it's {@link cz.metacentrum.perun.wui.json.JsonEvents JsonEvents}.
*
* @author Rastislav Kruták <[email protected]>
*/
public class InvitationsManager {

private static final String INVITATIONS_MANAGER = "invitationsManager/";

/**
* Check whether the invitation given by the UUID token exists and is in a pending state.
*
* @param invitationUUID UUID of an invitation to check
* @param events Events done on callback
*
* @return Request unique request
*/
public static Request canInvitationBeAccepted(String invitationUUID, JsonEvents events) {
JsonClient client = new JsonClient(events);
client.put("uuid", invitationUUID);
return client.call(INVITATIONS_MANAGER + "canInvitationBeAccepted");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cz.metacentrum.perun.wui.json.JsonEvents;
import cz.metacentrum.perun.wui.model.beans.Application;
import cz.metacentrum.perun.wui.model.beans.ApplicationFormItemData;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -245,11 +244,15 @@ public static Request getApplicationDataById(int applicationId, JsonEvents event
*
* @return Request unique request
*/
public static Request createApplication(Application application, List<ApplicationFormItemData> data, JsonEvents events) {
public static Request createApplication(Application application, List<ApplicationFormItemData> data, String invitationToken, JsonEvents events) {

JsonClient client = new JsonClient(true, events);
if (application != null) {
client.put("app", application);

if (application.getGroup() != null && invitationToken != null) {
client.put("token", invitationToken);
}
}
if (data != null) {
client.put("data", data);
Expand Down Expand Up @@ -381,5 +384,4 @@ public static Request updateFormItemsData(int applicationId, List<ApplicationFor
return client.call(REGISTRAR_MANAGER + "updateFormItemsData");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ private void resolve() {

setInfo(trans.registrarException(getBeanName()), null);

} else if ("InvalidInvitationStatusException".equalsIgnoreCase(exception.getName())) {
setInfo(trans.InvalidInvitationStatus(), null, false);

} else if ("InvitationNotExistsException".equalsIgnoreCase(exception.getName())) {
setInfo(trans.InvitationNotExists(), null, false);

} else if ("InvitationAlreadyAssignedToAnApplicationException".equalsIgnoreCase(exception.getName())) {
setInfo(trans.InvitationAlreadyAssignedToAnApplication(), null, false);

} else if ("0".equals(exception.getErrorId())) {

setInfo(trans.unableToSubmit(), trans.error0(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ public interface PerunRegistrarTranslation extends PerunTranslation {
@DefaultMessage("Your application to {0} has been submitted but there were an unexpected error. Your administrator has been informed and he will deal with it.")
public String registrarException(String voOrGroupName);

@DefaultMessage("The pre-approved invitation you have received is in an invalid state.")
public String InvalidInvitationStatus();

@DefaultMessage("The pre-approved invitation you have received does not exist.")
public String InvitationNotExists();

@DefaultMessage("The pre-approved invitation is already assigned to an existing application.")
public String InvitationAlreadyAssignedToAnApplication();

@DefaultMessage("Application to {0} has been submitted, but not approved automatically, due to unexpected error. Your administrator has been informed and he will deal with it.")
public String cantBeApproved(String voOrGroupName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import cz.metacentrum.perun.wui.client.utils.Utils;
import cz.metacentrum.perun.wui.json.ErrorTranslator;
import cz.metacentrum.perun.wui.json.JsonEvents;
import cz.metacentrum.perun.wui.json.managers.InvitationsManager;
import cz.metacentrum.perun.wui.json.managers.MembersManager;
import cz.metacentrum.perun.wui.json.managers.RegistrarManager;
import cz.metacentrum.perun.wui.json.managers.UsersManager;
import cz.metacentrum.perun.wui.model.BasicOverlayObject;
import cz.metacentrum.perun.wui.model.GeneralObject;
import cz.metacentrum.perun.wui.model.PerunException;
Expand Down Expand Up @@ -56,6 +56,14 @@
import cz.metacentrum.perun.wui.widgets.AlertErrorReporter;
import cz.metacentrum.perun.wui.widgets.PerunButton;
import cz.metacentrum.perun.wui.widgets.PerunLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import org.gwtbootstrap3.client.ui.Alert;
import org.gwtbootstrap3.client.ui.AnchorListItem;
import org.gwtbootstrap3.client.ui.Button;
Expand All @@ -74,15 +82,6 @@
import org.gwtbootstrap3.extras.notify.client.constants.NotifyType;
import org.gwtbootstrap3.extras.notify.client.ui.Notify;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
* View for displaying registration form of VO / Group
*
Expand Down Expand Up @@ -412,66 +411,30 @@ private void loadSteps(PerunPrincipal pp, RegistrarObject registrar) {
//////// This block of code should represent (guess) WHAT USER WANT to do. /////////
if (isApplyingToGroup(registrar)) {

if (voInitialFormExists(registrar)) {
String invitationToken = (Window.Location.getParameter("token") != null) ?
URL.decodeQueryString(Window.Location.getParameter("token")) : null;
if (invitationToken != null) {
InvitationsManager.canInvitationBeAccepted(invitationToken, new JsonEvents() {

// vo initial can't have group extension
stepManager.addStep(new VoInitStep(registrar, form));
stepManager.addStep(new GroupInitStep(registrar, form));
stepManager.addStep(new SummaryStep(formView));
stepManager.begin();

} else if (voExtensionFormExists(registrar)) {

if (isMemberOfGroup(registrar) && groupExtensionFormExists(registrar)) {
if (!neverExp) {
for (ApplicationFormItemData item : registrar.getVoFormExtension()) {
if (!item.getFormItem().getType().equals(ApplicationFormItem.ApplicationFormItemType.HTML_COMMENT) &&
!item.getFormItem().getType().equals(ApplicationFormItem.ApplicationFormItemType.HEADING)) {
// offer only when VO doesn't have empty or "You are registered" form.
stepManager.addStep(new VoExtOfferStep(registrar, form)); // will offer only if form is valid
break;
}
}
@Override
public void onFinished(JavaScriptObject result) {
form.setInvitationToken(invitationToken);
loadGroupForm(registrar, stepManager);
}

// only members with correct extension form can extend
stepManager.addStep(new GroupExtStep(registrar, form));

} else {

stepManager.addStep(new GroupInitStep(registrar, form));
if (!neverExp) {
for (ApplicationFormItemData item : registrar.getVoFormExtension()) {
if (!item.getFormItem().getType().equals(ApplicationFormItem.ApplicationFormItemType.HTML_COMMENT) &&
!item.getFormItem().getType().equals(ApplicationFormItem.ApplicationFormItemType.HEADING)) {
// offer only when VO doesn't have empty or "You are registered" form.
stepManager.addStep(new VoExtOfferStep(registrar, form)); // will offer only if form is valid
break;
}
}
@Override
public void onError(PerunException error) {
displayException(error, null);
}
}

stepManager.addStep(new SummaryStep(formView));
stepManager.begin();
@Override
public void onLoadingStart() {

}
});
} else {

// Because vo initial form can be empty (admin did not create it).
if (!isMemberOfVo(registrar) && !appliedToVo(registrar))
stepManager.addStep(new VoInitStep(registrar, form));

if (isMemberOfGroup(registrar) && groupExtensionFormExists(registrar)) {
// only members with correct extension form can extend
stepManager.addStep(new GroupExtStep(registrar, form));
} else {
stepManager.addStep(new GroupInitStep(registrar, form));
}
stepManager.addStep(new SummaryStep(formView));
stepManager.begin();

loadGroupForm(registrar, stepManager);
}

} else {

if (voInitialFormExists(registrar)) {
Expand Down Expand Up @@ -503,6 +466,74 @@ private void loadSteps(PerunPrincipal pp, RegistrarObject registrar) {

}

private void loadGroupForm(RegistrarObject registrar, StepManager stepManager) {
if (voInitialFormExists(registrar)) {

// vo initial can't have group extension
stepManager.addStep(new VoInitStep(registrar, form));
stepManager.addStep(new GroupInitStep(registrar, form));
stepManager.addStep(new SummaryStep(formView));
stepManager.begin();

} else if (voExtensionFormExists(registrar)) {

if (isMemberOfGroup(registrar) && groupExtensionFormExists(registrar)) {
if (!neverExp) {
for (ApplicationFormItemData item : registrar.getVoFormExtension()) {
if (!item.getFormItem().getType()
.equals(ApplicationFormItem.ApplicationFormItemType.HTML_COMMENT) &&
!item.getFormItem().getType()
.equals(ApplicationFormItem.ApplicationFormItemType.HEADING)) {
// offer only when VO doesn't have empty or "You are registered" form.
stepManager.addStep(new VoExtOfferStep(registrar,
form)); // will offer only if form is valid
break;
}
}
}

// only members with correct extension form can extend
stepManager.addStep(new GroupExtStep(registrar, form));

} else {

stepManager.addStep(new GroupInitStep(registrar, form));
if (!neverExp) {
for (ApplicationFormItemData item : registrar.getVoFormExtension()) {
if (!item.getFormItem().getType()
.equals(ApplicationFormItem.ApplicationFormItemType.HTML_COMMENT) &&
!item.getFormItem().getType()
.equals(ApplicationFormItem.ApplicationFormItemType.HEADING)) {
// offer only when VO doesn't have empty or "You are registered" form.
stepManager.addStep(new VoExtOfferStep(registrar,
form)); // will offer only if form is valid
break;
}
}
}
}

stepManager.addStep(new SummaryStep(formView));
stepManager.begin();

} else {

// Because vo initial form can be empty (admin did not create it).
if (!isMemberOfVo(registrar) && !appliedToVo(registrar))
stepManager.addStep(new VoInitStep(registrar, form));

if (isMemberOfGroup(registrar) && groupExtensionFormExists(registrar)) {
// only members with correct extension form can extend
stepManager.addStep(new GroupExtStep(registrar, form));
} else {
stepManager.addStep(new GroupInitStep(registrar, form));
}
stepManager.addStep(new SummaryStep(formView));
stepManager.begin();

}
}

private boolean voInitialFormExists(RegistrarObject ro) {
return !ro.getVoFormInitial().isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public void addResult(Result result) {
@Override
public String mustRevalidateEmail() {
for(Result result : results) {
if (result.getRegisteredMail() != null) {
if (result.getRegisteredMail() != null &&
!result.getApplication().getState().equals(Application.ApplicationState.VERIFIED) &&
!result.getApplication().getState().equals(Application.ApplicationState.APPROVED)) {
return result.getRegisteredMail();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
import cz.metacentrum.perun.wui.registrar.widgets.items.PerunFormItem;
import cz.metacentrum.perun.wui.registrar.widgets.items.SubmitButton;
import cz.metacentrum.perun.wui.widgets.PerunButton;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.gwtbootstrap3.client.ui.FieldSet;
import org.gwtbootstrap3.client.ui.Heading;
import org.gwtbootstrap3.client.ui.constants.ColumnOffset;
import org.gwtbootstrap3.client.ui.constants.ColumnSize;
import org.gwtbootstrap3.client.ui.constants.HeadingSize;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* Utility class used to handle Perun Application forms.
*
Expand Down Expand Up @@ -62,6 +61,7 @@ public enum FormState {
private FormState formState;
private boolean seeHiddenItems;
private Application app;
private String invitationToken;
private JsonEvents onSubmitEvent;
private PerunTranslation perunTranslation = GWT.create(PerunTranslation.class);

Expand Down Expand Up @@ -359,7 +359,7 @@ public void onLoadingStart() {
*/
private void createApplication(final PerunButton button) {

RegistrarManager.createApplication(app, getFormItemDataToSubmit(), new JsonEvents() {
RegistrarManager.createApplication(app, getFormItemDataToSubmit(), getInvitationToken(), new JsonEvents() {
@Override
public void onFinished(JavaScriptObject jso) {

Expand Down Expand Up @@ -515,6 +515,14 @@ public void setApp(Application app) {
this.app = app;
}

public String getInvitationToken() {
return invitationToken;
}

public void setInvitationToken(String invitationToken) {
this.invitationToken = invitationToken;
}

public JsonEvents getOnSubmitEvent() {
return onSubmitEvent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ formWrongFormed=Registrační formulář je špatně utvořen. Prosím kontaktuj
applicationNotCreatedBecauseLogin=Žádost nemohla být vytvořena. Pravděpodobně Váš login nemůže být rezervován.
applicationNotCreated=Žádost nemohla být vytvořena.
registrarException=Vaše přihláška do {0} byla odeslána, ale nastala neočekávaná chyba. Váš administrátor byl informován e-mailem a bude chybu řešit.
InvalidInvitationStatus=Předschválená pozvánka, kterou jste obdrželi, již není platná.
InvitationNotExists=Předschválená pozvánka, kterou jste obdrželi, neexistuje.
InvitationAlreadyAssignedToAnApplication="Předschválena pozvánka je již přiřazená k jiné přihlášce."
cantBeApproved=Vaše přihláška do {0} byla podána, ale nemohla být automaticky schválena, protože nastala neočekávaná chyba. Váš administrátor byl informován e-mailem a bude chybu řešit.
unableToSubmit=Formulář nelze odeslat
cantSubmitLoA=Nelze podat přihlášku
Expand Down

0 comments on commit bd866c5

Please sign in to comment.