completed member export and removed some "breaking" bugs, still work to be done on the XML output

This commit is contained in:
2026-02-26 16:19:24 -07:00
parent c74563be51
commit 344562c55c
10 changed files with 141 additions and 23 deletions
+12 -12
View File
@@ -199,12 +199,12 @@ type VCKey struct {
func VCardFromContactInfo(ctx context.Context, target *VCard, ci *database.ContactInfo) error {
target.Version = "2.0"
target.FullName = ci.FullName(false)
target.Name.Family = util.IIF(ci.FamilyName != nil, *ci.FamilyName, "")
target.Name.Given = util.IIF(ci.GivenName != nil, *ci.GivenName, "")
target.Name.Middle = util.IIF(ci.MiddleInit != nil, *ci.MiddleInit+".", "")
target.Name.Prefix = util.IIF(ci.Prefix != nil, *ci.Prefix, "")
target.Name.Suffix = util.IIF(ci.Suffix != nil, *ci.Suffix, "")
target.URL = util.IIF(ci.URL != nil, *ci.URL, "")
target.Name.Family = util.SRef(ci.FamilyName)
target.Name.Given = util.SRef(ci.GivenName)
target.Name.Middle = util.SRef(ci.MiddleInit)
target.Name.Prefix = util.SRef(ci.Prefix)
target.Name.Suffix = util.SRef(ci.Suffix)
target.URL = util.SRef(ci.URL)
if ci.LastUpdate != nil {
target.LastUpdate = ci.LastUpdate.Format(ISO8601)
}
@@ -213,12 +213,12 @@ func VCardFromContactInfo(ctx context.Context, target *VCard, ci *database.Conta
addr[0].Home.Local = "HOME"
addr[0].Postal.Local = "POSTAL"
addr[0].Preferred.Local = "PREF"
addr[0].Street = util.IIF(ci.Addr1 != nil, *ci.Addr1, "")
addr[0].ExtAddr = util.IIF(ci.Addr2 != nil, *ci.Addr2, "")
addr[0].Locality = util.IIF(ci.Locality != nil, *ci.Locality, "")
addr[0].Region = util.IIF(ci.Region != nil, *ci.Region, "")
addr[0].PCode = util.IIF(ci.PostalCode != nil, *ci.PostalCode, "")
addr[0].Country = util.IIF(ci.Country != nil, *ci.Country, "")
addr[0].Street = util.SRef(ci.Addr1)
addr[0].ExtAddr = util.SRef(ci.Addr2)
addr[0].Locality = util.SRef(ci.Locality)
addr[0].Region = util.SRef(ci.Region)
addr[0].PCode = util.SRef(ci.PostalCode)
addr[0].Country = util.SRef(ci.Country)
target.Address = &addr
phcount := util.IIF(ci.Phone != nil, 1, 0) + util.IIF(ci.Fax != nil, 1, 0) + util.IIF(ci.Mobile != nil, 1, 0)
+62 -2
View File
@@ -12,6 +12,9 @@ package exports
import (
"context"
"encoding/xml"
"fmt"
"io"
"strings"
"git.erbosoft.com/amy/amsterdam/database"
"git.erbosoft.com/amy/amsterdam/util"
@@ -73,6 +76,7 @@ type VIUCommunityJoin struct {
Community string `xml:",chardata"` // name of community joined
}
// VIUUserFromUser fills in a VIUUser structure with details from the given user.
func VIUUserFromUser(ctx context.Context, target *VIUUser, u *database.User) error {
// Fill base fields first.
target.ID = int(u.Uid)
@@ -80,7 +84,7 @@ func VIUUserFromUser(ctx context.Context, target *VIUUser, u *database.User) err
target.Password.Prehashed = true
target.Password.Hash = u.Passhash
target.PasswordReminder = u.PassReminder
target.Description = util.IIF(u.Description != nil, *u.Description, "")
target.Description = util.SRef(u.Description)
// Get the contact info.
ci, err := u.ContactInfo(ctx)
@@ -126,10 +130,66 @@ func VIUUserFromUser(ctx context.Context, target *VIUUser, u *database.User) err
return err
}
// Fill options from user flags.
target.Options.PostPictures = flags.Get(database.UserFlagPicturesInPosts)
target.Options.OptOut = flags.Get(database.UserFlagMassMailOptOut)
target.Options.NoPhoto = flags.Get(database.UserFlagDisallowSetPhoto)
// TODO - fill in Joins
// Get the list of communities for the user and set up the Joins list.
comms, err := database.AmGetCommunitiesForUser(ctx, u.Uid)
if err != nil {
return err
}
target.Joins = make([]VIUCommunityJoin, len(comms))
roles := database.AmRoleList("Community.AllUserlevels")
for i, c := range comms {
_, _, level, err := c.Membership(ctx, u)
if err != nil {
return err
}
target.Joins[i].Role = roles.FindForLevel(level).ID()
target.Joins[i].Community = c.Alias
}
return nil
}
// VIUStreamCommunityMembersList streams a list of users of the given community to the given stream in VIU format.
func VIUStreamCommunityMemberList(ctx context.Context, w io.Writer, comm *database.Community) error {
// Get the list of community members.
total, err := comm.MemberCount(ctx, false)
if err != nil {
return err
}
users, _, err := comm.ListMembers(ctx, database.ListMembersFieldNone, database.ListMembersOperNone, "", 0, total, false)
if err != nil {
return err
}
// Write the header of the file.
var b strings.Builder
b.WriteString(xml.Header)
b.WriteString("\r\n<venice-import-users>\r\n")
_, err = w.Write([]byte(b.String()))
if err != nil {
return err
}
// Create the XML encoder.
enc := xml.NewEncoder(w)
enc.Indent(" ", " ")
// Build each user and then encode them to the output.
for _, u := range users {
var encodedUser VIUUser
err = VIUUserFromUser(ctx, &encodedUser, u)
if err != nil {
return fmt.Errorf("error converting user %d: %v", u.Uid, err)
}
enc.Encode(encodedUser)
}
// Write the trailing tag.
_, err = w.Write([]byte("</venice-import-users>\r\n"))
return err
}