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

Make the "Public" column on the ExperimentAnnotations tableinfo an ExprColumn #405

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Changes from 1 commit
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 @@ -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 ")
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably won't work if a container is inheriting permissions from its parent. That may not be relevant for this use case though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I should have noted that these containers do not inherit permissions from parent, so that is not a concern.

.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