Add RequestTrialLicense function to the plugin API (#17551)
* Add RequestTrialLicense function to the plugin API * Fix strings IDs Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ee43bf9a84
Коммит
0bf7aed02e
@@ -1105,3 +1105,40 @@ func (api *PluginAPI) PublishPluginClusterEvent(ev model.PluginClusterEvent,
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequestTrialLicense requests a trial license and installs it in the server
|
||||||
|
func (api *PluginAPI) RequestTrialLicense(requesterID string, users int, termsAccepted bool, receiveEmailsAccepted bool) *model.AppError {
|
||||||
|
if *api.app.Config().ExperimentalSettings.RestrictSystemAdmin {
|
||||||
|
return model.NewAppError("RequestTrialLicense", "api.restricted_system_admin", nil, "", http.StatusForbidden)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !termsAccepted {
|
||||||
|
return model.NewAppError("RequestTrialLicense", "api.license.request-trial.bad-request.terms-not-accepted", nil, "", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
if users == 0 {
|
||||||
|
return model.NewAppError("RequestTrialLicense", "api.license.request-trial.bad-request", nil, "", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
requester, err := api.app.GetUser(requesterID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
trialLicenseRequest := &model.TrialLicenseRequest{
|
||||||
|
ServerID: api.app.TelemetryId(),
|
||||||
|
Name: requester.GetDisplayName(model.SHOW_FULLNAME),
|
||||||
|
Email: requester.Email,
|
||||||
|
SiteName: *api.app.Config().TeamSettings.SiteName,
|
||||||
|
SiteURL: *api.app.Config().ServiceSettings.SiteURL,
|
||||||
|
Users: users,
|
||||||
|
TermsAccepted: termsAccepted,
|
||||||
|
ReceiveEmailsAccepted: receiveEmailsAccepted,
|
||||||
|
}
|
||||||
|
|
||||||
|
if trialLicenseRequest.SiteURL == "" {
|
||||||
|
return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.no-site-url.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.app.Srv().RequestTrialLicense(trialLicenseRequest)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1066,6 +1066,11 @@ type API interface {
|
|||||||
//
|
//
|
||||||
// Minimum server version: 5.36
|
// Minimum server version: 5.36
|
||||||
PublishPluginClusterEvent(ev model.PluginClusterEvent, opts model.PluginClusterEventSendOptions) error
|
PublishPluginClusterEvent(ev model.PluginClusterEvent, opts model.PluginClusterEventSendOptions) error
|
||||||
|
|
||||||
|
// RequestTrialLicense requests a trial license and installs it in the server
|
||||||
|
//
|
||||||
|
// Minimum server version: 5.36
|
||||||
|
RequestTrialLicense(requesterID string, users int, termsAccepted bool, receiveEmailsAccepted bool) *model.AppError
|
||||||
}
|
}
|
||||||
|
|
||||||
var handshake = plugin.HandshakeConfig{
|
var handshake = plugin.HandshakeConfig{
|
||||||
|
|||||||
@@ -1127,3 +1127,10 @@ func (api *apiTimerLayer) PublishPluginClusterEvent(ev model.PluginClusterEvent,
|
|||||||
api.recordTime(startTime, "PublishPluginClusterEvent", _returnsA == nil)
|
api.recordTime(startTime, "PublishPluginClusterEvent", _returnsA == nil)
|
||||||
return _returnsA
|
return _returnsA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *apiTimerLayer) RequestTrialLicense(requesterID string, users int, termsAccepted bool, receiveEmailsAccepted bool) *model.AppError {
|
||||||
|
startTime := timePkg.Now()
|
||||||
|
_returnsA := api.apiImpl.RequestTrialLicense(requesterID, users, termsAccepted, receiveEmailsAccepted)
|
||||||
|
api.recordTime(startTime, "RequestTrialLicense", _returnsA == nil)
|
||||||
|
return _returnsA
|
||||||
|
}
|
||||||
|
|||||||
@@ -5000,3 +5000,34 @@ func (s *apiRPCServer) PublishPluginClusterEvent(args *Z_PublishPluginClusterEve
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Z_RequestTrialLicenseArgs struct {
|
||||||
|
A string
|
||||||
|
B int
|
||||||
|
C bool
|
||||||
|
D bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Z_RequestTrialLicenseReturns struct {
|
||||||
|
A *model.AppError
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *apiRPCClient) RequestTrialLicense(requesterID string, users int, termsAccepted bool, receiveEmailsAccepted bool) *model.AppError {
|
||||||
|
_args := &Z_RequestTrialLicenseArgs{requesterID, users, termsAccepted, receiveEmailsAccepted}
|
||||||
|
_returns := &Z_RequestTrialLicenseReturns{}
|
||||||
|
if err := g.client.Call("Plugin.RequestTrialLicense", _args, _returns); err != nil {
|
||||||
|
log.Printf("RPC call to RequestTrialLicense API failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
return _returns.A
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *apiRPCServer) RequestTrialLicense(args *Z_RequestTrialLicenseArgs, returns *Z_RequestTrialLicenseReturns) error {
|
||||||
|
if hook, ok := s.impl.(interface {
|
||||||
|
RequestTrialLicense(requesterID string, users int, termsAccepted bool, receiveEmailsAccepted bool) *model.AppError
|
||||||
|
}); ok {
|
||||||
|
returns.A = hook.RequestTrialLicense(args.A, args.B, args.C, args.D)
|
||||||
|
} else {
|
||||||
|
return encodableError(fmt.Errorf("API RequestTrialLicense called but not implemented."))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -2804,6 +2804,22 @@ func (_m *API) RemoveTeamIcon(teamID string) *model.AppError {
|
|||||||
return r0
|
return r0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequestTrialLicense provides a mock function with given fields: requesterID, users, termsAccepted, receiveEmailsAccepted
|
||||||
|
func (_m *API) RequestTrialLicense(requesterID string, users int, termsAccepted bool, receiveEmailsAccepted bool) *model.AppError {
|
||||||
|
ret := _m.Called(requesterID, users, termsAccepted, receiveEmailsAccepted)
|
||||||
|
|
||||||
|
var r0 *model.AppError
|
||||||
|
if rf, ok := ret.Get(0).(func(string, int, bool, bool) *model.AppError); ok {
|
||||||
|
r0 = rf(requesterID, users, termsAccepted, receiveEmailsAccepted)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0
|
||||||
|
}
|
||||||
|
|
||||||
// SaveConfig provides a mock function with given fields: config
|
// SaveConfig provides a mock function with given fields: config
|
||||||
func (_m *API) SaveConfig(config *model.Config) *model.AppError {
|
func (_m *API) SaveConfig(config *model.Config) *model.AppError {
|
||||||
ret := _m.Called(config)
|
ret := _m.Called(config)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user