summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/mattermost-server/v5/model/bot.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/bot.go')
-rw-r--r--vendor/github.com/mattermost/mattermost-server/v5/model/bot.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/model/bot.go b/vendor/github.com/mattermost/mattermost-server/v5/model/bot.go
index fb46be49..e58fc0be 100644
--- a/vendor/github.com/mattermost/mattermost-server/v5/model/bot.go
+++ b/vendor/github.com/mattermost/mattermost-server/v5/model/bot.go
@@ -17,6 +17,7 @@ const (
BOT_DESCRIPTION_MAX_RUNES = 1024
BOT_CREATOR_ID_MAX_RUNES = KEY_VALUE_PLUGIN_ID_MAX_RUNES // UserId or PluginId
BOT_WARN_METRIC_BOT_USERNAME = "mattermost-advisor"
+ BOT_SYSTEM_BOT_USERNAME = "system-bot"
)
// Bot is a special type of User meant for programmatic interactions.
@@ -82,7 +83,7 @@ func (b *Bot) IsValid() *AppError {
return NewAppError("Bot.IsValid", "model.bot.is_valid.description.app_error", b.Trace(), "", http.StatusBadRequest)
}
- if len(b.OwnerId) == 0 || utf8.RuneCountInString(b.OwnerId) > BOT_CREATOR_ID_MAX_RUNES {
+ if b.OwnerId == "" || utf8.RuneCountInString(b.OwnerId) > BOT_CREATOR_ID_MAX_RUNES {
return NewAppError("Bot.IsValid", "model.bot.is_valid.creator_id.app_error", b.Trace(), "", http.StatusBadRequest)
}
@@ -128,6 +129,8 @@ func BotFromJson(data io.Reader) *Bot {
}
// Patch modifies an existing bot with optional fields from the given patch.
+// TODO 6.0: consider returning a boolean to indicate whether or not the patch
+// applied any changes.
func (b *Bot) Patch(patch *BotPatch) {
if patch.Username != nil {
b.Username = *patch.Username
@@ -142,6 +145,23 @@ func (b *Bot) Patch(patch *BotPatch) {
}
}
+// WouldPatch returns whether or not the given patch would be applied or not.
+func (b *Bot) WouldPatch(patch *BotPatch) bool {
+ if patch == nil {
+ return false
+ }
+ if patch.Username != nil && *patch.Username != b.Username {
+ return true
+ }
+ if patch.DisplayName != nil && *patch.DisplayName != b.DisplayName {
+ return true
+ }
+ if patch.Description != nil && *patch.Description != b.Description {
+ return true
+ }
+ return false
+}
+
// ToJson serializes the bot patch to json.
func (b *BotPatch) ToJson() []byte {
data, err := json.Marshal(b)