Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
],
"dependencies": {
"@doist/cli-core": "0.26.2",
"@doist/comms-sdk": "0.11.0",
"@doist/comms-sdk": "2.0.1",
"@pnpm/tabtab": "0.5.4",
"chalk": "5.6.2",
"commander": "14.0.3",
Expand Down
21 changes: 21 additions & 0 deletions src/commands/channel/members.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ describe('tdc channel members list (default)', () => {
])
})

it('omits email for restricted members', async () => {
refsMocks.resolveChannelRef.mockResolvedValue(createChannel([6]))
apiMocks.getCommsClient.mockResolvedValue({
workspaceUsers: {
getUserById: vi.fn().mockResolvedValue({
id: 6,
fullName: 'Restricted User',
email: 'restricted@example.com',
restricted: true,
}),
},
})
const consoleSpy = captureConsole('log')
const program = createProgram()

await program.parseAsync(['node', 'tdc', 'channel', 'members', 'General', '--json'])

const payload = JSON.parse(consoleSpy.mock.calls[0][0] as string)
expect(payload.members[0]).toEqual({ id: 6, name: 'Restricted User', email: null })
Comment thread
gnapse marked this conversation as resolved.
})

it('falls back to user:<id> for unknown members', async () => {
refsMocks.resolveChannelRef.mockResolvedValue(createChannel([99]))
const consoleSpy = captureConsole('log')
Expand Down
4 changes: 3 additions & 1 deletion src/commands/channel/members.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isRestrictedWorkspaceUser } from '@doist/comms-sdk'
import { getCurrentWorkspaceId, getWorkspaceGroups } from '../../lib/api.js'
import type { ViewOptions } from '../../lib/options.js'
import { colors, formatJson, formatNdjson, pluralize } from '../../lib/output.js'
Expand All @@ -21,7 +22,8 @@ export async function listChannelMembers(

const members = userIds.map((id) => {
const user = userMap.get(id)
return { id, name: user?.fullName ?? null, email: user?.email ?? null }
const email = user && !isRestrictedWorkspaceUser(user) ? (user.email ?? null) : null
return { id, name: user?.fullName ?? null, email }
})

const slimPayload = {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/channel/membership-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Channel, Group, WorkspaceUser } from '@doist/comms-sdk'
import type { Channel, Group, VisibleWorkspaceUser } from '@doist/comms-sdk'
import {
addUsersToChannel,
getCommsClient,
Expand All @@ -20,7 +20,7 @@ export function channelUserIds(channel: Channel): number[] {
export async function fetchUsersByIds(
workspaceId: number,
userIds: number[],
): Promise<Map<number, WorkspaceUser>> {
): Promise<Map<number, VisibleWorkspaceUser>> {
if (userIds.length === 0) return new Map()
const client = await getCommsClient()
// Per-member fetch keeps latency tied to channel size, not workspace size
Expand All @@ -35,7 +35,7 @@ export async function fetchUsersByIds(
}
}),
)
const map = new Map<number, WorkspaceUser>()
const map = new Map<number, VisibleWorkspaceUser>()
for (const entry of entries) {
if (entry) map.set(entry[0], entry[1])
}
Expand Down
16 changes: 16 additions & 0 deletions src/commands/groups/groups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ describe('tdc groups view', () => {
expect(output).not.toHaveProperty('version')
})

it('omits email for restricted members', async () => {
mockGetUserById.mockResolvedValueOnce({
id: 1,
fullName: 'Restricted User',
email: 'restricted@example.com',
restricted: true,
})
const program = createProgram()
const consoleSpy = captureConsole('log')

await program.parseAsync(['node', 'tdc', 'groups', 'view', 'Frontend', '--json'])

const output = JSON.parse(consoleSpy.mock.calls[0][0])
expect(output.members[0]).toEqual({ id: 1, name: 'Restricted User', email: null })
Comment thread
gnapse marked this conversation as resolved.
})

it('renders user:N for members whose lookup fails', async () => {
mockGetUserById.mockImplementationOnce(async () => {
throw new Error('User not found')
Expand Down
4 changes: 3 additions & 1 deletion src/commands/groups/view.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isRestrictedWorkspaceUser } from '@doist/comms-sdk'
import { getCommsClient, getCurrentWorkspaceId } from '../../lib/api.js'
import type { ViewOptions } from '../../lib/options.js'
import { colors, formatJson, formatNdjson, pluralize } from '../../lib/output.js'
Expand All @@ -18,7 +19,8 @@ export async function viewGroup(ref: string, options: GroupViewOptions): Promise
workspaceId,
userId: id,
})
return { id, name: user.fullName, email: user.email ?? null }
const email = isRestrictedWorkspaceUser(user) ? null : (user.email ?? null)
return { id, name: user.fullName, email }
} catch {
return { id, name: null as string | null, email: null as string | null }
}
Expand Down
Loading