diff --git a/services/graph/pkg/identity/backend.go b/services/graph/pkg/identity/backend.go index 1ee6b1082..4079b15a4 100644 --- a/services/graph/pkg/identity/backend.go +++ b/services/graph/pkg/identity/backend.go @@ -5,7 +5,8 @@ import ( "net/url" "github.com/CiscoM31/godata" - cs3 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + cs3group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1" + cs3user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" libregraph "github.com/owncloud/libre-graph-api-go" "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode" ) @@ -103,9 +104,10 @@ type EducationBackend interface { RemoveTeacherFromEducationClass(ctx context.Context, classID string, teacherID string) error } -func CreateUserModelFromCS3(u *cs3.User) *libregraph.User { +// CreateUserModelFromCS3 converts a cs3 User object into a libregraph.User +func CreateUserModelFromCS3(u *cs3user.User) *libregraph.User { if u.Id == nil { - u.Id = &cs3.UserId{} + u.Id = &cs3user.UserId{} } return &libregraph.User{ DisplayName: &u.DisplayName, @@ -114,3 +116,14 @@ func CreateUserModelFromCS3(u *cs3.User) *libregraph.User { Id: &u.Id.OpaqueId, } } + +// CreateGroupModelFromCS3 converts a cs3 Group object into a libregraph.Group +func CreateGroupModelFromCS3(g *cs3group.Group) *libregraph.Group { + if g.Id == nil { + g.Id = &cs3group.GroupId{} + } + return &libregraph.Group{ + Id: &g.Id.OpaqueId, + DisplayName: &g.GroupName, + } +} diff --git a/services/graph/pkg/identity/cs3.go b/services/graph/pkg/identity/cs3.go index 8cdb391c1..730e66108 100644 --- a/services/graph/pkg/identity/cs3.go +++ b/services/graph/pkg/identity/cs3.go @@ -147,7 +147,7 @@ func (i *CS3) GetGroups(ctx context.Context, queryParam url.Values) ([]*libregra groups := make([]*libregraph.Group, 0, len(res.Groups)) for _, group := range res.Groups { - groups = append(groups, createGroupModelFromCS3(group)) + groups = append(groups, CreateGroupModelFromCS3(group)) } return groups, nil @@ -185,7 +185,7 @@ func (i *CS3) GetGroup(ctx context.Context, groupID string, queryParam url.Value return nil, errorcode.New(errorcode.GeneralException, res.Status.Message) } - return createGroupModelFromCS3(res.Group), nil + return CreateGroupModelFromCS3(res.Group), nil } // DeleteGroup implements the Backend Interface. It's currently not supported for the CS3 backend @@ -212,14 +212,3 @@ func (i *CS3) AddMembersToGroup(ctx context.Context, groupID string, memberID [] func (i *CS3) RemoveMemberFromGroup(ctx context.Context, groupID string, memberID string) error { return errorcode.New(errorcode.NotSupported, "not implemented") } - -func createGroupModelFromCS3(g *cs3group.Group) *libregraph.Group { - if g.Id == nil { - g.Id = &cs3group.GroupId{} - } - return &libregraph.Group{ - Id: &g.Id.OpaqueId, - DisplayName: &g.GroupName, - // TODO when to fetch and expand memberof, usernames or ids? - } -}