Skip to content

Commit

Permalink
Fixed logic that handles enablement of Endpoint View
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Nov 22, 2022
1 parent 85727f4 commit df391e1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,42 @@ public void setSelectedAccountPath(String selectedAccountPath) {
this.selectedAccountPath = selectedAccountPath;
}

/**
* Checks if the selected Account is at root level (it means it is kapua-sys)
*
* @return {@code true} if it is, {@code false} otherwise
* @since 2.0.0
*/
public boolean isSelectedAccountRootLevel() {
return isSelectedAccountAtLevel(0);
}

/**
* Checks if the selected Account is a first level (it means it is a direct son of kapua-sys)
*
* @return {@code true} if it is, {@code false} otherwise
* @since 2.0.0
*/
public boolean isSelectedAccountFirstLevel() {
return isSelectedAccountAtLevel(1);
}

/**
* Checks if the selected Account is the given level.
*
* <ul>
* <li>/1 = level 0</li>
* <li>/1/1234 = level 1</li>
* </ul>
*
* @param level The level to check against
* @return {@code true} if it is, {@code false} otherwise
* @since 2.0.0
*/
public boolean isSelectedAccountAtLevel(int level) {
return getSelectedAccountPath().split("/").length == (level + 2);
}

// User info
public String getUserId() {
return userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.kapua.app.console.module.api.client.ui.view.descriptor.AbstractEntityViewDescriptor;
import org.eclipse.kapua.app.console.module.api.shared.model.session.GwtSession;
import org.eclipse.kapua.app.console.module.endpoint.shared.model.GwtEndpoint;
import org.eclipse.kapua.app.console.module.endpoint.shared.model.permission.EndpointSessionPermission;

public class EndpointViewDescriptor extends AbstractEntityViewDescriptor<GwtEndpoint> {

Expand Down Expand Up @@ -47,6 +48,11 @@ public EntityView<GwtEndpoint> getViewInstance(GwtSession currentSession) {

@Override
public Boolean isEnabled(GwtSession currentSession) {
return currentSession.getAccountId().equals(currentSession.getSelectedAccountId());
return currentSession.hasPermission(EndpointSessionPermission.readAll()) &&
(
currentSession.isSelectedAccountRootLevel()
||
currentSession.isSelectedAccountFirstLevel()
);
}
}

0 comments on commit df391e1

Please sign in to comment.