Skip to content

Commit

Permalink
rename func arg from filter to pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneDutto committed Nov 12, 2024
1 parent ce6a41b commit b5dfae2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions internal/jimm/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,14 +791,14 @@ func (j *JIMM) RemoveGroup(ctx context.Context, user *openfga.User, name string)

// ListGroups returns a list of groups known to JIMM.
// `match` will filter the list for name or uuid matching it.
func (j *JIMM) ListGroups(ctx context.Context, user *openfga.User, filter pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error) {
func (j *JIMM) ListGroups(ctx context.Context, user *openfga.User, pagination pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error) {
const op = errors.Op("jimm.ListGroups")

if !user.JimmAdmin {
return nil, errors.E(op, errors.CodeUnauthorized, "unauthorized")
}

groups, err := j.Database.ListGroups(ctx, filter.Limit(), filter.Offset(), match)
groups, err := j.Database.ListGroups(ctx, pagination.Limit(), pagination.Offset(), match)
if err != nil {
return nil, errors.E(op, err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/jimm/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,8 @@ func TestListGroups(t *testing.T) {
u := openfga.NewUser(&user, ofgaClient)
u.JimmAdmin = true

filter := pagination.NewOffsetFilter(10, 0)
groups, err := j.ListGroups(ctx, u, filter, "")
pagination := pagination.NewOffsetFilter(10, 0)
groups, err := j.ListGroups(ctx, u, pagination, "")
c.Assert(err, qt.IsNil)
c.Assert(groups, qt.DeepEquals, []dbmodel.GroupEntry{group})

Expand All @@ -1095,7 +1095,7 @@ func TestListGroups(t *testing.T) {
_, err := j.AddGroup(ctx, u, name)
c.Assert(err, qt.IsNil)
}
groups, err = j.ListGroups(ctx, u, filter, "")
groups, err = j.ListGroups(ctx, u, pagination, "")
c.Assert(err, qt.IsNil)
sort.Slice(groups, func(i, j int) bool {
return groups[i].Name < groups[j].Name
Expand Down
2 changes: 1 addition & 1 deletion internal/jimmhttp/rebac_admin/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestListGroups(t *testing.T) {
}
jimm := jimmtest.JIMM{
GroupService: mocks.GroupService{
ListGroups_: func(ctx context.Context, user *openfga.User, filter pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error) {
ListGroups_: func(ctx context.Context, user *openfga.User, pagination pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error) {
return returnedGroups, listErr
},
CountGroups_: func(ctx context.Context, user *openfga.User) (int, error) {
Expand Down
6 changes: 3 additions & 3 deletions internal/jujuapi/access_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GroupService interface {
CountGroups(ctx context.Context, user *openfga.User) (int, error)
GetGroupByUUID(ctx context.Context, user *openfga.User, uuid string) (*dbmodel.GroupEntry, error)
GetGroupByName(ctx context.Context, user *openfga.User, name string) (*dbmodel.GroupEntry, error)
ListGroups(ctx context.Context, user *openfga.User, filter pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error)
ListGroups(ctx context.Context, user *openfga.User, pagination pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error)
RenameGroup(ctx context.Context, user *openfga.User, oldName, newName string) error
RemoveGroup(ctx context.Context, user *openfga.User, name string) error
}
Expand Down Expand Up @@ -118,8 +118,8 @@ func (r *controllerRoot) RemoveGroup(ctx context.Context, req apiparams.RemoveGr
func (r *controllerRoot) ListGroups(ctx context.Context, req apiparams.ListGroupsRequest) (apiparams.ListGroupResponse, error) {
const op = errors.Op("jujuapi.ListGroups")

filter := pagination.NewOffsetFilter(req.Limit, req.Offset)
groups, err := r.jimm.ListGroups(ctx, r.user, filter, "")
pagination := pagination.NewOffsetFilter(req.Limit, req.Offset)
groups, err := r.jimm.ListGroups(ctx, r.user, pagination, "")
if err != nil {
return apiparams.ListGroupResponse{}, errors.E(op, err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/testutils/jimmtest/mocks/jimm_group_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type GroupService struct {
CountGroups_ func(ctx context.Context, user *openfga.User) (int, error)
GetGroupByUUID_ func(ctx context.Context, user *openfga.User, uuid string) (*dbmodel.GroupEntry, error)
GetGroupByName_ func(ctx context.Context, user *openfga.User, name string) (*dbmodel.GroupEntry, error)
ListGroups_ func(ctx context.Context, user *openfga.User, filter pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error)
ListGroups_ func(ctx context.Context, user *openfga.User, pagination pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error)
RenameGroup_ func(ctx context.Context, user *openfga.User, oldName, newName string) error
RemoveGroup_ func(ctx context.Context, user *openfga.User, name string) error
}
Expand Down Expand Up @@ -55,11 +55,11 @@ func (j *GroupService) GetGroupByName(ctx context.Context, user *openfga.User, n
return j.GetGroupByName_(ctx, user, name)
}

func (j *GroupService) ListGroups(ctx context.Context, user *openfga.User, filters pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error) {
func (j *GroupService) ListGroups(ctx context.Context, user *openfga.User, pagination pagination.LimitOffsetPagination, match string) ([]dbmodel.GroupEntry, error) {
if j.ListGroups_ == nil {
return nil, errors.E(errors.CodeNotImplemented)
}
return j.ListGroups_(ctx, user, filters, match)
return j.ListGroups_(ctx, user, pagination, match)
}

func (j *GroupService) RemoveGroup(ctx context.Context, user *openfga.User, name string) error {
Expand Down

0 comments on commit b5dfae2

Please sign in to comment.