From e1ad437d9ef6f65b2347602de2cf86ecbfaed287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sw=C3=A4rd?= Date: Tue, 10 Jan 2023 17:12:49 +0700 Subject: [PATCH] Fix problem with non-public error type because of forgotten rebase. --- services/graph/pkg/identity/ldap_school.go | 32 +++++++++---------- .../graph/pkg/identity/ldap_school_test.go | 22 +++++++------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/services/graph/pkg/identity/ldap_school.go b/services/graph/pkg/identity/ldap_school.go index 4dcaadc21d4..a50f543fb67 100644 --- a/services/graph/pkg/identity/ldap_school.go +++ b/services/graph/pkg/identity/ldap_school.go @@ -34,13 +34,13 @@ type schoolAttributeMap struct { id string } -type SchoolUpdateOperation uint8 +type schoolUpdateOperation uint8 const ( - TooManyValues SchoolUpdateOperation = iota - SchoolUnchanged - DisplayNameUpdated - SchoolNumberUpdated + tooManyValues schoolUpdateOperation = iota + schoolUnchanged + displayNameUpdated + schoolNumberUpdated ) func defaultEducationConfig() educationConfig { @@ -104,7 +104,7 @@ func (i *LDAP) CreateEducationSchool(ctx context.Context, school libregraph.Educ 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", i.educationConfig.schoolAttributeMap.displayName, @@ -143,23 +143,23 @@ func (i *LDAP) CreateEducationSchool(ctx context.Context, school libregraph.Educ func (i *LDAP) UpdateEducationSchoolOperation( schoolUpdate libregraph.EducationSchool, currentSchool libregraph.EducationSchool, -) SchoolUpdateOperation { +) schoolUpdateOperation { providedDisplayName := schoolUpdate.GetDisplayName() schoolNumber := schoolUpdate.GetSchoolNumber() if providedDisplayName != "" && schoolNumber != "" { - return TooManyValues + return tooManyValues } if providedDisplayName != "" && providedDisplayName != currentSchool.GetDisplayName() { - return DisplayNameUpdated + return displayNameUpdated } if schoolNumber != "" && schoolNumber != currentSchool.GetSchoolNumber() { - return SchoolNumberUpdated + return schoolNumberUpdated } - return SchoolUnchanged + return schoolUnchanged } // 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.Debug().Str("backend", "ldap").Msg("UpdateEducationSchool") if !i.writeEnabled { - return nil, errReadOnly + return nil, ErrReadOnly } providedDisplayName := school.GetDisplayName() @@ -240,16 +240,16 @@ func (i *LDAP) UpdateEducationSchool(ctx context.Context, numberOrID string, sch currentSchool := i.createSchoolModelFromLDAP(e) 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") - case SchoolUnchanged: + case schoolUnchanged: logger.Debug().Str("backend", "ldap").Msg("UpdateEducationSchool: Nothing changed") return i.createSchoolModelFromLDAP(e), nil - case DisplayNameUpdated: + case displayNameUpdated: if err := i.updateDisplayName(ctx, e.DN, providedDisplayName); err != nil { return nil, err } - case SchoolNumberUpdated: + case schoolNumberUpdated: if err := i.updateSchoolNumber(ctx, e.DN, schoolNumber); err != nil { return nil, err } diff --git a/services/graph/pkg/identity/ldap_school_test.go b/services/graph/pkg/identity/ldap_school_test.go index 85c8af3d438..f27714755f9 100644 --- a/services/graph/pkg/identity/ldap_school_test.go +++ b/services/graph/pkg/identity/ldap_school_test.go @@ -81,37 +81,39 @@ func TestCreateEducationSchool(t *testing.T) { } func TestUpdateEducationSchoolOperation(t *testing.T) { + testSchoolName := "A name" + testSchoolNumber := "1234" tests := []struct { name string displayName string schoolNumber string - expectedOperation SchoolUpdateOperation + expectedOperation schoolUpdateOperation }{ { name: "Test using school with both number and name", - displayName: "A name", - schoolNumber: "1234", - expectedOperation: TooManyValues, + displayName: testSchoolName, + schoolNumber: testSchoolNumber, + expectedOperation: tooManyValues, }, { name: "Test with unchanged number", - schoolNumber: "1234", - expectedOperation: SchoolUnchanged, + schoolNumber: testSchoolNumber, + expectedOperation: schoolUnchanged, }, { name: "Test with unchanged name", - displayName: "A name", - expectedOperation: SchoolUnchanged, + displayName: testSchoolName, + expectedOperation: schoolUnchanged, }, { name: "Test new name", displayName: "Something new", - expectedOperation: DisplayNameUpdated, + expectedOperation: displayNameUpdated, }, { name: "Test new number", schoolNumber: "9876", - expectedOperation: SchoolNumberUpdated, + expectedOperation: schoolNumberUpdated, }, }