adds no password return by default, model cares about password but nothing downstream does
Some checks failed
gitea-deepak/gogmagog/pipeline/head There was a failure building this commit
Some checks failed
gitea-deepak/gogmagog/pipeline/head There was a failure building this commit
This commit is contained in:
parent
3ea8603368
commit
1d45635530
@ -44,7 +44,7 @@ func (ms *multiStore) SelectActionsByPlanID(plan *models.Plan) ([]*models.Action
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ms *multiStore) SelectUserByID(id int) (*models.User, error) {
|
func (ms *multiStore) SelectUserByID(id int) (*models.User, error) {
|
||||||
return nil, nil
|
return &models.User{UserID: int64(id), Username: "test", DisplayName: "Ted Est", Password: []byte("oh no")}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *multiStore) ConnectionLive() error {
|
func (ms *multiStore) ConnectionLive() error {
|
||||||
|
@ -3,19 +3,31 @@ package models
|
|||||||
// User represents the full DB user field, for inserts and compares.
|
// User represents the full DB user field, for inserts and compares.
|
||||||
// No reason to return the hashed pw on the route though.
|
// No reason to return the hashed pw on the route though.
|
||||||
type User struct {
|
type User struct {
|
||||||
|
UserID int64
|
||||||
|
Username string
|
||||||
|
DisplayName string
|
||||||
|
Password []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserNoPassword struct {
|
||||||
UserID int64 `json:"user_id"`
|
UserID int64 `json:"user_id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
Password []byte `json:"password"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// User returns a single plan from the store by plan_id.
|
// User returns a single plan from the store by plan_id.
|
||||||
func (m *Model) User(id int) (*User, error) {
|
func (m *Model) User(id int) (*UserNoPassword, error) {
|
||||||
user, err := m.SelectUserByID(id)
|
user, err := m.SelectUserByID(id)
|
||||||
return user, wrapNotFound(err)
|
if user == nil {
|
||||||
|
return nil, wrapNotFound(err)
|
||||||
|
}
|
||||||
|
return user.NoPassword(), wrapNotFound(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUser inserts a user into the store.
|
func (u *User) NoPassword() *UserNoPassword {
|
||||||
// func (m *Model) AddUser(u *User) (int, error) {
|
return &UserNoPassword{
|
||||||
// return m.InsertUser(u)
|
UserID: u.UserID,
|
||||||
// }
|
Username: u.Username,
|
||||||
|
DisplayName: u.DisplayName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ package models_test
|
|||||||
import (
|
import (
|
||||||
"gitea.deepak.science/deepak/gogmagog/models"
|
"gitea.deepak.science/deepak/gogmagog/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,5 +19,28 @@ func TestModelUsers(t *testing.T) {
|
|||||||
|
|
||||||
user, err := m.User(3)
|
user, err := m.User(3)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
assert.Nil(user)
|
assert.NotNil(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestErrorUsers(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
m := getErrorModel(fmt.Errorf("err"))
|
||||||
|
|
||||||
|
user, err := m.User(3)
|
||||||
|
assert.Nil(user)
|
||||||
|
assert.NotNil(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserNoPassword(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
id := int64(3)
|
||||||
|
username := "test"
|
||||||
|
displayName := "Ted Est"
|
||||||
|
pass := []byte("abc")
|
||||||
|
u := &models.User{UserID: id, Username: username, DisplayName: displayName, Password: pass}
|
||||||
|
|
||||||
|
unp := u.NoPassword()
|
||||||
|
assert.EqualValues(id, unp.UserID)
|
||||||
|
assert.Equal(username, unp.Username)
|
||||||
|
assert.Equal(displayName, unp.DisplayName)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user