Merge pull request #1363 from mattermost/plt-664

PLT-664 Omit unneeded fields from user object in getProfiles service
Этот коммит содержится в:
Christopher Speller
2015-11-10 08:06:11 -05:00
родитель 140952575b c07c266b27
Коммит c6065a2b02
4 изменённых файлов: 35 добавлений и 22 удалений

Просмотреть файл

@@ -669,6 +669,7 @@ func getProfiles(c *Context, w http.ResponseWriter, r *http.Request) {
} }
p.Sanitize(options) p.Sanitize(options)
p.ClearNonProfileFields()
profiles[k] = p profiles[k] = p
} }

Просмотреть файл

@@ -26,7 +26,6 @@ type Post struct {
ParentId string `json:"parent_id"` ParentId string `json:"parent_id"`
OriginalId string `json:"original_id"` OriginalId string `json:"original_id"`
Message string `json:"message"` Message string `json:"message"`
ImgCount int64 `json:"img_count"`
Type string `json:"type"` Type string `json:"type"`
Props StringInterface `json:"props"` Props StringInterface `json:"props"`
Hashtags string `json:"hashtags"` Hashtags string `json:"hashtags"`

Просмотреть файл

@@ -28,29 +28,29 @@ const (
type User struct { type User struct {
Id string `json:"id"` Id string `json:"id"`
CreateAt int64 `json:"create_at"` CreateAt int64 `json:"create_at,omitempty"`
UpdateAt int64 `json:"update_at"` UpdateAt int64 `json:"update_at,omitempty"`
DeleteAt int64 `json:"delete_at"` DeleteAt int64 `json:"delete_at"`
TeamId string `json:"team_id"` TeamId string `json:"team_id"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password,omitempty"`
AuthData string `json:"auth_data"` AuthData string `json:"auth_data,omitempty"`
AuthService string `json:"auth_service"` AuthService string `json:"auth_service,omitempty"`
Email string `json:"email"` Email string `json:"email"`
EmailVerified bool `json:"email_verified"` EmailVerified bool `json:"email_verified,omitempty"`
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` LastName string `json:"last_name"`
Roles string `json:"roles"` Roles string `json:"roles"`
LastActivityAt int64 `json:"last_activity_at"` LastActivityAt int64 `json:"last_activity_at,omitempty"`
LastPingAt int64 `json:"last_ping_at"` LastPingAt int64 `json:"last_ping_at,omitempty"`
AllowMarketing bool `json:"allow_marketing"` AllowMarketing bool `json:"allow_marketing,omitempty"`
Props StringMap `json:"props"` Props StringMap `json:"props,omitempty"`
NotifyProps StringMap `json:"notify_props"` NotifyProps StringMap `json:"notify_props,omitempty"`
ThemeProps StringMap `json:"theme_props"` ThemeProps StringMap `json:"theme_props,omitempty"`
LastPasswordUpdate int64 `json:"last_password_update"` LastPasswordUpdate int64 `json:"last_password_update,omitempty"`
LastPictureUpdate int64 `json:"last_picture_update"` LastPictureUpdate int64 `json:"last_picture_update,omitempty"`
FailedAttempts int `json:"failed_attempts"` FailedAttempts int `json:"failed_attempts,omitempty"`
} }
// IsValid validates the user and returns an error if it isn't configured // IsValid validates the user and returns an error if it isn't configured
@@ -221,17 +221,29 @@ func (u *User) Sanitize(options map[string]bool) {
u.FirstName = "" u.FirstName = ""
u.LastName = "" u.LastName = ""
} }
if len(options) != 0 && !options["skypeid"] {
// TODO - fill in when SkypeId is added to user model
}
if len(options) != 0 && !options["phonenumber"] {
// TODO - fill in when PhoneNumber is added to user model
}
if len(options) != 0 && !options["passwordupdate"] { if len(options) != 0 && !options["passwordupdate"] {
u.LastPasswordUpdate = 0 u.LastPasswordUpdate = 0
} }
} }
func (u *User) ClearNonProfileFields() {
u.CreateAt = 0
u.UpdateAt = 0
u.Password = ""
u.AuthData = ""
u.AuthService = ""
u.EmailVerified = false
u.LastActivityAt = 0
u.LastPingAt = 0
u.AllowMarketing = false
u.Props = StringMap{}
u.NotifyProps = StringMap{}
u.ThemeProps = StringMap{}
u.LastPasswordUpdate = 0
u.LastPictureUpdate = 0
u.FailedAttempts = 0
}
func (u *User) MakeNonNil() { func (u *User) MakeNonNil() {
if u.Props == nil { if u.Props == nil {
u.Props = make(map[string]string) u.Props = make(map[string]string)

Просмотреть файл

@@ -38,6 +38,7 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore {
} }
func (s SqlPostStore) UpgradeSchemaIfNeeded() { func (s SqlPostStore) UpgradeSchemaIfNeeded() {
s.RemoveColumnIfExists("Posts", "ImgCount") // remove after 1.3 release
} }
func (s SqlPostStore) CreateIndexesIfNotExists() { func (s SqlPostStore) CreateIndexesIfNotExists() {