Search in sources :

Example 1 with GetApplicationsForUser

use of cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationsForUser in project perun by CESNET.

the class SelfApplicationsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Applications");
    VerticalPanel bodyContents = new VerticalPanel();
    bodyContents.setWidth("100%");
    // callback
    final GetApplicationsForUser req = new GetApplicationsForUser(user.getId());
    req.setCheckable(false);
    // tab menu for filtering
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    tabMenu.addFilterWidget(new ExtendedSuggestBox(req.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            req.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterByVoOrGroup());
    bodyContents.add(tabMenu);
    CellTable<Application> appsTable = req.getTable(new FieldUpdater<Application, String>() {

        @Override
        public void update(int index, Application object, String value) {
            session.getTabManager().addTab(new SelfApplicationDetailTabItem(object));
        }
    });
    appsTable.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(appsTable);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    bodyContents.add(sp);
    this.contentWidget.setWidget(bodyContents);
    return getWidget();
}
Also used : GetApplicationsForUser(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationsForUser) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) Application(cz.metacentrum.perun.webgui.model.Application)

Example 2 with GetApplicationsForUser

use of cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationsForUser in project perun by CESNET.

the class ApplicationFormGui method loadPerunPrincipal.

/**
	 * Performs a login into the RPC, loads user and his roles into session and enables GUI.
	 */
