Skip to content

Commit

Permalink
Make "Public" column in the ExperimentAnnotations table an ExprColumn…
Browse files Browse the repository at this point in the history
… so that it can be sorted and filtered.
  • Loading branch information
vagisha committed Mar 16, 2024
1 parent 68c2026 commit c4e0e98
Showing 1 changed file with 15 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.labkey.api.security.permissions.Permission;
import org.labkey.api.security.roles.FolderAdminRole;
import org.labkey.api.security.roles.ProjectAdminRole;
import org.labkey.api.security.roles.ReaderRole;
import org.labkey.api.security.roles.Role;
import org.labkey.api.security.roles.RoleManager;
import org.labkey.api.settings.AppProps;
Expand Down Expand Up @@ -236,53 +237,7 @@ public void renderGridCellContents(RenderContext ctx, Writer out) throws IOExcep
runCountColumn.setLabel("Skyline Docs");
addColumn(runCountColumn);

var isPublicCol = wrapColumn("Public", getRealTable().getColumn("Id"));
isPublicCol.setDisplayColumnFactory(colInfo -> new DataColumn(colInfo)
{
@Override
public Object getValue(RenderContext ctx)
{
Integer experimentAnnotationsId = ctx.get(colInfo.getFieldKey(), Integer.class);
ExperimentAnnotations expAnnotations = ExperimentAnnotationsManager.get(experimentAnnotationsId);
if(expAnnotations != null)
{
return expAnnotations.isPublic() ? "Yes" : "No";
}
return "Row not found in ExperimentAnnotations for id " + experimentAnnotationsId;
}
@Override
public Object getDisplayValue(RenderContext ctx)
{
return getValue(ctx);
}
@Override
public @NotNull HtmlString getFormattedHtml(RenderContext ctx)
{
return HtmlString.of((String)getValue(ctx));
}
@Override
public Class getValueClass()
{
return String.class;
}
@Override
public Class getDisplayValueClass()
{
return String.class;
}

@Override
public boolean isFilterable()
{
return false;
}

@Override
public boolean isSortable()
{
return false;
}
});
var isPublicCol = getIsPublicCol();
addColumn(isPublicCol);

var licenseCol = wrapColumn("Data License", getRealTable().getColumn("Id"));
Expand Down Expand Up @@ -430,6 +385,19 @@ private ExprColumn getCatalogEntryCol()
return col;
}

private ExprColumn getIsPublicCol()
{
SQLFragment isPublicColSql = new SQLFragment(" (SELECT CASE WHEN EXISTS (SELECT 1 FROM ")
.append(CoreSchema.getInstance().getTableInfoRoleAssignments())
.append(" WHERE userId = ? AND role = ? AND resourceId = ").append(ExprColumn.STR_TABLE_ALIAS + ".Container").append(")")
.append(" THEN 'Yes' ELSE 'No' END ) ")
.add(Group.groupGuests)
.add(ReaderRole.class.getName());

ExprColumn isPublicCol = new ExprColumn(this, "Public", isPublicColSql, JdbcType.VARCHAR);
return isPublicCol;
}

@Override
public String getName()
{
Expand Down

0 comments on commit c4e0e98

Please sign in to comment.