* Extend Plugin API

* Use Error, NoError in tests

* Address suggestions

* Simplify code

* Add new line

* Add featureflag and GetCollectionMetadataByIds hook

* Add enter at the end of file

* make build-templates

* Fix test

* Fix GetCollectionMetadataByIds ret type

* Add GetTopicMetadataByIds hook

* Add log

* Extract i18n

* Add experimental notice on hooks

* Update model/feature_flags.go

* Swap user to userId

* Change userId to userID

Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Этот коммит содержится в:
Shota Gvinepadze
2022-11-03 22:43:30 +04:00
коммит произвёл GitHub
родитель cc69c917f2
Коммит b8da473da7
16 изменённых файлов: 847 добавлений и 3 удалений

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

@@ -807,6 +807,236 @@ func (s *hooksRPCServer) OnCloudLimitsUpdated(args *Z_OnCloudLimitsUpdatedArgs,
return nil
}
func init() {
hookNameToId["UserHasPermissionToCollection"] = UserHasPermissionToCollectionID
}
type Z_UserHasPermissionToCollectionArgs struct {
A *Context
B string
C string
D string
E *model.Permission
}
type Z_UserHasPermissionToCollectionReturns struct {
A bool
B error
}
func (g *hooksRPCClient) UserHasPermissionToCollection(c *Context, userID string, collectionType, collectionId string, permission *model.Permission) (bool, error) {
_args := &Z_UserHasPermissionToCollectionArgs{c, userID, collectionType, collectionId, permission}
_returns := &Z_UserHasPermissionToCollectionReturns{}
if g.implemented[UserHasPermissionToCollectionID] {
if err := g.client.Call("Plugin.UserHasPermissionToCollection", _args, _returns); err != nil {
g.log.Error("RPC call UserHasPermissionToCollection to plugin failed.", mlog.Err(err))
}
}
return _returns.A, _returns.B
}
func (s *hooksRPCServer) UserHasPermissionToCollection(args *Z_UserHasPermissionToCollectionArgs, returns *Z_UserHasPermissionToCollectionReturns) error {
if hook, ok := s.impl.(interface {
UserHasPermissionToCollection(c *Context, userID string, collectionType, collectionId string, permission *model.Permission) (bool, error)
}); ok {
returns.A, returns.B = hook.UserHasPermissionToCollection(args.A, args.B, args.C, args.D, args.E)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("Hook UserHasPermissionToCollection called but not implemented."))
}
return nil
}
func init() {
hookNameToId["GetAllCollectionIDsForUser"] = GetAllCollectionIDsForUserID
}
type Z_GetAllCollectionIDsForUserArgs struct {
A *Context
B string
C string
}
type Z_GetAllCollectionIDsForUserReturns struct {
A []string
B error
}
func (g *hooksRPCClient) GetAllCollectionIDsForUser(c *Context, userID, collectionType string) ([]string, error) {
_args := &Z_GetAllCollectionIDsForUserArgs{c, userID, collectionType}
_returns := &Z_GetAllCollectionIDsForUserReturns{}
if g.implemented[GetAllCollectionIDsForUserID] {
if err := g.client.Call("Plugin.GetAllCollectionIDsForUser", _args, _returns); err != nil {
g.log.Error("RPC call GetAllCollectionIDsForUser to plugin failed.", mlog.Err(err))
}
}
return _returns.A, _returns.B
}
func (s *hooksRPCServer) GetAllCollectionIDsForUser(args *Z_GetAllCollectionIDsForUserArgs, returns *Z_GetAllCollectionIDsForUserReturns) error {
if hook, ok := s.impl.(interface {
GetAllCollectionIDsForUser(c *Context, userID, collectionType string) ([]string, error)
}); ok {
returns.A, returns.B = hook.GetAllCollectionIDsForUser(args.A, args.B, args.C)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("Hook GetAllCollectionIDsForUser called but not implemented."))
}
return nil
}
func init() {
hookNameToId["GetAllUserIdsForCollection"] = GetAllUserIdsForCollectionID
}
type Z_GetAllUserIdsForCollectionArgs struct {
A *Context
B string
C string
}
type Z_GetAllUserIdsForCollectionReturns struct {
A []string
B error
}
func (g *hooksRPCClient) GetAllUserIdsForCollection(c *Context, collectionType, collectionID string) ([]string, error) {
_args := &Z_GetAllUserIdsForCollectionArgs{c, collectionType, collectionID}
_returns := &Z_GetAllUserIdsForCollectionReturns{}
if g.implemented[GetAllUserIdsForCollectionID] {
if err := g.client.Call("Plugin.GetAllUserIdsForCollection", _args, _returns); err != nil {
g.log.Error("RPC call GetAllUserIdsForCollection to plugin failed.", mlog.Err(err))
}
}
return _returns.A, _returns.B
}
func (s *hooksRPCServer) GetAllUserIdsForCollection(args *Z_GetAllUserIdsForCollectionArgs, returns *Z_GetAllUserIdsForCollectionReturns) error {
if hook, ok := s.impl.(interface {
GetAllUserIdsForCollection(c *Context, collectionType, collectionID string) ([]string, error)
}); ok {
returns.A, returns.B = hook.GetAllUserIdsForCollection(args.A, args.B, args.C)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("Hook GetAllUserIdsForCollection called but not implemented."))
}
return nil
}
func init() {
hookNameToId["GetTopicRedirect"] = GetTopicRedirectID
}
type Z_GetTopicRedirectArgs struct {
A *Context
B string
C string
}
type Z_GetTopicRedirectReturns struct {
A string
B error
}
func (g *hooksRPCClient) GetTopicRedirect(c *Context, topicType, topicID string) (string, error) {
_args := &Z_GetTopicRedirectArgs{c, topicType, topicID}
_returns := &Z_GetTopicRedirectReturns{}
if g.implemented[GetTopicRedirectID] {
if err := g.client.Call("Plugin.GetTopicRedirect", _args, _returns); err != nil {
g.log.Error("RPC call GetTopicRedirect to plugin failed.", mlog.Err(err))
}
}
return _returns.A, _returns.B
}
func (s *hooksRPCServer) GetTopicRedirect(args *Z_GetTopicRedirectArgs, returns *Z_GetTopicRedirectReturns) error {
if hook, ok := s.impl.(interface {
GetTopicRedirect(c *Context, topicType, topicID string) (string, error)
}); ok {
returns.A, returns.B = hook.GetTopicRedirect(args.A, args.B, args.C)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("Hook GetTopicRedirect called but not implemented."))
}
return nil
}
func init() {
hookNameToId["GetCollectionMetadataByIds"] = GetCollectionMetadataByIdsID
}
type Z_GetCollectionMetadataByIdsArgs struct {
A *Context
B string
C []string
}
type Z_GetCollectionMetadataByIdsReturns struct {
A map[string]*model.CollectionMetadata
B error
}
func (g *hooksRPCClient) GetCollectionMetadataByIds(c *Context, collectionType string, collectionIds []string) (map[string]*model.CollectionMetadata, error) {
_args := &Z_GetCollectionMetadataByIdsArgs{c, collectionType, collectionIds}
_returns := &Z_GetCollectionMetadataByIdsReturns{}
if g.implemented[GetCollectionMetadataByIdsID] {
if err := g.client.Call("Plugin.GetCollectionMetadataByIds", _args, _returns); err != nil {
g.log.Error("RPC call GetCollectionMetadataByIds to plugin failed.", mlog.Err(err))
}
}
return _returns.A, _returns.B
}
func (s *hooksRPCServer) GetCollectionMetadataByIds(args *Z_GetCollectionMetadataByIdsArgs, returns *Z_GetCollectionMetadataByIdsReturns) error {
if hook, ok := s.impl.(interface {
GetCollectionMetadataByIds(c *Context, collectionType string, collectionIds []string) (map[string]*model.CollectionMetadata, error)
}); ok {
returns.A, returns.B = hook.GetCollectionMetadataByIds(args.A, args.B, args.C)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("Hook GetCollectionMetadataByIds called but not implemented."))
}
return nil
}
func init() {
hookNameToId["GetTopicMetadataByIds"] = GetTopicMetadataByIdsID
}
type Z_GetTopicMetadataByIdsArgs struct {
A *Context
B string
C []string
}
type Z_GetTopicMetadataByIdsReturns struct {
A map[string]*model.TopicMetadata
B error
}
func (g *hooksRPCClient) GetTopicMetadataByIds(c *Context, topicType string, topicIds []string) (map[string]*model.TopicMetadata, error) {
_args := &Z_GetTopicMetadataByIdsArgs{c, topicType, topicIds}
_returns := &Z_GetTopicMetadataByIdsReturns{}
if g.implemented[GetTopicMetadataByIdsID] {
if err := g.client.Call("Plugin.GetTopicMetadataByIds", _args, _returns); err != nil {
g.log.Error("RPC call GetTopicMetadataByIds to plugin failed.", mlog.Err(err))
}
}
return _returns.A, _returns.B
}
func (s *hooksRPCServer) GetTopicMetadataByIds(args *Z_GetTopicMetadataByIdsArgs, returns *Z_GetTopicMetadataByIdsReturns) error {
if hook, ok := s.impl.(interface {
GetTopicMetadataByIds(c *Context, topicType string, topicIds []string) (map[string]*model.TopicMetadata, error)
}); ok {
returns.A, returns.B = hook.GetTopicMetadataByIds(args.A, args.B, args.C)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("Hook GetTopicMetadataByIds called but not implemented."))
}
return nil
}
type Z_RegisterCommandArgs struct {
A *model.Command
}
@@ -5708,3 +5938,33 @@ func (s *apiRPCServer) EnsureBotUser(args *Z_EnsureBotUserArgs, returns *Z_Ensur
}
return nil
}
type Z_RegisterCollectionAndTopicArgs struct {
A string
B string
}
type Z_RegisterCollectionAndTopicReturns struct {
A error
}
func (g *apiRPCClient) RegisterCollectionAndTopic(collectionType, topicType string) error {
_args := &Z_RegisterCollectionAndTopicArgs{collectionType, topicType}
_returns := &Z_RegisterCollectionAndTopicReturns{}
if err := g.client.Call("Plugin.RegisterCollectionAndTopic", _args, _returns); err != nil {
log.Printf("RPC call to RegisterCollectionAndTopic API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) RegisterCollectionAndTopic(args *Z_RegisterCollectionAndTopicArgs, returns *Z_RegisterCollectionAndTopicReturns) error {
if hook, ok := s.impl.(interface {
RegisterCollectionAndTopic(collectionType, topicType string) error
}); ok {
returns.A = hook.RegisterCollectionAndTopic(args.A, args.B)
returns.A = encodableError(returns.A)
} else {
return encodableError(fmt.Errorf("API RegisterCollectionAndTopic called but not implemented."))
}
return nil
}