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

Changes to Short URL admin page #4813

Merged
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
82 changes: 56 additions & 26 deletions core/src/org/labkey/core/admin/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9463,39 +9463,14 @@ public boolean isDelete()
{
return _delete;
}

public List<ShortURLRecord> getSavedShortURLs()
{
return _savedShortURLs;
}

public void setSavedShortURLs(List<ShortURLRecord> savedShortURLs)
{
_savedShortURLs = savedShortURLs;
}
}

@AdminConsoleAction
@RequiresPermission(AdminPermission.class)
public class ShortURLAdminAction extends FormViewAction<ShortURLForm>
public abstract class AbstractShortURLAdminAction extends FormViewAction<ShortURLForm>
{
@Override
public void validateCommand(ShortURLForm target, Errors errors) {}

@Override
public ModelAndView getView(ShortURLForm form, boolean reshow, BindException errors)
{
form.setSavedShortURLs(ShortURLService.get().getAllShortURLs());
JspView<ShortURLForm> newView = new JspView<>("/org/labkey/core/admin/createNewShortURL.jsp", form, errors);
newView.setTitle("Create New Short URL");
newView.setFrame(WebPartView.FrameType.PORTAL);
JspView<ShortURLForm> existingView = new JspView<>("/org/labkey/core/admin/existingShortURLs.jsp", form, errors);
existingView.setTitle("Existing Short URLs");
existingView.setFrame(WebPartView.FrameType.PORTAL);

return new VBox(newView, existingView);
}

@Override
public boolean handlePost(ShortURLForm form, BindException errors) throws Exception
{
Expand Down Expand Up @@ -9572,6 +9547,27 @@ public boolean handlePost(ShortURLForm form, BindException errors) throws Except
}
return true;
}
}

@AdminConsoleAction
@RequiresPermission(AdminPermission.class)
public class ShortURLAdminAction extends AbstractShortURLAdminAction
{
@Override
public ModelAndView getView(ShortURLForm form, boolean reshow, BindException errors)
{
JspView<ShortURLForm> newView = new JspView<>("/org/labkey/core/admin/createNewShortURL.jsp", form, errors);
newView.setTitle("Create New Short URL");
newView.setFrame(WebPartView.FrameType.PORTAL);

QuerySettings qSettings = new QuerySettings(getViewContext(), "ShortURL", "ShortURL");
qSettings.setBaseSort(new Sort("-Created"));
QueryView existingView = new QueryView(new CoreQuerySchema(getUser(), getContainer()), qSettings, errors);
existingView.setTitle("Existing Short URLs");
existingView.setFrame(WebPartView.FrameType.PORTAL);

return new VBox(newView, existingView);
}

@Override
public URLHelper getSuccessURL(ShortURLForm form)
Expand All @@ -9587,6 +9583,40 @@ public void addNavTrail(NavTree root)
}
}

@RequiresPermission(AdminOperationsPermission.class)
public class UpdateShortURLAction extends AbstractShortURLAdminAction
{
@Override
public ModelAndView getView(ShortURLForm form, boolean reshow, BindException errors)
{
var shortUrlRecord = ShortURLService.get().resolveShortURL(form.getShortURL());
if (shortUrlRecord == null)
{
errors.addError(new LabKeyError("Short URL does not exist: " + form.getShortURL()));
return new SimpleErrorView(errors);
}
form.setFullURL(shortUrlRecord.getFullURL());

JspView<ShortURLForm> view = new JspView<>("/org/labkey/core/admin/updateShortURL.jsp", form, errors);
view.setTitle("Update Short URL");
view.setFrame(WebPartView.FrameType.PORTAL);
return view;
}

@Override
public URLHelper getSuccessURL(ShortURLForm form)
{
return new ActionURL(ShortURLAdminAction.class, getContainer());
}

@Override
public void addNavTrail(NavTree root)
{
setHelpTopic("shortURL");
addAdminNavTrail(root, "Update Short URL", getClass());
}
}

// API for reporting client-side exceptions.
// UNDONE: Throttle by IP to avoid DOS from buggy clients.
@Marshal(Marshaller.Jackson)
Expand Down
60 changes: 0 additions & 60 deletions core/src/org/labkey/core/admin/existingShortURLs.jsp

This file was deleted.

37 changes: 37 additions & 0 deletions core/src/org/labkey/core/admin/updateShortURL.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%@ page import="org.labkey.api.view.HttpView" %>
<%@ page import="org.labkey.core.admin.AdminController" %>
<%@ page import="org.labkey.api.view.ActionURL" %>
<%@ page extends="org.labkey.api.jsp.JspBase" %>
<%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %>

<labkey:errors/>

<%
AdminController.ShortURLForm bean = (AdminController.ShortURLForm) HttpView.currentModel();
%>

<labkey:form action="<%=urlFor(AdminController.UpdateShortURLAction.class)%>" method="POST" id="updateShortUrlForm">
<table class="lk-fields-table">
<tr>
<td class="labkey-form-label">Short URL: </td>
<td>
<input type="hidden" name="shortURL" value="<%= h(bean.getShortURL()) %>"/>
<%= h(bean.getShortURL()) %>
</td>
</tr>
<tr>
<td class="labkey-form-label">Target URL: </td>
<td><textarea rows="3" cols="80" name="fullURL"><%= h(bean.getFullURL()) %></textarea></td>
</tr>
</table>
<div style="margin-top: 10px;">
<%= button("Update").submit(true) %>
<%= button("Cancel").href(new ActionURL(AdminController.ShortURLAdminAction.class, getContainer())) %>
</div>
</labkey:form>

<div style="margin-top: 20px;">
<%= button("Delete")
.usePost("Are you sure you want to delete the short URL " + bean.getShortURL() + "?")
.href(urlFor(AdminController.UpdateShortURLAction.class).addParameter("shortURL", bean.getShortURL()).addParameter("delete", true)) %>
</div>
4 changes: 4 additions & 0 deletions core/src/org/labkey/core/query/CoreQuerySchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class CoreQuerySchema extends UserSchema
public static final String USERS_MSG_SETTINGS_TABLE_NAME = "UsersMsgPrefs";
public static final String SCHEMA_DESCR = "Contains data about the system users and groups.";
public static final String VIEW_CATEGORY_TABLE_NAME = "ViewCategory";
public static final String SHORTURL_TABLE_NAME = "ShortURL";

public CoreQuerySchema(User user, Container c)
{
Expand Down Expand Up @@ -177,6 +178,9 @@ public TableInfo createTable(String name, ContainerFilter cf)
return new ViewCategoryTable(ViewCategoryManager.getInstance().getTableInfoCategories(), this, cf);
if (MISSING_VALUE_INDICATOR_TABLE_NAME.equalsIgnoreCase(name))
return getMVIndicatorTable(cf);
if (SHORTURL_TABLE_NAME.equalsIgnoreCase(name) && ShortUrlTableInfo.canDisplayTable(getUser(), getContainer()))
return new ShortUrlTableInfo(this);

return null;
}

Expand Down
Loading