Skip to content

Commit e18cb59

Browse files
authored
Keep a person's client flag when it is false (#1055)
chat messages, chat line and people show printed a non-client author with no client key, so a connector requiring client == false refused them. This moves the CLI to SDK v0.39.0, where Person.Client is a *bool. Trust decisions (the connector's project membership, and setup's operator, allowlist and Ping participant checks) refuse a person whose read left the flag out; display and filters keep reading a missing flag as not a client.
1 parent 56884dc commit e18cb59

14 files changed

Lines changed: 127 additions & 25 deletions

File tree

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
charm.land/bubbles/v2 v2.2.1
99
charm.land/bubbletea/v2 v2.1.0
1010
charm.land/lipgloss/v2 v2.0.6
11-
github.com/basecamp/basecamp-sdk/go v0.37.0
11+
github.com/basecamp/basecamp-sdk/go v0.39.0
1212
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9
1313
github.com/basecamp/mcp v0.0.0-20261118214004-663b2e5d2836
1414
github.com/basecamp/surfguard/go v0.1.0

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
8989
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
9090
github.com/basecamp/actioncable-go v1.2.0 h1:t0MxlfMTcmaGXZ5ztgKRs7ZiY1MwXtBRwSSSAh1ofVg=
9191
github.com/basecamp/actioncable-go v1.2.0/go.mod h1:ezaV5z1GXQAsqyejqTs6wCFl2D8Wj+COLQkHc/kwoRs=
92-
github.com/basecamp/basecamp-sdk/go v0.37.0 h1:/Tv7GALbwmj0/gk8y2kwAi9/OiiWEQlJcVDH9PfMHWM=
93-
github.com/basecamp/basecamp-sdk/go v0.37.0/go.mod h1:ynVJME8mVV3UHMUMnzBgygTnMtadQFxz1iYg7fqwUeM=
92+
github.com/basecamp/basecamp-sdk/go v0.39.0 h1:s9963I0FFXxLcldw5/faiAUvTi3j3IYc5/47sdg6o/g=
93+
github.com/basecamp/basecamp-sdk/go v0.39.0/go.mod h1:ynVJME8mVV3UHMUMnzBgygTnMtadQFxz1iYg7fqwUeM=
9494
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9 h1:3NfGs+zx23Tp6cf+97+UewrJHlzZMLzmvEXOmOJyQAk=
9595
github.com/basecamp/cli v0.2.2-0.20261023171439-c9bce8206df9/go.mod h1:iTBTaWvsPEFIcZfkxQHEfISyJ6sZ7036K6bNx0RY3EE=
9696
github.com/basecamp/mcp v0.0.0-20261118214004-663b2e5d2836 h1:ND4te8b+HVFFrgcm7+n8P83MKKPqBpIyoJ63tT9liRU=

