Removing old signup team API (#4950)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
b3f2ab654e
Коммит
635628cf30
52
api/team.go
52
api/team.go
@@ -25,7 +25,6 @@ func InitTeam() {
|
|||||||
l4g.Debug(utils.T("api.team.init.debug"))
|
l4g.Debug(utils.T("api.team.init.debug"))
|
||||||
|
|
||||||
BaseRoutes.Teams.Handle("/create", ApiAppHandler(createTeam)).Methods("POST")
|
BaseRoutes.Teams.Handle("/create", ApiAppHandler(createTeam)).Methods("POST")
|
||||||
BaseRoutes.Teams.Handle("/signup", ApiAppHandler(signupTeam)).Methods("POST")
|
|
||||||
BaseRoutes.Teams.Handle("/all", ApiAppHandler(getAll)).Methods("GET")
|
BaseRoutes.Teams.Handle("/all", ApiAppHandler(getAll)).Methods("GET")
|
||||||
BaseRoutes.Teams.Handle("/all_team_listings", ApiUserRequired(GetAllTeamListings)).Methods("GET")
|
BaseRoutes.Teams.Handle("/all_team_listings", ApiUserRequired(GetAllTeamListings)).Methods("GET")
|
||||||
BaseRoutes.Teams.Handle("/get_invite_info", ApiAppHandler(getInviteInfo)).Methods("POST")
|
BaseRoutes.Teams.Handle("/get_invite_info", ApiAppHandler(getInviteInfo)).Methods("POST")
|
||||||
@@ -52,57 +51,6 @@ func InitTeam() {
|
|||||||
BaseRoutes.Teams.Handle("/add_user_to_team_from_invite", ApiUserRequired(addUserToTeamFromInvite)).Methods("POST")
|
BaseRoutes.Teams.Handle("/add_user_to_team_from_invite", ApiUserRequired(addUserToTeamFromInvite)).Methods("POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
||||||
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail {
|
|
||||||
c.Err = model.NewLocAppError("signupTeam", "api.team.signup_team.email_disabled.app_error", nil, "")
|
|
||||||
c.Err.StatusCode = http.StatusNotImplemented
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
m := model.MapFromJson(r.Body)
|
|
||||||
email := strings.ToLower(strings.TrimSpace(m["email"]))
|
|
||||||
|
|
||||||
if len(email) == 0 {
|
|
||||||
c.SetInvalidParam("signupTeam", "email")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isTeamCreationAllowed(c, email) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
subject := c.T("api.templates.signup_team_subject",
|
|
||||||
map[string]interface{}{"SiteName": utils.ClientCfg["SiteName"]})
|
|
||||||
|
|
||||||
bodyPage := utils.NewHTMLTemplate("signup_team_body", c.Locale)
|
|
||||||
bodyPage.Props["SiteURL"] = c.GetSiteURL()
|
|
||||||
bodyPage.Props["Title"] = c.T("api.templates.signup_team_body.title")
|
|
||||||
bodyPage.Props["Button"] = c.T("api.templates.signup_team_body.button")
|
|
||||||
bodyPage.Html["Info"] = template.HTML(c.T("api.templates.signup_team_body.info",
|
|
||||||
map[string]interface{}{"SiteName": utils.ClientCfg["SiteName"]}))
|
|
||||||
|
|
||||||
props := make(map[string]string)
|
|
||||||
props["email"] = email
|
|
||||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
|
||||||
|
|
||||||
data := model.MapToJson(props)
|
|
||||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
|
||||||
|
|
||||||
bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_team_complete/?d=%s&h=%s", c.GetSiteURL(), url.QueryEscape(data), url.QueryEscape(hash))
|
|
||||||
|
|
||||||
if err := utils.SendMail(email, subject, bodyPage.Render()); err != nil {
|
|
||||||
c.Err = err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !utils.Cfg.EmailSettings.RequireEmailVerification {
|
|
||||||
m["follow_link"] = fmt.Sprintf("/signup_team_complete/?d=%s&h=%s", url.QueryEscape(data), url.QueryEscape(hash))
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", " *")
|
|
||||||
w.Write([]byte(model.MapToJson(m)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
team := model.TeamFromJson(r.Body)
|
team := model.TeamFromJson(r.Body)
|
||||||
|
|
||||||
|
|||||||
@@ -11,17 +11,6 @@ import (
|
|||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSignupTeam(t *testing.T) {
|
|
||||||
th := Setup().InitBasic()
|
|
||||||
th.BasicClient.Logout()
|
|
||||||
Client := th.BasicClient
|
|
||||||
|
|
||||||
_, err := Client.SignupTeam("test@nowhere.com", "name")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateTeam(t *testing.T) {
|
func TestCreateTeam(t *testing.T) {
|
||||||
th := Setup().InitBasic()
|
th := Setup().InitBasic()
|
||||||
th.BasicClient.Logout()
|
th.BasicClient.Logout()
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ func InitUser() {
|
|||||||
|
|
||||||
func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail || !utils.Cfg.TeamSettings.EnableUserCreation {
|
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail || !utils.Cfg.TeamSettings.EnableUserCreation {
|
||||||
c.Err = model.NewLocAppError("signupTeam", "api.user.create_user.signup_email_disabled.app_error", nil, "")
|
c.Err = model.NewLocAppError("createUser", "api.user.create_user.signup_email_disabled.app_error", nil, "")
|
||||||
c.Err.StatusCode = http.StatusNotImplemented
|
c.Err.StatusCode = http.StatusNotImplemented
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,22 +299,6 @@ func (c *Client) GetPing() (map[string]string, *AppError) {
|
|||||||
|
|
||||||
// Team Routes Section
|
// Team Routes Section
|
||||||
|
|
||||||
// SignupTeam sends an email with a team sign-up link to the provided address if email
|
|
||||||
// verification is enabled, otherwise it returns a map with a "follow_link" entry
|
|
||||||
// containing the team sign-up link.
|
|
||||||
func (c *Client) SignupTeam(email string, displayName string) (*Result, *AppError) {
|
|
||||||
m := make(map[string]string)
|
|
||||||
m["email"] = email
|
|
||||||
m["display_name"] = displayName
|
|
||||||
if r, err := c.DoApiPost("/teams/signup", MapToJson(m)); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
defer closeBody(r)
|
|
||||||
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
|
||||||
r.Header.Get(HEADER_ETAG_SERVER), MapFromJson(r.Body)}, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateTeam creates a team based on the provided Team struct. On success it returns
|
// CreateTeam creates a team based on the provided Team struct. On success it returns
|
||||||
// the Team struct with the Id, CreateAt and other server-decided fields populated.
|
// the Team struct with the Id, CreateAt and other server-decided fields populated.
|
||||||
func (c *Client) CreateTeam(team *Team) (*Result, *AppError) {
|
func (c *Client) CreateTeam(team *Team) (*Result, *AppError) {
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
|
||||||
// See License.txt for license information.
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TeamSignup struct {
|
|
||||||
Team Team `json:"team"`
|
|
||||||
User User `json:"user"`
|
|
||||||
Invites []string `json:"invites"`
|
|
||||||
Data string `json:"data"`
|
|
||||||
Hash string `json:"hash"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func TeamSignupFromJson(data io.Reader) *TeamSignup {
|
|
||||||
decoder := json.NewDecoder(data)
|
|
||||||
var o TeamSignup
|
|
||||||
err := decoder.Decode(&o)
|
|
||||||
if err == nil {
|
|
||||||
return &o
|
|
||||||
} else {
|
|
||||||
fmt.Println(err)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *TeamSignup) ToJson() string {
|
|
||||||
b, err := json.Marshal(o)
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
} else {
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
|
||||||
// See License.txt for license information.
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestTeamSignupJson(t *testing.T) {
|
|
||||||
team := Team{Id: NewId(), DisplayName: NewId()}
|
|
||||||
o := TeamSignup{Team: team, Data: "data"}
|
|
||||||
json := o.ToJson()
|
|
||||||
ro := TeamSignupFromJson(strings.NewReader(json))
|
|
||||||
|
|
||||||
if o.Team.Id != ro.Team.Id {
|
|
||||||
t.Fatal("Ids do not match")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -446,18 +446,6 @@ export default class Client {
|
|||||||
end(this.handleResponse.bind(this, 'exportTeam', success, error));
|
end(this.handleResponse.bind(this, 'exportTeam', success, error));
|
||||||
}
|
}
|
||||||
|
|
||||||
signupTeam(email, success, error) {
|
|
||||||
request.
|
|
||||||
post(`${this.getTeamsRoute()}/signup`).
|
|
||||||
set(this.defaultHeaders).
|
|
||||||
type('application/json').
|
|
||||||
accept('application/json').
|
|
||||||
send({email}).
|
|
||||||
end(this.handleResponse.bind(this, 'signupTeam', success, error));
|
|
||||||
|
|
||||||
this.track('api', 'api_teams_signup');
|
|
||||||
}
|
|
||||||
|
|
||||||
adminResetMfa(userId, success, error) {
|
adminResetMfa(userId, success, error) {
|
||||||
const data = {};
|
const data = {};
|
||||||
data.user_id = userId;
|
data.user_id = userId;
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
|
||||||
// See License.txt for license information.
|
|
||||||
|
|
||||||
import BrowserStore from 'stores/browser_store.jsx';
|
|
||||||
|
|
||||||
import {FormattedMessage} from 'react-intl';
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import {Link, browserHistory} from 'react-router/es6';
|
|
||||||
|
|
||||||
export default class SignupTeamComplete extends React.Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
|
|
||||||
this.updateParent = this.updateParent.bind(this);
|
|
||||||
}
|
|
||||||
componentWillMount() {
|
|
||||||
const data = JSON.parse(this.props.location.query.d);
|
|
||||||
this.hash = this.props.location.query.h;
|
|
||||||
|
|
||||||
var initialState = BrowserStore.getGlobalItem(this.hash);
|
|
||||||
|
|
||||||
if (!initialState) {
|
|
||||||
initialState = {};
|
|
||||||
initialState.wizard = 'welcome';
|
|
||||||
initialState.team = {};
|
|
||||||
initialState.team.email = data.email;
|
|
||||||
initialState.team.allowed_domains = '';
|
|
||||||
initialState.invites = [];
|
|
||||||
initialState.invites.push('');
|
|
||||||
initialState.invites.push('');
|
|
||||||
initialState.invites.push('');
|
|
||||||
initialState.user = {};
|
|
||||||
initialState.hash = this.hash;
|
|
||||||
initialState.data = this.props.location.query.d;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState(initialState);
|
|
||||||
}
|
|
||||||
componentDidMount() {
|
|
||||||
browserHistory.push('/signup_team_complete/welcome');
|
|
||||||
}
|
|
||||||
updateParent(state, skipSet) {
|
|
||||||
BrowserStore.setGlobalItem(this.hash, state);
|
|
||||||
|
|
||||||
if (!skipSet) {
|
|
||||||
this.setState(state);
|
|
||||||
browserHistory.push('/signup_team_complete/' + state.wizard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<div className='signup-header'>
|
|
||||||
<Link to='/'>
|
|
||||||
<span className='fa fa-chevron-left'/>
|
|
||||||
<FormattedMessage id='web.header.back'/>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
<div className='col-sm-12'>
|
|
||||||
<div className='signup-team__container'>
|
|
||||||
<div id='signup-team-complete'>
|
|
||||||
{React.cloneElement(this.props.children, {
|
|
||||||
state: this.state,
|
|
||||||
updateParent: this.updateParent
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SignupTeamComplete.defaultProps = {
|
|
||||||
};
|
|
||||||
|
|
||||||
SignupTeamComplete.propTypes = {
|
|
||||||
location: React.PropTypes.object,
|
|
||||||
children: React.PropTypes.node
|
|
||||||
};
|
|
||||||
@@ -22,22 +22,6 @@ describe('Client.Team', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('signupTeam', function(done) {
|
|
||||||
var client = TestHelper.createClient();
|
|
||||||
var email = TestHelper.fakeEmail();
|
|
||||||
|
|
||||||
client.signupTeam(
|
|
||||||
email,
|
|
||||||
function(data) {
|
|
||||||
assert.equal(data.email, email);
|
|
||||||
done();
|
|
||||||
},
|
|
||||||
function(err) {
|
|
||||||
done(new Error(err.message));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('createTeam', function(done) {
|
it('createTeam', function(done) {
|
||||||
var client = TestHelper.createClient();
|
var client = TestHelper.createClient();
|
||||||
var team = TestHelper.fakeTeam();
|
var team = TestHelper.fakeTeam();
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user