MM-12393 Server side of bot accounts. (#10378)

* bots model, store and api (#9903)

* bots model, store and api

Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119

* uncomment tests incorrectly commented, and fix merge issues

* add etags support

* add missing licenses

* remove unused sqlbuilder.go (for now...)

* rejig permissions

* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS

* conform to general rest api pattern

* eliminate redundant http.StatusOK

* Update api4/bot.go

Co-Authored-By: lieut-data <jesse.hallam@gmail.com>

* s/model.UserFromBotModel/model.UserFromBot/g

* Update model/bot.go

Co-Authored-By: lieut-data <jesse.hallam@gmail.com>

* Update model/client4.go

Co-Authored-By: lieut-data <jesse.hallam@gmail.com>

* move sessionHasPermissionToManageBot to app/authorization.go

* use api.ApiSessionRequired for createBot

* introduce BOT_DESCRIPTION_MAX_RUNES constant

* MM-13512 Prevent getting a user by email based on privacy settings (#10021)

* MM-13512 Prevent getting a user by email based on privacy settings

* Add additional config settings to tests

* upgrade db to 5.7 (#10019)

* MM-13526 Add validation when setting a user's Locale field (#10022)

* Fix typos (#10024)

* Fixing first user being created with system admin privilages without being explicity specified. (#10014)

* Revert "Support for Embeded chat (#9129)" (#10017)

This reverts commit 3fcecd521a.

* s/DisableBot/UpdateBotActive

* add permissions on upgrade

* Update NOTICE.txt (#10054)

- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates

* avoid leaking bot knowledge without permission

* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)

* 6798 added a new api to get the bulk reactions for posts

* 6798 added the permsission check before getting the reactions

* GH-6798 added a new app function for the new endpoint

* 6798 added a store method to get reactions for multiple posts

* 6798 connected the app function with the new store function

* 6798 fixed the review comments

* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)

Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023

* Trigger Login Hooks with OAuth (#10061)

* make BotStore.GetAll deterministic even on duplicate CreateAt

* fix spurious TestMuteCommandSpecificChannel test failure

See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw

* fix race in TestExportUserChannels

* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway

* MM-13117: bot tokens (#10111)

* eliminate redundant Client/AdminClient declarations

* harden TestUpdateChannelScheme to API failures

* eliminate unnecessary config restoration

* minor cleanup

* make TestGenerateMfaSecret config dependency explicit

* TestCreateUserAccessToken for bots

* TestGetUserAccessToken* for bots

* leverage SessionHasPermissionToUserOrBot for user token APIs

* Test(Revoke|Disable|Enable)UserAccessToken

* make EnableUserAccessTokens explicit, so as to not rely on local config.json

* uncomment TestResetPassword, but still skip

* mark assert(Invalid)Token as helper

* fix whitespace issues

* fix mangled comments

* MM-13116: bot plugin api (#10113)

* MM-13117: expose bot API to plugins

This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.

* gofmt issues

* expunge use of BotList in plugin/client API

* introduce model.BotGetOptions

* use botUserId term for clarity

* MM-13129 Adding functionality to deal with orphaned bots (#10238)

* Add way to list orphaned bots.

* Add /assign route to modify ownership of bot accounts.

* Apply suggestions from code review

Co-Authored-By: crspeller <crspeller@gmail.com>

* MM-13120: add IsBot field to returned user objects (#10103)

* MM-13104: forbid bot login (#10251)

* MM-13104: disallow bot login

* fix shadowing

* MM-13136 Disable user bots when user is disabled. (#10293)

* Disable user bots when user is disabled.

* Grammer.

Co-Authored-By: crspeller <crspeller@gmail.com>

* Fixing bot branch for test changes.

* Don't use external dependancies in bot plugin tests.

* Rename bot CreatorId to OwnerId

* Adding ability to re-enable bots

* Fixing IsBot to not attempt to be saved to DB.

* Adding diagnostics and licencing counting for bot accounts.

* Modifying gorp to allow reading of '-' fields.

* Removing unnessisary nil values from UserCountOptions.

* Changing comment to GoDoc format

* Improving user count SQL

* Some improvments from feedback.

* Omit empty on User.IsBot
Этот коммит содержится в:
Christopher Speller
2019-03-05 07:06:45 -08:00
коммит произвёл GitHub
родитель 80e0d01fe5
Коммит 06b579d18a
53 изменённых файлов: 5951 добавлений и 403 удалений

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

@@ -508,6 +508,36 @@ type API interface {
//
// Minimum server version: 5.7
SendMail(to, subject, htmlBody string) *model.AppError
// CreateBot creates the given bot and corresponding user.
//
// Minimum server version: 5.10
CreateBot(bot *model.Bot) (*model.Bot, *model.AppError)
// PatchBot applies the given patch to the bot and corresponding user.
//
// Minimum server version: 5.10
PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)
// GetBot returns the given bot.
//
// Minimum server version: 5.10
GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError)
// GetBots returns the requested page of bots.
//
// Minimum server version: 5.10
GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError)
// UpdateBotActive marks a bot as active or inactive, along with its corresponding user.
//
// Minimum server version: 5.10
UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError)
// PermanentDeleteBot permanently deletes a bot and its corresponding user.
//
// Minimum server version: 5.10
PermanentDeleteBot(botUserId string) *model.AppError
}
var handshake = plugin.HandshakeConfig{

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

@@ -3783,3 +3783,179 @@ func (s *apiRPCServer) SendMail(args *Z_SendMailArgs, returns *Z_SendMailReturns
}
return nil
}
type Z_CreateBotArgs struct {
A *model.Bot
}
type Z_CreateBotReturns struct {
A *model.Bot
B *model.AppError
}
func (g *apiRPCClient) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
_args := &Z_CreateBotArgs{bot}
_returns := &Z_CreateBotReturns{}
if err := g.client.Call("Plugin.CreateBot", _args, _returns); err != nil {
log.Printf("RPC call to CreateBot API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) CreateBot(args *Z_CreateBotArgs, returns *Z_CreateBotReturns) error {
if hook, ok := s.impl.(interface {
CreateBot(bot *model.Bot) (*model.Bot, *model.AppError)
}); ok {
returns.A, returns.B = hook.CreateBot(args.A)
} else {
return encodableError(fmt.Errorf("API CreateBot called but not implemented."))
}
return nil
}
type Z_PatchBotArgs struct {
A string
B *model.BotPatch
}
type Z_PatchBotReturns struct {
A *model.Bot
B *model.AppError
}
func (g *apiRPCClient) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) {
_args := &Z_PatchBotArgs{botUserId, botPatch}
_returns := &Z_PatchBotReturns{}
if err := g.client.Call("Plugin.PatchBot", _args, _returns); err != nil {
log.Printf("RPC call to PatchBot API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) PatchBot(args *Z_PatchBotArgs, returns *Z_PatchBotReturns) error {
if hook, ok := s.impl.(interface {
PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)
}); ok {
returns.A, returns.B = hook.PatchBot(args.A, args.B)
} else {
return encodableError(fmt.Errorf("API PatchBot called but not implemented."))
}
return nil
}
type Z_GetBotArgs struct {
A string
B bool
}
type Z_GetBotReturns struct {
A *model.Bot
B *model.AppError
}
func (g *apiRPCClient) GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError) {
_args := &Z_GetBotArgs{botUserId, includeDeleted}
_returns := &Z_GetBotReturns{}
if err := g.client.Call("Plugin.GetBot", _args, _returns); err != nil {
log.Printf("RPC call to GetBot API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) GetBot(args *Z_GetBotArgs, returns *Z_GetBotReturns) error {
if hook, ok := s.impl.(interface {
GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError)
}); ok {
returns.A, returns.B = hook.GetBot(args.A, args.B)
} else {
return encodableError(fmt.Errorf("API GetBot called but not implemented."))
}
return nil
}
type Z_GetBotsArgs struct {
A *model.BotGetOptions
}
type Z_GetBotsReturns struct {
A []*model.Bot
B *model.AppError
}
func (g *apiRPCClient) GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError) {
_args := &Z_GetBotsArgs{options}
_returns := &Z_GetBotsReturns{}
if err := g.client.Call("Plugin.GetBots", _args, _returns); err != nil {
log.Printf("RPC call to GetBots API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) GetBots(args *Z_GetBotsArgs, returns *Z_GetBotsReturns) error {
if hook, ok := s.impl.(interface {
GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError)
}); ok {
returns.A, returns.B = hook.GetBots(args.A)
} else {
return encodableError(fmt.Errorf("API GetBots called but not implemented."))
}
return nil
}
type Z_UpdateBotActiveArgs struct {
A string
B bool
}
type Z_UpdateBotActiveReturns struct {
A *model.Bot
B *model.AppError
}
func (g *apiRPCClient) UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError) {
_args := &Z_UpdateBotActiveArgs{botUserId, active}
_returns := &Z_UpdateBotActiveReturns{}
if err := g.client.Call("Plugin.UpdateBotActive", _args, _returns); err != nil {
log.Printf("RPC call to UpdateBotActive API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) UpdateBotActive(args *Z_UpdateBotActiveArgs, returns *Z_UpdateBotActiveReturns) error {
if hook, ok := s.impl.(interface {
UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError)
}); ok {
returns.A, returns.B = hook.UpdateBotActive(args.A, args.B)
} else {
return encodableError(fmt.Errorf("API UpdateBotActive called but not implemented."))
}
return nil
}
type Z_PermanentDeleteBotArgs struct {
A string
}
type Z_PermanentDeleteBotReturns struct {
A *model.AppError
}
func (g *apiRPCClient) PermanentDeleteBot(botUserId string) *model.AppError {
_args := &Z_PermanentDeleteBotArgs{botUserId}
_returns := &Z_PermanentDeleteBotReturns{}
if err := g.client.Call("Plugin.PermanentDeleteBot", _args, _returns); err != nil {
log.Printf("RPC call to PermanentDeleteBot API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) PermanentDeleteBot(args *Z_PermanentDeleteBotArgs, returns *Z_PermanentDeleteBotReturns) error {
if hook, ok := s.impl.(interface {
PermanentDeleteBot(botUserId string) *model.AppError
}); ok {
returns.A = hook.PermanentDeleteBot(args.A)
} else {
return encodableError(fmt.Errorf("API PermanentDeleteBot called but not implemented."))
}
return nil
}

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

@@ -87,6 +87,31 @@ func (_m *API) CopyFileInfos(userId string, fileIds []string) ([]string, *model.
return r0, r1
}
// CreateBot provides a mock function with given fields: bot
func (_m *API) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
ret := _m.Called(bot)
var r0 *model.Bot
if rf, ok := ret.Get(0).(func(*model.Bot) *model.Bot); ok {
r0 = rf(bot)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Bot)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(*model.Bot) *model.AppError); ok {
r1 = rf(bot)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// CreateChannel provides a mock function with given fields: channel
func (_m *API) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
ret := _m.Called(channel)
@@ -365,6 +390,56 @@ func (_m *API) EnablePlugin(id string) *model.AppError {
return r0
}
// GetBot provides a mock function with given fields: botUserId, includeDeleted
func (_m *API) GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError) {
ret := _m.Called(botUserId, includeDeleted)
var r0 *model.Bot
if rf, ok := ret.Get(0).(func(string, bool) *model.Bot); ok {
r0 = rf(botUserId, includeDeleted)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Bot)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok {
r1 = rf(botUserId, includeDeleted)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetBots provides a mock function with given fields: options
func (_m *API) GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError) {
ret := _m.Called(options)
var r0 []*model.Bot
if rf, ok := ret.Get(0).(func(*model.BotGetOptions) []*model.Bot); ok {
r0 = rf(options)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Bot)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(*model.BotGetOptions) *model.AppError); ok {
r1 = rf(options)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetChannel provides a mock function with given fields: channelId
func (_m *API) GetChannel(channelId string) (*model.Channel, *model.AppError) {
ret := _m.Called(channelId)
@@ -1884,6 +1959,47 @@ func (_m *API) OpenInteractiveDialog(dialog model.OpenDialogRequest) *model.AppE
return r0
}
// PatchBot provides a mock function with given fields: botUserId, botPatch
func (_m *API) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) {
ret := _m.Called(botUserId, botPatch)
var r0 *model.Bot
if rf, ok := ret.Get(0).(func(string, *model.BotPatch) *model.Bot); ok {
r0 = rf(botUserId, botPatch)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Bot)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, *model.BotPatch) *model.AppError); ok {
r1 = rf(botUserId, botPatch)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// PermanentDeleteBot provides a mock function with given fields: botUserId
func (_m *API) PermanentDeleteBot(botUserId string) *model.AppError {
ret := _m.Called(botUserId)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
r0 = rf(botUserId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
}
return r0
}
// PublishWebSocketEvent provides a mock function with given fields: event, payload, broadcast
func (_m *API) PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) {
_m.Called(event, payload, broadcast)
@@ -2215,6 +2331,31 @@ func (_m *API) UnregisterCommand(teamId string, trigger string) error {
return r0
}
// UpdateBotActive provides a mock function with given fields: botUserId, active
func (_m *API) UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError) {
ret := _m.Called(botUserId, active)
var r0 *model.Bot
if rf, ok := ret.Get(0).(func(string, bool) *model.Bot); ok {
r0 = rf(botUserId, active)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Bot)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok {
r1 = rf(botUserId, active)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// UpdateChannel provides a mock function with given fields: channel
func (_m *API) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
ret := _m.Called(channel)