From 4af08121e6ad32fe8ab228f2a64b139a62275b3c Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 18 Jun 2015 12:13:56 -0400 Subject: fix command comparator and team store --- api/command.go | 11 +++++----- web/react/components/team_settings.jsx | 10 +++++++++ web/react/stores/team_store.jsx | 38 +++++++++++----------------------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/api/command.go b/api/command.go index 94d2d8f60..aedbe07cc 100644 --- a/api/command.go +++ b/api/command.go @@ -9,6 +9,8 @@ import ( "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" "net/http" + "reflect" + "runtime" "strconv" "strings" ) @@ -19,14 +21,13 @@ var commands = []commandHandler{ logoutCommand, joinCommand, loadTestCommand, + echoCommand, } func InitCommand(r *mux.Router) { l4g.Debug("Initializing command api routes") r.Handle("/command", ApiUserRequired(command)).Methods("POST") - commands = append(commands, echoCommand) - hub.Start() } @@ -75,10 +76,10 @@ func checkCommand(c *Context, command *model.Command) bool { allowValet = tResult.Data.(*model.Team).AllowValet } - var ec commandHandler - ec = echoCommand + ec := runtime.FuncForPC(reflect.ValueOf(echoCommand).Pointer()).Name() + for _, v := range commands { - if !allowValet && &v == &ec { + if !allowValet && ec == runtime.FuncForPC(reflect.ValueOf(v).Pointer()).Name() { continue } diff --git a/web/react/components/team_settings.jsx b/web/react/components/team_settings.jsx index 8ad7d7043..0cec30f3e 100644 --- a/web/react/components/team_settings.jsx +++ b/web/react/components/team_settings.jsx @@ -33,6 +33,16 @@ var FeatureTab = React.createClass({ this.setState({ allow_valet: val }); this.refs.wrapper.getDOMNode().focus(); }, + componentWillReceiveProps: function(newProps) { + var team = newProps.team; + + var allow_valet = "false"; + if (team && team.allow_valet) { + allow_valet = "true"; + } + + this.setState({ allow_valet: allow_valet }); + }, getInitialState: function() { var team = this.props.team; diff --git a/web/react/stores/team_store.jsx b/web/react/stores/team_store.jsx index e29106b22..e95daeeba 100644 --- a/web/react/stores/team_store.jsx +++ b/web/react/stores/team_store.jsx @@ -22,35 +22,20 @@ var TeamStore = assign({}, EventEmitter.prototype, { this.removeListener(CHANGE_EVENT, callback); }, get: function(id) { - var current = null; var c = this._getTeams(); - - c.some(function(team) { - if (team.id == id) { - current = team; - return true; - } - return false; - }); - - return current; + return c[id]; }, getByName: function(name) { var current = null; - var c = this._getTeams(); - - c.some(function(team) { - if (team.name == name) { - current = team; - return true; - } + var t = this._getTeams(); - return false; - - }); - - return current; + for (id in t) { + if (t[id].name == name) { + return t[id]; + } + } + return null; }, getAll: function() { return this._getTeams(); @@ -78,12 +63,13 @@ var TeamStore = assign({}, EventEmitter.prototype, { this._storeTeams(teams); }, _storeTeams: function(teams) { - sessionStorage.setItem("teams", JSON.stringify(teams)); + sessionStorage.setItem("user_teams", JSON.stringify(teams)); }, _getTeams: function() { - var teams = []; + var teams = {}; + try { - teams = JSON.parse(sessionStorage.teams); + teams = JSON.parse(sessionStorage.user_teams); } catch (err) { } -- cgit v1.2.3-1-g7c22