MM-42268: We add more fields to Channel and Team (#19675)

Also added sessions as part of the user object

https://mattermost.atlassian.net/browse/MM-42268

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2022-03-07 20:14:53 +05:30
коммит произвёл GitHub
родитель 9f76cb6b95
Коммит cf6aa85d28
6 изменённых файлов: 105 добавлений и 21 удалений

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

@@ -116,3 +116,27 @@ func (u *user) Status(ctx context.Context) (*model.Status, error) {
return statuses[0], nil return statuses[0], nil
} }
// match with api4.getSessions
func (u *user) Sessions(ctx context.Context) ([]*model.Session, error) {
c, err := getCtx(ctx)
if err != nil {
return nil, err
}
if !c.App.SessionHasPermissionToUser(*c.AppContext.Session(), u.Id) {
c.SetPermissionError(model.PermissionEditOtherUsers)
return nil, c.Err
}
sessions, appErr := c.App.GetSessions(u.Id)
if appErr != nil {
return nil, appErr
}
for _, session := range sessions {
session.Sanitize()
}
return sessions, nil
}

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

@@ -56,6 +56,10 @@ func TestGraphQLUser(t *testing.T) {
Name string `json:"name"` Name string `json:"name"`
Value string `json:"value"` Value string `json:"value"`
} `json:"preferences"` } `json:"preferences"`
Sessions []struct {
ID string `json:"id"`
CreateAt float64 `json:"createAt"`
} `json:"sessions"`
} `json:"user"` } `json:"user"`
} }
@@ -64,27 +68,31 @@ func TestGraphQLUser(t *testing.T) {
OperationName: "user", OperationName: "user",
Query: ` Query: `
query user($id: String = "me") { query user($id: String = "me") {
user(id: $id) { user(id: $id) {
id id
username username
email email
firstName firstName
lastName lastName
isBot isBot
isGuest isGuest
isSystemAdmin isSystemAdmin
timezone timezone
props props
notifyProps notifyProps
roles { roles {
id id
name name
} }
preferences { preferences {
name name
value value
} }
} sessions {
id
createAt
}
}
} }
`, `,
} }
@@ -126,6 +134,13 @@ func TestGraphQLUser(t *testing.T) {
assert.Equal(t, q.User.Preferences[i].Name, prefs[i].Name) assert.Equal(t, q.User.Preferences[i].Name, prefs[i].Name)
assert.Equal(t, q.User.Preferences[i].Value, prefs[i].Value) assert.Equal(t, q.User.Preferences[i].Value, prefs[i].Value)
} }
assert.Len(t, q.User.Sessions, 2)
now := float64(model.GetMillis())
for _, session := range q.User.Sessions {
assert.NotEmpty(t, session.ID)
assert.Less(t, session.CreateAt, now)
}
}) })
t.Run("Update", func(t *testing.T) { t.Run("Update", func(t *testing.T) {

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

@@ -48,6 +48,10 @@ type Channel {
creatorId: String! creatorId: String!
schemeId: String schemeId: String
team: Team team: Team
groupConstrained: Boolean
shared: Boolean
lastPostAt: Float!
totalMsgCount: Float!
cursor: String cursor: String
} }
@@ -91,6 +95,7 @@ type User {
position: String! position: String!
roles: [Role]! roles: [Role]!
preferences: [Preference!]! preferences: [Preference!]!
sessions: [Session]!
} }
type CustomStatus { type CustomStatus {
@@ -127,12 +132,16 @@ type Team {
id: String! id: String!
displayName : String! displayName : String!
name : String! name : String!
updateAt : Float!
description : String! description : String!
email : String! email : String!
type : String! type : String!
companyName : String! companyName : String!
allowedDomains : String! allowedDomains : String!
inviteId : String! inviteId : String!
lastTeamIconUpdate: Float!
groupConstrained: Boolean
allowOpenInvite: Boolean!
} }
type TeamMember { type TeamMember {
@@ -155,3 +164,10 @@ type SidebarCategory {
collapsed: Boolean! collapsed: Boolean!
channelIds: [String!]! channelIds: [String!]!
} }
type Session {
id: String!
token: String!
createAt: Float!
expiresAt: Float!
}

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

@@ -178,6 +178,14 @@ func (o *Channel) DeleteAt_() float64 {
return float64(o.DeleteAt) return float64(o.DeleteAt)
} }
func (o *Channel) LastPostAt_() float64 {
return float64(o.LastPostAt)
}
func (o *Channel) TotalMsgCount_() float64 {
return float64(o.TotalMsgCount)
}
func (o *Channel) DeepCopy() *Channel { func (o *Channel) DeepCopy() *Channel {
copy := *o copy := *o
if copy.SchemeId != nil { if copy.SchemeId != nil {

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

@@ -218,3 +218,11 @@ func (s *Session) GetCSRF() string {
return s.Props["csrf"] return s.Props["csrf"]
} }
func (s *Session) CreateAt_() float64 {
return float64(s.CreateAt)
}
func (s *Session) ExpiresAt_() float64 {
return float64(s.ExpiresAt)
}

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

@@ -251,3 +251,16 @@ func (o *Team) Patch(patch *TeamPatch) {
func (o *Team) IsGroupConstrained() bool { func (o *Team) IsGroupConstrained() bool {
return o.GroupConstrained != nil && *o.GroupConstrained return o.GroupConstrained != nil && *o.GroupConstrained
} }
// The following are some GraphQL methods necessary to return the
// data in float64 type. The spec doesn't support 64 bit integers,
// so we have to pass the data in float64. The _ at the end is
// a hack to keep the attribute name same in GraphQL schema.
func (o *Team) UpdateAt_() float64 {
return float64(o.UpdateAt)
}
func (o *Team) LastTeamIconUpdate_() float64 {
return float64(o.LastTeamIconUpdate)
}