Skip to content

Commit 8992065

Browse files
authored
Expand test coverage over button permissions (#55)
* Expand test coverage over button permissions
1 parent 9d548be commit 8992065

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

LDK/api-src/org/labkey/api/ldk/table/SimpleButtonConfigFactory.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,17 @@ protected String getJsHandler(TableInfo ti)
125125
@Override
126126
public boolean isAvailable(TableInfo ti)
127127
{
128-
return _owner == null || ti.getUserSchema().getContainer().getActiveModules().contains(_owner);
128+
if (_owner != null && !ti.getUserSchema().getContainer().getActiveModules().contains(_owner))
129+
{
130+
return false;
131+
}
132+
133+
if (_permission != null && !ti.getUserSchema().getContainer().hasPermission(ti.getUserSchema().getUser(), _permission))
134+
{
135+
return false;
136+
}
137+
138+
return true;
129139
}
130140

131141
@Override

LDK/src/org/labkey/ldk/query/DefaultTableCustomizer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ private static boolean configureMoreActionsBtn(TableInfo ti, List<ButtonConfigFa
469469
for (ButtonConfigFactory fact : buttons)
470470
{
471471
NavTree newButton = fact.create(ti);
472+
if (!fact.isAvailable(ti) || !fact.isVisible(ti))
473+
{
474+
continue;
475+
}
476+
472477
if (!btnNameMap.containsKey(newButton.getText()))
473478
{
474479
btnNameMap.put(newButton.getText(), newButton);

LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ public void testSteps() throws Exception
240240
urlGenerationTest();
241241
peptideTableTest();
242242
searchPanelTest();
243+
244+
testButtonPermissions();
243245
}
244246

245247
protected void setUpTest() throws Exception
@@ -1877,4 +1879,25 @@ public void checkViews()
18771879
//the module contains an R report tied to a specific assay name, so view check fails when an assay of that name isnt present
18781880
//when module-based assays can supply reports this should be corrected
18791881
}
1882+
1883+
protected void testButtonPermissions() throws Exception
1884+
{
1885+
goToProjectHome();
1886+
_helper.clickNavPanelItem("Samples:", "Browse All");
1887+
1888+
DataRegionTable dr = new DataRegionTable("query", this);
1889+
dr.checkAllOnPage();
1890+
1891+
dr.clickHeaderButton("More Actions");
1892+
assertElementPresent(Locator.tagWithText("a", "Bulk Edit"));
1893+
1894+
impersonateRole("Editor");
1895+
refresh();
1896+
1897+
dr = new DataRegionTable("query", this);
1898+
dr.checkAllOnPage();
1899+
1900+
dr.clickHeaderButton("More Actions");
1901+
assertElementNotPresent(Locator.tagWithText("a", "Bulk Edit"));
1902+
}
18801903
}

0 commit comments

Comments
 (0)