Restrict the creation of dms/gms to user that you can see (#11695)

* Restrict the creation of dms/gms to user that you can see

* Adding tests

* Adding tests for CreateGroupChannel api endpoint
Этот коммит содержится в:
Jesús Espino
2019-07-31 18:37:28 +02:00
коммит произвёл GitHub
родитель 0ec0616d89
Коммит ee007962f4
2 изменённых файлов: 141 добавлений и 0 удалений

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

@@ -347,6 +347,22 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
otherUserId := userIds[0]
if c.App.Session.UserId == otherUserId {
otherUserId = userIds[1]
}
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, otherUserId)
if err != nil {
c.Err = err
return
}
if !canSee {
c.SetPermissionError(model.PERMISSION_VIEW_MEMBERS)
return
}
sc, err := c.App.GetOrCreateDirectChannel(userIds[0], userIds[1])
if err != nil {
c.Err = err
@@ -401,6 +417,25 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
canSeeAll := true
for _, id := range userIds {
if c.App.Session.UserId != id {
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, id)
if err != nil {
c.Err = err
return
}
if !canSee {
canSeeAll = false
}
}
}
if !canSeeAll {
c.SetPermissionError(model.PERMISSION_VIEW_MEMBERS)
return
}
groupChannel, err := c.App.CreateGroupChannel(userIds, c.App.Session.UserId)
if err != nil {
c.Err = err