IDEMPIERE-4084 Improve button access logic (#592)

This commit is contained in:
Diego Ruiz 2021-02-18 19:46:43 +01:00 committed by GitHub
parent b1d3f9c8fd
commit 3c220b6681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 58 deletions

View File

@ -153,6 +153,9 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
private List<ToolbarCustomButton> toolbarCustomButtons = new ArrayList<ToolbarCustomButton>();
private List<String> restrictionList;
private List<String> advancedList;
// Elaine 2008/12/04
/** Show Personal Lock */
public boolean isPersonalLock = MRole.getDefault().isPersonalLock();
@ -289,7 +292,7 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
overflows = new ArrayList<ToolBarButton>();
MToolBarButton[] officialButtons = MToolBarButton.getToolbarButtons("W", null);
for (MToolBarButton button : officialButtons) {
if (! button.isActive()) {
if (!button.isActive() || !hasAccess(BTNPREFIX+button.getComponentName())) {
buttons.remove(button.getComponentName());
} else {
if (button.isCustomization()) {
@ -476,6 +479,8 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
{
if(event.getTarget() instanceof ToolBarButton)
{
if (!event.getTarget().isVisible())
return;
if (!event.getTarget().getId().contentEquals(BTNPREFIX+"ShowMore"))
doOnClick(event);
else
@ -847,67 +852,30 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
private boolean ToolBarMenuRestictionLoaded = false;
private boolean hasAccess(String buttonName) {
ADWindow adwindow = ADWindow.get(windowNo);
if (restrictionList == null)
restrictionList = adwindow.getWindowToolbarRestrictList();
if (restrictionList.contains(buttonName))
return false;
if (!MRole.getDefault().isAccessAdvanced()) {
if (advancedList == null)
advancedList = adwindow.getWindowAdvancedButtonList();
if (advancedList.contains(buttonName))
return false;
}// All advanced btn
return true;
}
public void updateToolbarAccess(int xAD_Window_ID) {
if (ToolBarMenuRestictionLoaded)
return;
ADWindow adwindow = ADWindow.findADWindow(this);
List<String> restrictionList = adwindow.getWindowToolbarRestrictList();
for (String restrictName : restrictionList)
{
for (Component p = this.getFirstChild(); p != null; p = p.getNextSibling()) {
if (p instanceof ToolBarButton) {
if ( restrictName.equals(((ToolBarButton)p).getName()) ) {
this.removeChild(p);
break;
}
} else if (p instanceof Menupopup) {
for (Component p1 = p.getFirstChild(); p1 != null; p1 = p1.getNextSibling()) {
if ( p1 instanceof Menuitem && restrictName.equals((((Menuitem)p1).getValue())) ) {
p.removeChild(p1);
break;
}
}
}
else if (p instanceof Combobox) {
if (restrictName.equals(((Combobox) p).getId())) {
this.removeChild(p);
break;
}
}
}
} // All restrictions
if (!MRole.getDefault().isAccessAdvanced())
{
List<String> advancedList = adwindow.getWindowAdvancedButtonList();
for (String advancedName : advancedList)
{
for (Component p = this.getFirstChild(); p != null; p = p.getNextSibling()) {
if (p instanceof ToolBarButton) {
if ( advancedName.equals(((ToolBarButton)p).getName()) ) {
this.removeChild(p);
break;
}
} else if (p instanceof Menupopup) {
for (Component p1 = p.getFirstChild(); p1 != null; p1 = p1.getNextSibling()) {
if ( p1 instanceof Menuitem && advancedName.equals((((Menuitem)p1).getValue())) ) {
p.removeChild(p1);
break;
}
}
} else if (p instanceof Combobox) {
if (advancedName.equals(((Combobox) p).getId())) {
this.removeChild(p);
break;
}
}
}
} // All advanced btn
}
dynamicDisplay();
// If no workflow set for the table => disable btnWorkflow
@ -1196,6 +1164,7 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
}
public void setPressed(String buttonName, boolean pressed) {
if (getButton(buttonName) != null)
getButton(buttonName).setPressed(pressed);
}