mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-16 09:09:51 -06:00
correct naming of education backend methods
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
committed by
Ralf Haferkamp
parent
8967556b9d
commit
cd23d010a4
@@ -34,19 +34,20 @@ type Backend interface {
|
||||
|
||||
// EducationBackend defines the Interface for an EducationBackend implementation
|
||||
type EducationBackend interface {
|
||||
// CreateSchool creates the supplied school in the identity backend.
|
||||
CreateSchool(ctx context.Context, group libregraph.EducationSchool) (*libregraph.EducationSchool, error)
|
||||
// CreateEducationSchool creates the supplied school in the identity backend.
|
||||
CreateEducationSchool(ctx context.Context, group libregraph.EducationSchool) (*libregraph.EducationSchool, error)
|
||||
// DeleteSchool deletes a given school, identified by id
|
||||
DeleteSchool(ctx context.Context, id string) error
|
||||
// GetSchool reads a given school by id
|
||||
GetSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error)
|
||||
// GetSchools lists all schools
|
||||
GetSchools(ctx context.Context, queryParam url.Values) ([]*libregraph.EducationSchool, error)
|
||||
GetSchoolMembers(ctx context.Context, id string) ([]*libregraph.EducationUser, error)
|
||||
// AddMembersToSchool adds new members (reference by a slice of IDs) to supplied school in the identity backend.
|
||||
AddMembersToSchool(ctx context.Context, schoolID string, memberID []string) error
|
||||
// RemoveMemberFromSchool removes a single member (by ID) from a school
|
||||
RemoveMemberFromSchool(ctx context.Context, schoolID string, memberID string) error
|
||||
DeleteEducationSchool(ctx context.Context, id string) error
|
||||
// GetEducationSchool reads a given school by id
|
||||
GetEducationSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error)
|
||||
// GetEducationSchools lists all schools
|
||||
GetEducationSchools(ctx context.Context, queryParam url.Values) ([]*libregraph.EducationSchool, error)
|
||||
// GetEducationSchoolMembers lists all members of a school
|
||||
GetEducationSchoolMembers(ctx context.Context, id string) ([]*libregraph.EducationUser, error)
|
||||
// AddMembersToEducationSchool adds new members (reference by a slice of IDs) to supplied school in the identity backend.
|
||||
AddMembersToEducationSchool(ctx context.Context, schoolID string, memberID []string) error
|
||||
// RemoveMemberFromEducationSchool removes a single member (by ID) from a school
|
||||
RemoveMemberFromEducationSchool(ctx context.Context, schoolID string, memberID string) error
|
||||
|
||||
// CreateEducationUser creates a given education user in the identity backend.
|
||||
CreateEducationUser(ctx context.Context, user libregraph.EducationUser) (*libregraph.EducationUser, error)
|
||||
|
||||
@@ -77,10 +77,10 @@ func newSchoolAttributeMap() schoolAttributeMap {
|
||||
}
|
||||
}
|
||||
|
||||
// CreateSchool creates the supplied school in the identity backend.
|
||||
func (i *LDAP) CreateSchool(ctx context.Context, school libregraph.EducationSchool) (*libregraph.EducationSchool, error) {
|
||||
// CreateEducationSchool creates the supplied school in the identity backend.
|
||||
func (i *LDAP) CreateEducationSchool(ctx context.Context, school libregraph.EducationSchool) (*libregraph.EducationSchool, error) {
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("CreateSchool")
|
||||
logger.Debug().Str("backend", "ldap").Msg("CreateEducationSchool")
|
||||
if !i.writeEnabled {
|
||||
return nil, errReadOnly
|
||||
}
|
||||
@@ -118,10 +118,10 @@ func (i *LDAP) CreateSchool(ctx context.Context, school libregraph.EducationScho
|
||||
return i.createSchoolModelFromLDAP(e), nil
|
||||
}
|
||||
|
||||
// DeleteSchool deletes a given school, identified by id
|
||||
func (i *LDAP) DeleteSchool(ctx context.Context, id string) error {
|
||||
// DeleteEducationSchool deletes a given school, identified by id
|
||||
func (i *LDAP) DeleteEducationSchool(ctx context.Context, id string) error {
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("DeleteSchool")
|
||||
logger.Debug().Str("backend", "ldap").Msg("DeleteEducationSchool")
|
||||
if !i.writeEnabled {
|
||||
return errReadOnly
|
||||
}
|
||||
@@ -137,10 +137,10 @@ func (i *LDAP) DeleteSchool(ctx context.Context, id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSchool implements the EducationBackend interface for the LDAP backend.
|
||||
func (i *LDAP) GetSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error) {
|
||||
// GetEducationSchool implements the EducationBackend interface for the LDAP backend.
|
||||
func (i *LDAP) GetEducationSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error) {
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("GetSchool")
|
||||
logger.Debug().Str("backend", "ldap").Msg("GetEducationSchool")
|
||||
e, err := i.getSchoolByID(nameOrID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -149,8 +149,8 @@ func (i *LDAP) GetSchool(ctx context.Context, nameOrID string, queryParam url.Va
|
||||
return i.createSchoolModelFromLDAP(e), nil
|
||||
}
|
||||
|
||||
// GetSchools implements the EducationBackend interface for the LDAP backend.
|
||||
func (i *LDAP) GetSchools(ctx context.Context, queryParam url.Values) ([]*libregraph.EducationSchool, error) {
|
||||
// GetEducationSchools implements the EducationBackend interface for the LDAP backend.
|
||||
func (i *LDAP) GetEducationSchools(ctx context.Context, queryParam url.Values) ([]*libregraph.EducationSchool, error) {
|
||||
var filter string
|
||||
filter = fmt.Sprintf("(objectClass=%s)", i.educationConfig.schoolObjectClass)
|
||||
|
||||
@@ -176,7 +176,7 @@ func (i *LDAP) GetSchools(ctx context.Context, queryParam url.Values) ([]*libreg
|
||||
Int("scope", searchRequest.Scope).
|
||||
Int("sizelimit", searchRequest.SizeLimit).
|
||||
Interface("attributes", searchRequest.Attributes).
|
||||
Msg("GetSchools")
|
||||
Msg("GetEducationSchools")
|
||||
res, err := i.conn.Search(searchRequest)
|
||||
if err != nil {
|
||||
return nil, errorcode.New(errorcode.ItemNotFound, err.Error())
|
||||
@@ -194,18 +194,18 @@ func (i *LDAP) GetSchools(ctx context.Context, queryParam url.Values) ([]*libreg
|
||||
return schools, nil
|
||||
}
|
||||
|
||||
// GetSchoolMembers implements the EducationBackend interface for the LDAP backend.
|
||||
func (i *LDAP) GetSchoolMembers(ctx context.Context, id string) ([]*libregraph.EducationUser, error) {
|
||||
// GetEducationSchoolMembers implements the EducationBackend interface for the LDAP backend.
|
||||
func (i *LDAP) GetEducationSchoolMembers(ctx context.Context, id string) ([]*libregraph.EducationUser, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
// AddMembersToSchool adds new members (reference by a slice of IDs) to supplied school in the identity backend.
|
||||
func (i *LDAP) AddMembersToSchool(ctx context.Context, schoolID string, memberID []string) error {
|
||||
// AddMembersToEducationSchool adds new members (reference by a slice of IDs) to supplied school in the identity backend.
|
||||
func (i *LDAP) AddMembersToEducationSchool(ctx context.Context, schoolID string, memberID []string) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
// RemoveMemberFromSchool removes a single member (by ID) from a school
|
||||
func (i *LDAP) RemoveMemberFromSchool(ctx context.Context, schoolID string, memberID string) error {
|
||||
// RemoveMemberFromEducationSchool removes a single member (by ID) from a school
|
||||
func (i *LDAP) RemoveMemberFromEducationSchool(ctx context.Context, schoolID string, memberID string) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ var schoolEntry1 = ldap.NewEntry("ou=Test School1",
|
||||
"owncloudUUID": {"hijk-defg"},
|
||||
})
|
||||
|
||||
func TestCreateSchool(t *testing.T) {
|
||||
func TestCreateEducationSchool(t *testing.T) {
|
||||
lm := &mocks.Client{}
|
||||
lm.On("Add", mock.Anything).
|
||||
Return(nil)
|
||||
@@ -65,7 +65,7 @@ func TestCreateSchool(t *testing.T) {
|
||||
school.SetDisplayName("Test School")
|
||||
school.SetSchoolNumber("0123")
|
||||
school.SetId("abcd-defg")
|
||||
res_school, err := b.CreateSchool(context.Background(), *school)
|
||||
res_school, err := b.CreateEducationSchool(context.Background(), *school)
|
||||
lm.AssertNumberOfCalls(t, "Add", 1)
|
||||
lm.AssertNumberOfCalls(t, "Search", 1)
|
||||
assert.Nil(t, err)
|
||||
@@ -75,7 +75,7 @@ func TestCreateSchool(t *testing.T) {
|
||||
assert.Equal(t, res_school.GetSchoolNumber(), school.GetSchoolNumber())
|
||||
}
|
||||
|
||||
func TestDeleteSchool(t *testing.T) {
|
||||
func TestDeleteEducationSchool(t *testing.T) {
|
||||
lm := &mocks.Client{}
|
||||
sr1 := &ldap.SearchRequest{
|
||||
BaseDN: "",
|
||||
@@ -102,19 +102,19 @@ func TestDeleteSchool(t *testing.T) {
|
||||
b, err := getMockedBackend(lm, eduConfig, &logger)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = b.DeleteSchool(context.Background(), "abcd-defg")
|
||||
err = b.DeleteEducationSchool(context.Background(), "abcd-defg")
|
||||
lm.AssertNumberOfCalls(t, "Search", 1)
|
||||
lm.AssertNumberOfCalls(t, "Del", 1)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = b.DeleteSchool(context.Background(), "xxxx-xxxx")
|
||||
err = b.DeleteEducationSchool(context.Background(), "xxxx-xxxx")
|
||||
lm.AssertNumberOfCalls(t, "Search", 2)
|
||||
lm.AssertNumberOfCalls(t, "Del", 1)
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, "itemNotFound", err.Error())
|
||||
}
|
||||
|
||||
func TestGetSchool(t *testing.T) {
|
||||
func TestGetEducationSchool(t *testing.T) {
|
||||
lm := &mocks.Client{}
|
||||
sr1 := &ldap.SearchRequest{
|
||||
BaseDN: "",
|
||||
@@ -136,20 +136,20 @@ func TestGetSchool(t *testing.T) {
|
||||
lm.On("Search", sr2).Return(&ldap.SearchResult{Entries: []*ldap.Entry{}}, nil)
|
||||
b, err := getMockedBackend(lm, eduConfig, &logger)
|
||||
assert.Nil(t, err)
|
||||
school, err := b.GetSchool(context.Background(), "abcd-defg", nil)
|
||||
school, err := b.GetEducationSchool(context.Background(), "abcd-defg", nil)
|
||||
lm.AssertNumberOfCalls(t, "Search", 1)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "Test School", school.GetDisplayName())
|
||||
assert.Equal(t, "abcd-defg", school.GetId())
|
||||
assert.Equal(t, "0123", school.GetSchoolNumber())
|
||||
|
||||
school, err = b.GetSchool(context.Background(), "xxxx-xxxx", nil)
|
||||
school, err = b.GetEducationSchool(context.Background(), "xxxx-xxxx", nil)
|
||||
lm.AssertNumberOfCalls(t, "Search", 2)
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, "itemNotFound", err.Error())
|
||||
}
|
||||
|
||||
func TestGetSchools(t *testing.T) {
|
||||
func TestGetEducationSchools(t *testing.T) {
|
||||
lm := &mocks.Client{}
|
||||
sr1 := &ldap.SearchRequest{
|
||||
BaseDN: "",
|
||||
@@ -163,7 +163,7 @@ func TestGetSchools(t *testing.T) {
|
||||
// lm.On("Search", sr2).Return(&ldap.SearchResult{Entries: []*ldap.Entry{}}, nil)
|
||||
b, err := getMockedBackend(lm, eduConfig, &logger)
|
||||
assert.Nil(t, err)
|
||||
_, err = b.GetSchools(context.Background(), nil)
|
||||
_, err = b.GetEducationSchools(context.Background(), nil)
|
||||
lm.AssertNumberOfCalls(t, "Search", 1)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ type EducationBackend struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// AddMembersToSchool provides a mock function with given fields: ctx, schoolID, memberID
|
||||
func (_m *EducationBackend) AddMembersToSchool(ctx context.Context, schoolID string, memberID []string) error {
|
||||
// AddMembersToEducationSchool provides a mock function with given fields: ctx, schoolID, memberID
|
||||
func (_m *EducationBackend) AddMembersToEducationSchool(ctx context.Context, schoolID string, memberID []string) error {
|
||||
ret := _m.Called(ctx, schoolID, memberID)
|
||||
|
||||
var r0 error
|
||||
@@ -31,6 +31,29 @@ func (_m *EducationBackend) AddMembersToSchool(ctx context.Context, schoolID str
|
||||
return r0
|
||||
}
|
||||
|
||||
// CreateEducationSchool provides a mock function with given fields: ctx, group
|
||||
func (_m *EducationBackend) CreateEducationSchool(ctx context.Context, group libregraph.EducationSchool) (*libregraph.EducationSchool, error) {
|
||||
ret := _m.Called(ctx, group)
|
||||
|
||||
var r0 *libregraph.EducationSchool
|
||||
if rf, ok := ret.Get(0).(func(context.Context, libregraph.EducationSchool) *libregraph.EducationSchool); ok {
|
||||
r0 = rf(ctx, group)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*libregraph.EducationSchool)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, libregraph.EducationSchool) error); ok {
|
||||
r1 = rf(ctx, group)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CreateEducationUser provides a mock function with given fields: ctx, user
|
||||
func (_m *EducationBackend) CreateEducationUser(ctx context.Context, user libregraph.EducationUser) (*libregraph.EducationUser, error) {
|
||||
ret := _m.Called(ctx, user)
|
||||
@@ -54,27 +77,18 @@ func (_m *EducationBackend) CreateEducationUser(ctx context.Context, user libreg
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CreateSchool provides a mock function with given fields: ctx, group
|
||||
func (_m *EducationBackend) CreateSchool(ctx context.Context, group libregraph.EducationSchool) (*libregraph.EducationSchool, error) {
|
||||
ret := _m.Called(ctx, group)
|
||||
// DeleteEducationSchool provides a mock function with given fields: ctx, id
|
||||
func (_m *EducationBackend) DeleteEducationSchool(ctx context.Context, id string) error {
|
||||
ret := _m.Called(ctx, id)
|
||||
|
||||
var r0 *libregraph.EducationSchool
|
||||
if rf, ok := ret.Get(0).(func(context.Context, libregraph.EducationSchool) *libregraph.EducationSchool); ok {
|
||||
r0 = rf(ctx, group)
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) error); ok {
|
||||
r0 = rf(ctx, id)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*libregraph.EducationSchool)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, libregraph.EducationSchool) error); ok {
|
||||
r1 = rf(ctx, group)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
return r0
|
||||
}
|
||||
|
||||
// DeleteEducationUser provides a mock function with given fields: ctx, nameOrID
|
||||
@@ -91,18 +105,73 @@ func (_m *EducationBackend) DeleteEducationUser(ctx context.Context, nameOrID st
|
||||
return r0
|
||||
}
|
||||
|
||||
// DeleteSchool provides a mock function with given fields: ctx, id
|
||||
func (_m *EducationBackend) DeleteSchool(ctx context.Context, id string) error {
|
||||
ret := _m.Called(ctx, id)
|
||||
// GetEducationSchool provides a mock function with given fields: ctx, nameOrID, queryParam
|
||||
func (_m *EducationBackend) GetEducationSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error) {
|
||||
ret := _m.Called(ctx, nameOrID, queryParam)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) error); ok {
|
||||
r0 = rf(ctx, id)
|
||||
var r0 *libregraph.EducationSchool
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, url.Values) *libregraph.EducationSchool); ok {
|
||||
r0 = rf(ctx, nameOrID, queryParam)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*libregraph.EducationSchool)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, url.Values) error); ok {
|
||||
r1 = rf(ctx, nameOrID, queryParam)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetEducationSchoolMembers provides a mock function with given fields: ctx, id
|
||||
func (_m *EducationBackend) GetEducationSchoolMembers(ctx context.Context, id string) ([]*libregraph.EducationUser, error) {
|
||||
ret := _m.Called(ctx, id)
|
||||
|
||||
var r0 []*libregraph.EducationUser
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) []*libregraph.EducationUser); ok {
|
||||
r0 = rf(ctx, id)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*libregraph.EducationUser)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
|
||||
r1 = rf(ctx, id)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetEducationSchools provides a mock function with given fields: ctx, queryParam
|
||||
func (_m *EducationBackend) GetEducationSchools(ctx context.Context, queryParam url.Values) ([]*libregraph.EducationSchool, error) {
|
||||
ret := _m.Called(ctx, queryParam)
|
||||
|
||||
var r0 []*libregraph.EducationSchool
|
||||
if rf, ok := ret.Get(0).(func(context.Context, url.Values) []*libregraph.EducationSchool); ok {
|
||||
r0 = rf(ctx, queryParam)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*libregraph.EducationSchool)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, url.Values) error); ok {
|
||||
r1 = rf(ctx, queryParam)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetEducationUser provides a mock function with given fields: ctx, nameOrID, queryParam
|
||||
@@ -151,77 +220,8 @@ func (_m *EducationBackend) GetEducationUsers(ctx context.Context, queryParam ur
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetSchool provides a mock function with given fields: ctx, nameOrID, queryParam
|
||||
func (_m *EducationBackend) GetSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error) {
|
||||
ret := _m.Called(ctx, nameOrID, queryParam)
|
||||
|
||||
var r0 *libregraph.EducationSchool
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, url.Values) *libregraph.EducationSchool); ok {
|
||||
r0 = rf(ctx, nameOrID, queryParam)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*libregraph.EducationSchool)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, url.Values) error); ok {
|
||||
r1 = rf(ctx, nameOrID, queryParam)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetSchoolMembers provides a mock function with given fields: ctx, id
|
||||
func (_m *EducationBackend) GetSchoolMembers(ctx context.Context, id string) ([]*libregraph.EducationUser, error) {
|
||||
ret := _m.Called(ctx, id)
|
||||
|
||||
var r0 []*libregraph.EducationUser
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) []*libregraph.EducationUser); ok {
|
||||
r0 = rf(ctx, id)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*libregraph.EducationUser)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
|
||||
r1 = rf(ctx, id)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetSchools provides a mock function with given fields: ctx, queryParam
|
||||
func (_m *EducationBackend) GetSchools(ctx context.Context, queryParam url.Values) ([]*libregraph.EducationSchool, error) {
|
||||
ret := _m.Called(ctx, queryParam)
|
||||
|
||||
var r0 []*libregraph.EducationSchool
|
||||
if rf, ok := ret.Get(0).(func(context.Context, url.Values) []*libregraph.EducationSchool); ok {
|
||||
r0 = rf(ctx, queryParam)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*libregraph.EducationSchool)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, url.Values) error); ok {
|
||||
r1 = rf(ctx, queryParam)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// RemoveMemberFromSchool provides a mock function with given fields: ctx, schoolID, memberID
|
||||
func (_m *EducationBackend) RemoveMemberFromSchool(ctx context.Context, schoolID string, memberID string) error {
|
||||
// RemoveMemberFromEducationSchool provides a mock function with given fields: ctx, schoolID, memberID
|
||||
func (_m *EducationBackend) RemoveMemberFromEducationSchool(ctx context.Context, schoolID string, memberID string) error {
|
||||
ret := _m.Called(ctx, schoolID, memberID)
|
||||
|
||||
var r0 error
|
||||
|
||||
@@ -10,38 +10,38 @@ import (
|
||||
// NOOP is a dummy EducationBackend, doing nothing
|
||||
type NOOP struct{}
|
||||
|
||||
// CreateSchool creates the supplied school in the identity backend.
|
||||
func (i *NOOP) CreateSchool(ctx context.Context, school libregraph.EducationSchool) (*libregraph.EducationSchool, error) {
|
||||
// CreateEducationSchool creates the supplied school in the identity backend.
|
||||
func (i *NOOP) CreateEducationSchool(ctx context.Context, school libregraph.EducationSchool) (*libregraph.EducationSchool, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
// DeleteSchool deletes a given school, identified by id
|
||||
func (i *NOOP) DeleteSchool(ctx context.Context, id string) error {
|
||||
// DeleteEducationSchool deletes a given school, identified by id
|
||||
func (i *NOOP) DeleteEducationSchool(ctx context.Context, id string) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
// GetSchool implements the EducationBackend interface for the NOOP backend.
|
||||
func (i *NOOP) GetSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error) {
|
||||
// GetEducationSchool implements the EducationBackend interface for the NOOP backend.
|
||||
func (i *NOOP) GetEducationSchool(ctx context.Context, nameOrID string, queryParam url.Values) (*libregraph.EducationSchool, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
// GetSchools implements the EducationBackend interface for the NOOP backend.
|
||||
func (i *NOOP) GetSchools(ctx context.Context, queryParam url.Values) ([]*libregraph.EducationSchool, error) {
|
||||
// GetEducationSchools implements the EducationBackend interface for the NOOP backend.
|
||||
func (i *NOOP) GetEducationSchools(ctx context.Context, queryParam url.Values) ([]*libregraph.EducationSchool, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
// GetSchoolMembers implements the EducationBackend interface for the NOOP backend.
|
||||
func (i *NOOP) GetSchoolMembers(ctx context.Context, id string) ([]*libregraph.EducationUser, error) {
|
||||
// GetEducationSchoolMembers implements the EducationBackend interface for the NOOP backend.
|
||||
func (i *NOOP) GetEducationSchoolMembers(ctx context.Context, id string) ([]*libregraph.EducationUser, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
// AddMembersToSchool adds new members (reference by a slice of IDs) to supplied school in the identity backend.
|
||||
func (i *NOOP) AddMembersToSchool(ctx context.Context, schoolID string, memberID []string) error {
|
||||
// AddMembersToEducationSchool adds new members (reference by a slice of IDs) to supplied school in the identity backend.
|
||||
func (i *NOOP) AddMembersToEducationSchool(ctx context.Context, schoolID string, memberID []string) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
// RemoveMemberFromSchool removes a single member (by ID) from a school
|
||||
func (i *NOOP) RemoveMemberFromSchool(ctx context.Context, schoolID string, memberID string) error {
|
||||
// RemoveMemberFromEducationSchool removes a single member (by ID) from a school
|
||||
func (i *NOOP) RemoveMemberFromEducationSchool(ctx context.Context, schoolID string, memberID string) error {
|
||||
return errNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func (g Graph) GetEducationSchools(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
schools, err := g.identityEducationBackend.GetSchools(r.Context(), r.URL.Query())
|
||||
schools, err := g.identityEducationBackend.GetEducationSchools(r.Context(), r.URL.Query())
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not get schools: backend error")
|
||||
var errcode errorcode.Error
|
||||
@@ -84,7 +84,7 @@ func (g Graph) PostEducationSchool(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if school, err = g.identityEducationBackend.CreateSchool(r.Context(), *school); err != nil {
|
||||
if school, err = g.identityEducationBackend.CreateEducationSchool(r.Context(), *school); err != nil {
|
||||
logger.Debug().Err(err).Interface("school", school).Msg("could not create school: backend error")
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
@@ -162,7 +162,7 @@ func (g Graph) GetEducationSchool(w http.ResponseWriter, r *http.Request) {
|
||||
Str("id", schoolID).
|
||||
Interface("query", r.URL.Query()).
|
||||
Msg("calling get school on backend")
|
||||
school, err := g.identityEducationBackend.GetSchool(r.Context(), schoolID, r.URL.Query())
|
||||
school, err := g.identityEducationBackend.GetEducationSchool(r.Context(), schoolID, r.URL.Query())
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not get school: backend error")
|
||||
var errcode errorcode.Error
|
||||
@@ -196,7 +196,7 @@ func (g Graph) DeleteEducationSchool(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
logger.Debug().Str("id", schoolID).Msg("calling delete school on backend")
|
||||
err = g.identityEducationBackend.DeleteSchool(r.Context(), schoolID)
|
||||
err = g.identityEducationBackend.DeleteEducationSchool(r.Context(), schoolID)
|
||||
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not delete school: backend error")
|
||||
@@ -240,7 +240,7 @@ func (g Graph) GetEducationSchoolMembers(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
logger.Debug().Str("id", schoolID).Msg("calling get school members on backend")
|
||||
members, err := g.identityEducationBackend.GetSchoolMembers(r.Context(), schoolID)
|
||||
members, err := g.identityEducationBackend.GetEducationSchoolMembers(r.Context(), schoolID)
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not get school members: backend error")
|
||||
var errcode errorcode.Error
|
||||
@@ -308,7 +308,7 @@ func (g Graph) PostEducationSchoolMember(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
logger.Debug().Str("memberType", memberType).Str("id", id).Msg("calling add member on backend")
|
||||
err = g.identityEducationBackend.AddMembersToSchool(r.Context(), schoolID, []string{id})
|
||||
err = g.identityEducationBackend.AddMembersToEducationSchool(r.Context(), schoolID, []string{id})
|
||||
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not add school member: backend error")
|
||||
@@ -366,7 +366,7 @@ func (g Graph) DeleteEducationSchoolMember(w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
logger.Debug().Str("schoolID", schoolID).Str("memberID", memberID).Msg("calling delete member on backend")
|
||||
err = g.identityEducationBackend.RemoveMemberFromSchool(r.Context(), schoolID, memberID)
|
||||
err = g.identityEducationBackend.RemoveMemberFromEducationSchool(r.Context(), schoolID, memberID)
|
||||
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Msg("could not delete school member: backend error")
|
||||
|
||||
@@ -82,7 +82,7 @@ var _ = Describe("Schools", func() {
|
||||
})
|
||||
|
||||
It("handles invalid sorting queries", func() {
|
||||
identityEducationBackend.On("GetSchools", ctx, mock.Anything).Return([]*libregraph.EducationSchool{newSchool}, nil)
|
||||
identityEducationBackend.On("GetEducationSchools", ctx, mock.Anything).Return([]*libregraph.EducationSchool{newSchool}, nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/education/schools?$orderby=invalid", nil)
|
||||
svc.GetEducationSchools(rr, r)
|
||||
@@ -98,7 +98,7 @@ var _ = Describe("Schools", func() {
|
||||
})
|
||||
|
||||
It("handles unknown backend errors", func() {
|
||||
identityEducationBackend.On("GetSchools", ctx, mock.Anything).Return(nil, errors.New("failed"))
|
||||
identityEducationBackend.On("GetEducationSchools", ctx, mock.Anything).Return(nil, errors.New("failed"))
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/education/schools", nil)
|
||||
svc.GetEducationSchools(rr, r)
|
||||
@@ -113,7 +113,7 @@ var _ = Describe("Schools", func() {
|
||||
})
|
||||
|
||||
It("handles backend errors", func() {
|
||||
identityEducationBackend.On("GetSchools", ctx, mock.Anything).Return(nil, errorcode.New(errorcode.AccessDenied, "access denied"))
|
||||
identityEducationBackend.On("GetEducationSchools", ctx, mock.Anything).Return(nil, errorcode.New(errorcode.AccessDenied, "access denied"))
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/education/schools", nil)
|
||||
svc.GetEducationSchools(rr, r)
|
||||
@@ -129,7 +129,7 @@ var _ = Describe("Schools", func() {
|
||||
})
|
||||
|
||||
It("renders an empty list of schools", func() {
|
||||
identityEducationBackend.On("GetSchools", ctx, mock.Anything).Return([]*libregraph.EducationSchool{}, nil)
|
||||
identityEducationBackend.On("GetEducationSchools", ctx, mock.Anything).Return([]*libregraph.EducationSchool{}, nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/education/schools", nil)
|
||||
svc.GetEducationSchools(rr, r)
|
||||
@@ -145,7 +145,7 @@ var _ = Describe("Schools", func() {
|
||||
})
|
||||
|
||||
It("renders a list of schools", func() {
|
||||
identityEducationBackend.On("GetSchools", ctx, mock.Anything).Return([]*libregraph.EducationSchool{newSchool}, nil)
|
||||
identityEducationBackend.On("GetEducationSchools", ctx, mock.Anything).Return([]*libregraph.EducationSchool{newSchool}, nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/education/schools", nil)
|
||||
svc.GetEducationSchools(rr, r)
|
||||
@@ -181,7 +181,7 @@ var _ = Describe("Schools", func() {
|
||||
|
||||
Context("with an existing school", func() {
|
||||
BeforeEach(func() {
|
||||
identityEducationBackend.On("GetSchool", mock.Anything, mock.Anything, mock.Anything).Return(newSchool, nil)
|
||||
identityEducationBackend.On("GetEducationSchool", mock.Anything, mock.Anything, mock.Anything).Return(newSchool, nil)
|
||||
})
|
||||
|
||||
It("gets the school", func() {
|
||||
@@ -250,7 +250,7 @@ var _ = Describe("Schools", func() {
|
||||
newSchoolJson, err := json.Marshal(newSchool)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
identityEducationBackend.On("CreateSchool", mock.Anything, mock.Anything).Return(nil, errorcode.New(errorcode.AccessDenied, "access denied"))
|
||||
identityEducationBackend.On("CreateEducationSchool", mock.Anything, mock.Anything).Return(nil, errorcode.New(errorcode.AccessDenied, "access denied"))
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "/graph/v1.0/education/schools/", bytes.NewBuffer(newSchoolJson))
|
||||
|
||||
@@ -266,7 +266,7 @@ var _ = Describe("Schools", func() {
|
||||
newSchoolJson, err := json.Marshal(newSchool)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
identityEducationBackend.On("CreateSchool", mock.Anything, mock.Anything).Return(newSchool, nil)
|
||||
identityEducationBackend.On("CreateEducationSchool", mock.Anything, mock.Anything).Return(newSchool, nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "/graph/v1.0/education/schools/", bytes.NewBuffer(newSchoolJson))
|
||||
|
||||
@@ -330,12 +330,12 @@ var _ = Describe("Schools", func() {
|
||||
Describe("DeleteEducationSchool", func() {
|
||||
Context("with an existing school", func() {
|
||||
BeforeEach(func() {
|
||||
identityEducationBackend.On("GetSchool", mock.Anything, mock.Anything, mock.Anything).Return(newSchool, nil)
|
||||
identityEducationBackend.On("GetEducationSchool", mock.Anything, mock.Anything, mock.Anything).Return(newSchool, nil)
|
||||
})
|
||||
})
|
||||
|
||||
It("deletes the school", func() {
|
||||
identityEducationBackend.On("DeleteSchool", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
identityEducationBackend.On("DeleteEducationSchool", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
r := httptest.NewRequest(http.MethodPatch, "/graph/v1.0/education/schools", nil)
|
||||
rctx := chi.NewRouteContext()
|
||||
rctx.URLParams.Add("schoolID", *newSchool.Id)
|
||||
@@ -343,7 +343,7 @@ var _ = Describe("Schools", func() {
|
||||
svc.DeleteEducationSchool(rr, r)
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusNoContent))
|
||||
identityEducationBackend.AssertNumberOfCalls(GinkgoT(), "DeleteSchool", 1)
|
||||
identityEducationBackend.AssertNumberOfCalls(GinkgoT(), "DeleteEducationSchool", 1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -351,7 +351,7 @@ var _ = Describe("Schools", func() {
|
||||
It("gets the list of members", func() {
|
||||
user := libregraph.NewEducationUser()
|
||||
user.SetId("user")
|
||||
identityEducationBackend.On("GetSchoolMembers", mock.Anything, mock.Anything, mock.Anything).Return([]*libregraph.EducationUser{user}, nil)
|
||||
identityEducationBackend.On("GetEducationSchoolMembers", mock.Anything, mock.Anything, mock.Anything).Return([]*libregraph.EducationUser{user}, nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/education/schools/{schoolID}/members", nil)
|
||||
rctx := chi.NewRouteContext()
|
||||
@@ -414,7 +414,7 @@ var _ = Describe("Schools", func() {
|
||||
member.SetOdataId("/users/user")
|
||||
data, err := json.Marshal(member)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
identityEducationBackend.On("AddMembersToSchool", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
identityEducationBackend.On("AddMembersToEducationSchool", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "/graph/v1.0/education/schools/{schoolID}/members", bytes.NewBuffer(data))
|
||||
rctx := chi.NewRouteContext()
|
||||
@@ -423,7 +423,7 @@ var _ = Describe("Schools", func() {
|
||||
svc.PostEducationSchoolMember(rr, r)
|
||||
Expect(rr.Code).To(Equal(http.StatusNoContent))
|
||||
|
||||
identityEducationBackend.AssertNumberOfCalls(GinkgoT(), "AddMembersToSchool", 1)
|
||||
identityEducationBackend.AssertNumberOfCalls(GinkgoT(), "AddMembersToEducationSchool", 1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -446,7 +446,7 @@ var _ = Describe("Schools", func() {
|
||||
})
|
||||
|
||||
It("deletes members", func() {
|
||||
identityEducationBackend.On("RemoveMemberFromSchool", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
identityEducationBackend.On("RemoveMemberFromEducationSchool", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodDelete, "/graph/v1.0/education/schools/{schoolID}/members/{memberID}/$ref", nil)
|
||||
rctx := chi.NewRouteContext()
|
||||
@@ -456,7 +456,7 @@ var _ = Describe("Schools", func() {
|
||||
svc.DeleteEducationSchoolMember(rr, r)
|
||||
Expect(rr.Code).To(Equal(http.StatusNoContent))
|
||||
|
||||
identityEducationBackend.AssertNumberOfCalls(GinkgoT(), "RemoveMemberFromSchool", 1)
|
||||
identityEducationBackend.AssertNumberOfCalls(GinkgoT(), "RemoveMemberFromEducationSchool", 1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user