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
}
// 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"`
Value string `json:"value"`
} `json:"preferences"`
Sessions []struct {
ID string `json:"id"`
CreateAt float64 `json:"createAt"`
} `json:"sessions"`
} `json:"user"`
}
@@ -64,27 +68,31 @@ func TestGraphQLUser(t *testing.T) {
OperationName: "user",
Query: `
query user($id: String = "me") {
user(id: $id) {
id
username
email
firstName
lastName
isBot
isGuest
isSystemAdmin
timezone
props
notifyProps
roles {
id
name
}
preferences {
name
value
}
}
user(id: $id) {
id
username
email
firstName
lastName
isBot
isGuest
isSystemAdmin
timezone
props
notifyProps
roles {
id
name
}
preferences {
name
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].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) {

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

@@ -48,6 +48,10 @@ type Channel {
creatorId: String!
schemeId: String
team: Team
groupConstrained: Boolean
shared: Boolean
lastPostAt: Float!
totalMsgCount: Float!
cursor: String
}
@@ -91,6 +95,7 @@ type User {
position: String!
roles: [Role]!
preferences: [Preference!]!
sessions: [Session]!
}
type CustomStatus {
@@ -127,12 +132,16 @@ type Team {
id: String!
displayName : String!
name : String!
updateAt : Float!
description : String!
email : String!
type : String!
companyName : String!
allowedDomains : String!
inviteId : String!
lastTeamIconUpdate: Float!
groupConstrained: Boolean
allowOpenInvite: Boolean!
}
type TeamMember {
@@ -155,3 +164,10 @@ type SidebarCategory {
collapsed: Boolean!
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)
}
func (o *Channel) LastPostAt_() float64 {
return float64(o.LastPostAt)
}
func (o *Channel) TotalMsgCount_() float64 {
return float64(o.TotalMsgCount)
}
func (o *Channel) DeepCopy() *Channel {
copy := *o
if copy.SchemeId != nil {

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

@@ -218,3 +218,11 @@ func (s *Session) GetCSRF() string {
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 {
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)
}