diff --git a/core/group/group.go b/core/group/group.go index 3608acc74..42eed2a3b 100644 --- a/core/group/group.go +++ b/core/group/group.go @@ -6,7 +6,6 @@ import ( "github.com/raystack/frontier/internal/bootstrap/schema" - "github.com/raystack/frontier/core/relation" "github.com/raystack/frontier/pkg/metadata" ) @@ -32,7 +31,6 @@ type Repository interface { GetByIDs(ctx context.Context, groupIDs []string, flt Filter) ([]Group, error) List(ctx context.Context, flt Filter) ([]Group, error) UpdateByID(ctx context.Context, toUpdate Group) (Group, error) - ListGroupRelations(ctx context.Context, objectId, subjectType, role string) ([]relation.Relation, error) SetState(ctx context.Context, id string, state State) error Delete(ctx context.Context, id string) error } diff --git a/core/group/mocks/repository.go b/core/group/mocks/repository.go index 07cc5ce4c..c91c6c9a8 100644 --- a/core/group/mocks/repository.go +++ b/core/group/mocks/repository.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.2. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -7,8 +7,6 @@ import ( group "github.com/raystack/frontier/core/group" mock "github.com/stretchr/testify/mock" - - relation "github.com/raystack/frontier/core/relation" ) // Repository is an autogenerated mock type for the Repository type @@ -304,67 +302,6 @@ func (_c *Repository_List_Call) RunAndReturn(run func(context.Context, group.Fil return _c } -// ListGroupRelations provides a mock function with given fields: ctx, objectId, subjectType, role -func (_m *Repository) ListGroupRelations(ctx context.Context, objectId string, subjectType string, role string) ([]relation.Relation, error) { - ret := _m.Called(ctx, objectId, subjectType, role) - - if len(ret) == 0 { - panic("no return value specified for ListGroupRelations") - } - - var r0 []relation.Relation - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, string) ([]relation.Relation, error)); ok { - return rf(ctx, objectId, subjectType, role) - } - if rf, ok := ret.Get(0).(func(context.Context, string, string, string) []relation.Relation); ok { - r0 = rf(ctx, objectId, subjectType, role) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]relation.Relation) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { - r1 = rf(ctx, objectId, subjectType, role) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Repository_ListGroupRelations_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListGroupRelations' -type Repository_ListGroupRelations_Call struct { - *mock.Call -} - -// ListGroupRelations is a helper method to define mock.On call -// - ctx context.Context -// - objectId string -// - subjectType string -// - role string -func (_e *Repository_Expecter) ListGroupRelations(ctx interface{}, objectId interface{}, subjectType interface{}, role interface{}) *Repository_ListGroupRelations_Call { - return &Repository_ListGroupRelations_Call{Call: _e.mock.On("ListGroupRelations", ctx, objectId, subjectType, role)} -} - -func (_c *Repository_ListGroupRelations_Call) Run(run func(ctx context.Context, objectId string, subjectType string, role string)) *Repository_ListGroupRelations_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) - }) - return _c -} - -func (_c *Repository_ListGroupRelations_Call) Return(_a0 []relation.Relation, _a1 error) *Repository_ListGroupRelations_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *Repository_ListGroupRelations_Call) RunAndReturn(run func(context.Context, string, string, string) ([]relation.Relation, error)) *Repository_ListGroupRelations_Call { - _c.Call.Return(run) - return _c -} - // SetState provides a mock function with given fields: ctx, id, state func (_m *Repository) SetState(ctx context.Context, id string, state group.State) error { ret := _m.Called(ctx, id, state) diff --git a/internal/store/postgres/group_repository.go b/internal/store/postgres/group_repository.go index 5bd34dd7e..9d2028851 100644 --- a/internal/store/postgres/group_repository.go +++ b/internal/store/postgres/group_repository.go @@ -8,12 +8,9 @@ import ( "fmt" "strings" - "github.com/raystack/frontier/internal/bootstrap/schema" - "github.com/doug-martin/goqu/v9" "github.com/raystack/frontier/core/group" "github.com/raystack/frontier/core/organization" - "github.com/raystack/frontier/core/relation" "github.com/raystack/frontier/pkg/db" ) @@ -274,49 +271,6 @@ func (r GroupRepository) UpdateByID(ctx context.Context, grp group.Group) (group return updated, nil } -// TODO(kushsharma): no longer in use, delete if needed -func (r GroupRepository) ListGroupRelations(ctx context.Context, objectId string, subject_type string, role string) ([]relation.Relation, error) { - whereClauseExp := goqu.Ex{} - whereClauseExp["object_id"] = objectId - whereClauseExp["object_namespace_name"] = schema.GroupNamespace - - if subject_type != "" { - if subject_type == "user" { - whereClauseExp["subject_namespace_name"] = schema.UserPrincipal - } else if subject_type == "group" { - whereClauseExp["subject_namespace_name"] = schema.GroupPrincipal - } - } - - if role != "" { - like := "%:" + role - whereClauseExp["role_id"] = goqu.Op{"like": like} - } - - query, params, err := dialect.Select(&relationCols{}).From(TABLE_RELATIONS).Where(whereClauseExp).ToSQL() - if err != nil { - return []relation.Relation{}, fmt.Errorf("%w: %s", queryErr, err) - } - - var fetchedRelations []Relation - if err = r.dbc.WithTimeout(ctx, TABLE_GROUPS, "ListGroupRelations", func(ctx context.Context) error { - return r.dbc.SelectContext(ctx, &fetchedRelations, query, params...) - }); err != nil { - // List should return empty list and no error instead - if errors.Is(err, sql.ErrNoRows) { - return []relation.Relation{}, nil - } - return []relation.Relation{}, fmt.Errorf("%w: %s", dbErr, err) - } - - var transformedRelations []relation.Relation - for _, r := range fetchedRelations { - transformedRelations = append(transformedRelations, r.transformToRelationV2()) - } - - return transformedRelations, nil -} - func (r GroupRepository) SetState(ctx context.Context, id string, state group.State) error { query, params, err := dialect.Update(TABLE_GROUPS).Set( goqu.Record{ diff --git a/internal/store/postgres/group_repository_test.go b/internal/store/postgres/group_repository_test.go index 680c34ef3..a60ba2751 100644 --- a/internal/store/postgres/group_repository_test.go +++ b/internal/store/postgres/group_repository_test.go @@ -534,77 +534,6 @@ func (s *GroupRepositoryTestSuite) TestUpdateByID() { } } -func (s *GroupRepositoryTestSuite) TestListGroupRelations() { - type testCase struct { - Description string - ObjectID string - SubjectType string - Role string - ExpectedRelations []relation.Relation - ErrString string - } - - var testCases = []testCase{ - { - Description: "should get a list of relations", - ObjectID: s.groups[0].ID, - SubjectType: "user", - Role: "member", - ExpectedRelations: []relation.Relation{ - { - Object: relation.Object{ - ID: s.groups[0].ID, - Namespace: schema.GroupNamespace, - }, - Subject: relation.Subject{ - ID: s.users[0].ID, - Namespace: schema.UserPrincipal, - SubRelationName: "frontier/group:member", - }, - }, - { - Object: relation.Object{ - ID: s.groups[0].ID, - Namespace: schema.GroupNamespace, - }, - Subject: relation.Subject{ - ID: s.users[1].ID, - Namespace: schema.UserPrincipal, - SubRelationName: "frontier/group:member", - }, - }, - }, - }, - } - - for _, tc := range testCases { - s.Run(tc.Description, func() { - got, err := s.repository.ListGroupRelations(s.ctx, tc.ObjectID, tc.SubjectType, tc.Role) - if tc.ErrString != "" && err != nil { - if err.Error() != tc.ErrString { - s.T().Fatalf("got error %s, expected was %s", err.Error(), tc.ErrString) - } - } - - for _, rel := range got { - found := false - for _, expectedRel := range tc.ExpectedRelations { - if cmp.Equal(rel, expectedRel, cmpopts.IgnoreFields(relation.Relation{}, - "ID", - "CreatedAt", - "UpdatedAt")) { - found = true - break - } - } - if !found { - s.T().Fatalf("can't find relation %+v", rel) - } - } - }) - } -} - func (s *GroupRepositoryTestSuite) TestSetState() { type testCase struct { Description string