bump libre graph api
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ type Backend interface {
|
||||
// DeleteUser deletes a given user, identified by username or id, from the backend
|
||||
DeleteUser(ctx context.Context, nameOrID string) error
|
||||
// UpdateUser applies changes to given user, identified by username or id
|
||||
UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error)
|
||||
UpdateUser(ctx context.Context, nameOrID string, user libregraph.UserUpdate) (*libregraph.User, error)
|
||||
GetUser(ctx context.Context, nameOrID string, oreq *godata.GoDataRequest) (*libregraph.User, error)
|
||||
GetUsers(ctx context.Context, oreq *godata.GoDataRequest) ([]*libregraph.User, error)
|
||||
|
||||
@@ -124,9 +124,9 @@ func CreateUserModelFromCS3(u *cs3user.User) *libregraph.User {
|
||||
},
|
||||
},
|
||||
UserType: &userType,
|
||||
DisplayName: &u.DisplayName,
|
||||
DisplayName: u.DisplayName,
|
||||
Mail: &u.Mail,
|
||||
OnPremisesSamAccountName: &u.Username,
|
||||
OnPremisesSamAccountName: u.Username,
|
||||
Id: &u.Id.OpaqueId,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func (i *CS3) DeleteUser(ctx context.Context, nameOrID string) error {
|
||||
}
|
||||
|
||||
// UpdateUser implements the Backend Interface. It's currently not supported for the CS3 backend
|
||||
func (i *CS3) UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error) {
|
||||
func (i *CS3) UpdateUser(ctx context.Context, nameOrID string, user libregraph.UserUpdate) (*libregraph.User, error) {
|
||||
return nil, errNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ func (i *LDAP) DeleteUser(ctx context.Context, nameOrID string) error {
|
||||
}
|
||||
|
||||
// UpdateUser implements the Backend Interface for the LDAP Backend
|
||||
func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error) {
|
||||
func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.UserUpdate) (*libregraph.User, error) {
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("UpdateUser")
|
||||
if !i.writeEnabled {
|
||||
@@ -804,9 +804,9 @@ func (i *LDAP) createUserModelFromLDAP(e *ldap.Entry) *libregraph.User {
|
||||
|
||||
if id != "" && opsan != "" {
|
||||
user := &libregraph.User{
|
||||
DisplayName: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.displayName)),
|
||||
DisplayName: e.GetEqualFoldAttributeValue(i.userAttributeMap.displayName),
|
||||
Mail: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.mail)),
|
||||
OnPremisesSamAccountName: &opsan,
|
||||
OnPremisesSamAccountName: opsan,
|
||||
Id: &id,
|
||||
GivenName: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.givenName)),
|
||||
Surname: &surname,
|
||||
@@ -874,7 +874,7 @@ func (i *LDAP) userToLDAPAttrValues(user libregraph.User) (map[string][]string,
|
||||
if user.Surname != nil && *user.Surname != "" {
|
||||
sn = *user.Surname
|
||||
} else {
|
||||
sn = *user.OnPremisesSamAccountName
|
||||
sn = user.OnPremisesSamAccountName
|
||||
}
|
||||
attrs[i.userAttributeMap.surname] = []string{sn}
|
||||
|
||||
@@ -921,7 +921,7 @@ func (i *LDAP) getUserAttrTypes() []string {
|
||||
func (i *LDAP) getUserLDAPDN(user libregraph.User) string {
|
||||
attributeTypeAndValue := ldap.AttributeTypeAndValue{
|
||||
Type: "uid",
|
||||
Value: *user.OnPremisesSamAccountName,
|
||||
Value: user.OnPremisesSamAccountName,
|
||||
}
|
||||
return fmt.Sprintf("%s,%s", attributeTypeAndValue.String(), i.userBaseDN)
|
||||
}
|
||||
@@ -1256,7 +1256,7 @@ func (i *LDAP) mapLDAPError(err error, errmap ldapResultToErrMap) errorcode.Erro
|
||||
return errorcode.New(errorcode.GeneralException, err.Error())
|
||||
}
|
||||
|
||||
func isUserEnabledUpdate(user libregraph.User) bool {
|
||||
func isUserEnabledUpdate(user libregraph.UserUpdate) bool {
|
||||
switch {
|
||||
case user.Id != nil, user.DisplayName != nil,
|
||||
user.Drive != nil, user.Mail != nil, user.OnPremisesSamAccountName != nil,
|
||||
|
||||
@@ -511,7 +511,7 @@ func TestLDAP_UpdateEducationClass(t *testing.T) {
|
||||
args: args{
|
||||
id: "abcd-defg",
|
||||
class: libregraph.EducationClass{
|
||||
Members: []libregraph.User{*libregraph.NewUser()},
|
||||
Members: []libregraph.User{*libregraph.NewUser("display name", "username")},
|
||||
},
|
||||
},
|
||||
assertion: func(tt assert.TestingT, err error, i ...interface{}) bool { return assert.Error(tt, err) },
|
||||
|
||||
@@ -250,12 +250,10 @@ func (i *LDAP) GetEducationUsers(ctx context.Context) ([]*libregraph.EducationUs
|
||||
}
|
||||
|
||||
func (i *LDAP) educationUserToUser(eduUser libregraph.EducationUser) *libregraph.User {
|
||||
user := libregraph.NewUser()
|
||||
user.OnPremisesSamAccountName = eduUser.OnPremisesSamAccountName
|
||||
user := libregraph.NewUser(*eduUser.DisplayName, *eduUser.OnPremisesSamAccountName)
|
||||
user.Surname = eduUser.Surname
|
||||
user.AccountEnabled = eduUser.AccountEnabled
|
||||
user.GivenName = eduUser.GivenName
|
||||
user.DisplayName = eduUser.DisplayName
|
||||
user.Mail = eduUser.Mail
|
||||
user.UserType = eduUser.UserType
|
||||
user.Identities = eduUser.Identities
|
||||
@@ -266,11 +264,11 @@ func (i *LDAP) educationUserToUser(eduUser libregraph.EducationUser) *libregraph
|
||||
func (i *LDAP) userToEducationUser(user libregraph.User, e *ldap.Entry) *libregraph.EducationUser {
|
||||
eduUser := libregraph.NewEducationUser()
|
||||
eduUser.Id = user.Id
|
||||
eduUser.OnPremisesSamAccountName = user.OnPremisesSamAccountName
|
||||
eduUser.OnPremisesSamAccountName = &user.OnPremisesSamAccountName
|
||||
eduUser.Surname = user.Surname
|
||||
eduUser.AccountEnabled = user.AccountEnabled
|
||||
eduUser.GivenName = user.GivenName
|
||||
eduUser.DisplayName = user.DisplayName
|
||||
eduUser.DisplayName = &user.DisplayName
|
||||
eduUser.Mail = user.Mail
|
||||
eduUser.UserType = user.UserType
|
||||
|
||||
|
||||
@@ -135,10 +135,8 @@ func TestCreateUser(t *testing.T) {
|
||||
l.On("Add", ar).Return(nil)
|
||||
logger := log.NewLogger(log.Level("debug"))
|
||||
|
||||
user := libregraph.NewUser()
|
||||
user.SetDisplayName(displayName)
|
||||
user := libregraph.NewUser(displayName, userName)
|
||||
user.SetMail(mail)
|
||||
user.SetOnPremisesSamAccountName(userName)
|
||||
user.SetSurname(surname)
|
||||
user.SetGivenName(givenName)
|
||||
user.SetAccountEnabled(true)
|
||||
@@ -171,14 +169,14 @@ func TestCreateUserModelFromLDAP(t *testing.T) {
|
||||
if user == nil {
|
||||
t.Error("Converting a valid LDAP Entry should succeed")
|
||||
} else {
|
||||
if *user.OnPremisesSamAccountName != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.userName) {
|
||||
if user.OnPremisesSamAccountName != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.userName) {
|
||||
t.Errorf("Error creating msGraph User from LDAP Entry: %v != %v", user.OnPremisesSamAccountName, pointerOrNil(userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.userName)))
|
||||
}
|
||||
if *user.Mail != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.mail) {
|
||||
t.Errorf("Error creating msGraph User from LDAP Entry: %s != %s", *user.Mail, userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.mail))
|
||||
}
|
||||
if *user.DisplayName != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.displayName) {
|
||||
t.Errorf("Error creating msGraph User from LDAP Entry: %s != %s", *user.DisplayName, userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.displayName))
|
||||
if user.DisplayName != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.displayName) {
|
||||
t.Errorf("Error creating msGraph User from LDAP Entry: %s != %s", user.DisplayName, userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.displayName))
|
||||
}
|
||||
if *user.Id != userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.id) {
|
||||
t.Errorf("Error creating msGraph User from LDAP Entry: %s != %s", *user.Id, userEntry.GetEqualFoldAttributeValue(b.userAttributeMap.id))
|
||||
@@ -1447,7 +1445,7 @@ func TestUpdateUser(t *testing.T) {
|
||||
ldapConfig.DisableUserMechanism = tt.args.disableUserMechanism
|
||||
i, _ := getMockedBackend(lm, ldapConfig, &logger)
|
||||
|
||||
user := libregraph.User{
|
||||
user := libregraph.UserUpdate{
|
||||
Id: &tt.args.userProps.id,
|
||||
Mail: &tt.args.userProps.mail,
|
||||
DisplayName: &tt.args.userProps.displayName,
|
||||
@@ -1462,15 +1460,15 @@ func TestUpdateUser(t *testing.T) {
|
||||
want = &libregraph.User{
|
||||
Id: &tt.want.id,
|
||||
Mail: &tt.want.mail,
|
||||
DisplayName: &tt.want.displayName,
|
||||
OnPremisesSamAccountName: &tt.want.onPremisesSamAccountName,
|
||||
DisplayName: tt.want.displayName,
|
||||
OnPremisesSamAccountName: tt.want.onPremisesSamAccountName,
|
||||
Surname: &emptyString,
|
||||
GivenName: tt.want.givenName,
|
||||
UserType: tt.want.userType,
|
||||
}
|
||||
|
||||
if tt.want.accountEnabled != nil {
|
||||
want.AccountEnabled = *&tt.want.accountEnabled
|
||||
want.AccountEnabled = tt.want.accountEnabled
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
@@ -682,7 +682,7 @@ func (_c *Backend_UpdateGroupName_Call) RunAndReturn(run func(context.Context, s
|
||||
}
|
||||
|
||||
// UpdateUser provides a mock function with given fields: ctx, nameOrID, user
|
||||
func (_m *Backend) UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error) {
|
||||
func (_m *Backend) UpdateUser(ctx context.Context, nameOrID string, user libregraph.UserUpdate) (*libregraph.User, error) {
|
||||
ret := _m.Called(ctx, nameOrID, user)
|
||||
|
||||
if len(ret) == 0 {
|
||||
@@ -691,10 +691,10 @@ func (_m *Backend) UpdateUser(ctx context.Context, nameOrID string, user libregr
|
||||
|
||||
var r0 *libregraph.User
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, libregraph.User) (*libregraph.User, error)); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, libregraph.UserUpdate) (*libregraph.User, error)); ok {
|
||||
return rf(ctx, nameOrID, user)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, libregraph.User) *libregraph.User); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, libregraph.UserUpdate) *libregraph.User); ok {
|
||||
r0 = rf(ctx, nameOrID, user)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -702,7 +702,7 @@ func (_m *Backend) UpdateUser(ctx context.Context, nameOrID string, user libregr
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, libregraph.User) error); ok {
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, libregraph.UserUpdate) error); ok {
|
||||
r1 = rf(ctx, nameOrID, user)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
@@ -719,14 +719,14 @@ type Backend_UpdateUser_Call struct {
|
||||
// UpdateUser is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - nameOrID string
|
||||
// - user libregraph.User
|
||||
// - user libregraph.UserUpdate
|
||||
func (_e *Backend_Expecter) UpdateUser(ctx interface{}, nameOrID interface{}, user interface{}) *Backend_UpdateUser_Call {
|
||||
return &Backend_UpdateUser_Call{Call: _e.mock.On("UpdateUser", ctx, nameOrID, user)}
|
||||
}
|
||||
|
||||
func (_c *Backend_UpdateUser_Call) Run(run func(ctx context.Context, nameOrID string, user libregraph.User)) *Backend_UpdateUser_Call {
|
||||
func (_c *Backend_UpdateUser_Call) Run(run func(ctx context.Context, nameOrID string, user libregraph.UserUpdate)) *Backend_UpdateUser_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(context.Context), args[1].(string), args[2].(libregraph.User))
|
||||
run(args[0].(context.Context), args[1].(string), args[2].(libregraph.UserUpdate))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
@@ -736,7 +736,7 @@ func (_c *Backend_UpdateUser_Call) Return(_a0 *libregraph.User, _a1 error) *Back
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Backend_UpdateUser_Call) RunAndReturn(run func(context.Context, string, libregraph.User) (*libregraph.User, error)) *Backend_UpdateUser_Call {
|
||||
func (_c *Backend_UpdateUser_Call) RunAndReturn(run func(context.Context, string, libregraph.UserUpdate) (*libregraph.User, error)) *Backend_UpdateUser_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.40.2. DO NOT EDIT.
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -171,8 +171,9 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId *sto
|
||||
}
|
||||
permission.GrantedToV2 = &libregraph.SharePointIdentitySet{
|
||||
User: &libregraph.Identity{
|
||||
DisplayName: user.GetDisplayName(),
|
||||
Id: conversions.ToPointer(user.GetId()),
|
||||
DisplayName: user.GetDisplayName(),
|
||||
Id: conversions.ToPointer(user.GetId()),
|
||||
LibreGraphUserType: conversions.ToPointer(user.GetUserType()),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -394,6 +394,9 @@ var _ = Describe("Schools", func() {
|
||||
Describe("GetEducationSchoolUsers", func() {
|
||||
It("gets the list of members", func() {
|
||||
user := libregraph.NewEducationUser()
|
||||
user.SetOnPremisesSamAccountName("user")
|
||||
user.SetDisplayName("display name")
|
||||
user.SetMail("mail")
|
||||
user.SetId("user")
|
||||
identityEducationBackend.On("GetEducationSchoolUsers", mock.Anything, mock.Anything, mock.Anything).Return([]*libregraph.EducationUser{user}, nil)
|
||||
|
||||
@@ -520,12 +523,12 @@ var _ = Describe("Schools", func() {
|
||||
data, err := io.ReadAll(rr.Body)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
var members []*libregraph.User
|
||||
err = json.Unmarshal(data, &members)
|
||||
var classes []*libregraph.EducationClass
|
||||
err = json.Unmarshal(data, &classes)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(len(members)).To(Equal(1))
|
||||
Expect(members[0].GetId()).To(Equal("class"))
|
||||
Expect(len(classes)).To(Equal(1))
|
||||
Expect(classes[0].GetId()).To(Equal("class"))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ var _ = Describe("Groups", func() {
|
||||
group.SetDisplayName("Group Name")
|
||||
group.SetMembers(
|
||||
[]libregraph.User{
|
||||
libregraph.User{
|
||||
{
|
||||
Id: libregraph.PtrString("userid"),
|
||||
},
|
||||
},
|
||||
@@ -259,7 +259,7 @@ var _ = Describe("Groups", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
groupMap, err := res.Value[0].ToMap()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
for k, _ := range groupMap {
|
||||
for k := range groupMap {
|
||||
Expect(k).Should(BeElementOf([]string{"displayName", "id", "groupTypes"}))
|
||||
}
|
||||
})
|
||||
@@ -523,8 +523,8 @@ var _ = Describe("Groups", func() {
|
||||
|
||||
Describe("GetGroupMembers", func() {
|
||||
It("gets the list of members", func() {
|
||||
user := libregraph.NewUser()
|
||||
user.SetId("user")
|
||||
user := libregraph.NewUser("display name", "username")
|
||||
user.SetId("userid")
|
||||
identityBackend.On("GetGroupMembers", mock.Anything, mock.Anything, mock.Anything).Return([]*libregraph.User{user}, nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/groups/{groupID}/members", nil)
|
||||
@@ -542,7 +542,7 @@ var _ = Describe("Groups", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(len(members)).To(Equal(1))
|
||||
Expect(members[0].GetId()).To(Equal("user"))
|
||||
Expect(members[0].GetId()).To(Equal("userid"))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ func (g Graph) ChangeOwnPassword(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
newPwProfile := libregraph.NewPasswordProfile()
|
||||
newPwProfile.SetPassword(newPw)
|
||||
changes := libregraph.NewUser()
|
||||
changes := libregraph.NewUserUpdate()
|
||||
changes.SetPasswordProfile(*newPwProfile)
|
||||
_, err = g.identityBackend.UpdateUser(ctx, u.Id.OpaqueId, *changes)
|
||||
if err != nil {
|
||||
|
||||
@@ -339,7 +339,7 @@ func (g Graph) GetUsers(w http.ResponseWriter, r *http.Request) {
|
||||
func (g Graph) PostUser(w http.ResponseWriter, r *http.Request) {
|
||||
logger := g.logger.SubloggerWithRequestID(r.Context())
|
||||
logger.Debug().Msg("calling create user")
|
||||
u := libregraph.NewUser()
|
||||
u := libregraph.NewUser("", "")
|
||||
err := StrictJSONUnmarshal(r.Body, u)
|
||||
if err != nil {
|
||||
logger.Info().Err(err).Msg("could not create user: invalid request body")
|
||||
@@ -347,23 +347,16 @@ func (g Graph) PostUser(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := u.GetDisplayNameOk(); !ok {
|
||||
logger.Info().Err(err).Interface("user", u).Msg("could not create user: missing required Attribute: 'displayName'")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "missing required Attribute: 'displayName'")
|
||||
if u.GetDisplayName() == "" {
|
||||
logger.Info().Err(err).Interface("user", u).Msg("could not create user: empty displayname")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "Empty displayname")
|
||||
return
|
||||
}
|
||||
if accountName, ok := u.GetOnPremisesSamAccountNameOk(); ok {
|
||||
if !g.isValidUsername(*accountName) {
|
||||
logger.Info().Str("username", *accountName).Msg("could not create user: invalid username")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "Invalid username")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logger.Info().Interface("user", u).Msg("could not create user: missing required Attribute: 'onPremisesSamAccountName'")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "missing required Attribute: 'onPremisesSamAccountName'")
|
||||
if username := u.GetOnPremisesSamAccountName(); !g.isValidUsername(username) {
|
||||
logger.Info().Str("username", username).Msg("could not create user: invalid username")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "Invalid username")
|
||||
return
|
||||
}
|
||||
|
||||
if mail, ok := u.GetMailOk(); ok {
|
||||
if !isValidEmail(*mail) {
|
||||
logger.Info().Str("mail", *u.Mail).Msg("could not create user: invalid email address")
|
||||
@@ -715,7 +708,7 @@ func (g Graph) PatchMe(w http.ResponseWriter, r *http.Request) {
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "missing user id")
|
||||
return
|
||||
}
|
||||
changes := libregraph.NewUser()
|
||||
changes := libregraph.NewUserUpdate()
|
||||
err := StrictJSONUnmarshal(r.Body, changes)
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Interface("body", r.Body).Msg("could not update user: invalid request body")
|
||||
@@ -747,7 +740,7 @@ func (g Graph) PatchUser(w http.ResponseWriter, r *http.Request) {
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "unescaping user id failed")
|
||||
return
|
||||
}
|
||||
changes := libregraph.NewUser()
|
||||
changes := libregraph.NewUserUpdate()
|
||||
err = StrictJSONUnmarshal(r.Body, changes)
|
||||
if err != nil {
|
||||
logger.Debug().Err(err).Interface("body", r.Body).Msg("could not update user: invalid request body")
|
||||
@@ -764,7 +757,7 @@ func (g Graph) PatchUser(w http.ResponseWriter, r *http.Request) {
|
||||
g.patchUser(w, r, nameOrID, changes)
|
||||
}
|
||||
|
||||
func (g Graph) patchUser(w http.ResponseWriter, r *http.Request, nameOrID string, changes *libregraph.User) {
|
||||
func (g Graph) patchUser(w http.ResponseWriter, r *http.Request, nameOrID string, changes *libregraph.UserUpdate) {
|
||||
logger := g.logger.SubloggerWithRequestID(r.Context())
|
||||
logger.Debug().Msg("calling patch user")
|
||||
|
||||
@@ -875,7 +868,7 @@ func (g Graph) patchUser(w http.ResponseWriter, r *http.Request, nameOrID string
|
||||
}
|
||||
|
||||
if name, ok := changes.GetDisplayNameOk(); ok {
|
||||
addfeature("displayname", *name, oldUserValues.DisplayName)
|
||||
addfeature("displayname", *name, &oldUserValues.DisplayName)
|
||||
}
|
||||
|
||||
if userType, ok := changes.GetUserTypeOk(); ok {
|
||||
|
||||
@@ -301,7 +301,7 @@ var _ = Describe("Users", func() {
|
||||
|
||||
It("only returns a restricted set of attributes for unprivileged users", func() {
|
||||
permissionService.On("GetPermissionByID", mock.Anything, mock.Anything).Return(&settings.GetPermissionByIDResponse{}, nil)
|
||||
user := &libregraph.User{}
|
||||
user := libregraph.NewUser("abc user", "username")
|
||||
user.SetId("user1")
|
||||
user.SetPasswordProfile(
|
||||
libregraph.PasswordProfile{
|
||||
@@ -309,7 +309,6 @@ var _ = Describe("Users", func() {
|
||||
},
|
||||
)
|
||||
user.SetUserType("usertype")
|
||||
user.SetDisplayName("abc user")
|
||||
users := []*libregraph.User{user}
|
||||
|
||||
identityBackend.On("GetUsers", mock.Anything, mock.Anything, mock.Anything).Return(users, nil)
|
||||
@@ -325,8 +324,8 @@ var _ = Describe("Users", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
userMap, err := res.Value[0].ToMap()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
for k, _ := range userMap {
|
||||
Expect(k).Should(BeElementOf([]string{"mail", "displayName", "id", "userType"}))
|
||||
for k := range userMap {
|
||||
Expect(k).Should(BeElementOf([]string{"displayName", "onPremisesSamAccountName", "mail", "id", "userType"}))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -800,10 +799,7 @@ var _ = Describe("Users", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
user = &libregraph.User{}
|
||||
user.SetDisplayName("Display Name")
|
||||
user.SetOnPremisesSamAccountName("user")
|
||||
user.SetMail("user@example.com")
|
||||
user = libregraph.NewUser("Display Name", "user")
|
||||
})
|
||||
|
||||
It("handles invalid bodies", func() {
|
||||
@@ -814,15 +810,11 @@ var _ = Describe("Users", func() {
|
||||
})
|
||||
|
||||
It("handles missing display names", func() {
|
||||
user.DisplayName = nil
|
||||
user.SetDisplayName("")
|
||||
assertHandleBadAttributes(user)
|
||||
|
||||
})
|
||||
|
||||
It("handles missing OnPremisesSamAccountName", func() {
|
||||
user.OnPremisesSamAccountName = nil
|
||||
assertHandleBadAttributes(user)
|
||||
|
||||
user.SetOnPremisesSamAccountName("")
|
||||
assertHandleBadAttributes(user)
|
||||
})
|
||||
@@ -1034,16 +1026,23 @@ var _ = Describe("Users", func() {
|
||||
|
||||
Describe("PatchUser", func() {
|
||||
var (
|
||||
user *libregraph.User
|
||||
user *libregraph.User
|
||||
userUpdate *libregraph.UserUpdate
|
||||
expectedUser *libregraph.User
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
user = &libregraph.User{}
|
||||
user.SetDisplayName("Display Name")
|
||||
user.SetOnPremisesSamAccountName("user")
|
||||
user = libregraph.NewUser("Display Name", "user")
|
||||
user.SetMail("user@example.com")
|
||||
user.SetId("/users/user")
|
||||
|
||||
userUpdate = libregraph.NewUserUpdate()
|
||||
userUpdate.SetId(user.GetId())
|
||||
|
||||
expectedUser = libregraph.NewUser("Display Name", "user")
|
||||
expectedUser.SetMail(user.GetMail())
|
||||
expectedUser.SetId(user.GetId())
|
||||
|
||||
identityBackend.On("GetUser", mock.Anything, mock.Anything, mock.Anything).Return(user, nil)
|
||||
})
|
||||
|
||||
@@ -1065,13 +1064,13 @@ var _ = Describe("Users", func() {
|
||||
})
|
||||
|
||||
It("handles invalid email", func() {
|
||||
user.SetMail("invalid")
|
||||
data, err := json.Marshal(user)
|
||||
userUpdate.SetMail("invalid")
|
||||
data, err := json.Marshal(userUpdate)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "/graph/v1.0/users?$invalid=true", bytes.NewBuffer(data))
|
||||
rctx := chi.NewRouteContext()
|
||||
rctx.URLParams.Add("userID", user.GetId())
|
||||
rctx.URLParams.Add("userID", userUpdate.GetId())
|
||||
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
|
||||
svc.PatchUser(rr, r)
|
||||
|
||||
@@ -1079,13 +1078,13 @@ var _ = Describe("Users", func() {
|
||||
})
|
||||
|
||||
It("handles invalid userType", func() {
|
||||
user.SetUserType("Clown")
|
||||
data, err := json.Marshal(user)
|
||||
userUpdate.SetUserType("Clown")
|
||||
data, err := json.Marshal(userUpdate)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "/graph/v1.0/users?$invalid=true", bytes.NewBuffer(data))
|
||||
rctx := chi.NewRouteContext()
|
||||
rctx.URLParams.Add("userID", user.GetId())
|
||||
rctx.URLParams.Add("userID", userUpdate.GetId())
|
||||
r = r.WithContext(context.WithValue(revactx.ContextSetUser(ctx, currentUser), chi.RouteCtxKey, rctx))
|
||||
svc.PatchUser(rr, r)
|
||||
|
||||
@@ -1093,12 +1092,14 @@ var _ = Describe("Users", func() {
|
||||
})
|
||||
|
||||
It("updates attributes", func() {
|
||||
user.SetUserType("Member")
|
||||
identityBackend.On("UpdateUser", mock.Anything, user.GetId(), mock.Anything).Return(user, nil)
|
||||
userUpdate.SetUserType("Member")
|
||||
userUpdate.SetDisplayName("New Display Name")
|
||||
|
||||
user.SetUserType(("Member"))
|
||||
user.SetDisplayName("New Display Name")
|
||||
data, err := json.Marshal(user)
|
||||
expectedUser.SetUserType("Member")
|
||||
expectedUser.SetDisplayName("New Display Name")
|
||||
identityBackend.On("UpdateUser", mock.Anything, userUpdate.GetId(), mock.Anything).Return(expectedUser, nil)
|
||||
|
||||
data, err := json.Marshal(userUpdate)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
r := httptest.NewRequest(http.MethodPost, "/graph/v1.0/users", bytes.NewBuffer(data))
|
||||
@@ -1111,11 +1112,11 @@ var _ = Describe("Users", func() {
|
||||
data, err = io.ReadAll(rr.Body)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
updatedUser := libregraph.User{}
|
||||
err = json.Unmarshal(data, &updatedUser)
|
||||
unmarshaledUser := libregraph.User{}
|
||||
err = json.Unmarshal(data, &unmarshaledUser)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(updatedUser.GetUserType()).To(Equal("Member"))
|
||||
Expect(updatedUser.GetDisplayName()).To(Equal("New Display Name"))
|
||||
Expect(unmarshaledUser.GetUserType()).To(Equal("Member"))
|
||||
Expect(unmarshaledUser.GetDisplayName()).To(Equal("New Display Name"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -68,7 +68,7 @@ func (b Backend) CreateUser(ctx context.Context, invitation *invitations.Invitat
|
||||
user := &libregraph.User{
|
||||
Mail: &invitation.InvitedUserEmailAddress,
|
||||
AccountEnabled: boolP(true),
|
||||
OnPremisesSamAccountName: &invitation.InvitedUserEmailAddress,
|
||||
OnPremisesSamAccountName: invitation.InvitedUserEmailAddress,
|
||||
Id: stringP(u.String()),
|
||||
UserType: stringP(userType),
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ func (c *cs3backend) CreateUserFromClaims(ctx context.Context, claims map[string
|
||||
newUser, err := c.libregraphUserFromClaims(claims)
|
||||
if err != nil {
|
||||
c.logger.Error().Err(err).Interface("claims", claims).Msg("Error creating user from claims")
|
||||
return nil, fmt.Errorf("Error creating user from claims: %w", err)
|
||||
return nil, fmt.Errorf("error creating user from claims: %w", err)
|
||||
}
|
||||
|
||||
req := lgClient.UsersApi.CreateUser(newctx).User(newUser)
|
||||
@@ -242,11 +242,16 @@ func (c cs3backend) UpdateUserIfNeeded(ctx context.Context, user *cs3.User, clai
|
||||
|
||||
// Check if the user needs to be updated, only updates of "displayName" and "mail" are supported
|
||||
// currently.
|
||||
userupdate := libregraph.NewUserUpdate()
|
||||
switch {
|
||||
case newUser.GetDisplayName() != user.GetDisplayName():
|
||||
fallthrough
|
||||
userupdate.SetDisplayName(newUser.GetDisplayName())
|
||||
case newUser.GetMail() != user.GetMail():
|
||||
return c.updateLibregraphUser(user.GetId().GetOpaqueId(), newUser)
|
||||
userupdate.SetMail(newUser.GetMail())
|
||||
}
|
||||
|
||||
if userupdate.HasDisplayName() || userupdate.HasMail() {
|
||||
return c.updateLibregraphUser(user.GetId().GetOpaqueId(), *userupdate)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -389,7 +394,7 @@ func (c cs3backend) getLibregraphGroup(ctx context.Context, client *libregraph.A
|
||||
return lgGroup, nil
|
||||
}
|
||||
|
||||
func (c cs3backend) updateLibregraphUser(userid string, user libregraph.User) error {
|
||||
func (c cs3backend) updateLibregraphUser(userid string, user libregraph.UserUpdate) error {
|
||||
gatewayClient, err := c.gatewaySelector.Next()
|
||||
if err != nil {
|
||||
c.logger.Error().Err(err).Msg("could not select next gateway client")
|
||||
@@ -408,7 +413,7 @@ func (c cs3backend) updateLibregraphUser(userid string, user libregraph.User) er
|
||||
return err
|
||||
}
|
||||
|
||||
req := lgClient.UserApi.UpdateUser(newctx, userid).User(user)
|
||||
req := lgClient.UserApi.UpdateUser(newctx, userid).UserUpdate(user)
|
||||
|
||||
_, resp, err := req.Execute()
|
||||
defer resp.Body.Close()
|
||||
@@ -420,7 +425,7 @@ func (c cs3backend) updateLibregraphUser(userid string, user libregraph.User) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c cs3backend) setupLibregraphClient(ctx context.Context, cs3token string) (*libregraph.APIClient, error) {
|
||||
func (c cs3backend) setupLibregraphClient(_ context.Context, cs3token string) (*libregraph.APIClient, error) {
|
||||
// Use micro registry to resolve next graph service endpoint
|
||||
next, err := c.graphSelector.Select("com.owncloud.web.graph")
|
||||
if err != nil {
|
||||
@@ -469,12 +474,12 @@ func (c cs3backend) libregraphUserFromClaims(claims map[string]interface{}) (lib
|
||||
if dn, ok := claims[c.autoProvisionClaims.DisplayName].(string); ok {
|
||||
user.SetDisplayName(dn)
|
||||
} else {
|
||||
return user, fmt.Errorf("Missing claim '%s' (displayName)", c.autoProvisionClaims.DisplayName)
|
||||
return user, fmt.Errorf("missing claim '%s' (displayName)", c.autoProvisionClaims.DisplayName)
|
||||
}
|
||||
if username, ok := claims[c.autoProvisionClaims.Username].(string); ok {
|
||||
user.SetOnPremisesSamAccountName(username)
|
||||
} else {
|
||||
return user, fmt.Errorf("Missing claim '%s' (username)", c.autoProvisionClaims.Username)
|
||||
return user, fmt.Errorf("missing claim '%s' (username)", c.autoProvisionClaims.Username)
|
||||
}
|
||||
// Email is optional so we don't need an 'else' here
|
||||
if mail, ok := claims[c.autoProvisionClaims.Email].(string); ok {
|
||||
@@ -494,7 +499,7 @@ func (c cs3backend) libregraphUserFromClaims(claims map[string]interface{}) (lib
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (c cs3backend) cs3UserFromLibregraph(ctx context.Context, lu *libregraph.User) cs3.User {
|
||||
func (c cs3backend) cs3UserFromLibregraph(_ context.Context, lu *libregraph.User) cs3.User {
|
||||
cs3id := cs3.UserId{
|
||||
Type: cs3.UserType_USER_TYPE_PRIMARY,
|
||||
Idp: c.oidcISS,
|
||||
|
||||
Reference in New Issue
Block a user