Skip to content

Commit 212d269

Browse files
committed
Only wrap ehr_lookups tables whose pseudo-PK differs from the real PK
The generic fallback in EHRLookupsUserSchema.createTable() wrapped any hard table with a single non-rowid key field and a container column in a ContainerScopedTable. For tables whose user-facing key is the true DB PK (clinpath_status, project_types, full_snomed, flag_values), the PK constraint already enforces uniqueness and the wrapper made the key column hidden and non-insertable in the UI. The heuristic now compares the promoted key against the real PK from JDBC metadata, so those tables get CustomPermissionsTable while all 26 rowid-plus-pseudo-PK tables keep container scoping. Claude-Session: https://claude.ai/code/session_013WM8RcTJDaaopwMTK4H9KX
1 parent d52e004 commit 212d269

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

ehr/src/org/labkey/ehr/query/EHRLookupsUserSchema.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,18 @@ else if (EHRSchema.TABLE_LOOKUP_SETS.equalsIgnoreCase(name))
212212

213213
// By default, any hard tables in the ehr_lookups schema not accounted for above will fall into one of the
214214
// two categories below. Both of these will add a check that makes sure the user has EHRDataAdminPermission
215-
// in order to insert/update/delete on the table. The ContainerScopedTable case is for those tables that
216-
// have a true DB PK or rowid but a User pseudoPK that should be accounted for at the container level.
215+
// in order to insert/update/delete on the table. The ContainerScopedTable case is for tables whose
216+
// user-facing key (promoted via isKeyField in ehr_lookups.xml) differs from the true DB PK: the PK
217+
// constraint does not enforce uniqueness of the pseudo-PK, so the wrapper enforces it per container and
218+
// resolves the pseudo-PK to the real PK on update. Tables whose user-facing key is the true PK
219+
// (e.g. project_types) get CustomPermissionsTable instead: the PK constraint already enforces uniqueness,
220+
// and container-scoping such a table made its key column non-insertable in the UI.
217221
String pkColName = getPkColName(ti);
218-
if (pkColName != null && !"rowid".equalsIgnoreCase(pkColName) && ti.getColumn("container") != null)
222+
List<String> realPk = _dbSchema.getTable(name).getPkColumnNames();
223+
boolean singleColumnPks = pkColName != null && realPk.size() == 1;
224+
boolean realPkMatchesPseudoPk = singleColumnPks && realPk.get(0).equalsIgnoreCase(pkColName);
225+
226+
if (singleColumnPks && !realPkMatchesPseudoPk && ti.getColumn("container") != null)
219227
return getContainerScopedTable(name, cf, pkColName, EHRDataAdminPermission.class);
220228
else
221229
return getCustomPermissionTable(createSourceTable(name), cf, EHRDataAdminPermission.class);

0 commit comments

Comments
 (0)