Changeset 0.21.1.1 (#87)

This commit is contained in:
2026-03-01 16:40:26 +00:00
parent 70aa78e486
commit 09c7281552
20 changed files with 853 additions and 102 deletions

View File

@@ -268,3 +268,24 @@ func (s *ChannelStore) UserOwns(ctx context.Context, channelID, userID string) (
channelID, userID).Scan(&exists)
return exists, err
}
// ResolveWorkspaceID returns the effective workspace for a channel.
// Resolution: channel.workspace_id > project.workspace_id.
// Returns empty string if no workspace is bound.
func (s *ChannelStore) ResolveWorkspaceID(ctx context.Context, channelID string) (string, error) {
var wsID sql.NullString
err := DB.QueryRowContext(ctx, `
SELECT COALESCE(c.workspace_id, p.workspace_id)
FROM channels c
LEFT JOIN project_channels pc ON pc.channel_id = c.id
LEFT JOIN projects p ON p.id = pc.project_id
WHERE c.id = ?
LIMIT 1`, channelID).Scan(&wsID)
if err != nil {
if err == sql.ErrNoRows {
return "", nil
}
return "", err
}
return NullableString(wsID), nil
}