private void loadPerunPrincipal(final JsonCallbackEvents externalEvents) {
    // events after getting PerunPrincipal from RPC
    GetPerunPrincipal principal = new GetPerunPrincipal(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // store perun principal into session for future use
            PerunPrincipal pp = (PerunPrincipal) jso;
            session.setPerunPrincipal(pp);
            // store users roles and editable entities into session
            if (pp.getRoles().hasAnyRole()) {
                session.setRoles(pp.getRoles());
            }
            // proceed after GUI configuration is loaded
            GetGuiConfiguration getConf = new GetGuiConfiguration(new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // store configuration
                    session.setConfiguration((BasicOverlayType) jso.cast());
                    if (Utils.getVosToSkipCaptchaFor().contains(vo.getShortName())) {
                        // skip captcha
                        final GetApplicationsForUser request;
                        if (session.getUser() == null) {
                            // if not yet user in perun, search by actor / extSourceName
                            request = new GetApplicationsForUser(0, externalEvents);
                        } else {
                            // if user in perun
                            request = new GetApplicationsForUser(session.getUser().getId(), externalEvents);
                        }
                        request.retrieveData();
                        // finish loading GUI
                        loadingBox.hide();
                        bodySplitter.clear();
                        bodySplitter.add(ft);
                    // challange captcha only for default URL (non)
                    } else if (session.getRpcUrl().startsWith("/non/rpc")) {
                        if (Location.getParameterMap().keySet().contains("m") && Location.getParameterMap().keySet().contains("i")) {
                            // passed params doesn't matter, different UI is loaded.
                            final GetApplicationsForUser request;
                            if (session.getUser() == null) {
                                // if not yet user in perun, search by actor / extSourceName
                                request = new GetApplicationsForUser(0, externalEvents);
                            } else {
                                // if user in perun
                                request = new GetApplicationsForUser(session.getUser().getId(), externalEvents);
                            }
                            request.retrieveData();
                            // finish loading GUI
                            loadingBox.hide();
                            bodySplitter.clear();
                            bodySplitter.add(ft);
                        } else {
                            // CHALLENGE WITH CAPTCHA
                            FlexTable ft = new FlexTable();
                            ft.setSize("100%", "500px");
                            // captcha with public key
                            String key = Utils.getReCaptchaPublicKey();
                            if (key == null) {
                                PerunError error = new JSONObject().getJavaScriptObject().cast();
                                error.setErrorId("0");
                                error.setName("Missing public key");
                                error.setErrorInfo("Public key for Re-Captcha service is missing. Please add public key to GUIs configuration file.");
                                error.setRequestURL("");
                                UiElements.generateError(error, "Missing public key", "Public key for Re-Captcha service is missing.<br />Accessing application form without authorization is not possible.");
                                loadingBox.hide();
                                return;
                            }
                            final RecaptchaWidget captcha = new RecaptchaWidget(key, LocaleInfo.getCurrentLocale().getLocaleName(), "clean");
                            final CustomButton cb = new CustomButton();
                            cb.setIcon(SmallIcons.INSTANCE.arrowRightIcon());
                            cb.setText(ApplicationMessages.INSTANCE.captchaSendButton());
                            cb.setImageAlign(true);
                            final TextBox response = new TextBox();
                            captcha.setOwnTextBox(response);
                            Scheduler.get().scheduleDeferred(new Command() {

                                @Override
                                public void execute() {
                                    response.setFocus(true);
                                }
                            });
                            response.addKeyDownHandler(new KeyDownHandler() {

                                @Override
                                public void onKeyDown(KeyDownEvent event) {
                                    if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                                        cb.click();
                                    }
                                }
                            });
                            cb.addClickHandler(new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent clickEvent) {
                                    VerifyCaptcha req = new VerifyCaptcha(captcha.getChallenge(), captcha.getResponse(), JsonCallbackEvents.disableButtonEvents(cb, new JsonCallbackEvents() {

                                        public void onFinished(JavaScriptObject jso) {
                                            BasicOverlayType bt = jso.cast();
                                            if (bt.getBoolean()) {
                                                // OK captcha answer - load GUI
                                                // Authorized anonymous user
                                                session.getUiElements().setLogText("Auth OK");
                                                final GetApplicationsForUser request;
                                                if (session.getUser() == null) {
                                                    // if not yet user in perun, search by actor / extSourceName
                                                    request = new GetApplicationsForUser(0, externalEvents);
                                                } else {
                                                    // if user in perun
                                                    request = new GetApplicationsForUser(session.getUser().getId(), externalEvents);
                                                }
                                                request.retrieveData();
                                            } else {
                                                // wrong captcha answer
                                                UiElements.generateAlert(ApplicationMessages.INSTANCE.captchaErrorHeader(), ApplicationMessages.INSTANCE.captchaErrorMessage());
                                            }
                                        }
                                    }));
                                    req.retrieveData();
                                }
                            });
                            // set layout
                            int row = 0;
                            // display VO logo if present in attribute
                            for (int i = 0; i < vo.getAttributes().length(); i++) {
                                if (vo.getAttributes().get(i).getFriendlyName().equalsIgnoreCase("voLogoURL")) {
                                    ft.setWidget(row, 0, new Image(vo.getAttributes().get(i).getValue()));
                                    ft.getFlexCellFormatter().setAlignment(row, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
                                    row++;
                                }
                            }
                            ft.getFlexCellFormatter().setAlignment(row, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
                            ft.setHTML(row, 0, ApplicationMessages.INSTANCE.captchaDescription());
                            ft.setWidget(row + 1, 0, captcha);
                            ft.getFlexCellFormatter().setHorizontalAlignment(row + 1, 0, HasHorizontalAlignment.ALIGN_CENTER);
                            ft.getFlexCellFormatter().setVerticalAlignment(row + 1, 0, HasVerticalAlignment.ALIGN_BOTTOM);
                            FlexTable sendFt = new FlexTable();
                            sendFt.setStyleName("inputFormFlexTable");
                            sendFt.setWidget(0, 0, response);
                            sendFt.setWidget(0, 1, cb);
                            ft.setWidget(row + 2, 0, sendFt);
                            ft.getFlexCellFormatter().setHorizontalAlignment(row + 2, 0, HasHorizontalAlignment.ALIGN_CENTER);
                            ft.getFlexCellFormatter().setVerticalAlignment(row + 2, 0, HasVerticalAlignment.ALIGN_TOP);
                            ft.setHeight("100%");
                            ft.getFlexCellFormatter().setHeight(row, 0, "50%");
                            ft.getFlexCellFormatter().setHeight(row + 2, 0, "50%");
                            // finish loading GUI
                            loadingBox.hide();
                            bodySplitter.clear();
                            bodySplitter.add(ft);
                        }
                    } else {
                        // Authorized known user
                        session.getUiElements().setLogText("Auth OK");
                        final GetApplicationsForUser req;
                        if (session.getUser() == null) {
                            // if not yet user in perun, search by actor / extSourceName
                            req = new GetApplicationsForUser(0, externalEvents);
                        } else {
                            // if user in perun
                            req = new GetApplicationsForUser(session.getUser().getId(), externalEvents);
                        }
                        req.retrieveData();
                    }
                }
            });
            getConf.retrieveData();
        }
    });
    principal.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) GetApplicationsForUser(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationsForUser) VerifyCaptcha(cz.metacentrum.perun.webgui.json.registrarManager.VerifyCaptcha) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) JSONObject(com.google.gwt.json.client.JSONObject) Command(com.google.gwt.user.client.Command) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetPerunPrincipal(cz.metacentrum.perun.webgui.json.authzResolver.GetPerunPrincipal) RecaptchaWidget(cz.metacentrum.perun.webgui.widgets.recaptcha.RecaptchaWidget) GetPerunPrincipal(cz.metacentrum.perun.webgui.json.authzResolver.GetPerunPrincipal) GetGuiConfiguration(cz.metacentrum.perun.webgui.json.GetGuiConfiguration)

Aggregations

GetApplicationsForUser (cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationsForUser)2 JSONObject (com.google.gwt.json.client.JSONObject)1 Command (com.google.gwt.user.client.Command)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 GetGuiConfiguration (cz.metacentrum.perun.webgui.json.GetGuiConfiguration)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetPerunPrincipal (cz.metacentrum.perun.webgui.json.authzResolver.GetPerunPrincipal)1 VerifyCaptcha (cz.metacentrum.perun.webgui.json.registrarManager.VerifyCaptcha)1 Application (cz.metacentrum.perun.webgui.model.Application)1 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 RecaptchaWidget (cz.metacentrum.perun.webgui.widgets.recaptcha.RecaptchaWidget)1