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