Remove code references to members

This commit is contained in:
Ben Visness 2021-04-16 19:01:13 -05:00
parent 97a80e7c4f
commit 6ed2bd0c02
7 changed files with 57 additions and 69 deletions

View File

@ -1,22 +0,0 @@
package models
type Member struct {
UserID int
Name *string `db:"name"` // TODO: Migrate to not null
Bio *string `db:"bio"`
Blurb *string `db:"blurb"`
Signature *string `db:"signature"`
Avatar *string `db:"avatar"` // TODO: Image field stuff?
DarkTheme bool `db:"darktheme"`
Timezone string `db:"timezone"`
ProfileColor1 string `db:"color_1"`
ProfileColor2 string `db:"color_2"`
ShowEmail bool `db:"showemail"`
CanEditLibrary bool `db:"edit_library"`
DiscordSaveShowcase bool `db:"discord_save_showcase"`
DiscordDeleteSnippetOnMessageDelete bool `db:"discord_delete_snippet_on_message_delete"`
}

View File

@ -20,4 +20,21 @@ type User struct {
IsSuperuser bool `db:"is_superuser"` IsSuperuser bool `db:"is_superuser"`
IsStaff bool `db:"is_staff"` IsStaff bool `db:"is_staff"`
IsActive bool `db:"is_active"` IsActive bool `db:"is_active"`
Name string `db:"name"`
Bio string `db:"bio"`
Blurb string `db:"blurb"`
Signature string `db:"signature"`
Avatar *string `db:"avatar"` // TODO: Image field stuff?
DarkTheme bool `db:"darktheme"`
Timezone string `db:"timezone"`
ProfileColor1 string `db:"color_1"`
ProfileColor2 string `db:"color_2"`
ShowEmail bool `db:"showemail"`
CanEditLibrary bool `db:"edit_library"`
DiscordSaveShowcase bool `db:"discord_save_showcase"`
DiscordDeleteSnippetOnMessageDelete bool `db:"discord_delete_snippet_on_message_delete"`
} }

View File

