diff --git a/backend/internal/dto/user_dto.go b/backend/internal/dto/user_dto.go index e337528f..545e4ccc 100644 --- a/backend/internal/dto/user_dto.go +++ b/backend/internal/dto/user_dto.go @@ -23,6 +23,7 @@ type UserDto struct { } type UserCreateDto struct { + ID string `json:"id" binding:"omitempty,uuid"` Username string `json:"username" binding:"required,username,min=1,max=50" unorm:"nfc"` Email *string `json:"email" binding:"omitempty,email" unorm:"nfc"` EmailVerified bool `json:"emailVerified"` diff --git a/backend/internal/dto/user_dto_test.go b/backend/internal/dto/user_dto_test.go index 62dd6188..87b76b37 100644 --- a/backend/internal/dto/user_dto_test.go +++ b/backend/internal/dto/user_dto_test.go @@ -23,6 +23,18 @@ func TestUserCreateDto_Validate(t *testing.T) { }, wantErr: "", }, + { + name: "with custom id", + input: UserCreateDto{ + ID: "e8b81981-1c92-46e3-bfbf-07096560e6bb", + Username: "testuser", + Email: new("test@example.com"), + FirstName: "John", + LastName: "Doe", + DisplayName: "John Doe", + }, + wantErr: "", + }, { name: "missing username", input: UserCreateDto{ diff --git a/backend/internal/service/user_service.go b/backend/internal/service/user_service.go index 34a1ee07..09740f83 100644 --- a/backend/internal/service/user_service.go +++ b/backend/internal/service/user_service.go @@ -285,6 +285,9 @@ func (s *UserService) createUserInternal(ctx context.Context, input dto.UserCrea Disabled: input.Disabled, UserGroups: userGroups, } + if input.ID != "" { + user.ID = input.ID + } if input.LdapID != "" { user.LdapID = &input.LdapID }