Open platform to collect and prioritize feedback
Only include email when listing the members.
Matt Roberts35ef53e052ca
diff --git a/app/handlers/admin.go b/app/handlers/admin.goindex 9bdae3174..38959925b 100644--- a/app/handlers/admin.go+++ b/app/handlers/admin.go@@ -5,6 +5,7 @@ import ("github.com/getfider/fider/app/actions""github.com/getfider/fider/app/models/cmd"+ "github.com/getfider/fider/app/models/entity""github.com/getfider/fider/app/models/query""github.com/getfider/fider/app/pkg/bus""github.com/getfider/fider/app/pkg/web"@@ -126,11 +127,19 @@ func ManageMembers() web.HandlerFunc {return c.Failure(err)}+ // Create an array of UserWithEmail structs from the allUsers.Result+ allUsersWithEmail := make([]entity.UserWithEmail, len(allUsers.Result))+ for i, user := range allUsers.Result {+ allUsersWithEmail[i] = entity.UserWithEmail{+ User: user,+ }+ }+return c.Page(http.StatusOK, web.Props{Page: "Administration/pages/ManageMembers.page",Title: "Manage Members · Site Settings",Data: web.Map{- "users": allUsers.Result,+ "users": allUsersWithEmail,},})}diff --git a/app/models/entity/user.go b/app/models/entity/user.goindex 5e6df4923..8e270e293 100644--- a/app/models/entity/user.go+++ b/app/models/entity/user.go@@ -1,13 +1,17 @@package entity-import "github.com/getfider/fider/app/models/enum"+import (+ "encoding/json"++ "github.com/getfider/fider/app/models/enum"+)// User represents an user inside our applicationtype User struct {ID int `json:"id"`Name string `json:"name"`Tenant *Tenant `json:"-"`- Email string `json:"email"`+ Email string `json:"-"`Role enum.Role `json:"role"`Providers []*UserProvider `json:"-"`AvatarBlobKey string `json:"-"`@@ -41,3 +45,19 @@ type UserProvider struct {Name stringUID string}++// UserWithEmail is a wrapper around User that includes the email field when marshaling to JSON+type UserWithEmail struct {+ *User+}++func (umc UserWithEmail) MarshalJSON() ([]byte, error) {+ type Alias User // Prevent recursion+ return json.Marshal(&struct {+ *Alias+ Email string `json:"email"`+ }{+ Alias: (*Alias)(umc.User),+ Email: umc.User.Email,+ })+}diff --git a/app/models/entity/user_test.go b/app/models/entity/user_test.gonew file mode 100644index 000000000..af391886b--- /dev/null+++ b/app/models/entity/user_test.go@@ -0,0 +1,55 @@+package entity_test++import (+ "encoding/json"+ "testing"++ "github.com/getfider/fider/app/models/entity"+ . "github.com/getfider/fider/app/pkg/assert"+)++func TestUserWithEmail_MarshalJSON(t *testing.T) {++ RegisterT(t)+ user := entity.UserWithEmail{+ User: &entity.User{+ ID: 1,+ Name: "John Doe",+ Email: "[email protected]",+ Role: 1,+ Status: 1,+ },+ }++ expectedJSON := `{"id":1,"name":"John Doe","role":"visitor","status":"active","email":"[email protected]"}`++ jsonData, err := json.Marshal(user)+ if err != nil {+ t.Errorf("Failed to marshal user to JSON: %v", err)+ }++ Expect(string(jsonData)).Equals(expectedJSON)++}++func TestUser_MarshalJSON(t *testing.T) {++ RegisterT(t)+ user := entity.User{+ ID: 1,+ Name: "John Doe",+ Email: "[email protected]",+ Role: 1,+ Status: 1,+ }++ expectedJSON := `{"id":1,"name":"John Doe","role":"visitor","status":"active"}`++ jsonData, err := json.Marshal(user)+ if err != nil {+ t.Errorf("Failed to marshal user to JSON: %v", err)+ }++ Expect(string(jsonData)).Equals(expectedJSON)++}