From 3f5993eedfd52a0497f7a537601b2d7c9e4d744d Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 11 Aug 2015 14:36:45 -0400 Subject: Added initial api to allow clientside code to query serverside configuration --- api/api.go | 1 + api/config.go | 23 +++++++++++++++++++++++ web/react/utils/client.jsx | 21 +++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 api/config.go diff --git a/api/api.go b/api/api.go index 2ea27ed9f..9770930f7 100644 --- a/api/api.go +++ b/api/api.go @@ -40,6 +40,7 @@ func InitApi() { InitWebSocket(r) InitFile(r) InitCommand(r) + InitConfig(r) templatesDir := utils.FindDir("api/templates") l4g.Debug("Parsing server templates at %v", templatesDir) diff --git a/api/config.go b/api/config.go new file mode 100644 index 000000000..91097b4a1 --- /dev/null +++ b/api/config.go @@ -0,0 +1,23 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package api + +import ( + l4g "code.google.com/p/log4go" + "github.com/gorilla/mux" + "github.com/mattermost/platform/utils" + "net/http" + "strconv" +) + +func InitConfig(r *mux.Router) { + l4g.Debug("Initializing config api routes") + + sr := r.PathPrefix("/config").Subrouter() + sr.Handle("/get/bypass_email", ApiAppHandler(getBypassEmail)).Methods("GET") +} + +func getBypassEmail(c *Context, w http.ResponseWriter, r *http.Request) { + w.Write([]byte(strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail))) +} diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 6a1f7c820..5b5d8dc32 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -849,3 +849,24 @@ module.exports.updateValetFeature = function(data, success, error) { module.exports.track('api', 'api_teams_update_valet_feature'); }; + +module.exports.isEmailEnabledSynchronous = function() { + var enabled = false; + + $.ajax({ + async: false, + url: '/api/v1/config/get/bypass_email', + dataType: 'json', + type: 'GET', + success: function(value) { + enabled = !value; + }, + error: function(xhr, status, err) { + if (status != 200) { + handleError("isEmailEnabled", xhr, status, err); + } + } + }); + + return enabled; +}; -- cgit v1.2.3-1-g7c22 From e27ba7454d0bfe9f50736edcc15d0c47bfd48089 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 11 Aug 2015 15:47:48 -0400 Subject: Disabled the invite email portion of the team setup when email is disabled on the server --- web/react/components/signup_team_complete.jsx | 70 ++++++++++++++++++--------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/web/react/components/signup_team_complete.jsx b/web/react/components/signup_team_complete.jsx index 3f35a5912..238385a0b 100644 --- a/web/react/components/signup_team_complete.jsx +++ b/web/react/components/signup_team_complete.jsx @@ -428,23 +428,27 @@ SendInivtesPage = React.createClass({ e.preventDefault(); var valid = true; - var emails = []; - for (var i = 0; i < this.props.state.invites.length; i++) { - if (!this.refs['email_' + i].validate(this.props.state.team.email)) { - valid = false; - } else { - emails.push(this.refs['email_' + i].getValue()); + if (this.state.emailEnabled) { + var emails = []; + + for (var i = 0; i < this.props.state.invites.length; i++) { + if (!this.refs['email_' + i].validate(this.props.state.team.email)) { + valid = false; + } else { + emails.push(this.refs['email_' + i].getValue()); + } } - } - if (!valid) { - return; + if (valid) { + this.props.state.invites = emails; + } } - this.props.state.wizard = "username"; - this.props.state.invites = emails; - this.props.updateParent(this.props.state); + if (valid) { + this.props.state.wizard = "username"; + this.props.updateParent(this.props.state); + } }, submitAddInvite: function (e) { e.preventDefault(); @@ -461,22 +465,43 @@ SendInivtesPage = React.createClass({ this.props.updateParent(this.props.state); }, getInitialState: function() { - return { }; + return { + emailEnabled: client.isEmailEnabledSynchronous() + }; }, render: function() { - client.track('signup', 'signup_team_05_send_invites'); var name_error = this.state.name_error ? : null; - var emails = []; + var content = null; + var bottomContent = null; - for (var i = 0; i < this.props.state.invites.length; i++) { - if (i == 0) { - emails.push(); - } else { - emails.push(); + if (this.state.emailEnabled) { + var emails = []; + + for (var i = 0; i < this.props.state.invites.length; i++) { + if (i == 0) { + emails.push(); + } else { + emails.push(); + } } + + content = ( +
+ {emails} + +
+ ); + + bottomContent = ( +

{"if you prefer, you can invite " + strings.Team + " members later"}
and skip this step for now.

+ ); + } else { + content = ( +
Email is currently disabled for your team, and emails cannot be sent. Contact your system administrator to enable email and email invitations.
+ ); } return ( @@ -484,11 +509,10 @@ SendInivtesPage = React.createClass({

{"Invite " + utils.toTitleCase(strings.Team) + " Members"}

- { emails } - + {content}
-

{"if you prefer, you can invite " + strings.Team + " members later"}
and skip this step for now.

+ {bottomContent} -- cgit v1.2.3-1-g7c22 From 37909f52ad4f9cca9ffecd008956912b4a6cf5c7 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 11 Aug 2015 15:48:07 -0400 Subject: Disabled the invite members dialog when email is disabled on the server --- web/react/components/invite_member_modal.jsx | 65 +++++++++++++++++++++++----- web/react/pages/channel.jsx | 2 +- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/web/react/components/invite_member_modal.jsx b/web/react/components/invite_member_modal.jsx index 3eca79bae..fb3d46b0a 100644 --- a/web/react/components/invite_member_modal.jsx +++ b/web/react/components/invite_member_modal.jsx @@ -35,6 +35,10 @@ module.exports = React.createClass({ }); }, handleSubmit: function(e) { + if (!this.state.emailEnabled) { + return; + } + var inviteIds = this.state.inviteIds; var count = inviteIds.length; var invites = []; @@ -147,12 +151,18 @@ module.exports = React.createClass({ idCount: 0, emailErrors: {}, firstNameErrors: {}, - lastNameErrors: {} + lastNameErrors: {}, + emailEnabled: Client.isEmailEnabledSynchronous() }; }, render: function() { var currentUser = UserStore.getCurrentUser(); + var inputDisabled = ''; + if (!this.state.emailEnabled) { + inputDisabled = 'disabled'; + } + if (currentUser != null) { var inviteSections = []; var inviteIds = this.state.inviteIds; @@ -195,13 +205,13 @@ module.exports = React.createClass({ nameFields = (
- + {firstNameError}
- + {lastNameError}
@@ -212,7 +222,7 @@ module.exports = React.createClass({
{removeButton}
- + {emailError}
{nameFields} @@ -225,6 +235,45 @@ module.exports = React.createClass({ serverError =
; } + var content = null; + var sendButton = null; + if (this.state.emailEnabled) { + content = ( +
+ {serverError} + +
+
+ People invited automatically join Town Square channel. +
+ ); + + sendButton = + } else { + var teamInviteLink = null; + if (currentUser && this.props.teamType === 'O') { + var linkUrl = utils.getWindowLocationOrigin() + '/signup_user_complete/?id=' + currentUser.team_id; + var link = Team Invite Link; + + teamInviteLink = ( +

+ You can also invite people using the {link}. +

+ ); + } + + content = ( +
+

Email is currently disabled for your team, and email invitations cannot be sent. Contact your system administrator to enable email and email invitations.

+ {teamInviteLink} +
+ ); + } + return (
- + {sendButton}
diff --git a/web/react/pages/channel.jsx b/web/react/pages/channel.jsx index 90d90b29f..99d5c5e9f 100644 --- a/web/react/pages/channel.jsx +++ b/web/react/pages/channel.jsx @@ -99,7 +99,7 @@ global.window.setup_channel_page = function(team_name, team_type, team_id, chann ); React.render( - , + , document.getElementById('invite_member_modal') ); -- cgit v1.2.3-1-g7c22 From d35065d6fd8237468ee3aa63bfba3b2aa29bc4af Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 11 Aug 2015 16:52:36 -0400 Subject: Reformatted code to match the style guide --- web/react/components/signup_team_complete.jsx | 548 ++++++++++++++------------ web/react/pages/channel.jsx | 16 +- web/react/utils/client.jsx | 4 +- 3 files changed, 306 insertions(+), 262 deletions(-) diff --git a/web/react/components/signup_team_complete.jsx b/web/react/components/signup_team_complete.jsx index 238385a0b..ee690f692 100644 --- a/web/react/components/signup_team_complete.jsx +++ b/web/react/components/signup_team_complete.jsx @@ -1,7 +1,6 @@ // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. - var utils = require('../utils/utils.jsx'); var client = require('../utils/client.jsx'); var UserStore = require('../stores/user_store.jsx'); @@ -11,111 +10,132 @@ var constants = require('../utils/constants.jsx'); WelcomePage = React.createClass({ submitNext: function (e) { if (!BrowserStore.isLocalStorageSupported()) { - this.setState({ storage_error: "This service requires local storage to be enabled. Please enable it or exit private browsing."} ); + this.setState({storageError: 'This service requires local storage to be enabled. Please enable it or exit private browsing.'}); return; } e.preventDefault(); - this.props.state.wizard = "team_display_name"; + this.props.state.wizard = 'team_display_name'; this.props.updateParent(this.props.state); }, handleDiffEmail: function (e) { e.preventDefault(); - this.setState({ use_diff: true }); + this.setState({useDiff: true}); }, handleDiffSubmit: function (e) { e.preventDefault(); - var state = { use_diff: true, server_error: "" }; + var state = {useDiff: true, serverError: ''}; var email = this.refs.email.getDOMNode().value.trim().toLowerCase(); if (!email || !utils.isEmail(email)) { - state.email_error = "Please enter a valid email address"; + state.emailError = 'Please enter a valid email address'; this.setState(state); return; - } - else if (!BrowserStore.isLocalStorageSupported()) { - state.email_error = "This service requires local storage to be enabled. Please enable it or exit private browsing."; + } else if (!BrowserStore.isLocalStorageSupported()) { + state.emailError = 'This service requires local storage to be enabled. Please enable it or exit private browsing.'; this.setState(state); return; - } - else { - state.email_error = ""; + } else { + state.emailError = ''; } client.signupTeam(email, function(data) { - if (data["follow_link"]) { - window.location.href = data["follow_link"]; + if (data['follow_link']) { + window.location.href = data['follow_link']; } else { - this.props.state.wizard = "finished"; + this.props.state.wizard = 'finished'; this.props.updateParent(this.props.state); - window.location.href = "/signup_team_confirm/?email=" + encodeURIComponent(team.email); + window.location.href = '/signup_team_confirm/?email=' + encodeURIComponent(team.email); } }.bind(this), function(err) { - this.state.server_error = err.message; + this.state.serverError = err.message; this.setState(this.state); }.bind(this) ); }, getInitialState: function() { - return { use_diff: false }; + return {useDiff: false}; }, handleKeyPress: function(event) { - if (event.keyCode == 13) { + if (event.keyCode === 13) { this.submitNext(event); } }, componentWillMount: function() { - document.addEventListener("keyup", this.handleKeyPress, false); + document.addEventListener('keyup', this.handleKeyPress, false); }, componentWillUnmount: function() { - document.removeEventListener("keyup", this.handleKeyPress, false); + document.removeEventListener('keyup', this.handleKeyPress, false); }, render: function() { - client.track('signup', 'signup_team_01_welcome'); - var storage_error = this.state.storage_error ? : null; - var email_error = this.state.email_error ? : null; - var server_error = this.state.server_error ?
: null; + var storageError = null; + if (this.state.storageError) { + storageError = ; + } + + var emailError = null; + var emailDivClass = 'form-group'; + if (this.state.emailError) { + emailError = ; + emailDivClass += ' has-error'; + } + + var serverError = null; + if (this.state.serverError) { + serverError = ( +
+ +
+ ); + } + + var differentEmailLinkClass = ''; + var emailDivContainerClass = 'hidden'; + if (this.state.useDiff) { + differentEmailLinkClass = 'hidden'; + emailDivContainerClass = ''; + } return (

- -

Welcome to:

-

{config.SiteName}

+ +

Welcome to:

+

{config.SiteName}

-

Let's set up your new team

+

Let's set up your new team

Please confirm your email address:
-

-
{ this.props.state.team.email }
+
+
{this.props.state.team.email}

-

+

Your account will administer the new team site.
You can add other administrators later.

-
- - { storage_error } +
+ + {storageError}

-
-
-
-
- +
+
+
+
+
- { email_error } + {emailError}
- { server_error } - + {serverError} +
- Use a different email + Use a different email
); } @@ -124,7 +144,7 @@ WelcomePage = React.createClass({ TeamDisplayNamePage = React.createClass({ submitBack: function (e) { e.preventDefault(); - this.props.state.wizard = "welcome"; + this.props.state.wizard = 'welcome'; this.props.updateParent(this.props.state); }, submitNext: function (e) { @@ -132,17 +152,17 @@ TeamDisplayNamePage = React.createClass({ var display_name = this.refs.name.getDOMNode().value.trim(); if (!display_name) { - this.setState({name_error: "This field is required"}); + this.setState({nameError: 'This field is required'}); return; } - this.props.state.wizard = "team_url"; + this.props.state.wizard = 'team_url'; this.props.state.team.display_name = display_name; this.props.state.team.name = utils.cleanUpUrlable(display_name); this.props.updateParent(this.props.state); }, getInitialState: function() { - return { }; + return {}; }, handleFocus: function(e) { e.preventDefault(); @@ -150,31 +170,35 @@ TeamDisplayNamePage = React.createClass({ e.currentTarget.select(); }, render: function() { - client.track('signup', 'signup_team_02_name'); - var name_error = this.state.name_error ? : null; + var nameError = null; + var nameDivClass = 'form-group'; + if (this.state.nameError) { + nameError = ; + nameDivClass += ' has-error'; + } return (
- + -

{utils.toTitleCase(strings.Team) + " Name"}

-
-
-
- +

{utils.toTitleCase(strings.Team) + ' Name'}

+
+
+
+ +
+
+ {nameError}
-
- { name_error } -
-
{"Name your " + strings.Team + " in any language. Your " + strings.Team + " name shows in menus and headings."}
- - - +
{'Name your ' + strings.Team + ' in any language. Your ' + strings.Team + ' name shows in menus and headings.'}
+ + +
); } @@ -183,7 +207,7 @@ TeamDisplayNamePage = React.createClass({ TeamURLPage = React.createClass({ submitBack: function (e) { e.preventDefault(); - this.props.state.wizard = "team_display_name"; + this.props.state.wizard = 'team_display_name'; this.props.updateParent(this.props.state); }, submitNext: function (e) { @@ -191,25 +215,24 @@ TeamURLPage = React.createClass({ var name = this.refs.name.getDOMNode().value.trim(); if (!name) { - this.setState({name_error: "This field is required"}); + this.setState({nameError: 'This field is required'}); return; } - var cleaned_name = utils.cleanUpUrlable(name); + var cleanedName = utils.cleanUpUrlable(name); var urlRegex = /^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$/g; - if (cleaned_name != name || !urlRegex.test(name)) { - this.setState({name_error: "Must be lowercase alphanumeric characters"}); + if (cleanedName !== name || !urlRegex.test(name)) { + this.setState({nameError: 'Must be lowercase alphanumeric characters'}); return; - } - else if (cleaned_name.length <= 3 || cleaned_name.length > 15) { - this.setState({name_error: "Name must be 4 or more characters up to a maximum of 15"}) + } else if (cleanedName.length <= 3 || cleanedName.length > 15) { + this.setState({nameError: 'Name must be 4 or more characters up to a maximum of 15'}); return; } for (var index = 0; index < constants.RESERVED_TEAM_NAMES.length; index++) { - if (cleaned_name.indexOf(constants.RESERVED_TEAM_NAMES[index]) == 0) { - this.setState({name_error: "This team name is unavailable"}) + if (cleanedName.indexOf(constants.RESERVED_TEAM_NAMES[index]) === 0) { + this.setState({nameError: 'This team name is unavailable'}); return; } } @@ -218,28 +241,27 @@ TeamURLPage = React.createClass({ function(data) { if (!data) { if (config.AllowSignupDomainsWizard) { - this.props.state.wizard = "allowed_domains"; + this.props.state.wizard = 'allowed_domains'; } else { - this.props.state.wizard = "send_invites"; + this.props.state.wizard = 'send_invites'; this.props.state.team.type = 'O'; } this.props.state.team.name = name; this.props.updateParent(this.props.state); - } - else { - this.state.name_error = "This URL is unavailable. Please try another."; + } else { + this.state.nameError = 'This URL is unavailable. Please try another.'; this.setState(this.state); } }.bind(this), function(err) { - this.state.name_error = err.message; + this.state.nameError = err.message; this.setState(this.state); }.bind(this) ); }, getInitialState: function() { - return { }; + return {}; }, handleFocus: function(e) { e.preventDefault(); @@ -247,40 +269,44 @@ TeamURLPage = React.createClass({ e.currentTarget.select(); }, render: function() { - $('body').tooltip( {selector: '[data-toggle=tooltip]', trigger: 'hover click'} ); client.track('signup', 'signup_team_03_url'); - var name_error = this.state.name_error ? : null; + var nameError = null; + var nameDivClass = 'form-group'; + if (this.state.nameError) { + nameError = ; + nameDivClass += ' has-error'; + } return (
- -

{utils.toTitleCase(strings.Team) + " URL"}

-
-
-
-
- { utils.getWindowLocationOrigin() + "/" } - + +

{utils.toTitleCase(strings.Team) + ' URL'}

+
+
+
+
+ {utils.getWindowLocationOrigin() + '/'} + +
+
+ {nameError}
-
- { name_error } -
-

{"Choose the web address of your new " + strings.Team + ":"}

-
    -
  • Short and memorable is best
  • -
  • Use lowercase letters, numbers and dashes
  • -
  • Must start with a letter and can't end in a dash
  • -
- - - +

{'Choose the web address of your new ' + strings.Team + ':'}

+
    +
  • Short and memorable is best
  • +
  • Use lowercase letters, numbers and dashes
  • +
  • Must start with a letter and can't end in a dash
  • +
+ + +
); } @@ -289,14 +315,14 @@ TeamURLPage = React.createClass({ AllowedDomainsPage = React.createClass({ submitBack: function (e) { e.preventDefault(); - this.props.state.wizard = "team_url"; + this.props.state.wizard = 'team_url'; this.props.updateParent(this.props.state); }, submitNext: function (e) { e.preventDefault(); if (this.refs.open_network.getDOMNode().checked) { - this.props.state.wizard = "send_invites"; + this.props.state.wizard = 'send_invites'; this.props.state.team.type = 'O'; this.props.updateParent(this.props.state); return; @@ -304,65 +330,72 @@ AllowedDomainsPage = React.createClass({ if (this.refs.allow.getDOMNode().checked) { var name = this.refs.name.getDOMNode().value.trim(); - var domainRegex = /^\w+\.\w+$/ + var domainRegex = /^\w+\.\w+$/; if (!name) { - this.setState({name_error: "This field is required"}); + this.setState({nameError: 'This field is required'}); return; } - if(!name.trim().match(domainRegex)) { - this.setState({name_error: "The domain doesn't appear valid"}); + if (!name.trim().match(domainRegex)) { + this.setState({nameError: 'The domain doesn\'t appear valid'}); return; } - this.props.state.wizard = "send_invites"; + this.props.state.wizard = 'send_invites'; this.props.state.team.allowed_domains = name; this.props.state.team.type = 'I'; this.props.updateParent(this.props.state); - } - else { - this.props.state.wizard = "send_invites"; + } else { + this.props.state.wizard = 'send_invites'; this.props.state.team.type = 'I'; this.props.updateParent(this.props.state); } }, getInitialState: function() { - return { }; + return {}; }, render: function() { - client.track('signup', 'signup_team_04_allow_domains'); - var name_error = this.state.name_error ? : null; + var nameError = null; + var nameDivClass = 'form-group'; + if (this.state.nameError) { + nameError = ; + nameDivClass += ' has-error'; + } return (
- -

Email Domain

-

-

-

-

{"Check this box to allow your " + strings.Team + " members to sign up using their " + strings.Company + " email addresses if you share the same domain--otherwise, you need to invite everyone yourself."}

-

{"Your " + strings.Team + "'s domain for emails"}

-
-
-
-
- @ - + +

Email Domain

+

+

+ +
+

+

{'Check this box to allow your ' + strings.Team + ' members to sign up using their ' + strings.Company + ' email addresses if you share the same domain--otherwise, you need to invite everyone yourself.'}

+

{'Your ' + strings.Team + '\'s domain for emails'}

+
+
+
+
+ @ + +
+
+ {nameError}
-
- { name_error } -
-

To allow signups from multiple domains, separate each with a comma.

-

-

-

-   - - +

To allow signups from multiple domains, separate each with a comma.

+

+

+ +
+

+   + +
); } @@ -370,10 +403,10 @@ AllowedDomainsPage = React.createClass({ EmailItem = React.createClass({ getInitialState: function() { - return { }; + return {}; }, getValue: function() { - return this.refs.email.getDOMNode().value.trim() + return this.refs.email.getDOMNode().value.trim(); }, validate: function(teamEmail) { var email = this.refs.email.getDOMNode().value.trim().toLowerCase(); @@ -383,43 +416,44 @@ EmailItem = React.createClass({ } if (!utils.isEmail(email)) { - this.state.email_error = "Please enter a valid email address"; + this.state.emailError = 'Please enter a valid email address'; this.setState(this.state); return false; - } - else if (email === teamEmail) { - this.state.email_error = "Please use a different email than the one used at signup"; + } else if (email === teamEmail) { + this.state.emailError = 'Please use a different email than the one used at signup'; this.setState(this.state); return false; - } - else { - this.state.email_error = ""; + } else { + this.state.emailError = ''; this.setState(this.state); return true; } }, render: function() { - - var email_error = this.state.email_error ? : null; + var emailError = null; + var emailDivClass = 'form-group'; + if (this.state.emailError) { + emailError = ; + emailDivClass += ' has-error'; + } return ( -
- - { email_error } +
+ + {emailError}
); } }); - SendInivtesPage = React.createClass({ submitBack: function (e) { e.preventDefault(); if (config.AllowSignupDomainsWizard) { - this.props.state.wizard = "allowed_domains"; + this.props.state.wizard = 'allowed_domains'; } else { - this.props.state.wizard = "team_url"; + this.props.state.wizard = 'team_url'; } this.props.updateParent(this.props.state); @@ -446,22 +480,22 @@ SendInivtesPage = React.createClass({ } if (valid) { - this.props.state.wizard = "username"; + this.props.state.wizard = 'username'; this.props.updateParent(this.props.state); } }, submitAddInvite: function (e) { e.preventDefault(); - this.props.state.wizard = "send_invites"; - if (this.props.state.invites == null || this.props.state.invites.length == 0) { + this.props.state.wizard = 'send_invites'; + if (!this.props.state.invites) { this.props.state.invites = []; } - this.props.state.invites.push(""); + this.props.state.invites.push(''); this.props.updateParent(this.props.state); }, submitSkip: function (e) { e.preventDefault(); - this.props.state.wizard = "username"; + this.props.state.wizard = 'username'; this.props.updateParent(this.props.state); }, getInitialState: function() { @@ -472,8 +506,6 @@ SendInivtesPage = React.createClass({ render: function() { client.track('signup', 'signup_team_05_send_invites'); - var name_error = this.state.name_error ? : null; - var content = null; var bottomContent = null; @@ -481,7 +513,7 @@ SendInivtesPage = React.createClass({ var emails = []; for (var i = 0; i < this.props.state.invites.length; i++) { - if (i == 0) { + if (i === 0) { emails.push(); } else { emails.push(); @@ -491,12 +523,12 @@ SendInivtesPage = React.createClass({ content = ( ); bottomContent = ( -

{"if you prefer, you can invite " + strings.Team + " members later"}
and skip this step for now.

+

{'if you prefer, you can invite ' + strings.Team + ' members later'}
and skip this step for now.

); } else { content = ( @@ -507,14 +539,16 @@ SendInivtesPage = React.createClass({ return (
- -

{"Invite " + utils.toTitleCase(strings.Team) + " Members"}

+ +

{'Invite ' + utils.toTitleCase(strings.Team) + ' Members'}

{content} -
+
+ +
{bottomContent} - ); @@ -532,12 +566,12 @@ UsernamePage = React.createClass({ var name = this.refs.name.getDOMNode().value.trim(); - var username_error = utils.isValidUsername(name); - if (username_error === 'Cannot use a reserved word as a username.') { - this.setState({name_error: 'This username is reserved, please choose a new one.'}); + var usernameError = utils.isValidUsername(name); + if (usernameError === 'Cannot use a reserved word as a username.') { + this.setState({nameError: 'This username is reserved, please choose a new one.'}); return; - } else if (username_error) { - this.setState({name_error: "Username must begin with a letter, and contain 3 to 15 characters in total, which may be numbers, lowercase letters, or any of the symbols '.', '-', or '_'"}); + } else if (usernameError) { + this.setState({nameError: 'Username must begin with a letter, and contain 3 to 15 characters in total, which may be numbers, lowercase letters, or any of the symbols \'.\', \'-\', or \'_\''}); return; } @@ -551,31 +585,36 @@ UsernamePage = React.createClass({ render: function() { client.track('signup', 'signup_team_06_username'); - var name_error = this.state.name_error ? : null; + var nameError = null; + var nameDivClass = 'form-group'; + if (this.state.nameError) { + nameError = ; + nameDivClass += ' has-error'; + } return (
- -

Your username

-
{'Select a memorable username that makes it easy for ' + strings.Team + 'mates to identify you:'}
-
-
-
-
-
Choose your username
- -
Usernames must begin with a letter and contain 3 to 15 characters made up of lowercase letters, numbers, and the symbols '.', '-' and '_'
+ +

Your username

+
{'Select a memorable username that makes it easy for ' + strings.Team + 'mates to identify you:'}
+
+
+
+
+
Choose your username
+ +
Usernames must begin with a letter and contain 3 to 15 characters made up of lowercase letters, numbers, and the symbols '.', '-' and '_'
+
+
+ {nameError}
- {name_error} + + -
- - - +
); } @@ -584,7 +623,7 @@ UsernamePage = React.createClass({ PasswordPage = React.createClass({ submitBack: function (e) { e.preventDefault(); - this.props.state.wizard = "username"; + this.props.state.wizard = 'username'; this.props.updateParent(this.props.state); }, submitNext: function (e) { @@ -592,11 +631,11 @@ PasswordPage = React.createClass({ var password = this.refs.password.getDOMNode().value.trim(); if (!password || password.length < 5) { - this.setState({password_error: "Please enter at least 5 characters"}); + this.setState({passwordError: 'Please enter at least 5 characters'}); return; } - this.setState({password_error: null, server_error: null}); + this.setState({passwordError: null, serverError: null}); $('#finish-button').button('loading'); var teamSignup = JSON.parse(JSON.stringify(this.props.state)); teamSignup.user.password = password; @@ -606,13 +645,12 @@ PasswordPage = React.createClass({ client.createTeamFromSignup(teamSignup, function(data) { - client.track('signup', 'signup_team_08_complete'); var props = this.props; $('#sign-up-button').button('reset'); - props.state.wizard = "finished"; + props.state.wizard = 'finished'; props.updateParent(props.state, true); window.location.href = utils.getWindowLocationOrigin() + '/' + props.state.team.name + '/login?email=' + encodeURIComponent(teamSignup.team.email); @@ -625,55 +663,63 @@ PasswordPage = React.createClass({ // window.location.href = '/channels/town-square'; // }.bind(ctl), // function(err) { - // this.setState({name_error: err.message}); + // this.setState({nameError: err.message}); // }.bind(ctl) // ); }.bind(this), function(err) { - this.setState({server_error: err.message}); + this.setState({serverError: err.message}); $('#sign-up-button').button('reset'); }.bind(this) ); }, getInitialState: function() { - return { }; + return {}; }, render: function() { - client.track('signup', 'signup_team_07_password'); - var password_error = this.state.password_error ?
: null; - var server_error = this.state.server_error ?
: null; + var passwordError = null; + var passwordDivStyle = 'form-group'; + if (this.state.passwordError) { + passwordError =
; + passwordDivStyle = ' has-error'; + } + + var serverError = null; + if (this.state.serverError) { + serverError =
; + } return (
- -

Your password

-
Select a password that you'll use to login with your email address:
-
-
Email
-
{this.props.state.team.email}
-
-
-
-
Choose your password
- -
Passwords must contain 5 to 50 characters. Your password will be strongest if it contains a mix of symbols, numbers, and upper and lowercase characters.
+ +

Your password

+
Select a password that you'll use to login with your email address:
+
+
Email
+
{this.props.state.team.email}
+
+
+
+
Choose your password
+ +
Passwords must contain 5 to 50 characters. Your password will be strongest if it contains a mix of symbols, numbers, and upper and lowercase characters.
+
+
+ {passwordError} + {serverError}
- { password_error } - { server_error } +
+
-
-
- -
-

By proceeding to create your account and use { config.SiteName }, you agree to our Terms of Service and Privacy Policy. If you do not agree, you cannot use {config.SiteName}.

- - +

By proceeding to create your account and use {config.SiteName}, you agree to our Terms of Service and Privacy Policy. If you do not agree, you cannot use {config.SiteName}.

+ +
); } @@ -692,14 +738,14 @@ module.exports = React.createClass({ if (!props) { props = {}; - props.wizard = "welcome"; + props.wizard = 'welcome'; props.team = {}; props.team.email = this.props.email; - props.team.allowed_domains = ""; + props.team.allowed_domains = ''; props.invites = []; - props.invites.push(""); - props.invites.push(""); - props.invites.push(""); + props.invites.push(''); + props.invites.push(''); + props.invites.push(''); props.user = {}; props.hash = this.props.hash; props.data = this.props.data; @@ -708,36 +754,34 @@ module.exports = React.createClass({ return props; }, render: function() { - if (this.state.wizard == "welcome") { - return + if (this.state.wizard === 'welcome') { + return ; } - if (this.state.wizard == "team_display_name") { - return + if (this.state.wizard === 'team_display_name') { + return ; } - if (this.state.wizard == "team_url") { - return + if (this.state.wizard === 'team_url') { + return ; } - if (this.state.wizard == "allowed_domains") { - return + if (this.state.wizard === 'allowed_domains') { + return ; } - if (this.state.wizard == "send_invites") { - return + if (this.state.wizard === 'send_invites') { + return ; } - if (this.state.wizard == "username") { - return + if (this.state.wizard === 'username') { + return ; } - if (this.state.wizard == "password") { - return + if (this.state.wizard === 'password') { + return ; } return (
You've already completed the signup process for this invitation or this invitation has expired.
); } }); - - diff --git a/web/react/pages/channel.jsx b/web/react/pages/channel.jsx index 99d5c5e9f..732835dc7 100644 --- a/web/react/pages/channel.jsx +++ b/web/react/pages/channel.jsx @@ -43,14 +43,14 @@ var ActionTypes = Constants.ActionTypes; global.window.setup_channel_page = function(team_name, team_type, team_id, channel_name, channel_id) { AppDispatcher.handleViewAction({ - type: ActionTypes.CLICK_CHANNEL, - name: channel_name, - id: channel_id + type: ActionTypes.CLICK_CHANNEL, + name: channel_name, + id: channel_id }); AppDispatcher.handleViewAction({ - type: ActionTypes.CLICK_TEAM, - id: team_id + type: ActionTypes.CLICK_TEAM, + id: team_id }); React.render( @@ -194,17 +194,17 @@ global.window.setup_channel_page = function(team_name, team_type, team_id, chann ); React.render( - , + , document.getElementById('post_mention_tab') ); React.render( - , + , document.getElementById('reply_mention_tab') ); React.render( - , + , document.getElementById('edit_mention_tab') ); diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 5b5d8dc32..6ae25c66d 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -862,8 +862,8 @@ module.exports.isEmailEnabledSynchronous = function() { enabled = !value; }, error: function(xhr, status, err) { - if (status != 200) { - handleError("isEmailEnabled", xhr, status, err); + if (status !== '200') { + handleError('isEmailEnabled', xhr, status, err); } } }); -- cgit v1.2.3-1-g7c22 From ca919538cc402ed90ce42ffc3ef98994bb1081f4 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Thu, 13 Aug 2015 13:01:21 -0400 Subject: Added ConfigStore that is populated from the server --- api/config.go | 16 +++++++++++ web/react/pages/channel.jsx | 3 ++- web/react/pages/signup_team.jsx | 8 ++++-- web/react/stores/config_store.jsx | 56 +++++++++++++++++++++++++++++++++++++++ web/react/utils/async_client.jsx | 26 ++++++++++++++++++ web/react/utils/client.jsx | 15 +++++++++++ web/react/utils/constants.jsx | 2 ++ 7 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 web/react/stores/config_store.jsx diff --git a/api/config.go b/api/config.go index 91097b4a1..d8d52ca67 100644 --- a/api/config.go +++ b/api/config.go @@ -5,7 +5,9 @@ package api import ( l4g "code.google.com/p/log4go" + "encoding/json" "github.com/gorilla/mux" + "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" "net/http" "strconv" @@ -15,9 +17,23 @@ func InitConfig(r *mux.Router) { l4g.Debug("Initializing config api routes") sr := r.PathPrefix("/config").Subrouter() + sr.Handle("/get_all", ApiAppHandler(getConfig)).Methods("GET") sr.Handle("/get/bypass_email", ApiAppHandler(getBypassEmail)).Methods("GET") } +func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { + settings := make(map[string]string) + + settings["ByPassEmail"] = strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail) + + if bytes, err := json.Marshal(settings); err != nil { + c.Err = model.NewAppError("getConfig", "Unable to marshall configuration data", err.Error()) + return + } else { + w.Write(bytes) + } +} + func getBypassEmail(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail))) } diff --git a/web/react/pages/channel.jsx b/web/react/pages/channel.jsx index 732835dc7..929499715 100644 --- a/web/react/pages/channel.jsx +++ b/web/react/pages/channel.jsx @@ -1,7 +1,6 @@ // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. - var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); var Navbar = require('../components/navbar.jsx'); var Sidebar = require('../components/sidebar.jsx'); @@ -36,11 +35,13 @@ var AccessHistoryModal = require('../components/access_history_modal.jsx'); var ActivityLogModal = require('../components/activity_log_modal.jsx'); var RemovedFromChannelModal = require('../components/removed_from_channel_modal.jsx') +var AsyncClient = require('../utils/async_client.jsx'); var Constants = require('../utils/constants.jsx'); var ActionTypes = Constants.ActionTypes; global.window.setup_channel_page = function(team_name, team_type, team_id, channel_name, channel_id) { + AsyncClient.getConfig(); AppDispatcher.handleViewAction({ type: ActionTypes.CLICK_CHANNEL, diff --git a/web/react/pages/signup_team.jsx b/web/react/pages/signup_team.jsx index e982f5a79..37c441d4f 100644 --- a/web/react/pages/signup_team.jsx +++ b/web/react/pages/signup_team.jsx @@ -1,11 +1,15 @@ // Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. -var SignupTeam =require('../components/signup_team.jsx'); +var SignupTeam = require('../components/signup_team.jsx'); + +var AsyncClient = require('../utils/async_client.jsx'); global.window.setup_signup_team_page = function() { + AsyncClient.getConfig(); + React.render( , document.getElementById('signup-team') ); -}; \ No newline at end of file +}; diff --git a/web/react/stores/config_store.jsx b/web/react/stores/config_store.jsx new file mode 100644 index 000000000..7ff177b35 --- /dev/null +++ b/web/react/stores/config_store.jsx @@ -0,0 +1,56 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); +var EventEmitter = require('events').EventEmitter; +var assign = require('object-assign'); + +var BrowserStore = require('../stores/browser_store.jsx'); + +var Constants = require('../utils/constants.jsx'); +var ActionTypes = Constants.ActionTypes; + +var CHANGE_EVENT = 'change'; + +var ConfigStore = assign({}, EventEmitter.prototype, { + emitChange: function emitChange() { + this.emit(CHANGE_EVENT); + }, + addChangeListener: function addChangeListener(callback) { + this.on(CHANGE_EVENT, callback); + }, + removeChangeListener: function removeChangeListener(callback) { + this.removeListener(CHANGE_EVENT, callback); + }, + getSetting: function getSetting(key, defaultValue) { + return BrowserStore.getItem('config_' + key, defaultValue); + }, + getSettingAsBoolean: function getSettingAsNumber(key, defaultValue) { + var value = ConfigStore.getSetting(key, defaultValue); + + if (typeof value !== 'string') { + return !!value; + } else { + return value === 'true'; + } + }, + updateStoredSettings: function updateStoredSettings(settings) { + for (var key in settings) { + BrowserStore.setItem('config_' + key, settings[key]); + } + } +}); + +ConfigStore.dispatchToken = AppDispatcher.register(function registry(payload) { + var action = payload.action; + + switch (action.type) { + case ActionTypes.RECIEVED_CONFIG: + ConfigStore.updateStoredSettings(action.settings); + ConfigStore.emitChange(); + break; + default: + } +}); + +module.exports = ConfigStore; diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index f35b0f6cc..afb9a1d79 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -4,6 +4,7 @@ var client = require('./client.jsx'); var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); var ChannelStore = require('../stores/channel_store.jsx'); +var ConfigStore = require('../stores/config_store.jsx'); var PostStore = require('../stores/post_store.jsx'); var UserStore = require('../stores/user_store.jsx'); var utils = require('./utils.jsx'); @@ -383,3 +384,28 @@ module.exports.getMyTeam = function() { } ); } + +function getConfig() { + if (isCallInProgress('getConfig')) { + return; + } + + callTracker['getConfig'] = utils.getTimestamp(); + client.getConfig( + function(data, textStatus, xhr) { + callTracker['getConfig'] = 0; + + if (data && xhr.status !== 304) { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_CONFIG, + settings: data + }); + } + }, + function(err) { + callTracker['getConfig'] = 0; + dispatchError(err, 'getConfig'); + } + ); +} +module.exports.getConfig = getConfig; diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 6ae25c66d..250e3edbd 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -850,6 +850,21 @@ module.exports.updateValetFeature = function(data, success, error) { module.exports.track('api', 'api_teams_update_valet_feature'); }; +function getConfig(success, error) { + $.ajax({ + url: '/api/v1/config/get_all', + dataType: 'json', + type: 'GET', + ifModified: true, + success: success, + error: function(xhr, status, err) { + var e = handleError('getConfig', xhr, status, err); + error(e); + } + }); +}; +module.exports.getConfig = getConfig; + module.exports.isEmailEnabledSynchronous = function() { var enabled = false; diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx index bed0ec556..36c6ab653 100644 --- a/web/react/utils/constants.jsx +++ b/web/react/utils/constants.jsx @@ -30,6 +30,8 @@ module.exports = { CLICK_TEAM: null, RECIEVED_TEAM: null, + + RECIEVED_CONFIG: null }), PayloadSources: keyMirror({ -- cgit v1.2.3-1-g7c22 From 8fc4456213c5ee16863b7f1bcb20e35a19469a1d Mon Sep 17 00:00:00 2001 From: hmhealey Date: Thu, 13 Aug 2015 13:23:56 -0400 Subject: Removed isEmailEnabledSynchronous and switched the email disabled warnings to use ConfigStore --- api/config.go | 5 ----- web/react/components/invite_member_modal.jsx | 3 ++- web/react/components/signup_team_complete.jsx | 3 ++- web/react/utils/client.jsx | 21 --------------------- 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/api/config.go b/api/config.go index d8d52ca67..142d1ca66 100644 --- a/api/config.go +++ b/api/config.go @@ -18,7 +18,6 @@ func InitConfig(r *mux.Router) { sr := r.PathPrefix("/config").Subrouter() sr.Handle("/get_all", ApiAppHandler(getConfig)).Methods("GET") - sr.Handle("/get/bypass_email", ApiAppHandler(getBypassEmail)).Methods("GET") } func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { @@ -33,7 +32,3 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { w.Write(bytes) } } - -func getBypassEmail(c *Context, w http.ResponseWriter, r *http.Request) { - w.Write([]byte(strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail))) -} diff --git a/web/react/components/invite_member_modal.jsx b/web/react/components/invite_member_modal.jsx index fb3d46b0a..ef63465c8 100644 --- a/web/react/components/invite_member_modal.jsx +++ b/web/react/components/invite_member_modal.jsx @@ -2,6 +2,7 @@ // See License.txt for license information. var utils = require('../utils/utils.jsx'); +var ConfigStore = require('../stores/config_store.jsx'); var Client = require('../utils/client.jsx'); var UserStore = require('../stores/user_store.jsx'); var ConfirmModal = require('./confirm_modal.jsx'); @@ -152,7 +153,7 @@ module.exports = React.createClass({ emailErrors: {}, firstNameErrors: {}, lastNameErrors: {}, - emailEnabled: Client.isEmailEnabledSynchronous() + emailEnabled: !ConfigStore.getSettingAsBoolean('ByPassEmail', false) }; }, render: function() { diff --git a/web/react/components/signup_team_complete.jsx b/web/react/components/signup_team_complete.jsx index ee690f692..e27fcd19d 100644 --- a/web/react/components/signup_team_complete.jsx +++ b/web/react/components/signup_team_complete.jsx @@ -2,6 +2,7 @@ // See License.txt for license information. var utils = require('../utils/utils.jsx'); +var ConfigStore = require('../stores/config_store.jsx'); var client = require('../utils/client.jsx'); var UserStore = require('../stores/user_store.jsx'); var BrowserStore = require('../stores/browser_store.jsx'); @@ -500,7 +501,7 @@ SendInivtesPage = React.createClass({ }, getInitialState: function() { return { - emailEnabled: client.isEmailEnabledSynchronous() + emailEnabled: !ConfigStore.getSettingAsBoolean('ByPassEmail', false) }; }, render: function() { diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 250e3edbd..8178ab01a 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -864,24 +864,3 @@ function getConfig(success, error) { }); }; module.exports.getConfig = getConfig; - -module.exports.isEmailEnabledSynchronous = function() { - var enabled = false; - - $.ajax({ - async: false, - url: '/api/v1/config/get/bypass_email', - dataType: 'json', - type: 'GET', - success: function(value) { - enabled = !value; - }, - error: function(xhr, status, err) { - if (status !== '200') { - handleError('isEmailEnabled', xhr, status, err); - } - } - }); - - return enabled; -}; -- cgit v1.2.3-1-g7c22