@ -2,23 +2,6 @@ package templates
import "git.handmade.network/hmn/hmn/src/models" import "git.handmade.network/hmn/hmn/src/models"
func MemberToTemplate(m *models.Member) Member {
return Member{
Name: maybeString(m.Name),
Blurb: maybeString(m.Blurb),
Signature: maybeString(m.Signature),
DarkTheme: m.DarkTheme,
Timezone: m.Timezone,
ProfileColor1: m.ProfileColor1,
ProfileColor2: m.ProfileColor2,
CanEditLibrary: m.CanEditLibrary,
DiscordSaveShowcase: m.DiscordSaveShowcase,
DiscordDeleteSnippetOnMessageDelete: m.DiscordDeleteSnippetOnMessageDelete,
}
}
func PostToTemplate(p *models.Post) Post { func PostToTemplate(p *models.Post) Post {
return Post{ return Post{
Preview: p.Preview, Preview: p.Preview,
@ -48,6 +31,19 @@ func UserToTemplate(u *models.User) User {
Email: u.Email, Email: u.Email,
IsSuperuser: u.IsSuperuser, IsSuperuser: u.IsSuperuser,
IsStaff: u.IsStaff, IsStaff: u.IsStaff,
Name: u.Name,
Blurb: u.Blurb,
Signature: u.Signature,
DarkTheme: u.DarkTheme,
Timezone: u.Timezone,
ProfileColor1: u.ProfileColor1,
ProfileColor2: u.ProfileColor2,
CanEditLibrary: u.CanEditLibrary,
DiscordSaveShowcase: u.DiscordSaveShowcase,
DiscordDeleteSnippetOnMessageDelete: u.DiscordDeleteSnippetOnMessageDelete,
} }
} }

View File

@ -12,22 +12,6 @@ type BaseData struct {
User *User User *User
} }
type Member struct {
Name string
Blurb string
Signature string
// Avatar??
DarkTheme bool
Timezone string
ProfileColor1 string
ProfileColor2 string
CanEditLibrary bool
DiscordSaveShowcase bool
DiscordDeleteSnippetOnMessageDelete bool
}
type Post struct { type Post struct {
Preview string Preview string
ReadOnly bool ReadOnly bool
@ -54,6 +38,20 @@ type User struct {
Email string Email string
IsSuperuser bool IsSuperuser bool
IsStaff bool IsStaff bool
Name string
Blurb string
Signature string
// TODO: Avatar??
DarkTheme bool
Timezone string
ProfileColor1 string
ProfileColor2 string
CanEditLibrary bool
DiscordSaveShowcase bool
DiscordDeleteSnippetOnMessageDelete bool
} }
type OpenGraphItem struct { type OpenGraphItem struct {

View File

@ -55,6 +55,11 @@ func Index(c *RequestContext) ResponseData {
allProjects := iterProjects.ToSlice() allProjects := iterProjects.ToSlice()
c.Logger.Info().Interface("allProjects", allProjects).Msg("all the projects") c.Logger.Info().Interface("allProjects", allProjects).Msg("all the projects")
var currentUserId *int
if c.CurrentUser != nil {
currentUserId = &c.CurrentUser.ID
}
for _, projRow := range allProjects { for _, projRow := range allProjects {
proj := projRow.(*models.Project) proj := projRow.(*models.Project)
@ -64,7 +69,6 @@ func Index(c *RequestContext) ResponseData {
CatLastReadTime *time.Time `db:"clri.lastread"` CatLastReadTime *time.Time `db:"clri.lastread"`
} }
memberId := 3 // TODO: NO
projectPostIter, err := db.Query(c.Context(), c.Conn, ProjectPost{}, projectPostIter, err := db.Query(c.Context(), c.Conn, ProjectPost{},
` `
SELECT $columns SELECT $columns
@ -74,11 +78,11 @@ func Index(c *RequestContext) ResponseData {
JOIN handmade_category AS cat ON cat.id = thread.category_id JOIN handmade_category AS cat ON cat.id = thread.category_id
LEFT OUTER JOIN handmade_threadlastreadinfo AS tlri ON ( LEFT OUTER JOIN handmade_threadlastreadinfo AS tlri ON (
tlri.thread_id = thread.id tlri.thread_id = thread.id
AND tlri.member_id = $1 AND tlri.user_id = $1
) )
LEFT OUTER JOIN handmade_categorylastreadinfo AS clri ON ( LEFT OUTER JOIN handmade_categorylastreadinfo AS clri ON (
clri.category_id = cat.id clri.category_id = cat.id
AND clri.member_id = $1 AND clri.user_id = $1
) )
WHERE WHERE
cat.project_id = $2 cat.project_id = $2
@ -88,7 +92,7 @@ func Index(c *RequestContext) ResponseData {
ORDER BY postdate DESC ORDER BY postdate DESC
LIMIT $7 LIMIT $7
`, `,
memberId, currentUserId,
proj.ID, proj.ID,
models.CatTypeBlog, models.CatTypeForum, models.CatTypeWiki, models.CatTypeLibraryResource, models.CatTypeBlog, models.CatTypeForum, models.CatTypeWiki, models.CatTypeLibraryResource,
maxPosts, maxPosts,

View File

@ -49,7 +49,6 @@ type RequestContext struct {
Conn *pgxpool.Pool Conn *pgxpool.Pool
CurrentProject *models.Project CurrentProject *models.Project
CurrentUser *models.User CurrentUser *models.User
// CurrentMember *models.Member
} }
func NewRequestContext(rw http.ResponseWriter, req *http.Request, pathParams httprouter.Params) *RequestContext { func NewRequestContext(rw http.ResponseWriter, req *http.Request, pathParams httprouter.Params) *RequestContext {

View File

@ -278,9 +278,9 @@ func CommonWebsiteDataWrapper(c *RequestContext) (bool, ResponseData) {
sessionCookie, err := c.Req.Cookie(auth.SessionCookieName) sessionCookie, err := c.Req.Cookie(auth.SessionCookieName)
if err == nil { if err == nil {
user, err := getCurrentUserAndMember(c, sessionCookie.Value) user, err := getCurrentUser(c, sessionCookie.Value)
if err != nil { if err != nil {
return false, ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to get current user and member")) return false, ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to get current user"))
} }
c.CurrentUser = user c.CurrentUser = user
@ -290,11 +290,9 @@ func CommonWebsiteDataWrapper(c *RequestContext) (bool, ResponseData) {
return true, ResponseData{} return true, ResponseData{}
} }
// Given a session id, fetches user and member data from the database. Will return nil for // Given a session id, fetches user data from the database. Will return nil if
// both if neither can be found, and will only return an error if it's serious. // the user cannot be found, and will only return an error if it's serious.
// func getCurrentUser(c *RequestContext, sessionId string) (*models.User, error) {
// TODO: actually return members :)
func getCurrentUserAndMember(c *RequestContext, sessionId string) (*models.User, error) {
session, err := auth.GetSession(c.Context(), c.Conn, sessionId) session, err := auth.GetSession(c.Context(), c.Conn, sessionId)
if err != nil { if err != nil {
if errors.Is(err, auth.ErrNoSession) { if errors.Is(err, auth.ErrNoSession) {
@ -315,7 +313,5 @@ func getCurrentUserAndMember(c *RequestContext, sessionId string) (*models.User,
} }
user := userRow.(*models.User) user := userRow.(*models.User)
// TODO: Also get the member model
return user, nil return user, nil
} }