Changeset 0.21.1.1 (#87)
This commit is contained in:
@@ -266,3 +266,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 = $1
|
||||
LIMIT 1`, channelID).Scan(&wsID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return "", nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return NullableString(wsID), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user