mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-19 03:48:58 -06:00
Make ldap functions package local and remove a superfluous comment.
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/CiscoM31/godata"
|
||||
cs3 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode"
|
||||
)
|
||||
@@ -41,10 +40,6 @@ type Backend interface {
|
||||
AddMembersToGroup(ctx context.Context, groupID string, memberID []string) error
|
||||
// RemoveMemberFromGroup removes a single member (by ID) from a group
|
||||
RemoveMemberFromGroup(ctx context.Context, groupID string, memberID string) error
|
||||
// RemoveEntryByDNAndAttributeFromEntry creates a request to remove a single member entry by attribute and DN from an ldap entry
|
||||
RemoveEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string, attribute string) (*ldap.ModifyRequest, error)
|
||||
// ExpandLDAPAttributeEntries reads an attribute from an ldap entry and expands to users
|
||||
ExpandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, attribute string) ([]*ldap.Entry, error)
|
||||
}
|
||||
|
||||
// EducationBackend defines the Interface for an EducationBackend implementation
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
cs3user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
@@ -208,16 +207,6 @@ func (i *CS3) RemoveMemberFromGroup(ctx context.Context, groupID string, memberI
|
||||
return errorcode.New(errorcode.NotSupported, "not implemented")
|
||||
}
|
||||
|
||||
// RemoveEntryByDNAndAttributeFromEntry implements the Backend Interface. It's currently not supported for the CS3 backend
|
||||
func (i *CS3) RemoveEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string, attribute string) (*ldap.ModifyRequest, error) {
|
||||
return nil, errorcode.New(errorcode.NotSupported, "not implemented")
|
||||
}
|
||||
|
||||
// ExpandLDAPAttributeEntries implements the Backend Interface. It's currently not supported for the CS3 backend
|
||||
func (i *CS3) ExpandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, attribute string) ([]*ldap.Entry, error) {
|
||||
return nil, errorcode.New(errorcode.NotSupported, "not implemented")
|
||||
}
|
||||
|
||||
func createGroupModelFromCS3(g *cs3group.Group) *libregraph.Group {
|
||||
if g.Id == nil {
|
||||
g.Id = &cs3group.GroupId{}
|
||||
|
||||
@@ -180,7 +180,7 @@ func (i *LDAP) DeleteUser(ctx context.Context, nameOrID string) error {
|
||||
for _, group := range groupEntries {
|
||||
logger.Debug().Str("group", group.DN).Str("user", e.DN).Msg("Cleaning up group membership")
|
||||
|
||||
if mr, err := i.RemoveEntryByDNAndAttributeFromEntry(group, e.DN, i.groupAttributeMap.member); err == nil {
|
||||
if mr, err := i.removeEntryByDNAndAttributeFromEntry(group, e.DN, i.groupAttributeMap.member); err == nil {
|
||||
if err = i.conn.Modify(mr); err != nil {
|
||||
// Errors when deleting the memberships are only logged as warnings but not returned
|
||||
// to the user as we already successfully deleted the users itself
|
||||
@@ -610,8 +610,8 @@ func stringToScope(scope string) (int, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// RemoveEntryByDNAndAttributeFromEntry creates a request to remove a single member entry by attribute and DN from an ldap entry
|
||||
func (i *LDAP) RemoveEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string, attribute string) (*ldap.ModifyRequest, error) {
|
||||
// removeEntryByDNAndAttributeFromEntry creates a request to remove a single member entry by attribute and DN from an ldap entry
|
||||
func (i *LDAP) removeEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string, attribute string) (*ldap.ModifyRequest, error) {
|
||||
nOldDN, err := ldapdn.ParseNormalize(dn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -647,8 +647,8 @@ func (i *LDAP) RemoveEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string
|
||||
return &mr, nil
|
||||
}
|
||||
|
||||
// ExpandLDAPAttributeEntries reads an attribute from an ldap entry and expands to users
|
||||
func (i *LDAP) ExpandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, attribute string) ([]*ldap.Entry, error) {
|
||||
// expandLDAPAttributeEntries reads an attribute from an ldap entry and expands to users
|
||||
func (i *LDAP) expandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, attribute string) ([]*ldap.Entry, error) {
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("ExpandLDAPAttributeEntries")
|
||||
result := []*ldap.Entry{}
|
||||
|
||||
@@ -228,7 +228,7 @@ func (i *LDAP) GetEducationClassMembers(ctx context.Context, id string) ([]*libr
|
||||
return nil, err
|
||||
}
|
||||
|
||||
memberEntries, err := i.ExpandLDAPAttributeEntries(ctx, e, i.groupAttributeMap.member)
|
||||
memberEntries, err := i.expandLDAPAttributeEntries(ctx, e, i.groupAttributeMap.member)
|
||||
result := make([]*libregraph.EducationUser, 0, len(memberEntries))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -351,7 +351,7 @@ func (i *LDAP) GetEducationClassTeachers(ctx context.Context, classID string) ([
|
||||
return nil, err
|
||||
}
|
||||
|
||||
teacherEntries, err := i.ExpandLDAPAttributeEntries(ctx, class, i.educationConfig.classAttributeMap.teachers)
|
||||
teacherEntries, err := i.expandLDAPAttributeEntries(ctx, class, i.educationConfig.classAttributeMap.teachers)
|
||||
result := make([]*libregraph.EducationUser, 0, len(teacherEntries))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -445,7 +445,7 @@ func (i *LDAP) RemoveTeacherFromEducationClass(ctx context.Context, classID stri
|
||||
return err
|
||||
}
|
||||
|
||||
if mr, err := i.RemoveEntryByDNAndAttributeFromEntry(class, teacher.DN, i.educationConfig.classAttributeMap.teachers); err == nil {
|
||||
if mr, err := i.removeEntryByDNAndAttributeFromEntry(class, teacher.DN, i.educationConfig.classAttributeMap.teachers); err == nil {
|
||||
return i.conn.Modify(mr)
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func (i *LDAP) GetGroup(ctx context.Context, nameOrID string, queryParam url.Val
|
||||
return nil, errorcode.New(errorcode.ItemNotFound, "not found")
|
||||
}
|
||||
if slices.Contains(sel, "members") || slices.Contains(exp, "members") {
|
||||
members, err := i.ExpandLDAPAttributeEntries(ctx, e, i.groupAttributeMap.member)
|
||||
members, err := i.expandLDAPAttributeEntries(ctx, e, i.groupAttributeMap.member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func (i *LDAP) GetGroups(ctx context.Context, queryParam url.Values) ([]*libregr
|
||||
continue
|
||||
}
|
||||
if expandMembers {
|
||||
members, err := i.ExpandLDAPAttributeEntries(ctx, e, i.groupAttributeMap.member)
|
||||
members, err := i.expandLDAPAttributeEntries(ctx, e, i.groupAttributeMap.member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func (i *LDAP) GetGroupMembers(ctx context.Context, groupID string) ([]*libregra
|
||||
return nil, err
|
||||
}
|
||||
|
||||
memberEntries, err := i.ExpandLDAPAttributeEntries(ctx, e, i.groupAttributeMap.member)
|
||||
memberEntries, err := i.expandLDAPAttributeEntries(ctx, e, i.groupAttributeMap.member)
|
||||
result := make([]*libregraph.User, 0, len(memberEntries))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -279,7 +279,7 @@ func (i *LDAP) RemoveMemberFromGroup(ctx context.Context, groupID string, member
|
||||
}
|
||||
logger.Debug().Str("backend", "ldap").Str("groupdn", ge.DN).Str("member", me.DN).Msg("remove member")
|
||||
|
||||
if mr, err := i.RemoveEntryByDNAndAttributeFromEntry(ge, me.DN, i.groupAttributeMap.member); err == nil {
|
||||
if mr, err := i.removeEntryByDNAndAttributeFromEntry(ge, me.DN, i.groupAttributeMap.member); err == nil {
|
||||
return i.conn.Modify(mr)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
|
||||
godata "github.com/CiscoM31/godata"
|
||||
|
||||
ldap "github.com/go-ldap/ldap/v3"
|
||||
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
@@ -109,29 +107,6 @@ func (_m *Backend) DeleteUser(ctx context.Context, nameOrID string) error {
|
||||
return r0
|
||||
}
|
||||
|
||||
// ExpandLDAPAttributeEntries provides a mock function with given fields: ctx, e, attribute
|
||||
func (_m *Backend) ExpandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, attribute string) ([]*ldap.Entry, error) {
|
||||
ret := _m.Called(ctx, e, attribute)
|
||||
|
||||
var r0 []*ldap.Entry
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *ldap.Entry, string) []*ldap.Entry); ok {
|
||||
r0 = rf(ctx, e, attribute)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*ldap.Entry)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *ldap.Entry, string) error); ok {
|
||||
r1 = rf(ctx, e, attribute)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetGroup provides a mock function with given fields: ctx, nameOrID, queryParam
|
||||
func (_m *Backend) GetGroup(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.Group, error) {
|
||||
ret := _m.Called(ctx, nameOrID, queryParam)
|
||||
@@ -247,29 +222,6 @@ func (_m *Backend) GetUsers(ctx context.Context, oreq *godata.GoDataRequest) ([]
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// RemoveEntryByDNAndAttributeFromEntry provides a mock function with given fields: entry, dn, attribute
|
||||
func (_m *Backend) RemoveEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string, attribute string) (*ldap.ModifyRequest, error) {
|
||||
ret := _m.Called(entry, dn, attribute)
|
||||
|
||||
var r0 *ldap.ModifyRequest
|
||||
if rf, ok := ret.Get(0).(func(*ldap.Entry, string, string) *ldap.ModifyRequest); ok {
|
||||
r0 = rf(entry, dn, attribute)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*ldap.ModifyRequest)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*ldap.Entry, string, string) error); ok {
|
||||
r1 = rf(entry, dn, attribute)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// RemoveMemberFromGroup provides a mock function with given fields: ctx, groupID, memberID
|
||||
func (_m *Backend) RemoveMemberFromGroup(ctx context.Context, groupID string, memberID string) error {
|
||||
ret := _m.Called(ctx, groupID, memberID)
|
||||
|
||||
@@ -463,7 +463,6 @@ func (g Graph) GetEducationClassTeachers(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
logger.Debug().Str("id", classID).Msg("calling get class teachers on backend")
|
||||
teachers, err := g.identityEducationBackend.GetEducationClassTeachers(r.Context(), classID)
|
||||
// teachers, err := g.identityEducationBackend.GetEducationClassMembers(r.Context(), classID)
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not get class teachers: backend error")
|
||||
var errcode errorcode.Error
|
||||
|
||||
Reference in New Issue
Block a user