Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.Container;
import org.labkey.api.data.SimpleFilter;
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.TableSelector;
import org.labkey.api.module.Module;
import org.labkey.api.query.QueryService;
import org.labkey.api.query.QueryUrls;
import org.labkey.api.query.UserSchema;
import org.labkey.api.security.User;
import org.labkey.api.settings.LookAndFeelProperties;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.logging.LogHelper;
Expand Down Expand Up @@ -85,4 +90,40 @@ public Module getOwnerModule()
{
return _owner;
}

protected void genericQueryCheck(Container c, User u, StringBuilder msg, String schemaName, String queryName, String message)
{
genericQueryCheck(c, u, msg, schemaName, queryName, message, null);
}

protected void genericQueryCheck(Container c, User u, StringBuilder msg, String schemaName, String queryName, String message, @Nullable SimpleFilter filter)
{
TableInfo ti = getTableInfo(u, c, schemaName, queryName);

TableSelector ts = new TableSelector(ti, filter, null);
long count = ts.getRowCount();
if (count > 0)
{
msg.append("<b>WARNING: There are ").append(count).append(" ").append(message).append("</b><br>\n");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escape message? PageFlowUtil.filter(message)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a valid point, although I think the thing to do is refactor all of NotificationService to use HtmlString. That touches a lot of code. There are no user-supplied values, so the notifications should be pretty safe, but I will make a note to look into this at some point.

msg.append("<p><a href='").append(getExecuteQueryUrl(c, schemaName, queryName, null, filter)).append("'>Click here to view them</a><br>\n\n");
msg.append("<hr>\n\n");
}
}

protected TableInfo getTableInfo(User u, Container c, String schemaName, String queryName)
{
UserSchema us = QueryService.get().getUserSchema(u, c, schemaName);
if (us == null)
{
throw new IllegalStateException("Missing user schema: " + schemaName);
}

TableInfo ti = us.getTable(queryName);
if (ti == null)
{
throw new IllegalStateException("Missing table: " + schemaName + "." + queryName);
}

return ti;
}
}