‎internal/commands/chat_test.go‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,3 +2443,60 @@ func TestChatPostPostsHTMLWithAMention(t *testing.T) {
24432443
assert.Contains(t, content, "<ul><li>one</li></ul>")
24442444
assert.NotContains(t, content, "&lt;")
24452445
}
2446+
2447+
// mockChatCreatorTransport serves one line whose creator is creatorJSON.
2448+
type mockChatCreatorTransport struct {
2449+
creatorJSON string
2450+
}
2451+
2452+
func (t *mockChatCreatorTransport) RoundTrip(req *http.Request) (*http.Response, error) {
2453+
header := make(http.Header)
2454+
header.Set("Content-Type", "application/json")
2455+
if req.Method != "GET" || !strings.Contains(req.URL.Path, "/lines/") {
2456+
return nil, errors.New("unexpected request " + req.Method + " " + req.URL.Path)
2457+
}
2458+
body := `{"id": 111, "content": "Hello", "type": "Chat::Lines::Text", "creator": ` + t.creatorJSON + `}`
2459+
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(body)), Header: header}, nil
2460+
}
2461+
2462+
// TestChatLineKeepsTheCreatorsClientFlag verifies that a line's creator keeps
2463+
// what Basecamp said about being a client. A non-client author used to come
2464+
// out with no client key at all, so the local agent connector's project
2465+
// trust, which requires client == false, refused every Campfire mention from
2466+
// anyone but its operator.
2467+
func TestChatLineKeepsTheCreatorsClientFlag(t *testing.T) {
2468+
for _, tc := range []struct {
2469+
name string
2470+
creator string
2471+
want string // the client key's raw JSON; "" for no key
2472+
}{
2473+
{"not a client", `{"id": 1, "name": "Tester", "client": false, "employee": true}`, "false"},
2474+
{"a client", `{"id": 1, "name": "Tester", "client": true}`, "true"},
2475+
{"not said", `{"id": 1, "name": "Tester"}`, ""},
2476+
} {
2477+
t.Run(tc.name, func(t *testing.T) {
2478+
t.Setenv("BASECAMP_NO_KEYRING", "1")
2479+
2480+
app, buf := newChatDeleteTestApp(&mockChatCreatorTransport{creatorJSON: tc.creator})
2481+
err := executeChatCommand(NewChatCmd(), app, "line", "https://3.basecamp.com/99999/buckets/123/chats/456/lines/111")
2482+
require.NoError(t, err)
2483+
2484+
var out struct {
2485+
Data struct {
2486+
ID int64 `json:"id"`
2487+
Creator map[string]json.RawMessage `json:"creator"`
2488+
} `json:"data"`
2489+
}
2490+
require.NoError(t, json.Unmarshal(buf.Bytes(), &out), buf.String())
2491+
require.EqualValues(t, 111, out.Data.ID, "the line was printed")
2492+
require.NotNil(t, out.Data.Creator, "the line carries its creator")
2493+
2494+
got, present := out.Data.Creator["client"]
2495+
if tc.want == "" {
2496+
assert.False(t, present, "client = %s, want no key", got)
2497+
return
2498+
}
2499+
assert.Equal(t, tc.want, string(got))
2500+
})
2501+
}
2502+
}

