Skip to content

Commit 2fbfa12

Browse files
authored
Add link to "Register" for a new account (#1173)
- We will enable self-sign-up on PanoramaWeb. Add a link to "Register" for a new account. - Show "Register" link only if AuthenticationManager.isRegistrationEnabled() - Added test
1 parent c032f95 commit 2fbfa12

2 files changed

Lines changed: 107 additions & 7 deletions

File tree

src/org/labkey/targetedms/TargetedMSController.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
import org.labkey.api.reports.report.RedirectReport;
134134
import org.labkey.api.reports.report.ReportDescriptor;
135135
import org.labkey.api.security.ActionNames;
136+
import org.labkey.api.security.AuthenticationManager;
136137
import org.labkey.api.security.Group;
137138
import org.labkey.api.security.LoginUrls;
138139
import org.labkey.api.security.RequiresLogin;
@@ -2309,10 +2310,9 @@ public ModelAndView getView(ChromatogramForm form, BindException errors)
23092310
@Override
23102311
public void addNavTrail(NavTree root)
23112312
{
2313+
root.addChild("Targeted MS Runs", getShowListURL(getContainer()));
23122314
if (null != _run)
23132315
{
2314-
root.addChild("Targeted MS Runs", getShowListURL(getContainer()));
2315-
23162316
root.addChild(_run.getDescription(), getShowRunURL(getContainer(), _run.getId()));
23172317

23182318
ActionURL pepDetailsUrl = new ActionURL(ShowPeptideAction.class, getContainer());
@@ -4461,13 +4461,20 @@ public String getDataRegionNameSmallMolecule()
44614461
@NotNull
44624462
private static HtmlView getLoginView(ViewContext context, Container container)
44634463
{
4464+
ActionURL loginUrl = PageFlowUtil.urlProvider(LoginUrls.class).getLoginURL(container, context.getActionURL());
4465+
ActionURL registerUrl = PageFlowUtil.urlProvider(LoginUrls.class).getRegisterURL(container, context.getActionURL());
4466+
HtmlString loginLink = DOM.createHtmlFragment(
4467+
DOM.A(at(style, "font-weight: bold;", href, loginUrl),"Login"),
4468+
" to view this data");
4469+
HtmlString registerLink = DOM.createHtmlFragment(
4470+
DOM.BR(),
4471+
"Don't have an account? ",
4472+
DOM.A(at(style, "font-weight: bold;", href, registerUrl), "Register"));
4473+
44644474
return new HtmlView(DOM.createHtmlFragment(
44654475
DOM.DIV(cl("alert alert-info"),
4466-
"Please ",
4467-
DOM.A(at(style, "font-weight: bold;",
4468-
href, PageFlowUtil.urlProvider(LoginUrls.class).getLoginURL(container, context.getActionURL())),
4469-
"login"),
4470-
" to view this data")));
4476+
loginLink,
4477+
AuthenticationManager.isRegistrationEnabled() ? registerLink : "")));
44714478
}
44724479

44734480
@RequiresPermission(ReadPermission.class)

test/src/org/labkey/test/tests/targetedms/TargetedMSExperimentTest.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import org.labkey.test.Locator;
3131
import org.labkey.test.TestFileUtils;
3232
import org.labkey.test.components.FilesWebPart;
33+
import org.labkey.test.pages.core.admin.ShowAdminPage;
34+
import org.labkey.test.pages.core.login.LoginConfigurePage;
35+
import org.labkey.test.util.ApiPermissionsHelper;
3336
import org.labkey.test.util.DataRegionTable;
3437
import org.labkey.test.util.Ext4Helper;
3538
import org.labkey.test.util.FileBrowserHelper;
@@ -47,9 +50,11 @@
4750
import java.util.Set;
4851

4952
import static org.junit.Assert.assertEquals;
53+
import static org.junit.Assert.assertFalse;
5054
import static org.junit.Assert.assertNull;
5155
import static org.junit.Assert.assertTrue;
5256
import static org.labkey.test.util.DataRegionTable.DataRegion;
57+
import static org.labkey.test.util.PermissionsHelper.READER_ROLE;
5358

