Skip to content

Commit 8497ee8

Browse files
committed
fix(team)!: move team.accessLogs to use cursor/limit
1 parent 5025544 commit 8497ee8

File tree

3 files changed

+48
-38
lines changed

3 files changed

+48
-38
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
106106
> // Use nextCursor for the next page: params.Cursor = nextCursor
107107
> ```
108108
109+
- **`GetAccessLogs` now uses cursor-based pagination** — `AccessLogParameters` replaces
110+
`Count`/`Page` with `Cursor`/`Limit` (and adds `Before`), and `GetAccessLogs`/
111+
`GetAccessLogsContext` now return `string` (next cursor) instead of `*Paging`.
112+
Slack's `team.accessLogs` API warns `use_cursor_pagination_instead` when using the old
113+
parameters.
114+
115+
> [!WARNING]
116+
> **Breaking change.** Both the parameters and return signature have changed:
117+
>
118+
> ```go
119+
> // Before
120+
> params := slack.NewAccessLogParameters()
121+
> params.Count = 100
122+
> params.Page = 2
123+
> logins, paging, err := api.GetAccessLogs(params)
124+
>
125+
> // After
126+
> params := slack.NewAccessLogParameters()
127+
> params.Limit = 100
128+
> logins, nextCursor, err := api.GetAccessLogs(params)
129+
> // Use nextCursor for the next page: params.Cursor = nextCursor
130+
> ```
131+
109132
### Fixed
110133
111134
- **`WorkflowButtonBlockElement` missing from `UnmarshalJSON`** — `workflow_button` blocks

team.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import (
66
"strconv"
77
)
88

9-
const (
10-
DEFAULT_LOGINS_COUNT = 100
11-
DEFAULT_LOGINS_PAGE = 1
12-
)
13-
149
type TeamResponse struct {
1510
Team TeamInfo `json:"team"`
1611
SlackResponse
@@ -46,8 +41,8 @@ type TeamProfileField struct {
4641

4742
type LoginResponse struct {
4843
Logins []Login `json:"logins"`
49-
Paging `json:"paging"`
5044
SlackResponse
45+
ResponseMetadata `json:"response_metadata"`
5146
}
5247

5348
type Login struct {
@@ -75,16 +70,14 @@ type BillingActive struct {
7570
// AccessLogParameters contains all the parameters necessary (including the optional ones) for a GetAccessLogs() request
7671
type AccessLogParameters struct {
7772
TeamID string
78-
Count int
79-
Page int
73+
Cursor string
74+
Limit int
75+
Before int
8076
}
8177

8278
// NewAccessLogParameters provides an instance of AccessLogParameters with all the sane default values set
8379
func NewAccessLogParameters() AccessLogParameters {
84-
return AccessLogParameters{
85-
Count: DEFAULT_LOGINS_COUNT,
86-
Page: DEFAULT_LOGINS_PAGE,
87-
}
80+
return AccessLogParameters{}
8881
}
8982

9083
func (api *Client) teamRequest(ctx context.Context, path string, values url.Values) (*TeamResponse, error) {
@@ -193,31 +186,34 @@ func (api *Client) GetTeamProfileContext(ctx context.Context, teamID ...string)
193186

194187
// GetAccessLogs retrieves a page of logins according to the parameters given.
195188
// For more information see the GetAccessLogsContext documentation.
196-
func (api *Client) GetAccessLogs(params AccessLogParameters) ([]Login, *Paging, error) {
189+
func (api *Client) GetAccessLogs(params AccessLogParameters) ([]Login, string, error) {
197190
return api.GetAccessLogsContext(context.Background(), params)
198191
}
199192

200193
// GetAccessLogsContext retrieves a page of logins according to the parameters given with a custom context.
201194
// Slack API docs: https://api.slack.com/methods/team.accessLogs
202-
func (api *Client) GetAccessLogsContext(ctx context.Context, params AccessLogParameters) ([]Login, *Paging, error) {
195+
func (api *Client) GetAccessLogsContext(ctx context.Context, params AccessLogParameters) ([]Login, string, error) {
203196
values := url.Values{
204197
"token": {api.token},
205198
}
206199
if params.TeamID != "" {
207200
values.Add("team_id", params.TeamID)
208201
}
209-
if params.Count != DEFAULT_LOGINS_COUNT {
210-
values.Add("count", strconv.Itoa(params.Count))
202+
if params.Cursor != "" {
203+
values.Add("cursor", params.Cursor)
204+
}
205+
if params.Limit != 0 {
206+
values.Add("limit", strconv.Itoa(params.Limit))
211207
}
212-
if params.Page != DEFAULT_LOGINS_PAGE {
213-
values.Add("page", strconv.Itoa(params.Page))
208+
if params.Before != 0 {
209+
values.Add("before", strconv.Itoa(params.Before))
214210
}
215211

216212
response, err := api.accessLogsRequest(ctx, "team.accessLogs", values)
217213
if err != nil {
218-
return nil, nil, err
214+
return nil, "", err
219215
}
220-
return response.Logins, &response.Paging, nil
216+
return response.Logins, response.ResponseMetadata.Cursor, nil
221217
}
222218

223219
type GetBillableInfoParams struct {

team_test.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,8 @@ func getTeamAccessLogs(rw http.ResponseWriter, r *http.Request) {
150150
"country": null,
151151
"region": null
152152
}],
153-
"paging": {
154-
"count": 2,
155-
"total": 2,
156-
"page": 1,
157-
"pages": 1
153+
"response_metadata": {
154+
"next_cursor": "dGVhbV9pZDo5MDAwMTcw"
158155
}
159156
}`)
160157
rw.Write(response)
@@ -166,7 +163,10 @@ func TestGetAccessLogs(t *testing.T) {
166163
once.Do(startServer)
167164
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
168165

169-
logins, paging, err := api.GetAccessLogs(NewAccessLogParameters())
166+
params := NewAccessLogParameters()
167+
params.Limit = 2
168+
params.TeamID = "T12345"
169+
logins, nextCursor, err := api.GetAccessLogs(params)
170170
if err != nil {
171171
t.Errorf("Unexpected error: %s", err)
172172
return
@@ -222,17 +222,8 @@ func TestGetAccessLogs(t *testing.T) {
222222
t.Fatal(ErrIncorrectResponse)
223223
}
224224

225-
// test the paging
226-
if paging.Count != 2 {
227-
t.Fatal(ErrIncorrectResponse)
228-
}
229-
if paging.Total != 2 {
230-
t.Fatal(ErrIncorrectResponse)
231-
}
232-
if paging.Page != 1 {
233-
t.Fatal(ErrIncorrectResponse)
234-
}
235-
if paging.Pages != 1 {
236-
t.Fatal(ErrIncorrectResponse)
225+
// test the cursor
226+
if nextCursor != "dGVhbV9pZDo5MDAwMTcw" {
227+
t.Fatalf("Expected cursor %q, got %q", "dGVhbV9pZDo5MDAwMTcw", nextCursor)
237228
}
238229
}

0 commit comments

Comments
 (0)