‎internal/commands/connect_setup_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ func startConnectSetupServer(t *testing.T) *connectSetupServer {
166166
}
167167
writeJSON(w, profile)
168168
case setupOperatorToken:
169-
writeJSON(w, map[string]any{"id": setupOperatorPerson, "name": "Operator", "personable_type": "User"})
169+
writeJSON(w, map[string]any{"id": setupOperatorPerson, "name": "Operator", "personable_type": "User", "client": false})
170170
case setupBotToken:
171-
writeJSON(w, map[string]any{"id": setupBotPerson, "name": "Bot", "personable_type": "User"})
171+
writeJSON(w, map[string]any{"id": setupBotPerson, "name": "Bot", "personable_type": "User", "client": false})
172172
default:
173173
w.WriteHeader(http.StatusUnauthorized)
174174
}
@@ -178,14 +178,14 @@ func startConnectSetupServer(t *testing.T) *connectSetupServer {
178178
w.WriteHeader(http.StatusForbidden)
179179
return
180180
}
181-
writeJSON(w, map[string]any{"id": setupOperatorPerson, "name": "Operator", "personable_type": "User"})
181+
writeJSON(w, map[string]any{"id": setupOperatorPerson, "name": "Operator", "personable_type": "User", "client": false})
182182
})
183183
mux.HandleFunc(fmt.Sprintf("/999/people/%d", setupOperatorPerson+1), func(w http.ResponseWriter, r *http.Request) {
184184
if bearer(r) != setupOperatorToken {
185185
w.WriteHeader(http.StatusForbidden) // as bc3 refuses an Agent today
186186
return
187187
}
188-
writeJSON(w, map[string]any{"id": setupOperatorPerson + 1, "name": "Colleague", "personable_type": "User"})
188+
writeJSON(w, map[string]any{"id": setupOperatorPerson + 1, "name": "Colleague", "personable_type": "User", "client": false})
189189
})
190190
mux.HandleFunc(fmt.Sprintf("/999/people/%d", setupAgentPerson), func(w http.ResponseWriter, _ *http.Request) {
191191
writeJSON(w, map[string]any{"id": setupAgentPerson, "name": "Marie Chef", "personable_type": "Agent"})
@@ -1625,8 +1625,8 @@ func TestConnectSetupLetsAPersonIntoOnePing(t *testing.T) {
16251625
s.bodies = map[string]any{fmt.Sprintf("/999/circles/%d", ping): map[string]any{
16261626
"id": ping, "title": "Launch",
16271627
"people": []map[string]any{
1628-
{"id": setupOperatorPerson, "name": "Operator", "personable_type": "User"},
1629-
{"id": guest, "name": "Jorge", "personable_type": "User"},
1628+
{"id": setupOperatorPerson, "name": "Operator", "personable_type": "User", "client": false},
1629+
{"id": guest, "name": "Jorge", "personable_type": "User", "client": false},
16301630
{"id": setupClientPerson, "name": "Client", "personable_type": "User", "client": true},
16311631
{"id": setupPeerAgent, "name": "Peer (agent)", "personable_type": "Agent"},
16321632
},

‎internal/commands/people.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ func runPeopleList(cmd *cobra.Command, projectID string, limit, page int, all bo
700700
Title: p.Title,
701701
Employee: p.Employee,
702702
Admin: p.Admin,
703-
Client: p.Client,
703+
Client: basecamp.Deref(p.Client),
704704
}
705705
}
706706

@@ -1148,7 +1148,7 @@ func runPeopleClientsList(cmd *cobra.Command, projectID string) error {
11481148
}
11491149
items := make([]clientListItem, 0)
11501150
for _, p := range result.People {
1151-
if !p.Client {
1151+
if !basecamp.Deref(p.Client) {
11521152
continue
11531153
}
11541154
item := clientListItem{ID: p.ID, Name: p.Name, EmailAddress: p.EmailAddress, Title: p.Title}
@@ -1702,7 +1702,7 @@ func clientEnablementError(ctx context.Context, app *appctx.App, bucketID int64,
17021702
if roster, listErr := app.Account().People().ListProjectPeople(ctx, bucketID, &basecamp.PeopleListOptions{}); listErr == nil {
17031703
var ids []int64
17041704
for _, p := range roster.People {
1705-
if p.Client {
1705+
if basecamp.Deref(p.Client) {
17061706
ids = append(ids, p.ID)
17071707
}
17081708
}

‎internal/connector/admission/sdk.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ func NewMembers(client *basecamp.AccountClient, now func() time.Time) *Members {
162162
}
163163

164164
// NonClientMember implements MemberReader. A member for trust is a person the
165-
// project's listing names who is neither a client nor an Agent principal (the
166-
// listing serves agents, with client false).
165+
// project's listing names, says is not a client, and does not mark as an
166+
// Agent principal (the listing serves agents, with client false). A person
167+
// the listing does not say either way about is not a member: trust is not
168+
// given on a field that is missing.
167169
//
168170
// "Yes" is served from a cached listing for its TTL. "No" discards the event,
169171
// so it is served only from a listing read at or after asOf; everyone the
@@ -198,7 +200,7 @@ func (m *Members) NonClientMember(ctx context.Context, bucketID, personID int64,
198200
}
199201
people := projectPeople{members: make(map[int64]bool, len(res.People))}
200202
for _, p := range res.People {
201-
if p.ID > 0 && !p.Client && p.PersonableType != personableAgent {
203+
if p.ID > 0 && p.Client != nil && !*p.Client && p.PersonableType != personableAgent {
202204
people.members[p.ID] = true
203205
}
204206
}

‎internal/connector/admission/sdk_test.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,19 @@ func (l *listing) client(t *testing.T) *basecamp.AccountClient {
252252
}
253253

254254
func TestMembershipExcludesClientsAndAgents(t *testing.T) {
255+
// unsaidID is listed without a client flag. Trust is not given on a field
256+
// that is missing, so the listing does not make them a member.
257+
const unsaidID int64 = 1006
255258
l := &listing{}
256-
l.set(fmt.Sprintf(`[{"id":%d,"personable_type":"User","client":false},{"id":%d,"personable_type":"Client","client":true},{"id":%d,"personable_type":"Agent","client":false}]`, memberID, clientID, otherAgent))
259+
l.set(fmt.Sprintf(`[{"id":%d,"personable_type":"User","client":false},{"id":%d,"personable_type":"Client","client":true},{"id":%d,"personable_type":"Agent","client":false},{"id":%d,"personable_type":"User"}]`, memberID, clientID, otherAgent, unsaidID))
257260
c := &clock{now: testNow}
258261
members := NewMembers(l.client(t), c.Now)
259262
seen := testNow.Add(-time.Second)
260263

261264
for _, tc := range []struct {
262265
id int64
263266
want bool
264-
}{{memberID, true}, {clientID, false}, {otherAgent, false}, {strangerID, false}} {
267+
}{{memberID, true}, {clientID, false}, {otherAgent, false}, {strangerID, false}, {unsaidID, false}} {
265268
got, err := members.NonClientMember(context.Background(), servedProj, tc.id, seen)
266269
require.NoError(t, err)
267270
assert.Equal(t, tc.want, got, "person %d", tc.id)

‎internal/connector/setup/checks.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ type Person struct {
3939
Name string
4040
PersonableType string
4141
Client bool
42+
// ClientUnsaid marks a person read through the SDK (fromSDK) whose read
43+
// left the client flag out. The checks refuse them as they refuse a
44+
// client. It is false on a Person built any other way, such as the
45+
// agent's boss taken from its profile, so it says nothing about those.
46+
ClientUnsaid bool
4247
}
4348

4449
// Reader is what the checks read, as the agent, in the agent's account.
@@ -167,7 +172,7 @@ func fromSDK(p *basecamp.Person) Person {
167172
if p == nil {
168173
return Person{}
169174
}
170-
return Person{ID: p.ID, Name: p.Name, PersonableType: p.PersonableType, Client: p.Client}
175+
return Person{ID: p.ID, Name: p.Name, PersonableType: p.PersonableType, Client: basecamp.Deref(p.Client), ClientUnsaid: p.Client == nil}
171176
}
172177

173178
// httpStatus is the status a failed read answered with, 0 when it did not
@@ -382,6 +387,8 @@ func verifyPerson(ctx context.Context, r Reader, name string, p Person, agentID
382387
c.Status, c.Message = StatusFail, fmt.Sprintf("Person %d is an Agent; agents never authorize", p.ID)
383388
case p.Client:
384389
c.Status, c.Message = StatusFail, fmt.Sprintf("Person %d is a client of the account; only members are trusted", p.ID)
390+
case p.ClientUnsaid:
391+
c.Status, c.Message = StatusFail, fmt.Sprintf("Basecamp did not say whether person %d is a client; only members are trusted", p.ID)
385392
default:
386393
c.Status = StatusPass
387394
c.Message = fmt.Sprintf("Person %d, %s%s", p.ID, richtext.SanitizeSingleLine(p.Name), source)
@@ -563,6 +570,8 @@ func verifyPingPerson(ping Ping, readErr error, pingID, id, agentID int64, recor
563570
c.Message = fmt.Sprintf("Person %d is an Agent; agents never authorize, and are allowed only with --allow-agent", id)
564571
case p.Client:
565572
c.Status, c.Message = StatusFail, fmt.Sprintf("Person %d is a client of the account; only members are trusted", id)
573+
case p.ClientUnsaid:
574+
c.Status, c.Message = StatusFail, fmt.Sprintf("Basecamp did not say whether person %d is a client; only members are trusted", id)
566575
default:
567576
c.Status = StatusPass
568577
c.Message = fmt.Sprintf("Person %d, %s, may ask by mention in Ping %d alone", id, richtext.SanitizeSingleLine(p.Name), pingID)

‎internal/connector/setup/checks_test.go‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func TestVerifyTrust(t *testing.T) {
165165
7: {ID: 7, PersonableType: PersonableAgent},
166166
8: {ID: 8, Client: true},
167167
9: {ID: 9, Name: "Member"},
168+
11: {ID: 11, Name: "Unsaid", ClientUnsaid: true},
168169
}
169170
r := &fakeReader{people: people}
170171
forbidden := &fakeReader{personErr: status(http.StatusForbidden)}
@@ -211,6 +212,12 @@ func TestVerifyTrust(t *testing.T) {
211212
t.Run("property 5: not a client", func(t *testing.T) {
212213
assert.Equal(t, []string{"Operator=fail"}, verify(r, Trust{Operator: Person{ID: 8}}))
213214
assert.Equal(t, []string{"Operator=pass", "Allowlist 8=fail"}, verify(r, Trust{Operator: Person{ID: operatorID}, Allowlist: []int64{8}}))
215+
assert.Equal(t, []string{"Operator=pass", "Allowlist 9=pass"}, verify(r, Trust{Operator: Person{ID: operatorID}, Allowlist: []int64{9}}),
216+
"the control: a member the read says is no client passes")
217+
})
218+
t.Run("property 5b: a read that does not say is not a member", func(t *testing.T) {
219+
assert.Equal(t, []string{"Operator=fail"}, verify(r, Trust{Operator: Person{ID: 11}}))
220+
assert.Equal(t, []string{"Operator=pass", "Allowlist 11=fail"}, verify(r, Trust{Operator: Person{ID: operatorID}, Allowlist: []int64{11}}))
214221
})
215222
t.Run("property 6: the read answers for the id asked", func(t *testing.T) {
216223
liar := &fakeReader{people: map[int64]Person{operatorID: {ID: 9, Name: "Someone else"}}}
@@ -371,3 +378,25 @@ func TestProjectChecksQuoteTheProfileInTheHint(t *testing.T) {
371378
assert.Equal(t, f.Profile, string(out), "first setup %v", firstSetup)
372379
}
373380
}
381+
382+
// fromSDK keeps whether a person's read said they are a client: a read that
383+
// left the flag out is ClientUnsaid, which the checks refuse.
384+
func TestFromSDKKeepsWhetherTheReadSaidClient(t *testing.T) {
385+
for _, tc := range []struct {
386+
name string
387+
client *bool
388+
wantClient bool
389+
wantUnsaid bool
390+
}{
391+
{"not a client", basecamp.Ptr(false), false, false},
392+
{"a client", basecamp.Ptr(true), true, false},
393+
{"not said", nil, false, true},
394+
} {
395+
t.Run(tc.name, func(t *testing.T) {
396+
p := fromSDK(&basecamp.Person{ID: 5, Name: "Annie", Client: tc.client})
397+
assert.Equal(t, int64(5), p.ID)
398+
assert.Equal(t, tc.wantClient, p.Client)
399+
assert.Equal(t, tc.wantUnsaid, p.ClientUnsaid)
400+
})
401+
}
402+
}

‎internal/connector/setup/pings_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func TestVerifyPings(t *testing.T) {
9090
{ID: operatorID, Name: "Operator"},
9191
{ID: guest, Name: "Jorge"},
9292
{ID: 9, Name: "A client", Client: true},
93+
{ID: 11, Name: "Unsaid", ClientUnsaid: true},
9394
{ID: peerAgent, Name: "Peer (agent)", PersonableType: PersonableAgent},
9495
}}}}
9596
verify := func(r Reader, id int64, recorded bool) Check {
@@ -112,6 +113,7 @@ func TestVerifyPings(t *testing.T) {
112113
assert.Equal(t, StatusFail, verify(r, peerAgent, false).Status, "no agent is a participant")
113114
assert.Equal(t, StatusFail, verify(r, peerAgent, true).Status, "recorded or not")
114115
assert.Equal(t, StatusFail, verify(r, 9, false).Status, "a client is refused, as project trust refuses one")
116+
assert.Equal(t, StatusFail, verify(r, 11, false).Status, "so is one the read did not say is no client")
115117
assert.Equal(t, StatusFail, verify(r, agentID, false).Status, "the agent itself")
116118
assert.Equal(t, StatusFail, verify(r, guest2, false).Status, "someone not in the Ping")
117119
assert.Equal(t, StatusWarn, verify(r, guest2, true).Status, "one recorded who has since left is a warning")

0 commit comments

Comments
 (0)