Allows creating new remote clusters without providing a password (#27864)
* Allows creating new remote clusters without providing a password If the endpoint receives a request with no password, it will generate one internally and return it in the response, so the frotend can show it to the user. * Use a random string instead of a UUID for the generated password * Update function name to avoid CString reference and adds assertion * Update server/channels/utils/textgeneration.go Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com> * Extends the charset --------- Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
06d8c857ea
Коммит
eec9a4742a
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/remotecluster"
|
||||
)
|
||||
|
||||
@@ -366,11 +367,6 @@ func createRemoteCluster(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if rcWithTeamAndPassword.Password == "" {
|
||||
c.SetInvalidParam("password")
|
||||
return
|
||||
}
|
||||
|
||||
url := c.App.GetSiteURL()
|
||||
if url == "" {
|
||||
c.Err = model.NewAppError("createRemoteCluster", "api.get_site_url_error", nil, "", http.StatusUnprocessableEntity)
|
||||
@@ -398,7 +394,12 @@ func createRemoteCluster(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
rcSaved.Sanitize()
|
||||
|
||||
inviteCode, iErr := c.App.CreateRemoteClusterInvite(rcSaved.RemoteId, url, rcSaved.Token, rcWithTeamAndPassword.Password)
|
||||
password := rcWithTeamAndPassword.Password
|
||||
if password == "" {
|
||||
password = utils.SecureRandString(16)
|
||||
}
|
||||
|
||||
inviteCode, iErr := c.App.CreateRemoteClusterInvite(rcSaved.RemoteId, url, rcSaved.Token, password)
|
||||
if iErr != nil {
|
||||
c.Err = iErr
|
||||
return
|
||||
@@ -408,7 +409,12 @@ func createRemoteCluster(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddEventResultState(rcSaved)
|
||||
auditRec.AddEventObjectType("remotecluster")
|
||||
|
||||
b, err := json.Marshal(model.RemoteClusterWithInvite{RemoteCluster: rcSaved, Invite: inviteCode})
|
||||
resp := model.RemoteClusterWithInvite{RemoteCluster: rcSaved, Invite: inviteCode}
|
||||
if rcWithTeamAndPassword.Password == "" {
|
||||
resp.Password = password
|
||||
}
|
||||
|
||||
b, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("createRemoteCluster", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
|
||||
Ссылка в новой задаче
Block a user