diff --git a/services/graph/pkg/identity/backend.go b/services/graph/pkg/identity/backend.go index 8d8d25bb638..8a599dc87aa 100644 --- a/services/graph/pkg/identity/backend.go +++ b/services/graph/pkg/identity/backend.go @@ -19,6 +19,12 @@ var ( ErrNotFound = errorcode.New(errorcode.ItemNotFound, "not found") ) +const ( + UserTypeMember = "Member" + UserTypeGuest = "Guest" + UserTypeFederated = "Federated" +) + // Backend defines the Interface for an IdentityBackend implementation type Backend interface { // CreateUser creates a given user in the identity backend. @@ -109,6 +115,7 @@ func CreateUserModelFromCS3(u *cs3user.User) *libregraph.User { if u.Id == nil { u.Id = &cs3user.UserId{} } + userType := cs3UserTypeToGraph(u.GetId().GetType()) return &libregraph.User{ Identities: []libregraph.ObjectIdentity{ { @@ -116,6 +123,7 @@ func CreateUserModelFromCS3(u *cs3user.User) *libregraph.User { IssuerAssignedId: &u.GetId().OpaqueId, }, }, + UserType: &userType, DisplayName: &u.DisplayName, Mail: &u.Mail, OnPremisesSamAccountName: &u.Username, @@ -123,6 +131,18 @@ func CreateUserModelFromCS3(u *cs3user.User) *libregraph.User { } } +func cs3UserTypeToGraph(cs3type cs3user.UserType) string { + switch cs3type { + case cs3user.UserType_USER_TYPE_PRIMARY: + return UserTypeMember + case cs3user.UserType_USER_TYPE_FEDERATED: + return UserTypeFederated + case cs3user.UserType_USER_TYPE_GUEST: + return UserTypeGuest + } + return "unknown" +} + // CreateGroupModelFromCS3 converts a cs3 Group object into a libregraph.Group func CreateGroupModelFromCS3(g *cs3group.Group) *libregraph.Group { if g.Id == nil { diff --git a/services/graph/pkg/identity/ldap.go b/services/graph/pkg/identity/ldap.go index dea9f3a6d7e..37f164d986e 100644 --- a/services/graph/pkg/identity/ldap.go +++ b/services/graph/pkg/identity/ldap.go @@ -810,9 +810,14 @@ func (i *LDAP) createUserModelFromLDAP(e *ldap.Entry) *libregraph.User { Id: &id, GivenName: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.givenName)), Surname: &surname, - UserType: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.userType)), AccountEnabled: booleanOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.accountEnabled)), } + + userType := e.GetEqualFoldAttributeValue(i.userAttributeMap.userType) + if userType == "" { + userType = UserTypeMember + } + user.SetUserType(userType) var identities []libregraph.ObjectIdentity for _, identityStr := range e.GetEqualFoldAttributeValues(i.userAttributeMap.identities) { parts := strings.SplitN(identityStr, "$", 3) diff --git a/services/graph/pkg/identity/ldap_test.go b/services/graph/pkg/identity/ldap_test.go index 36630cbf759..8d38ec83f98 100644 --- a/services/graph/pkg/identity/ldap_test.go +++ b/services/graph/pkg/identity/ldap_test.go @@ -397,6 +397,7 @@ func TestUpdateUser(t *testing.T) { displayName: "testUser", onPremisesSamAccountName: "testUser", accountEnabled: nil, + userType: &memberType, }, assertion: func(t assert.TestingT, err error, args ...interface{}) bool { return assert.Nil(t, err, args...) @@ -526,6 +527,7 @@ func TestUpdateUser(t *testing.T) { displayName: "newName", onPremisesSamAccountName: "testUser", accountEnabled: nil, + userType: &memberType, }, assertion: func(t assert.TestingT, err error, args ...interface{}) bool { return assert.Nil(t, err, args...) @@ -655,6 +657,7 @@ func TestUpdateUser(t *testing.T) { displayName: "newName", onPremisesSamAccountName: "newName", accountEnabled: nil, + userType: &memberType, }, assertion: func(t assert.TestingT, err error, args ...interface{}) bool { return assert.Nil(t, err, args...) @@ -844,6 +847,7 @@ func TestUpdateUser(t *testing.T) { displayName: "testUser", onPremisesSamAccountName: "testUser", accountEnabled: &falseBool, + userType: &memberType, }, assertion: func(t assert.TestingT, err error, args ...interface{}) bool { return assert.Nil(t, err, args...) @@ -974,6 +978,7 @@ func TestUpdateUser(t *testing.T) { displayName: "testUser", onPremisesSamAccountName: "testUser", accountEnabled: &falseBool, + userType: &memberType, }, assertion: func(t assert.TestingT, err error, args ...interface{}) bool { return assert.Nil(t, err, args...) @@ -1140,6 +1145,7 @@ func TestUpdateUser(t *testing.T) { displayName: "testUser", onPremisesSamAccountName: "testUser", accountEnabled: &trueBool, + userType: &memberType, }, assertion: func(t assert.TestingT, err error, args ...interface{}) bool { return assert.Nil(t, err, args...)