MM-16990 - Fix webhooks visible to users without viewing permissions (#11698)
* Filtered incoming webhooks for users wihtout PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS * Filtered outgoing webhooks for users without PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS * Refactored GetOutgoingByTeamByUser to its own method in app and store * Fixed paging condition for outgoing webhooks in store * Separated test cases into separate t.run in WebhookStore * Improved unit test. PR Feedback * Filtered outgoing webhooks by channel for users without PERMISSION_MANAGE_OTHERS * Filtered getting full list of outgoing webhooks for users without PERMISSION_MANAGE_OTHERS * Added missing signature for GetOutgoingWebhooksPage in app * Expanded permissions in test to SYSTEM_USER_ROLE * Filtered getting full list of incoming webhooks for users without PERMISSION_MANAGE_OTHERS * Removed unnecessary sq.and operator
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8f4dab0162
Коммит
3187907b67
@@ -7,6 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
@@ -174,9 +175,27 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByChannel(channelId string) *mod
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingList(offset, limit int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
return s.GetIncomingListByUser("", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingListByUser(userId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
var webhooks []*model.IncomingWebhook
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Limit": limit, "Offset": offset}); err != nil {
|
||||
query := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("IncomingWebhooks").
|
||||
Where(sq.Eq{"DeleteAt": int(0)}).Limit(uint64(limit)).Offset(uint64(offset))
|
||||
|
||||
if len(userId) > 0 {
|
||||
query = query.Where(sq.Eq{"UserId": userId})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetIncomingList", "store.sql_webhooks.get_incoming_by_user.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetIncomingList", "store.sql_webhooks.get_incoming_by_user.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -184,16 +203,37 @@ func (s SqlWebhookStore) GetIncomingList(offset, limit int) ([]*model.IncomingWe
|
||||
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingByTeam(teamId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
func (s SqlWebhookStore) GetIncomingByTeamByUser(teamId string, userId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
var webhooks []*model.IncomingWebhook
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset}); err != nil {
|
||||
query := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("IncomingWebhooks").
|
||||
Where(sq.And{
|
||||
sq.Eq{"TeamId": teamId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
}).Limit(uint64(limit)).Offset(uint64(offset))
|
||||
|
||||
if len(userId) > 0 {
|
||||
query = query.Where(sq.Eq{"UserId": userId})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetIncomingByUser", "store.sql_webhooks.get_incoming_by_user.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetIncomingByUser", "store.sql_webhooks.get_incoming_by_user.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingByTeam(teamId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
return s.GetIncomingByTeamByUser(teamId, "", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
var webhooks []*model.IncomingWebhook
|
||||
|
||||
@@ -232,50 +272,105 @@ func (s SqlWebhookStore) GetOutgoing(id string) (*model.OutgoingWebhook, *model.
|
||||
return &webhook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
func (s SqlWebhookStore) GetOutgoingListByUser(userId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
var webhooks []*model.OutgoingWebhook
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM OutgoingWebhooks WHERE DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
|
||||
query := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("OutgoingWebhooks").
|
||||
Where(sq.And{
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
}).Limit(uint64(limit)).Offset(uint64(offset))
|
||||
|
||||
if len(userId) > 0 {
|
||||
query = query.Where(sq.Eq{"CreatorId": userId})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoingByChannel", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoingList", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
func (s SqlWebhookStore) GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
return s.GetOutgoingListByUser("", offset, limit)
|
||||
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByChannelByUser(channelId string, userId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
var webhooks []*model.OutgoingWebhook
|
||||
|
||||
query := ""
|
||||
if limit < 0 || offset < 0 {
|
||||
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0"
|
||||
} else {
|
||||
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset"
|
||||
query := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("OutgoingWebhooks").
|
||||
Where(sq.And{
|
||||
sq.Eq{"ChannelId": channelId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
})
|
||||
|
||||
if len(userId) > 0 {
|
||||
query = query.Where(sq.Eq{"CreatorId": userId})
|
||||
}
|
||||
if limit >= 0 && offset >= 0 {
|
||||
query = query.Limit(uint64(limit)).Offset(uint64(offset))
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil {
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoingByChannel", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoingByChannel", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, "channelId="+channelId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByTeam(teamId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
return s.GetOutgoingByChannelByUser(channelId, "", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByTeamByUser(teamId string, userId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
var webhooks []*model.OutgoingWebhook
|
||||
|
||||
query := ""
|
||||
if limit < 0 || offset < 0 {
|
||||
query = "SELECT * FROM OutgoingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0"
|
||||
} else {
|
||||
query = "SELECT * FROM OutgoingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset"
|
||||
query := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("OutgoingWebhooks").
|
||||
Where(sq.And{
|
||||
sq.Eq{"TeamId": teamId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
})
|
||||
|
||||
if len(userId) > 0 {
|
||||
query = query.Where(sq.Eq{"CreatorId": userId})
|
||||
}
|
||||
if limit >= 0 && offset >= 0 {
|
||||
query = query.Limit(uint64(limit)).Offset(uint64(offset))
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, query, map[string]interface{}{"TeamId": teamId, "Offset": offset, "Limit": limit}); err != nil {
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoingByTeam", "store.sql_webhooks.get_outgoing_by_team.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoingByTeam", "store.sql_webhooks.get_outgoing_by_team.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByTeam(teamId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
return s.GetOutgoingByTeamByUser(teamId, "", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) *model.AppError {
|
||||
_, err := s.GetMaster().Exec("Update OutgoingWebhooks SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": webhookId})
|
||||
if err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user