5459
@Category({})
5560
@BaseWebDriverTest.ClassTimeout(minutes = 8)
@@ -96,6 +101,9 @@ public void testSteps() throws IOException, CommandException
96101
// Verify product ion labels
97102
importData(SKY_FILE3, ++jobCount);
98103
verifyFragmentIonLabels(SKY_FILE3);
104+
105+
// Verify that guests access is blocked on some actions
106+
verifyGuestAccess();
99107
}
100108

101109
@LogMethod
@@ -799,4 +807,89 @@ private void verifyFragmentIonLabels(String fileName)
799807

800808
assertTrue("Missing legend items in chromatogram plot - " + missing, missing.isEmpty());
801809
}
810+
811+
@LogMethod
812+
private void verifyGuestAccess()
813+
{
814+
// Enable self sign up
815+
ShowAdminPage adminPage = goToAdminConsole();
816+
LoginConfigurePage loginConfigurePage = adminPage.clickAuthentication();
817+
loginConfigurePage.setSelfSignup(true);
818+
loginConfigurePage.clickSaveAndFinish();
819+
820+
// Make folder public
821+
goToProjectHome(getProjectName());
822+
ApiPermissionsHelper permissionsHelper = new ApiPermissionsHelper(this);
823+
permissionsHelper.setSiteGroupPermissions("Guests", READER_ROLE);
824+
825+
// Signout
826+
signOut();
827+
verifyGuestAccess(true);
828+
829+
// Disable self-signup
830+
signIn();
831+
adminPage = goToAdminConsole();
832+
loginConfigurePage = adminPage.clickAuthentication();
833+
loginConfigurePage.setSelfSignup(false);
834+
loginConfigurePage.clickSaveAndFinish();
835+
836+
// Message on blocked pages should not include link to register
837+
signOut();
838+
verifyGuestAccess(false);
839+
}
840+
841+
private void verifyGuestAccess(boolean selfSignupEnabled)
842+
{
843+
goToProjectHome(getProjectName());
844+
goToDashboard();
845+
846+
// Verify guest CAN view the document details page (ShowPrecursorListAction)
847+
clickAndWait(Locator.linkWithText(SKY_FILE));
848+
assertTextPresent("Document Summary");
849+
850+
// Verify guest CAN view the protein details page (ShowProteinAction)
851+
String targetProtein = "YAL038W";
852+
clickAndWait(Locator.linkWithText(targetProtein));
853+
assertTextPresentInThisOrder(targetProtein,
854+
"Protein",
855+
"Sequence Coverage",
856+
"Annotations for " + targetProtein,
857+
"Peptides",
858+
"Chromatograms",
859+
"Summary Charts");
860+
861+
// Verify guest CAN view the peptide details page (ShowPeptideAction)
862+
String targetPeptide = "LTSLNVVAGSDLR";
863+
clickAndWait(Locator.linkWithText(targetPeptide));
864+
assertTextPresentInThisOrder(targetPeptide,
865+
"Peptide Summary",
866+
"Chromatograms",
867+
"Summary Charts",
868+
"LTSLNVVAGSDLR, Charge 2"); // Title of the MS/MS spectrum viewer panel
869+
870+
// Verify guest CANNOT view the precursor details page (PrecursorAllChromatogramsChartAction)
871+
clickAndWait(Locator.linkWithImage("TransitionGroupLib.png"));
872+
verifyNoGuestAccessMessage(selfSignupEnabled);
873+
874+
// Go back to the document details page and in Document Summary click the transitions link
875+
// Verify guest CANNOT view the transitions list (ShowTransitionListAction)
876+
goToDashboard();
877+
clickAndWait(Locator.linkWithText(SKY_FILE));
878+
clickAndWait(Locator.linkWithText("296 transitions"));
879+
verifyNoGuestAccessMessage(selfSignupEnabled);
880+
}
881+
882+
private void verifyNoGuestAccessMessage(boolean selfSignupEnabled)
883+
{
884+
String fullBodyText = getBodyText();
885+
if (selfSignupEnabled)
886+
{
887+
assertTrue(fullBodyText.contains("Login to view this data" + "\n" + "Don't have an account? Register"));
888+
}
889+
else
890+
{
891+
assertTrue(fullBodyText.contains("Login to view this data"));
892+
assertFalse(fullBodyText.contains("Don't have an account? Register"));
893+
}
894+
}
802895
}

0 commit comments

Comments
 (0)