Skip to content

Commit

Permalink
Deprecated GwtSession.getRootAccountId and GwtSession.getRootAccountN…
Browse files Browse the repository at this point in the history
…ame because they were misleading on their actual usage

Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Nov 22, 2022
1 parent aa826a7 commit 85727f4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,27 @@
*******************************************************************************/
package org.eclipse.kapua.app.console.core.client;

import java.util.List;

import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Point;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import org.eclipse.kapua.app.console.core.client.util.TokenCleaner;
import org.eclipse.kapua.app.console.core.shared.service.GwtAuthorizationService;
import org.eclipse.kapua.app.console.core.shared.service.GwtAuthorizationServiceAsync;
Expand All @@ -38,52 +57,40 @@
import org.eclipse.kapua.app.console.module.authentication.shared.service.GwtMfaCredentialOptionsService;
import org.eclipse.kapua.app.console.module.authentication.shared.service.GwtMfaCredentialOptionsServiceAsync;

import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Point;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import java.util.List;

public class NorthView extends LayoutContainer {

private static final ConsoleMessages MSGS = GWT.create(ConsoleMessages.class);
private static final ConsoleCredentialMessages CREDENTIAL_MSGS = GWT.create(ConsoleCredentialMessages.class);

private final GwtAuthorizationServiceAsync gwtAuthorizationService = GWT.create(GwtAuthorizationService.class);
private final GwtAccountServiceAsync gwtAccountService = GWT.create(GwtAccountService.class);
private final GwtConsoleServiceAsync gwtConsoleService = GWT.create(GwtConsoleService.class);
private final GwtSettingsServiceAsync gwtSettingService = GWT.create(GwtSettingsService.class);
private final GwtMfaCredentialOptionsServiceAsync gwtMfaCredentialOptionsService = GWT.create(GwtMfaCredentialOptionsService.class);

// UI stuff
private KapuaCloudConsole parent;
private final KapuaCloudConsole parent;
private Menu subAccountMenu;
private Button userActionButton;

// Data
private GwtSession currentSession;
private String rootAccountId;
private String userId;
private final GwtSession currentSession;

private final String accountId;
private final String accountName;

private String username;
private final String selectedAccountId;
private final String selectedAccountName;

// Following 2 have been commented after deprecation of GwtSession.getRootAccount* methods
// private String rootAccountId;
// private String rootAccountName;

private final String userId;
private final String username;
private String userDisplayName;
private String rootAccountName;
private String selectedAccountName;

// Listener
private final SelectionListener<MenuEvent> switchToAccountListener = new SelectionListener<MenuEvent>() {
Expand All @@ -98,13 +105,21 @@ public NorthView(GwtSession currentSession, KapuaCloudConsole parent) {
this.parent = parent;

this.currentSession = currentSession;
this.rootAccountId = currentSession.getRootAccountId();
this.userId = currentSession.getUserId();

this.accountId = currentSession.getAccountId();
this.accountName = currentSession.getAccountName();

this.selectedAccountId = currentSession.getSelectedAccountId();
this.selectedAccountName = currentSession.getSelectedAccountName();

// Following 2 have been commented after deprecation of GwtSession.getRootAccount* methods
// this.rootAccountId = currentSession.getRootAccountId();
// this.rootAccountName = currentSession.getRootAccountName();

this.userId = currentSession.getUserId();
this.username = currentSession.getUserName();
this.userDisplayName = currentSession.getUserDisplayName();
this.rootAccountName = currentSession.getRootAccountName();
this.selectedAccountName = currentSession.getSelectedAccountName();

}

@Override
Expand Down Expand Up @@ -274,20 +289,20 @@ public void onSuccess(String result) {
* @return the MenuItem
*/
public MenuItem createAccountNavigationMenuItem() {
KapuaMenuItem rootAccountMenuItem = new KapuaMenuItem();
rootAccountMenuItem.setText(MSGS.accountSelectorItemYourAccount(rootAccountName));
rootAccountMenuItem.setToolTip(MSGS.accountSelectorTooltipYourAccount());
rootAccountMenuItem.setIcon(IconSet.USER_MD);
rootAccountMenuItem.setId(rootAccountId);
rootAccountMenuItem.addSelectionListener(switchToAccountListener);
KapuaMenuItem mainAccountMenuItem = new KapuaMenuItem();
mainAccountMenuItem.setText(MSGS.accountSelectorItemYourAccount(accountName));
mainAccountMenuItem.setToolTip(MSGS.accountSelectorTooltipYourAccount());
mainAccountMenuItem.setIcon(IconSet.USER_MD);
mainAccountMenuItem.setId(accountId);
mainAccountMenuItem.addSelectionListener(switchToAccountListener);

subAccountMenu = new Menu();
subAccountMenu.setAutoWidth(true);
subAccountMenu.setAutoHeight(true);
subAccountMenu.add(rootAccountMenuItem);
subAccountMenu.add(mainAccountMenuItem);
subAccountMenu.add(new SeparatorMenuItem());

populateNavigatorMenu(subAccountMenu, rootAccountId);
populateNavigatorMenu(subAccountMenu, accountId);

KapuaMenuItem switchToAccountMenuItem = new KapuaMenuItem();
switchToAccountMenuItem.setText(MSGS.consoleHeaderUserActionSwitchToAccount());
Expand All @@ -309,7 +324,7 @@ private void populateNavigatorMenu(final Menu menu, String accountId) {
loadingChildAccounts = new KapuaMenuItem(MSGS.accountSelectorLoadingChildAccounts());
loadingChildAccounts.setToolTip(MSGS.accountSelectorTooltipYourAccount());
loadingChildAccounts.setIcon(IconSet.USER_MD);
loadingChildAccounts.setId(rootAccountId);
loadingChildAccounts.setId(accountId);
loadingChildAccounts.disable();

menu.add(loadingChildAccounts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,28 +291,31 @@ public Account call() throws Exception {

// Console info
SystemSetting commonsConfig = SystemSetting.getInstance();

gwtSession.setVersion(commonsConfig.getString(SystemSettingKey.VERSION));
gwtSession.setBuildVersion(commonsConfig.getString(SystemSettingKey.BUILD_VERSION));
gwtSession.setBuildNumber(commonsConfig.getString(SystemSettingKey.BUILD_NUMBER));
gwtSession.setSsoEnabled(ConsoleSsoLocator.getLocator(this).getService().isEnabled());
gwtSession.setDatastoreDisabled(DatastoreSettings.getInstance().getBoolean(DatastoreSettingsKey.DISABLE_DATASTORE, false));

// User info
gwtSession.setUserId(gwtUser.getId());
// Account Info
gwtSession.setAccountId(gwtAccount.getId());
gwtSession.setRootAccountId(gwtAccount.getId());
gwtSession.setSelectedAccountId(gwtAccount.getId());

gwtSession.setUserName(gwtUser.getUsername());
gwtSession.setUserDisplayName(gwtUser.getDisplayName());
gwtSession.setAccountName(gwtAccount.getName());
gwtSession.setRootAccountName(gwtAccount.getName());
gwtSession.setSelectedAccountName(gwtAccount.getName());

gwtSession.setAccountPath(gwtAccount.getParentAccountPath());
// Following 2 have been commented after deprecation of GwtSession.getRootAccount* methods
// gwtSession.setRootAccountId(gwtAccount.getId());
// gwtSession.setRootAccountName(gwtAccount.getName());

// Selected Account info
gwtSession.setSelectedAccountId(gwtAccount.getId());
gwtSession.setSelectedAccountName(gwtAccount.getName());
gwtSession.setSelectedAccountPath(gwtAccount.getParentAccountPath());

// Setting Id token
// User info
gwtSession.setUserId(gwtUser.getId());
gwtSession.setUserName(gwtUser.getUsername());
gwtSession.setUserDisplayName(gwtUser.getDisplayName());
gwtSession.setTokenId(kapuaSession.getAccessToken().getTokenId());
gwtSession.setOpenIDIdToken(kapuaSession.getOpenIDidToken());

// Setting Mfa trust key
Expand Down Expand Up @@ -352,8 +355,8 @@ public void run() throws Exception {
}
});

// Save AccessToken
gwtSession.setTokenId(kapuaSession.getAccessToken().getTokenId());
//
// Return session
return gwtSession;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ public class GwtSession extends KapuaBaseModel implements Serializable {
private String accountId;
private String accountName;
private String accountPath;

/**
* @deprecated Since 2.0.0. This is very misleading since it seems that is a reference to the kapua-sys account (aka root account) but is not.
*/
@Deprecated
private String rootAccountId;
/**
* @deprecated Since 2.0.0. This is very misleading since it seems that is a reference to the kapua-sys account (aka root account) but is not.
*/
@Deprecated
private String rootAccountName;

// Selected Account info
Expand Down Expand Up @@ -135,18 +144,34 @@ public void setAccountPath(String accountPath) {
this.accountPath = accountPath;
}

/**
* @deprecated Since 2.0.0. This is very misleading since it seems that is a reference to the kapua-sys account (aka root account) but is not.
*/
@Deprecated
public String getRootAccountId() {
return rootAccountId;
}

/**
* @deprecated Since 2.0.0. This is very misleading since it seems that is a reference to the kapua-sys account (aka root account) but is not.
*/
@Deprecated
public void setRootAccountId(String rootAccountId) {
this.rootAccountId = rootAccountId;
}

/**
* @deprecated Since 2.0.0. This is very misleading since it seems that is a reference to the kapua-sys account (aka root account) but is not.
*/
@Deprecated
public String getRootAccountName() {
return rootAccountName;
}

/**
* @deprecated Since 2.0.0. This is very misleading since it seems that is a reference to the kapua-sys account (aka root account) but is not.
*/
@Deprecated
public void setRootAccountName(String rootAccountName) {
this.rootAccountName = rootAccountName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public EntityView<GwtEndpoint> getViewInstance(GwtSession currentSession) {

@Override
public Boolean isEnabled(GwtSession currentSession) {
return currentSession.getRootAccountId().equals(currentSession.getSelectedAccountId());
return currentSession.getAccountId().equals(currentSession.getSelectedAccountId());
}
}

0 comments on commit 85727f4

Please sign in to comment.