Merge pull request #1049 from apaatsio/full-teams-data
Use display name instead of name in team switcher menu
Этот коммит содержится в:
23
api/team.go
23
api/team.go
@@ -52,7 +52,7 @@ func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !isTreamCreationAllowed(c, email) {
|
||||
if !isTeamCreationAllowed(c, email) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func createTeamFromSSO(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !isTreamCreationAllowed(c, team.Email) {
|
||||
if !isTeamCreationAllowed(c, team.Email) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !isTreamCreationAllowed(c, teamSignup.Team.Email) {
|
||||
if !isTeamCreationAllowed(c, teamSignup.Team.Email) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ func CreateTeam(c *Context, team *model.Team) *model.Team {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !isTreamCreationAllowed(c, team.Email) {
|
||||
if !isTeamCreationAllowed(c, team.Email) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -276,12 +276,12 @@ func CreateTeam(c *Context, team *model.Team) *model.Team {
|
||||
}
|
||||
}
|
||||
|
||||
func isTreamCreationAllowed(c *Context, email string) bool {
|
||||
func isTeamCreationAllowed(c *Context, email string) bool {
|
||||
|
||||
email = strings.ToLower(email)
|
||||
|
||||
if !utils.Cfg.TeamSettings.EnableTeamCreation {
|
||||
c.Err = model.NewAppError("isTreamCreationAllowed", "Team creation has been disabled. Please ask your systems administrator for details.", "")
|
||||
c.Err = model.NewAppError("isTeamCreationAllowed", "Team creation has been disabled. Please ask your systems administrator for details.", "")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ func isTreamCreationAllowed(c *Context, email string) bool {
|
||||
}
|
||||
|
||||
if len(utils.Cfg.TeamSettings.RestrictCreationToDomains) > 0 && !matched {
|
||||
c.Err = model.NewAppError("isTreamCreationAllowed", "Email must be from a specific domain (e.g. @example.com). Please ask your systems administrator for details.", "")
|
||||
c.Err = model.NewAppError("isTeamCreationAllowed", "Email must be from a specific domain (e.g. @example.com). Please ask your systems administrator for details.", "")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -409,14 +409,13 @@ func findTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
} else {
|
||||
teams := result.Data.([]*model.Team)
|
||||
|
||||
s := make([]string, 0, len(teams))
|
||||
|
||||
m := make(map[string]*model.Team)
|
||||
for _, v := range teams {
|
||||
s = append(s, v.Name)
|
||||
v.Sanitize()
|
||||
m[v.Id] = v
|
||||
}
|
||||
|
||||
w.Write([]byte(model.ArrayToJson(s)))
|
||||
w.Write([]byte(model.TeamMapToJson(m)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,9 +121,12 @@ func TestFindTeamByEmail(t *testing.T) {
|
||||
if r1, err := Client.FindTeams(user.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
domains := r1.Data.([]string)
|
||||
if domains[0] != team.Name {
|
||||
t.Fatal(domains)
|
||||
teams := r1.Data.(map[string]*model.Team)
|
||||
if teams[team.Id].Name != team.Name {
|
||||
t.Fatal()
|
||||
}
|
||||
if teams[team.Id].DisplayName != team.DisplayName {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ func (c *Client) FindTeams(email string) (*Result, *AppError) {
|
||||
} else {
|
||||
|
||||
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||
r.Header.Get(HEADER_ETAG_SERVER), ArrayFromJson(r.Body)}, nil
|
||||
r.Header.Get(HEADER_ETAG_SERVER), TeamMapFromJson(r.Body)}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,3 +219,9 @@ func CleanTeamName(s string) string {
|
||||
|
||||
func (o *Team) PreExport() {
|
||||
}
|
||||
|
||||
func (o *Team) Sanitize() {
|
||||
o.Email = ""
|
||||
o.Type = ""
|
||||
o.AllowedDomains = ""
|
||||
}
|
||||
|
||||
@@ -11,7 +11,24 @@ var AboutBuildModal = require('./about_build_modal.jsx');
|
||||
var Constants = require('../utils/constants.jsx');
|
||||
|
||||
function getStateFromStores() {
|
||||
return {teams: UserStore.getTeams()};
|
||||
let teams = [];
|
||||
let teamsObject = UserStore.getTeams();
|
||||
for (let teamId in teamsObject) {
|
||||
if (teamsObject.hasOwnProperty(teamId)) {
|
||||
teams.push(teamsObject[teamId]);
|
||||
}
|
||||
}
|
||||
teams.sort(function sortByDisplayName(teamA, teamB) {
|
||||
let teamADisplayName = teamA.display_name.toLowerCase();
|
||||
let teamBDisplayName = teamB.display_name.toLowerCase();
|
||||
if (teamADisplayName < teamBDisplayName) {
|
||||
return -1;
|
||||
} else if (teamADisplayName > teamBDisplayName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
return {teams};
|
||||
}
|
||||
|
||||
export default class NavbarDropdown extends React.Component {
|
||||
@@ -154,9 +171,9 @@ export default class NavbarDropdown extends React.Component {
|
||||
</li>
|
||||
);
|
||||
|
||||
this.state.teams.forEach((teamName) => {
|
||||
if (teamName !== this.props.teamName) {
|
||||
teams.push(<li key={teamName}><a href={Utils.getWindowLocationOrigin() + '/' + teamName}>{'Switch to ' + teamName}</a></li>);
|
||||
this.state.teams.forEach((team) => {
|
||||
if (team.name !== this.props.teamName) {
|
||||
teams.push(<li key={team.name}><a href={Utils.getWindowLocationOrigin() + '/' + team.name}>{'Switch to ' + team.display_name}</a></li>);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user