Skip to content

Commit

Permalink
Fix problem with non-public error type because of forgotten rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Swärd authored and rhafer committed Jan 11, 2023
1 parent e15b3cd commit e1ad437
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
32 changes: 16 additions & 16 deletions services/graph/pkg/identity/ldap_school.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
}
Expand Down
22 changes: 12 additions & 10 deletions services/graph/pkg/identity/ldap_school_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down

0 comments on commit e1ad437

Please sign in to comment.