snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
447
server/channels/store/sqlstore/webhook_store.go
Normal file
447
server/channels/store/sqlstore/webhook_store.go
Normal file
@@ -0,0 +1,447 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces"
|
||||
)
|
||||
|
||||
type SqlWebhookStore struct {
|
||||
*SqlStore
|
||||
metrics einterfaces.MetricsInterface
|
||||
|
||||
incomingWebhookSelectQuery sq.SelectBuilder
|
||||
outgoingWebhookSelectQuery sq.SelectBuilder
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) ClearCaches() {
|
||||
}
|
||||
|
||||
func newSqlWebhookStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.WebhookStore {
|
||||
s := &SqlWebhookStore{
|
||||
SqlStore: sqlStore,
|
||||
metrics: metrics,
|
||||
}
|
||||
|
||||
// Initialize query builders for incoming webhooks
|
||||
s.incomingWebhookSelectQuery = s.getQueryBuilder().
|
||||
Select(
|
||||
"Id",
|
||||
"CreateAt",
|
||||
"UpdateAt",
|
||||
"DeleteAt",
|
||||
"UserId",
|
||||
"ChannelId",
|
||||
"TeamId",
|
||||
"DisplayName",
|
||||
"Description",
|
||||
"Username",
|
||||
"IconURL",
|
||||
"ChannelLocked",
|
||||
"LastUsed",
|
||||
).
|
||||
From("IncomingWebhooks")
|
||||
|
||||
// Initialize query builders for outgoing webhooks
|
||||
s.outgoingWebhookSelectQuery = s.getQueryBuilder().
|
||||
Select(
|
||||
"Id",
|
||||
"Token",
|
||||
"CreateAt",
|
||||
"UpdateAt",
|
||||
"DeleteAt",
|
||||
"CreatorId",
|
||||
"ChannelId",
|
||||
"TeamId",
|
||||
"TriggerWords",
|
||||
"TriggerWhen",
|
||||
"CallbackURLs",
|
||||
"DisplayName",
|
||||
"Description",
|
||||
"ContentType",
|
||||
"Username",
|
||||
"IconURL",
|
||||
).
|
||||
From("OutgoingWebhooks")
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) InvalidateWebhookCache(webhookId string) {
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, error) {
|
||||
if webhook.Id != "" {
|
||||
return nil, store.NewErrInvalidInput("IncomingWebhook", "id", webhook.Id)
|
||||
}
|
||||
|
||||
webhook.PreSave()
|
||||
if err := webhook.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO IncomingWebhooks
|
||||
(Id, CreateAt, UpdateAt, DeleteAt, UserId, ChannelId, TeamId, DisplayName, Description, Username, IconURL, ChannelLocked, LastUsed)
|
||||
VALUES
|
||||
(:Id, :CreateAt, :UpdateAt, :DeleteAt, :UserId, :ChannelId, :TeamId, :DisplayName, :Description, :Username, :IconURL, :ChannelLocked, :LastUsed)`, webhook); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to save IncomingWebhook with id=%s", webhook.Id)
|
||||
}
|
||||
|
||||
return webhook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) UpdateIncoming(hook *model.IncomingWebhook) (*model.IncomingWebhook, error) {
|
||||
hook.UpdateAt = model.GetMillis()
|
||||
|
||||
_, err := s.GetMaster().NamedExec(`UPDATE IncomingWebhooks SET
|
||||
CreateAt=:CreateAt, UpdateAt=:UpdateAt, DeleteAt=:DeleteAt, ChannelId=:ChannelId, TeamId=:TeamId, DisplayName=:DisplayName,
|
||||
Description=:Description, Username=:Username, IconURL=:IconURL, ChannelLocked=:ChannelLocked
|
||||
WHERE Id=:Id`, hook)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update IncomingWebhook with id=%s", hook.Id)
|
||||
}
|
||||
|
||||
return hook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) UpdateIncomingLastUsed(webhookID string, lastUsed int64) error {
|
||||
_, err := s.GetMaster().Exec(
|
||||
`UPDATE IncomingWebhooks SET LastUsed = ? WHERE Id = ? AND DeleteAt = 0`,
|
||||
lastUsed,
|
||||
webhookID,
|
||||
)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update LastUsed for IncomingWebhook id=%s", webhookID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, error) {
|
||||
var webhook model.IncomingWebhook
|
||||
|
||||
query := s.incomingWebhookSelectQuery.
|
||||
Where(sq.And{
|
||||
sq.Eq{"Id": id},
|
||||
sq.Eq{"DeleteAt": 0},
|
||||
})
|
||||
|
||||
if err := s.GetReplica().GetBuilder(&webhook, query); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("IncomingWebhook", id)
|
||||
}
|
||||
return nil, errors.Wrapf(err, "failed to get IncomingWebhook with id=%s", id)
|
||||
}
|
||||
|
||||
return &webhook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) error {
|
||||
_, err := s.GetMaster().Exec("UPDATE IncomingWebhooks SET DeleteAt = ?, UpdateAt = ? WHERE Id = ?", time, time, webhookId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update IncomingWebhook with id=%s", webhookId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) error {
|
||||
_, err := s.GetMaster().Exec("DELETE FROM IncomingWebhooks WHERE UserId = ?", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete IncomingWebhook with userId=%s", userId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) PermanentDeleteIncomingByChannel(channelId string) error {
|
||||
_, err := s.GetMaster().Exec("DELETE FROM IncomingWebhooks WHERE ChannelId = ?", channelId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete IncomingWebhook with channelId=%s", channelId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingList(offset, limit int) ([]*model.IncomingWebhook, error) {
|
||||
return s.GetIncomingListByUser("", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingListByUser(userId string, offset, limit int) ([]*model.IncomingWebhook, error) {
|
||||
webhooks := []*model.IncomingWebhook{}
|
||||
|
||||
query := s.incomingWebhookSelectQuery.
|
||||
Where(sq.Eq{"DeleteAt": 0}).
|
||||
OrderBy("DisplayName", "Id").
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset))
|
||||
|
||||
if userId != "" {
|
||||
query = query.Where(sq.Eq{"UserId": userId})
|
||||
}
|
||||
|
||||
if err := s.GetReplica().SelectBuilder(&webhooks, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find IncomingWebhooks")
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingByTeamByUser(teamId string, userId string, offset, limit int) ([]*model.IncomingWebhook, error) {
|
||||
webhooks := []*model.IncomingWebhook{}
|
||||
|
||||
query := s.incomingWebhookSelectQuery.
|
||||
Where(sq.And{
|
||||
sq.Eq{"TeamId": teamId},
|
||||
sq.Eq{"DeleteAt": 0},
|
||||
}).
|
||||
OrderBy("DisplayName", "Id").
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset))
|
||||
|
||||
if userId != "" {
|
||||
query = query.Where(sq.Eq{"UserId": userId})
|
||||
}
|
||||
|
||||
if err := s.GetReplica().SelectBuilder(&webhooks, query); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find IncomingWebhook with teamId=%s", teamId)
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingByTeam(teamId string, offset, limit int) ([]*model.IncomingWebhook, error) {
|
||||
return s.GetIncomingByTeamByUser(teamId, "", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, error) {
|
||||
webhooks := []*model.IncomingWebhook{}
|
||||
|
||||
query := s.incomingWebhookSelectQuery.
|
||||
Where(sq.And{
|
||||
sq.Eq{"ChannelId": channelId},
|
||||
sq.Eq{"DeleteAt": 0},
|
||||
})
|
||||
|
||||
if err := s.GetReplica().SelectBuilder(&webhooks, query); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find IncomingWebhooks with channelId=%s", channelId)
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, error) {
|
||||
if webhook.Id != "" {
|
||||
return nil, store.NewErrInvalidInput("OutgoingWebhook", "id", webhook.Id)
|
||||
}
|
||||
|
||||
webhook.PreSave()
|
||||
if err := webhook.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO OutgoingWebhooks
|
||||
(Id, Token, CreateAt, UpdateAt, DeleteAt, CreatorId, ChannelId, TeamId, TriggerWords, TriggerWhen,
|
||||
CallbackURLs, DisplayName, Description, ContentType, Username, IconURL)
|
||||
VALUES
|
||||
(:Id, :Token, :CreateAt, :UpdateAt, :DeleteAt, :CreatorId, :ChannelId, :TeamId, :TriggerWords, :TriggerWhen,
|
||||
:CallbackURLs, :DisplayName, :Description, :ContentType, :Username, :IconURL)`, webhook); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to save OutgoingWebhook with id=%s", webhook.Id)
|
||||
}
|
||||
|
||||
return webhook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoing(id string) (*model.OutgoingWebhook, error) {
|
||||
var webhook model.OutgoingWebhook
|
||||
|
||||
query := s.outgoingWebhookSelectQuery.
|
||||
Where(sq.And{
|
||||
sq.Eq{"Id": id},
|
||||
sq.Eq{"DeleteAt": 0},
|
||||
})
|
||||
|
||||
if err := s.GetReplica().GetBuilder(&webhook, query); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("OutgoingWebhook", id)
|
||||
}
|
||||
|
||||
return nil, errors.Wrapf(err, "failed to get OutgoingWebhook with id=%s", id)
|
||||
}
|
||||
|
||||
return &webhook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingListByUser(userId string, offset, limit int) ([]*model.OutgoingWebhook, error) {
|
||||
webhooks := []*model.OutgoingWebhook{}
|
||||
|
||||
query := s.outgoingWebhookSelectQuery.
|
||||
Where(sq.And{
|
||||
sq.Eq{"DeleteAt": 0},
|
||||
}).
|
||||
OrderBy("DisplayName", "Id").
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset))
|
||||
|
||||
if userId != "" {
|
||||
query = query.Where(sq.Eq{"CreatorId": userId})
|
||||
}
|
||||
|
||||
if err := s.GetReplica().SelectBuilder(&webhooks, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find OutgoingWebhooks")
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, error) {
|
||||
return s.GetOutgoingListByUser("", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByChannelByUser(channelId string, userId string, offset, limit int) ([]*model.OutgoingWebhook, error) {
|
||||
webhooks := []*model.OutgoingWebhook{}
|
||||
|
||||
query := s.outgoingWebhookSelectQuery.
|
||||
Where(sq.And{
|
||||
sq.Eq{"ChannelId": channelId},
|
||||
sq.Eq{"DeleteAt": 0},
|
||||
}).
|
||||
OrderBy("DisplayName", "Id")
|
||||
|
||||
if userId != "" {
|
||||
query = query.Where(sq.Eq{"CreatorId": userId})
|
||||
}
|
||||
if limit >= 0 && offset >= 0 {
|
||||
query = query.Limit(uint64(limit)).Offset(uint64(offset))
|
||||
}
|
||||
|
||||
if err := s.GetReplica().SelectBuilder(&webhooks, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find OutgoingWebhooks")
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) ([]*model.OutgoingWebhook, error) {
|
||||
return s.GetOutgoingByChannelByUser(channelId, "", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByTeamByUser(teamId string, userId string, offset, limit int) ([]*model.OutgoingWebhook, error) {
|
||||
webhooks := []*model.OutgoingWebhook{}
|
||||
|
||||
query := s.outgoingWebhookSelectQuery.
|
||||
Where(sq.And{
|
||||
sq.Eq{"TeamId": teamId},
|
||||
sq.Eq{"DeleteAt": 0},
|
||||
}).
|
||||
OrderBy("DisplayName", "Id")
|
||||
|
||||
if userId != "" {
|
||||
query = query.Where(sq.Eq{"CreatorId": userId})
|
||||
}
|
||||
if limit >= 0 && offset >= 0 {
|
||||
query = query.Limit(uint64(limit)).Offset(uint64(offset))
|
||||
}
|
||||
|
||||
if err := s.GetReplica().SelectBuilder(&webhooks, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find OutgoingWebhooks")
|
||||
}
|
||||
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByTeam(teamId string, offset, limit int) ([]*model.OutgoingWebhook, error) {
|
||||
return s.GetOutgoingByTeamByUser(teamId, "", offset, limit)
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) error {
|
||||
_, err := s.GetMaster().Exec("Update OutgoingWebhooks SET DeleteAt = ?, UpdateAt = ? WHERE Id = ?", time, time, webhookId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update OutgoingWebhook with id=%s", webhookId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) error {
|
||||
_, err := s.GetMaster().Exec("DELETE FROM OutgoingWebhooks WHERE CreatorId = ?", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete OutgoingWebhook with creatorId=%s", userId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) PermanentDeleteOutgoingByChannel(channelId string) error {
|
||||
_, err := s.GetMaster().Exec("DELETE FROM OutgoingWebhooks WHERE ChannelId = ?", channelId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete OutgoingWebhook with channelId=%s", channelId)
|
||||
}
|
||||
|
||||
s.ClearCaches()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, error) {
|
||||
hook.UpdateAt = model.GetMillis()
|
||||
|
||||
_, err := s.GetMaster().NamedExec(`UPDATE OutgoingWebhooks SET
|
||||
CreateAt = :CreateAt, UpdateAt = :UpdateAt, DeleteAt = :DeleteAt, Token = :Token, CreatorId = :CreatorId,
|
||||
ChannelId = :ChannelId, TeamId = :TeamId, TriggerWords = :TriggerWords, TriggerWhen = :TriggerWhen,
|
||||
CallbackURLs = :CallbackURLs, DisplayName = :DisplayName, Description = :Description,
|
||||
ContentType = :ContentType, Username = :Username, IconURL = :IconURL WHERE Id = :Id`, hook)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update OutgoingWebhook with id=%s", hook.Id)
|
||||
}
|
||||
|
||||
return hook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) AnalyticsIncomingCount(teamID string, userID string) (int64, error) {
|
||||
queryBuilder :=
|
||||
s.getQueryBuilder().
|
||||
Select("COUNT(*)").
|
||||
From("IncomingWebhooks").
|
||||
Where("DeleteAt = 0")
|
||||
|
||||
if teamID != "" {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"TeamId": teamID})
|
||||
}
|
||||
|
||||
if userID != "" {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"UserId": userID})
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplica().GetBuilder(&count, queryBuilder); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count IncomingWebhooks")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) AnalyticsOutgoingCount(teamId string) (int64, error) {
|
||||
queryBuilder :=
|
||||
s.getQueryBuilder().
|
||||
Select("COUNT(*)").
|
||||
From("OutgoingWebhooks").
|
||||
Where("DeleteAt = 0")
|
||||
|
||||
if teamId != "" {
|
||||
queryBuilder = queryBuilder.Where("TeamId", teamId)
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplica().GetBuilder(&count, queryBuilder); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count OutgoingWebhooks")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
Reference in New Issue
Block a user