Fix problem with non-public error type because of forgotten rebase.
This commit is contained in:
committed by
Ralf Haferkamp
parent
e15b3cd8cc
commit
e1ad437d9e
@@ -34,13 +34,13 @@ type schoolAttributeMap struct {
|
|||||||
id string
|
id string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SchoolUpdateOperation uint8
|
type schoolUpdateOperation uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TooManyValues SchoolUpdateOperation = iota
|
tooManyValues schoolUpdateOperation = iota
|
||||||
SchoolUnchanged
|
schoolUnchanged
|
||||||
DisplayNameUpdated
|
displayNameUpdated
|
||||||
SchoolNumberUpdated
|
schoolNumberUpdated
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultEducationConfig() educationConfig {
|
func defaultEducationConfig() educationConfig {
|
||||||
@@ -104,7 +104,7 @@ func (i *LDAP) CreateEducationSchool(ctx context.Context, school libregraph.Educ
|
|||||||
return nil, ErrReadOnly
|
return nil, ErrReadOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Verify that the school number is not already in use
|
// Here we should verify that the school number is not already used
|
||||||
|
|
||||||
dn := fmt.Sprintf("%s=%s,%s",
|
dn := fmt.Sprintf("%s=%s,%s",
|
||||||
i.educationConfig.schoolAttributeMap.displayName,
|
i.educationConfig.schoolAttributeMap.displayName,
|
||||||
@@ -143,23 +143,23 @@ func (i *LDAP) CreateEducationSchool(ctx context.Context, school libregraph.Educ
|
|||||||
func (i *LDAP) UpdateEducationSchoolOperation(
|
func (i *LDAP) UpdateEducationSchoolOperation(
|
||||||
schoolUpdate libregraph.EducationSchool,
|
schoolUpdate libregraph.EducationSchool,
|
||||||
currentSchool libregraph.EducationSchool,
|
currentSchool libregraph.EducationSchool,
|
||||||
) SchoolUpdateOperation {
|
) schoolUpdateOperation {
|
||||||
providedDisplayName := schoolUpdate.GetDisplayName()
|
providedDisplayName := schoolUpdate.GetDisplayName()
|
||||||
schoolNumber := schoolUpdate.GetSchoolNumber()
|
schoolNumber := schoolUpdate.GetSchoolNumber()
|
||||||
|
|
||||||
if providedDisplayName != "" && schoolNumber != "" {
|
if providedDisplayName != "" && schoolNumber != "" {
|
||||||
return TooManyValues
|
return tooManyValues
|
||||||
}
|
}
|
||||||
|
|
||||||
if providedDisplayName != "" && providedDisplayName != currentSchool.GetDisplayName() {
|
if providedDisplayName != "" && providedDisplayName != currentSchool.GetDisplayName() {
|
||||||
return DisplayNameUpdated
|
return displayNameUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
if schoolNumber != "" && schoolNumber != currentSchool.GetSchoolNumber() {
|
if schoolNumber != "" && schoolNumber != currentSchool.GetSchoolNumber() {
|
||||||
return SchoolNumberUpdated
|
return schoolNumberUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
return SchoolUnchanged
|
return schoolUnchanged
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateDisplayName updates the school OU in the identity backend
|
// updateDisplayName updates the school OU in the identity backend
|
||||||
@@ -223,7 +223,7 @@ func (i *LDAP) UpdateEducationSchool(ctx context.Context, numberOrID string, sch
|
|||||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||||
logger.Debug().Str("backend", "ldap").Msg("UpdateEducationSchool")
|
logger.Debug().Str("backend", "ldap").Msg("UpdateEducationSchool")
|
||||||
if !i.writeEnabled {
|
if !i.writeEnabled {
|
||||||
return nil, errReadOnly
|
return nil, ErrReadOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
providedDisplayName := school.GetDisplayName()
|
providedDisplayName := school.GetDisplayName()
|
||||||
@@ -240,16 +240,16 @@ func (i *LDAP) UpdateEducationSchool(ctx context.Context, numberOrID string, sch
|
|||||||
|
|
||||||
currentSchool := i.createSchoolModelFromLDAP(e)
|
currentSchool := i.createSchoolModelFromLDAP(e)
|
||||||
switch i.UpdateEducationSchoolOperation(school, *currentSchool) {
|
switch i.UpdateEducationSchoolOperation(school, *currentSchool) {
|
||||||
case TooManyValues:
|
case tooManyValues:
|
||||||
return nil, fmt.Errorf("school name and school number cannot be updated in the same request")
|
return nil, fmt.Errorf("school name and school number cannot be updated in the same request")
|
||||||
case SchoolUnchanged:
|
case schoolUnchanged:
|
||||||
logger.Debug().Str("backend", "ldap").Msg("UpdateEducationSchool: Nothing changed")
|
logger.Debug().Str("backend", "ldap").Msg("UpdateEducationSchool: Nothing changed")
|
||||||
return i.createSchoolModelFromLDAP(e), nil
|
return i.createSchoolModelFromLDAP(e), nil
|
||||||
case DisplayNameUpdated:
|
case displayNameUpdated:
|
||||||
if err := i.updateDisplayName(ctx, e.DN, providedDisplayName); err != nil {
|
if err := i.updateDisplayName(ctx, e.DN, providedDisplayName); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case SchoolNumberUpdated:
|
case schoolNumberUpdated:
|
||||||
if err := i.updateSchoolNumber(ctx, e.DN, schoolNumber); err != nil {
|
if err := i.updateSchoolNumber(ctx, e.DN, schoolNumber); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,37 +81,39 @@ func TestCreateEducationSchool(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateEducationSchoolOperation(t *testing.T) {
|
func TestUpdateEducationSchoolOperation(t *testing.T) {
|
||||||
|
testSchoolName := "A name"
|
||||||
|
testSchoolNumber := "1234"
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
displayName string
|
displayName string
|
||||||
schoolNumber string
|
schoolNumber string
|
||||||
expectedOperation SchoolUpdateOperation
|
expectedOperation schoolUpdateOperation
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test using school with both number and name",
|
name: "Test using school with both number and name",
|
||||||
displayName: "A name",
|
displayName: testSchoolName,
|
||||||
schoolNumber: "1234",
|
schoolNumber: testSchoolNumber,
|
||||||
expectedOperation: TooManyValues,
|
expectedOperation: tooManyValues,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test with unchanged number",
|
name: "Test with unchanged number",
|
||||||
schoolNumber: "1234",
|
schoolNumber: testSchoolNumber,
|
||||||
expectedOperation: SchoolUnchanged,
|
expectedOperation: schoolUnchanged,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test with unchanged name",
|
name: "Test with unchanged name",
|
||||||
displayName: "A name",
|
displayName: testSchoolName,
|
||||||
expectedOperation: SchoolUnchanged,
|
expectedOperation: schoolUnchanged,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test new name",
|
name: "Test new name",
|
||||||
displayName: "Something new",
|
displayName: "Something new",
|
||||||
expectedOperation: DisplayNameUpdated,
|
expectedOperation: displayNameUpdated,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test new number",
|
name: "Test new number",
|
||||||
schoolNumber: "9876",
|
schoolNumber: "9876",
|
||||||
expectedOperation: SchoolNumberUpdated,
|
expectedOperation: schoolNumberUpdated,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user