коммит произвёл
Christopher Speller
родитель
08e54ed824
Коммит
d23ca07133
@@ -432,6 +432,75 @@ func (s *hooksRPCServer) UserHasLeftTeam(args *Z_UserHasLeftTeamArgs, returns *Z
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
hookNameToId["UserWillLogIn"] = UserWillLogInId
|
||||
}
|
||||
|
||||
type Z_UserWillLogInArgs struct {
|
||||
A *Context
|
||||
B *model.User
|
||||
}
|
||||
|
||||
type Z_UserWillLogInReturns struct {
|
||||
A string
|
||||
}
|
||||
|
||||
func (g *hooksRPCClient) UserWillLogIn(c *Context, user *model.User) string {
|
||||
_args := &Z_UserWillLogInArgs{c, user}
|
||||
_returns := &Z_UserWillLogInReturns{}
|
||||
if g.implemented[UserWillLogInId] {
|
||||
if err := g.client.Call("Plugin.UserWillLogIn", _args, _returns); err != nil {
|
||||
g.log.Error("RPC call UserWillLogIn to plugin failed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
return _returns.A
|
||||
}
|
||||
|
||||
func (s *hooksRPCServer) UserWillLogIn(args *Z_UserWillLogInArgs, returns *Z_UserWillLogInReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
UserWillLogIn(c *Context, user *model.User) string
|
||||
}); ok {
|
||||
returns.A = hook.UserWillLogIn(args.A, args.B)
|
||||
} else {
|
||||
return fmt.Errorf("Hook UserWillLogIn called but not implemented.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
hookNameToId["UserHasLoggedIn"] = UserHasLoggedInId
|
||||
}
|
||||
|
||||
type Z_UserHasLoggedInArgs struct {
|
||||
A *Context
|
||||
B *model.User
|
||||
}
|
||||
|
||||
type Z_UserHasLoggedInReturns struct {
|
||||
}
|
||||
|
||||
func (g *hooksRPCClient) UserHasLoggedIn(c *Context, user *model.User) {
|
||||
_args := &Z_UserHasLoggedInArgs{c, user}
|
||||
_returns := &Z_UserHasLoggedInReturns{}
|
||||
if g.implemented[UserHasLoggedInId] {
|
||||
if err := g.client.Call("Plugin.UserHasLoggedIn", _args, _returns); err != nil {
|
||||
g.log.Error("RPC call UserHasLoggedIn to plugin failed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *hooksRPCServer) UserHasLoggedIn(args *Z_UserHasLoggedInArgs, returns *Z_UserHasLoggedInReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
UserHasLoggedIn(c *Context, user *model.User)
|
||||
}); ok {
|
||||
hook.UserHasLoggedIn(args.A, args.B)
|
||||
} else {
|
||||
return fmt.Errorf("Hook UserHasLoggedIn called but not implemented.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_RegisterCommandArgs struct {
|
||||
A *model.Command
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ const (
|
||||
UserHasLeftTeamId = 12
|
||||
ChannelHasBeenCreatedId = 13
|
||||
FileWillBeUploadedId = 14
|
||||
UserWillLogInId = 15
|
||||
UserHasLoggedInId = 16
|
||||
TotalHooksId = iota
|
||||
)
|
||||
|
||||
@@ -119,6 +121,13 @@ type Hooks interface {
|
||||
// If actor is not nil, the user was removed from the team by the actor.
|
||||
UserHasLeftTeam(c *Context, teamMember *model.TeamMember, actor *model.User)
|
||||
|
||||
// UserWillLogIn before the login of the user is returned. Returning a non empty string will reject the login event.
|
||||
// If you don't need to reject the login event, see UserHasLoggedIn
|
||||
UserWillLogIn(c *Context, user *model.User) string
|
||||
|
||||
// UserHasLoggedIn is invoked after a user has logged in.
|
||||
UserHasLoggedIn(c *Context, user *model.User)
|
||||
|
||||
// FileWillBeUploaded is invoked when a file is uploaded, but before it is committed to backing store.
|
||||
// Read from file to retrieve the body of the uploaded file. You may modify the body of the file by writing to output.
|
||||
// Returned FileInfo will be used instead of input FileInfo. Return nil to reject the file upload and include a text reason as the second argument.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package plugintest
|
||||
|
||||
import http "net/http"
|
||||
import io "io"
|
||||
import mock "github.com/stretchr/testify/mock"
|
||||
import model "github.com/mattermost/mattermost-server/model"
|
||||
import plugin "github.com/mattermost/mattermost-server/plugin"
|
||||
@@ -44,6 +45,29 @@ func (_m *Hooks) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// FileWillBeUploaded provides a mock function with given fields: c, info, file, output
|
||||
func (_m *Hooks) FileWillBeUploaded(c *plugin.Context, info *model.FileInfo, file io.Reader, output io.Writer) (*model.FileInfo, string) {
|
||||
ret := _m.Called(c, info, file, output)
|
||||
|
||||
var r0 *model.FileInfo
|
||||
if rf, ok := ret.Get(0).(func(*plugin.Context, *model.FileInfo, io.Reader, io.Writer) *model.FileInfo); ok {
|
||||
r0 = rf(c, info, file, output)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.FileInfo)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 string
|
||||
if rf, ok := ret.Get(1).(func(*plugin.Context, *model.FileInfo, io.Reader, io.Writer) string); ok {
|
||||
r1 = rf(c, info, file, output)
|
||||
} else {
|
||||
r1 = ret.Get(1).(string)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Implemented provides a mock function with given fields:
|
||||
func (_m *Hooks) Implemented() ([]string, error) {
|
||||
ret := _m.Called()
|
||||
@@ -189,3 +213,22 @@ func (_m *Hooks) UserHasLeftChannel(c *plugin.Context, channelMember *model.Chan
|
||||
func (_m *Hooks) UserHasLeftTeam(c *plugin.Context, teamMember *model.TeamMember, actor *model.User) {
|
||||
_m.Called(c, teamMember, actor)
|
||||
}
|
||||
|
||||
// UserHasLoggedIn provides a mock function with given fields: c, user
|
||||
func (_m *Hooks) UserHasLoggedIn(c *plugin.Context, user *model.User) {
|
||||
_m.Called(c, user)
|
||||
}
|
||||
|
||||
// UserWillLogIn provides a mock function with given fields: c, user
|
||||
func (_m *Hooks) UserWillLogIn(c *plugin.Context, user *model.User) string {
|
||||
ret := _m.Called(c, user)
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func(*plugin.Context, *model.User) string); ok {
|
||||
r0 = rf(c, user)
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user