dev(data-access): add app owner relationship

It turns out self-referencing tables add some nuances to what is and
what isn't ambiguous in SQL queries, so getting this right took a little
longer than expected. Following the entire chain doesn't seem to be
possible so a compromise is made by only traversing one level of depth.
(you can the uid of the owner of the app, but not the uid of the owner
app's own owner)
This commit is contained in:
KernelDeimos
2026-01-20 16:28:22 -05:00
committed by Eric Dubé
parent 1a8130b8fd
commit 3839afd805
@@ -45,12 +45,14 @@ export default class AppService extends BaseService {
const userCanEditOnly = Array.prototype.includes.call(predicate, 'user-can-edit');
const stmt = 'SELECT *, ' +
const stmt = 'SELECT apps.*, ' +
'owner_user.username AS owner_user_username, ' +
'owner_user.uuid AS owner_user_uuid ' +
'owner_user.uuid AS owner_user_uuid, ' +
'app_owner.uid AS app_owner_uid ' +
'FROM apps ' +
'LEFT JOIN user owner_user ON owner_user_id = owner_user.id ' +
`${userCanEditOnly ? 'WHERE owner_user_id=?' : ''} ` +
'LEFT JOIN user owner_user ON apps.owner_user_id = owner_user.id ' +
'LEFT JOIN apps app_owner ON apps.app_owner = app_owner.id ' +
`${userCanEditOnly ? 'WHERE apps.owner_user_id=?' : ''} ` +
'LIMIT 5000';
const values = userCanEditOnly ? [Context.get('user').id] : [];
const rows = await db.read(stmt, values);
@@ -83,6 +85,10 @@ export default class AppService extends BaseService {
// app.filetype_associations = row.filetype_associations;
// app.owner = row.owner;
app.app_owner = {
uid: row.app_owner_uid,
};
{
const owner_user = extract_from_prefix(row, 'owner_user_');
app.owner_user = user_to_client(owner_user);