Skip to content

Commit

Permalink
Add synchronization for project groups page
Browse files Browse the repository at this point in the history
Track usage of ensureAdminMode
  • Loading branch information
labkey-tchad committed Jan 22, 2025
1 parent ad0c013 commit cfe663e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
34 changes: 34 additions & 0 deletions src/org/labkey/test/LabKeySiteWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,53 @@ protected void setSystemMaintenance(boolean enable)
@Deprecated
public void ensureAdminMode()
{
boolean didSomething = false;
if (!onLabKeyPage())
{
goToHome();
didSomething = true;
}
if (!isSignedIn())
{
simpleSignIn();
didSomething = true;
}
else if (!isUserSystemAdmin() && isImpersonating())
{
stopImpersonating(false);
didSomething = true;
}
Locator projectMenu = ProjectMenu.Locators.menuProjectNav;
if (!isElementPresent(projectMenu))
{
goToHome();
waitForElement(projectMenu, WAIT_FOR_PAGE);
didSomething = true;
}
assertTrue("Test user '" + getCurrentUser() + "' is not an admin", isUserAdmin());

StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StringBuilder relevantCalls = new StringBuilder();
for (int i = 1; i < stackTrace.length; i++)
{
if (stackTrace[i].getClassName().contains("labkey"))
{
relevantCalls.append("\n");
relevantCalls.append(stackTrace[i].toString());
}
else
{
break;
}
}
if (didSomething)
{
TestLogger.warn("Necessary call to 'ensureAdminMode'. Consider refactoring to make it unnecessary." + relevantCalls);
}
else
{
TestLogger.warn("Unnecessary call to 'ensureAdminMode'. Consider removing it." + relevantCalls);
}
}

public ShowAdminPage goToAdminConsole()
Expand Down
1 change: 0 additions & 1 deletion src/org/labkey/test/tests/GroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ protected void createProjectCopyPerms()
{
String projectName = getProject2Name();

ensureAdminMode();
navBar()
.goToCreateProjectPage()
.setProjectName(projectName)
Expand Down
18 changes: 11 additions & 7 deletions src/org/labkey/test/util/UIPermissionsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public Integer createGlobalPermissionsGroup(@LoggedParam String groupName, boole
public Integer createPermissionsGroup(String groupName)
{
_driver.log("Creating permissions group " + groupName);
enterPermissionsUI();
_driver._ext4Helper.clickTabContainingText("Project Groups");
goToProjectGroups();
_driver.setFormElement(Locator.xpath("//input[contains(@name, 'projectgroupsname')]"), groupName);
_driver.clickButton("Create New Group", 0);
_driver._extHelper.waitForExtDialog(groupName + " Information");
Expand All @@ -110,6 +109,13 @@ public Integer createPermissionsGroup(String groupName)
return Integer.parseInt(addedGroup.getAttribute("groupId"));
}

private void goToProjectGroups()
{
enterPermissionsUI();
_driver._ext4Helper.clickTabContainingText("Project Groups");
_driver.shortWait().until(ExpectedConditions.visibilityOfElementLocated(Locator.tagWithClass("div", "pGroup").withText("Guests")));
}

@Override
public void assertNoPermission(String userOrGroupName, String permissionSetting)
{
Expand Down Expand Up @@ -349,8 +355,7 @@ public boolean doesGroupExist(String groupName, String projectName)
{
_driver.ensureAdminMode();
_driver.clickProject(projectName);
enterPermissionsUI();
_driver._ext4Helper.clickTabContainingText("Project Groups");
goToProjectGroups();
_driver.waitForText("Member Groups");
List<Ext4CmpRef> refs = _driver._ext4Helper.componentQuery("grid", Ext4CmpRef.class);
Ext4CmpRef ref = refs.get(0);
Expand All @@ -364,8 +369,7 @@ public boolean isUserInGroup(String user, String groupName, String projectName,
{
_driver.ensureAdminMode();
_driver.clickProject(projectName);
enterPermissionsUI();
_driver._ext4Helper.clickTabContainingText("Project Groups");
goToProjectGroups();
_driver.waitForElement(Locator.css(".groupPicker"), BaseWebDriverTest.WAIT_FOR_JAVASCRIPT);
_driver.waitAndClick(Locator.xpath("//div[text()='" + groupName + "']"));
_driver._extHelper.waitForExtDialog(groupName + " Information");
Expand Down Expand Up @@ -400,7 +404,7 @@ public Integer createPermissionsGroup(String groupName, String... memberNames)

public void openGroupPermissionsDisplay(String groupName)
{
_driver._ext4Helper.clickTabContainingText("Project Groups");
goToProjectGroups();
// warning Administrators can appear multiple times
List<Ext4CmpRef> refs = _driver._ext4Helper.componentQuery("grid", Ext4CmpRef.class);
Ext4CmpRef ref = refs.get(0);
Expand Down

0 comments on commit cfe663e

Please sign in to comment.