MM-30704: Change to idiomatic receiver names for model.Session (#16298)

```release-note
NONE
```

https://mattermost.atlassian.net/browse/MM-30704
Этот коммит содержится в:
Agniva De Sarker
2020-11-18 20:41:05 +05:30
коммит произвёл GitHub
родитель b30acfdee6
Коммит 09c7f7c445

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

@@ -53,20 +53,20 @@ type Session struct {
// Returns true if the session is unrestricted, which should grant it // Returns true if the session is unrestricted, which should grant it
// with all permissions. This is used for local mode sessions // with all permissions. This is used for local mode sessions
func (me *Session) IsUnrestricted() bool { func (s *Session) IsUnrestricted() bool {
return me.Local return s.Local
} }
func (me *Session) DeepCopy() *Session { func (s *Session) DeepCopy() *Session {
copySession := *me copySession := *s
if me.Props != nil { if s.Props != nil {
copySession.Props = CopyStringMap(me.Props) copySession.Props = CopyStringMap(s.Props)
} }
if me.TeamMembers != nil { if s.TeamMembers != nil {
copySession.TeamMembers = make([]*TeamMember, len(me.TeamMembers)) copySession.TeamMembers = make([]*TeamMember, len(s.TeamMembers))
for index, tm := range me.TeamMembers { for index, tm := range s.TeamMembers {
copySession.TeamMembers[index] = new(TeamMember) copySession.TeamMembers[index] = new(TeamMember)
*copySession.TeamMembers[index] = *tm *copySession.TeamMembers[index] = *tm
} }
@@ -75,45 +75,45 @@ func (me *Session) DeepCopy() *Session {
return &copySession return &copySession
} }
func (me *Session) ToJson() string { func (s *Session) ToJson() string {
b, _ := json.Marshal(me) b, _ := json.Marshal(s)
return string(b) return string(b)
} }
func SessionFromJson(data io.Reader) *Session { func SessionFromJson(data io.Reader) *Session {
var me *Session var s *Session
json.NewDecoder(data).Decode(&me) json.NewDecoder(data).Decode(&s)
return me return s
} }
func (me *Session) PreSave() { func (s *Session) PreSave() {
if me.Id == "" { if s.Id == "" {
me.Id = NewId() s.Id = NewId()
} }
if me.Token == "" { if s.Token == "" {
me.Token = NewId() s.Token = NewId()
} }
me.CreateAt = GetMillis() s.CreateAt = GetMillis()
me.LastActivityAt = me.CreateAt s.LastActivityAt = s.CreateAt
if me.Props == nil { if s.Props == nil {
me.Props = make(map[string]string) s.Props = make(map[string]string)
} }
} }
func (me *Session) Sanitize() { func (s *Session) Sanitize() {
me.Token = "" s.Token = ""
} }
func (me *Session) IsExpired() bool { func (s *Session) IsExpired() bool {
if me.ExpiresAt <= 0 { if s.ExpiresAt <= 0 {
return false return false
} }
if GetMillis() > me.ExpiresAt { if GetMillis() > s.ExpiresAt {
return true return true
} }
@@ -123,25 +123,25 @@ func (me *Session) IsExpired() bool {
// Deprecated: SetExpireInDays is deprecated and should not be used. // Deprecated: SetExpireInDays is deprecated and should not be used.
// Use (*App).SetSessionExpireInDays instead which handles the // Use (*App).SetSessionExpireInDays instead which handles the
// cases where the new ExpiresAt is not relative to CreateAt. // cases where the new ExpiresAt is not relative to CreateAt.
func (me *Session) SetExpireInDays(days int) { func (s *Session) SetExpireInDays(days int) {
if me.CreateAt == 0 { if s.CreateAt == 0 {
me.ExpiresAt = GetMillis() + (1000 * 60 * 60 * 24 * int64(days)) s.ExpiresAt = GetMillis() + (1000 * 60 * 60 * 24 * int64(days))
} else { } else {
me.ExpiresAt = me.CreateAt + (1000 * 60 * 60 * 24 * int64(days)) s.ExpiresAt = s.CreateAt + (1000 * 60 * 60 * 24 * int64(days))
} }
} }
func (me *Session) AddProp(key string, value string) { func (s *Session) AddProp(key string, value string) {
if me.Props == nil { if s.Props == nil {
me.Props = make(map[string]string) s.Props = make(map[string]string)
} }
me.Props[key] = value s.Props[key] = value
} }
func (me *Session) GetTeamByTeamId(teamId string) *TeamMember { func (s *Session) GetTeamByTeamId(teamId string) *TeamMember {
for _, team := range me.TeamMembers { for _, team := range s.TeamMembers {
if team.TeamId == teamId { if team.TeamId == teamId {
return team return team
} }
@@ -150,12 +150,12 @@ func (me *Session) GetTeamByTeamId(teamId string) *TeamMember {
return nil return nil
} }
func (me *Session) IsMobileApp() bool { func (s *Session) IsMobileApp() bool {
return len(me.DeviceId) > 0 || me.IsMobile() return len(s.DeviceId) > 0 || s.IsMobile()
} }
func (me *Session) IsMobile() bool { func (s *Session) IsMobile() bool {
val, ok := me.Props[USER_AUTH_SERVICE_IS_MOBILE] val, ok := s.Props[USER_AUTH_SERVICE_IS_MOBILE]
if !ok { if !ok {
return false return false
} }
@@ -167,8 +167,8 @@ func (me *Session) IsMobile() bool {
return isMobile return isMobile
} }
func (me *Session) IsSaml() bool { func (s *Session) IsSaml() bool {
val, ok := me.Props[USER_AUTH_SERVICE_IS_SAML] val, ok := s.Props[USER_AUTH_SERVICE_IS_SAML]
if !ok { if !ok {
return false return false
} }
@@ -180,8 +180,8 @@ func (me *Session) IsSaml() bool {
return isSaml return isSaml
} }
func (me *Session) IsOAuthUser() bool { func (s *Session) IsOAuthUser() bool {
val, ok := me.Props[USER_AUTH_SERVICE_IS_OAUTH] val, ok := s.Props[USER_AUTH_SERVICE_IS_OAUTH]
if !ok { if !ok {
return false return false
} }
@@ -193,26 +193,26 @@ func (me *Session) IsOAuthUser() bool {
return isOAuthUser return isOAuthUser
} }
func (me *Session) IsSSOLogin() bool { func (s *Session) IsSSOLogin() bool {
return me.IsOAuthUser() || me.IsSaml() return s.IsOAuthUser() || s.IsSaml()
} }
func (me *Session) GetUserRoles() []string { func (s *Session) GetUserRoles() []string {
return strings.Fields(me.Roles) return strings.Fields(s.Roles)
} }
func (me *Session) GenerateCSRF() string { func (s *Session) GenerateCSRF() string {
token := NewId() token := NewId()
me.AddProp("csrf", token) s.AddProp("csrf", token)
return token return token
} }
func (me *Session) GetCSRF() string { func (s *Session) GetCSRF() string {
if me.Props == nil { if s.Props == nil {
return "" return ""
} }
return me.Props["csrf"] return s.Props["csrf"]
} }
func SessionsToJson(o []*Session) string { func SessionsToJson(o []*Session) string {