Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate to a single SMTP help message code path and fix docs link #6385

Merged
merged 2 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/src/org/labkey/api/data/ContainerFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,18 @@ public ContainerFilter create(ContainerUser cu)
}
}

public static ContainerFilter current(Container c, User user)
{
return Type.Current.create(c, user);
}

public static ContainerFilter current(ContainerUser cu)
{
return Type.Current.create(cu);
}

// Does not validate permissions!
@Deprecated // Use current(Container, User) or current(ContainerUser) instead
public static ContainerFilter current(Container c)
{
return new CurrentContainerFilter(c);
Expand Down
48 changes: 31 additions & 17 deletions api/src/org/labkey/api/security/SecurityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,7 @@ public static HtmlString addUser(ViewContext context, ValidEmail email, boolean

ActionURL messageContentsURL = null;
User currentUser = context.getUser();
boolean emailFailure = false;

try
{
Expand Down Expand Up @@ -2317,6 +2318,9 @@ else if (sendMail)

if (null != newUser)
UserManager.addToUserHistory(newUser, newUser.getEmail() + " was added to the system. Sending the verification email failed.");

// Error message above includes a link to the email contents; set this flag to skip rendering this link again. Issue #51936.
emailFailure = true;
}
catch (UserManagementException e)
{
Expand All @@ -2327,20 +2331,24 @@ else if (sendMail)
// hide showRegistrationEmail link if provider is specified for now
if (messageContentsURL != null && provider == null)
{
LinkBuilder link = new LinkBuilder("here").href(messageContentsURL).target("_blank").clearClasses();
message.append(" Click ").append(link).append(" to see the email.");
// Email failure message already includes link to the contents
if (!emailFailure)
{
LinkBuilder link = new LinkBuilder("here").href(messageContentsURL).target("_blank").clearClasses();
message.append(" Click ").append(link).append(" to see the email.");
}

if (!context.getContainer().isRoot())
{
LinkBuilder projectGroupLink = new LinkBuilder("here").href(PageFlowUtil.urlProvider(SecurityUrls.class).getPermissionsURL(context.getContainer())).clearClasses();
message.append(" Add the new user to a Project Group ").append(projectGroupLink).append(".");
message.append(" Add the new user to a Project Group ").append(projectGroupLink).append(".").append(HtmlString.BR).append(HtmlString.BR);
}
}

return message.getHtmlString();
}

@SuppressWarnings("unused") // Called from mGAP
@SuppressWarnings("unused") // Called from mGAP and mcc
public static void sendRegistrationEmail(ViewContext context, ValidEmail email, String mailPrefix, NewUserStatus newUserStatus, @Nullable List<Pair<String, String>> extraParameters) throws Exception
{
sendRegistrationEmail(context, email, mailPrefix, newUserStatus, extraParameters, null, true);
Expand Down Expand Up @@ -2391,26 +2399,32 @@ private static void appendMailHelpText(HtmlStringBuilder builder, ActionURL mess
{
if (isAdmin)
{
builder.append("You can attempt to resend this mail later by going to the Site Users link, clicking on the appropriate user from the list, and resetting their password.");

if (messageContentsURL != null)
{
builder.append(" Alternatively, you can copy the ");
builder.append(new LinkBuilder("contents of the message").href(messageContentsURL).target("_blank").clearClasses());
builder.append(" into an email client and send it to the user manually.");
}

builder.unsafeAppend("</p>");
builder.unsafeAppend("<p>For help on fixing your mail server settings, please consult the SMTP section of the ");
builder.append(new HelpTopic("labkeyxml").getSimpleLinkHtml("LabKey documentation on modifying your configuration file"));
builder.append(".").append(HtmlString.BR);
builder
.unsafeAppend("<p>")
.append("You can attempt to resend this mail later by going to the Site Users link, clicking on the appropriate user from the list, and resetting their password.");
appendAdminMailHelpHtml(builder, messageContentsURL);
}
else
{
builder.append("Please contact your site administrator.");
}
}

public static void appendAdminMailHelpHtml(HtmlStringBuilder builder, ActionURL messageContentsURL)
{
if (messageContentsURL != null)
{
builder.append(" Alternatively, you can copy the ")
.append(new LinkBuilder("contents of the message").href(messageContentsURL).target("_blank").clearClasses())
.append(" into an email client and send it to the user manually.");
}

builder.unsafeAppend("</p><p>")
.append("Get help fixing your SMTP mail server settings ")
.append(new HelpTopic("SMTPsettings").getSimpleLinkHtml("here"))
.append(".")
.unsafeAppend("</p>");
}

public static void createNewProjectGroups(Container project, User user)
{
Expand Down
13 changes: 2 additions & 11 deletions core/src/org/labkey/core/security/SecurityController.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
import org.labkey.api.util.HelpTopic;
import org.labkey.api.util.HtmlString;
import org.labkey.api.util.HtmlStringBuilder;
import org.labkey.api.util.Link;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.Pair;
import org.labkey.api.util.TestContext;
Expand Down Expand Up @@ -2040,16 +2039,8 @@ private HtmlString getMailHelpText(User user)
HtmlStringBuilder builder = HtmlStringBuilder.of()
.unsafeAppend("<p>")
.append("You can attempt to resend this mail later by going to the Site Users link, clicking on the appropriate user from the list, and resetting their password.");
if (mailHref != null)
{
builder.append(" Alternatively, you can copy the ")
.append(new Link.LinkBuilder("contents of the message").href(mailHref).target("_blank").clearClasses())
.append(" into an email client and send it to the user manually.");
}
builder.unsafeAppend("</p>\n<p>")
.append("For help on fixing your mail server settings, please consult the SMTP section of the ")
.append(new HelpTopic("labkeyxml").getSimpleLinkHtml("LabKey Server documentation on modifying your configuration file"))
.unsafeAppend(".</p>");

SecurityManager.appendAdminMailHelpHtml(builder, mailHref);

return builder.getHtmlString();
}
Expand Down