diff --git a/Makefile b/Makefile index 222d4ffe4f4..14a6ffc7d7d 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ GOFLAGS ?= $(GOFLAGS:) BUILD_NUMBER ?= $(BUILD_NUMBER:) GO=$(GOPATH)/bin/godep go +ESLINT=web/react/node_modules/eslint/bin/eslint.js ifeq ($(BUILD_NUMBER),) BUILD_NUMBER := dev @@ -62,6 +63,14 @@ install: @cd web/react/ && npm install +check: install + @echo Running ESLint... + @$(ESLINT) web/react/components/* + @$(ESLINT) web/react/dispatcher/* + @$(ESLINT) web/react/pages/* + @$(ESLINT) web/react/stores/* + @$(ESLINT) web/react/utils/* + test: install @mkdir -p logs @$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=180s ./api || exit 1 diff --git a/NOTICE.md b/NOTICE.md deleted file mode 100644 index b8b9196079b..00000000000 --- a/NOTICE.md +++ /dev/null @@ -1,67 +0,0 @@ -Mattermost Platform Preview
-© 2015 Spinpunch, Inc. All Rights Reserved. See LICENSE.txt for license information. - -NOTICES: --------- - -This product contains a modified portion of 'react', a declarative, efficient, and flexible JavaScript library for building user interfaces by Facebook, Inc. - -* HOMEPAGE: - * https://github.com/facebook/react - -* LICENSE: - -BSD License - -For React software - -Copyright (c) 2013-2015, Facebook, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name Facebook nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This product contains a modified portion of 'perfect-scrollbar', a scrollbar plugin by Hyunje Alex Jun and other contributors. -* HOMEPAGE: - * https://github.com/noraesae/perfect-scrollbar - -* LICENSE: - -The MIT License (MIT) Copyright (c) 2015 Hyunje Alex Jun and other contributors. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -This product contains a modified portion of 'golang-lru', a golang LRU cache by hashicorp, based on Groupcache by Google Inc. - -* HOMEPAGE: - * https://github.com/hashicorp/golang-lru - -* LICENSE: - -This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/NOTICE.txt b/NOTICE.txt new file mode 100644 index 00000000000..af77fe8ec5f --- /dev/null +++ b/NOTICE.txt @@ -0,0 +1,270 @@ +Mattermost Platform +© 2015 Spinpunch, Inc. All Rights Reserved. See LICENSE.txt for license information. + +NOTICES: +-------- + +This product contains a modified portion of 'react', a declarative, efficient, and +flexible JavaScript library for building user interfaces by Facebook, Inc. + +* HOMEPAGE: + * https://github.com/facebook/react + +* LICENSE: + +BSD License + +For React software + +Copyright (c) 2013-2015, Facebook, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name Facebook nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--- + +This product contains a modified portion of 'perfect-scrollbar', a scrollbar plugin +by Hyunje Alex Jun and other contributors. +* HOMEPAGE: + * https://github.com/noraesae/perfect-scrollbar + +* LICENSE: + +The MIT License (MIT) Copyright (c) 2015 Hyunje Alex Jun and other contributors. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +--- + +This product contains a modified portion of 'golang-lru', a golang LRU cache by hashicorp, +based on Groupcache by Google Inc. + +* HOMEPAGE: + * https://github.com/hashicorp/golang-lru + +* LICENSE: + +This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a +copy of the MPL was not distributed with this file, You can obtain one at +http://mozilla.org/MPL/2.0/. + +--- + +This product contains a modified portion of 'golang-freetype', a port of the Freetype +font rasterizer (www.freetype.org) to the Go programming. + +Portions of this software are copyright © 2010 The FreeType Project (www.freetype.org). +All rights reserved. + +* HOMEPAGE: + * http://www.freetype.org + +* LICENSE: + + The FreeType Project LICENSE + ---------------------------- + + 2006-Jan-27 + + Copyright 1996-2002, 2006 by + David Turner, Robert Wilhelm, and Werner Lemberg + + + +Introduction +============ + + The FreeType Project is distributed in several archive packages; + some of them may contain, in addition to the FreeType font engine, + various tools and contributions which rely on, or relate to, the + FreeType Project. + + This license applies to all files found in such packages, and + which do not fall under their own explicit license. The license + affects thus the FreeType font engine, the test programs, + documentation and makefiles, at the very least. + + This license was inspired by the BSD, Artistic, and IJG + (Independent JPEG Group) licenses, which all encourage inclusion + and use of free software in commercial and freeware products + alike. As a consequence, its main points are that: + + o We don't promise that this software works. However, we will be + interested in any kind of bug reports. (`as is' distribution) + + o You can use this software for whatever you want, in parts or + full form, without having to pay us. (`royalty-free' usage) + + o You may not pretend that you wrote this software. If you use + it, or only parts of it, in a program, you must acknowledge + somewhere in your documentation that you have used the + FreeType code. (`credits') + + We specifically permit and encourage the inclusion of this + software, with or without modifications, in commercial products. + We disclaim all warranties covering The FreeType Project and + assume no liability related to The FreeType Project. + + + Finally, many people asked us for a preferred form for a + credit/disclaimer to use in compliance with this license. We thus + encourage you to use the following text: + + """ + Portions of this software are copyright � The FreeType + Project (www.freetype.org). All rights reserved. + """ + + Please replace with the value from the FreeType version you + actually use. + + +Legal Terms +=========== + +0. Definitions +-------------- + + Throughout this license, the terms `package', `FreeType Project', + and `FreeType archive' refer to the set of files originally + distributed by the authors (David Turner, Robert Wilhelm, and + Werner Lemberg) as the `FreeType Project', be they named as alpha, + beta or final release. + + `You' refers to the licensee, or person using the project, where + `using' is a generic term including compiling the project's source + code as well as linking it to form a `program' or `executable'. + This program is referred to as `a program using the FreeType + engine'. + + This license applies to all files distributed in the original + FreeType Project, including all source code, binaries and + documentation, unless otherwise stated in the file in its + original, unmodified form as distributed in the original archive. + If you are unsure whether or not a particular file is covered by + this license, you must contact us to verify this. + + The FreeType Project is copyright (C) 1996-2000 by David Turner, + Robert Wilhelm, and Werner Lemberg. All rights reserved except as + specified below. + +1. No Warranty +-------------- + + THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO + USE, OF THE FREETYPE PROJECT. + +2. Redistribution +----------------- + + This license grants a worldwide, royalty-free, perpetual and + irrevocable right and license to use, execute, perform, compile, + display, copy, create derivative works of, distribute and + sublicense the FreeType Project (in both source and object code + forms) and derivative works thereof for any purpose; and to + authorize others to exercise some or all of the rights granted + herein, subject to the following conditions: + + o Redistribution of source code must retain this license file + (`FTL.TXT') unaltered; any additions, deletions or changes to + the original files must be clearly indicated in accompanying + documentation. The copyright notices of the unaltered, + original files must be preserved in all copies of source + files. + + o Redistribution in binary form must provide a disclaimer that + states that the software is based in part of the work of the + FreeType Team, in the distribution documentation. We also + encourage you to put an URL to the FreeType web page in your + documentation, though this isn't mandatory. + + These conditions apply to any software derived from or based on + the FreeType Project, not just the unmodified files. If you use + our work, you must acknowledge us. However, no fee need be paid + to us. + +3. Advertising +-------------- + + Neither the FreeType authors and contributors nor you shall use + the name of the other for commercial, advertising, or promotional + purposes without specific prior written permission. + + We suggest, but do not require, that you use one or more of the + following phrases to refer to this software in your documentation + or advertising materials: `FreeType Project', `FreeType Engine', + `FreeType library', or `FreeType Distribution'. + + As you have not signed this license, you are not required to + accept it. However, as the FreeType Project is copyrighted + material, only this license, or another one contracted with the + authors, grants you the right to use, distribute, and modify it. + Therefore, by using, distributing, or modifying the FreeType + Project, you indicate that you understand and accept all the terms + of this license. + +4. Contacts +----------- + + There are two mailing lists related to FreeType: + + o freetype@nongnu.org + + Discusses general use and applications of FreeType, as well as + future and wanted additions to the library and distribution. + If you are looking for support, start in this list if you + haven't found anything to help you in the documentation. + + o freetype-devel@nongnu.org + + Discusses bugs, as well as engine internals, design issues, + specific licenses, porting, etc. + + Our home page can be found at + + http://www.freetype.org + + +--- end of FTL.TXT --- diff --git a/STYLE-GUIDE.md b/STYLE-GUIDE.md new file mode 100644 index 00000000000..e3fe2addfe8 --- /dev/null +++ b/STYLE-GUIDE.md @@ -0,0 +1,167 @@ +# Mattermost Style Guide + +1. [GO](#go) +2. [Javascript](#javascript) +3. [React-JSX](#react-jsx) + + +## Go + +All go code must follow the golang official [Style Guide](https://golang.org/doc/effective_go.html) + +In addition all code must be run though the official go formatter tool [gofmt](https://golang.org/cmd/gofmt/) + + +## Javascript + +Part of the build process is running ESLint. ESLint is the final authority on all style issues. PRs will not be accepted unless there are no errors or warnings running ESLint. The ESLint configuration file can be found in: [web/react/.eslintrc](https://github.com/mattermost/platform/blob/master/web/react/.eslintrc.json) + +Instructions on how to use ESLint with your favourite editor can be found here: [http://eslint.org/docs/user-guide/integrations](http://eslint.org/docs/user-guide/integrations) + +The following is an abridged version of the [Airbnb Javascript Style Guide](https://github.com/airbnb/javascript/blob/master/README.md#airbnb-javascript-style-guide-), with modifications. Anything that is unclear here follow that guide. If there is a conflict, follow what is said below. + +### Whitespace + +- Indentation is four spaces +- Use a space before the leading brace +- Use one space between the comma and the next argument in a bracketed list. No other space. +- Use whitespace to make code more readable. +- Do not use more than one newline to separate code blocks. +- Do not use a newline as the first line of a function + +```javascript +// Correct +function myFunction(parm1, parm2) { + stuff...; + + morestuff; +} + +// Incorrect +function myFunction ( parm1, parm2 ){ + stuff...; + + + morestuff; +} + +``` + +### Semicolons + +- You must use them always + +```javascript +// Correct +var x = 1; + +// Incorrect +var x = 1 +``` + +### Variables + +- Declarations must always use var, let or const. +- Prefer let or const over var. +- camelCase for all variable names. + +```javascript +// Correct +let myVariable = 4; + +// OK +var myVariable = 4; + +// Incorrect +myVariable = 4; +var my_variable = 4; +``` + +### Blocks + +- Braces must be used on all blocks. +- Braces must start on the same line as the statement starting the block. +- Else and else if must be on the same line as the if block closing brace. + +```javascript +// Correct +if (somthing) { + stuff...; +} else if (otherthing) { + stuff...; +} + +// Incorrect +if (somthing) +{ + stuff...; +} +else +{ + stuff...; +} + +// Incorrect +if (somthing) stuff...; +if (somthing) + stuff...; + +``` + +### Strings + +- Use template strings instead of concatenation. + +```javascript +// Correct +function getStr(stuff) { + return "This is the ${stuff} string"; +} + +// Incorrect +function wrongGetStr(stuff) { + return "This is the " + stuff + " string"; +} +``` + +## React-JSX + +Part of the build process is running ESLint. ESLint is the final authority on all style issues. PRs will not be accepted unless there are no errors or warnings running ESLint. The ESLint configuration file can be found in: [web/react/.eslintrc](https://github.com/mattermost/platform/blob/master/web/react/.eslintrc.json) + +Instructions on how to use ESLint with your favourite editor can be found here: [http://eslint.org/docs/user-guide/integrations](http://eslint.org/docs/user-guide/integrations) + +This is an abridged version of the [Airbnb React/JSX Style Guide](https://github.com/airbnb/javascript/tree/master/react#airbnb-reactjsx-style-guide). Anything that is unclear here follow that guide. If there is a conflict, follow what is said below. + +### General + +- Include only one React component per file. +- Use class \ extends React.Component over React.createClass unless you need mixins +- CapitalCamelCase with .jsx extension for component filenames. +- Filenames should be the component name. + +### Alignment + +- Follow alignment styles shown below: +```xml +// Correct + + + + +// Correct + +``` + +### Naming + +- Property names use camelCase. +- React component names use CapitalCamelCase. +- Do not use an understore for internal methods in a react component. + +```xml +// Correct + +``` diff --git a/api/context.go b/api/context.go index ac9dffcbc9b..16da0a6eb49 100644 --- a/api/context.go +++ b/api/context.go @@ -101,6 +101,12 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) w.Header().Set(model.HEADER_VERSION_ID, utils.Cfg.ServiceSettings.Version) + // Instruct the browser not to display us in an iframe for anti-clickjacking + if !h.isApi { + w.Header().Set("X-Frame-Options", "DENY") + w.Header().Set("Content-Security-Policy", "frame-ancestors none") + } + sessionId := "" // attempt to parse the session token from the header diff --git a/api/file.go b/api/file.go index 889c9dd1bcb..3ef50fbbd5e 100644 --- a/api/file.go +++ b/api/file.go @@ -33,7 +33,7 @@ func InitFile(r *mux.Router) { sr := r.PathPrefix("/files").Subrouter() sr.Handle("/upload", ApiUserRequired(uploadFile)).Methods("POST") - sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+\\.[A-Za-z0-9]{3,}}", ApiAppHandler(getFile)).Methods("GET") + sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+(\\.[A-Za-z0-9]{3,})?}", ApiAppHandler(getFile)).Methods("GET") sr.Handle("/get_public_link", ApiUserRequired(getPublicLink)).Methods("POST") } diff --git a/api/team.go b/api/team.go index 1145e6e81c7..c9fe42eccf8 100644 --- a/api/team.go +++ b/api/team.go @@ -35,25 +35,18 @@ func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) { m := model.MapFromJson(r.Body) email := strings.ToLower(strings.TrimSpace(m["email"])) - displayName := strings.TrimSpace(m["display_name"]) if len(email) == 0 { c.SetInvalidParam("signupTeam", "email") return } - if len(displayName) == 0 { - c.SetInvalidParam("signupTeam", "display_name") - return - } - subjectPage := NewServerTemplatePage("signup_team_subject", c.GetSiteURL()) bodyPage := NewServerTemplatePage("signup_team_body", c.GetSiteURL()) bodyPage.Props["TourUrl"] = utils.Cfg.TeamSettings.TourLink props := make(map[string]string) props["email"] = email - props["display_name"] = displayName props["time"] = fmt.Sprintf("%v", model.GetMillis()) data := model.MapToJson(props) diff --git a/api/templates/email_change_body.html b/api/templates/email_change_body.html index f8f3845e78a..439fffd5b0a 100644 --- a/api/templates/email_change_body.html +++ b/api/templates/email_change_body.html @@ -8,7 +8,7 @@ - @@ -32,7 +32,7 @@ -
+
+

diff --git a/api/templates/find_teams_body.html b/api/templates/find_teams_body.html index 6eaaf56e07e..a73ed0ad4a7 100644 --- a/api/templates/find_teams_body.html +++ b/api/templates/find_teams_body.html @@ -8,7 +8,7 @@
- @@ -40,7 +40,7 @@ -
+
+

diff --git a/api/templates/invite_body.html b/api/templates/invite_body.html index 46189fae57a..ad0658e3d19 100644 --- a/api/templates/invite_body.html +++ b/api/templates/invite_body.html @@ -8,7 +8,7 @@
- @@ -35,7 +35,7 @@ -
+
+

diff --git a/api/templates/password_change_body.html b/api/templates/password_change_body.html index 515c0a7d9df..1d4a6e1c86e 100644 --- a/api/templates/password_change_body.html +++ b/api/templates/password_change_body.html @@ -8,7 +8,7 @@
- @@ -32,7 +32,7 @@ -
+
+

diff --git a/api/templates/post_body.html b/api/templates/post_body.html index c0f4375d8e1..0aa913db56b 100644 --- a/api/templates/post_body.html +++ b/api/templates/post_body.html @@ -8,7 +8,7 @@
- @@ -35,7 +35,7 @@ -
+
+

diff --git a/api/templates/reset_body.html b/api/templates/reset_body.html index af9f6b4e8b5..4c2fec1e741 100644 --- a/api/templates/reset_body.html +++ b/api/templates/reset_body.html @@ -8,7 +8,7 @@
- @@ -35,7 +35,7 @@ -
+
+

diff --git a/api/templates/signup_team_body.html b/api/templates/signup_team_body.html index 5a5ae4d4774..5e60a042bcf 100644 --- a/api/templates/signup_team_body.html +++ b/api/templates/signup_team_body.html @@ -8,7 +8,7 @@
- @@ -38,7 +38,7 @@ -
+
+

diff --git a/api/templates/verify_body.html b/api/templates/verify_body.html index 67ded9c20ea..1a68c16f50b 100644 --- a/api/templates/verify_body.html +++ b/api/templates/verify_body.html @@ -8,7 +8,7 @@
- @@ -35,7 +35,7 @@ -
+
+

diff --git a/api/templates/welcome_body.html b/api/templates/welcome_body.html index 7107bc2e066..cc4d95fb113 100644 --- a/api/templates/welcome_body.html +++ b/api/templates/welcome_body.html @@ -8,7 +8,7 @@
- @@ -32,7 +32,7 @@ -
+
+

diff --git a/model/utils.go b/model/utils.go index 093a54e38c2..c7f991da200 100644 --- a/model/utils.go +++ b/model/utils.go @@ -319,6 +319,6 @@ func ClearMentionTags(post string) string { } var UrlRegex = regexp.MustCompile(`^((?:[a-z]+:\/\/)?(?:(?:[a-z0-9\-]+\.)+(?:[a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(?:\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(?:\?[a-z0-9+_~\-\.%=&]*)?)?(?:#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(?:\s+|$)$`) -var PartialUrlRegex = regexp.MustCompile(`/([A-Za-z0-9]{26})/([A-Za-z0-9]{26})/((?:[A-Za-z0-9]{26})?.+\.[A-Za-z0-9]{3,})`) +var PartialUrlRegex = regexp.MustCompile(`/([A-Za-z0-9]{26})/([A-Za-z0-9]{26})/((?:[A-Za-z0-9]{26})?.+(?:\.[A-Za-z0-9]{3,})?)`) var SplitRunes = map[rune]bool{',': true, ' ': true, '.': true, '!': true, '?': true, ':': true, ';': true, '\n': true, '<': true, '>': true, '(': true, ')': true, '{': true, '}': true, '[': true, ']': true, '+': true, '/': true, '\\': true} diff --git a/store/sql_store.go b/store/sql_store.go index 606b2cbc165..0d4f76a7226 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -224,7 +224,7 @@ func (ss SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName st func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, fullText bool) { if utils.Cfg.SqlSettings.DriverName == "postgres" { - _, err := ss.GetMaster().SelectStr("SELECT to_regclass($1)", indexName) + _, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName) // It should fail if the index does not exist if err == nil { return diff --git a/web/react/.eslintrc b/web/react/.eslintrc new file mode 100644 index 00000000000..d8b36f6ca7d --- /dev/null +++ b/web/react/.eslintrc @@ -0,0 +1,139 @@ +{ + "ecmaFeatures": { + "jsx": true, + "blockBindings": true, + "modules": true + }, + "plugins": [ + "react" + ], + "env": { + "browser": true, + "node": true, + "jquery": true, + "es6": true + }, + "globals": { + "React": false + }, + "rules": { + "comma-dangle": [2, "never"], + "no-cond-assign": [2, "except-parens"], + "no-console": 1, + "no-constant-condition": 1, + "no-debugger": 1, + "no-dupe-args": 2, + "no-dupe-keys": 2, + "no-duplicate-case": 2, + "no-empty": 1, + "no-ex-assign": 1, + "no-extra-semi": 2, + "no-func-assign": 1, + "no-inner-declarations": 0, + "no-invalid-regexp": 2, + "no-irregular-whitespace": 2, + "no-unreachable": 2, + "valid-typeof": 2, + "no-unexpected-multiline": 2, + + "block-scoped-var": 1, + "complexity": [1, 8], + "consistent-return": 2, + "curly": [2, "all"], + "dot-notation": 2, + "dot-location": [2, "object"], + "eqeqeq": [2, "smart"], + "guard-for-in": 1, + "no-alert": 1, + "no-caller": 2, + "no-div-regex": 1, + "no-else-return": 1, + "no-eval": 2, + "no-extend-native": 2, + "no-floating-decimal": 2, + "no-labels": 2, + "no-lone-blocks": 1, + "no-multi-spaces": [2, { "exceptions": { "Property": false } }], + "no-multi-str": 0, + "no-param-reassign": 2, + "no-process-env": 2, + "no-redeclare": 2, + "no-return-assign": [2, "always"], + "no-script-url": 2, + "no-self-compare": 2, + "no-sequences": 2, + "no-throw-literal": 2, + "no-unused-expressions": 2, + "no-void": 2, + "no-warning-comments": 0, + "no-with": 2, + "radix": 2, + "vars-on-top": 0, + "wrap-iife": [2, "outside"], + "yoda": [2, "never", {"exceptRange": false, "onlyEquality": false}], + + "no-undefined": 2, + "no-shadow": [2, {"hoist": "functions"}], + "no-unused-vars": [2, {"vars": "all", "args": "all"}], + "no-use-before-define": [2, "nofunc"], + + // Style + "array-bracket-spacing": [2, "never"], + "brace-style": [2, "1tbs", { "allowSingleLine": false }], + "camelcase": [2, {"properties": "always"}], + "comma-spacing": [2, {"before": false, "after": true}], + "comma-style": [2, "last"], + "computed-property-spacing": [2, "never"], + "consistent-this": [2, "self"], + "func-names": 2, + "func-style": [2, "declaration"], + "indent": [2, 4, {"indentSwitchCase": false}], + "key-spacing": [2, {"beforeColon": false, "afterColon": true}], + "lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true, "allowBlockStart": true, "allowBlockEnd": true }], + "linebreak-style": 2, + "new-cap": 2, + "new-parens": 2, + "no-lonely-if": 2, + "no-mixed-spaces-and-tabs": 2, + "no-multiple-empty-lines": [2, {"max": 1}], + "no-spaced-func": 2, + "no-ternary": 2, + "no-trailing-spaces": [2, { "skipBlankLines": false }], + "no-underscore-dangle": 2, + "no-unneeded-ternary": 2, + "object-curly-spacing": [2, "never"], + "one-var": [2, "never"], + "operator-linebreak": [2, "after"], + "padded-blocks": [2, "never"], + "quote-props": [2, "as-needed"], + "quotes": [2, "single", "avoid-escape"], + "semi-spacing": [2, {"before": false, "after": true}], + "semi": [2, "always"], + "space-after-keywords": [2, "always"], + "space-before-blocks": [2, "always"], + "space-before-function-paren": [2, "never"], + "space-in-parens": [2, "never"], + "space-infix-ops": 2, + "space-return-throw-case": 2, + "space-unary-ops": [2, { "words": true, "nonwords": false }], + "wrap-regex": 2, + + // React Specific + "react/display-name": [2, { "acceptTranspilerName": true }], + "react/jsx-boolean-value": [2, "always"], + "react/jsx-curly-spacing": [2, "never"], + "react/jsx-no-duplicate-props": [2, { "ignoreCase": false }], + "react/jsx-no-undef": 2, + "react/jsx-quotes": [2, "single", "avoid-escape"], + "react/jsx-uses-react": 2, + "react/jsx-uses-vars": 2, + "react/no-danger": 0, + "react/no-did-mount-set-state": 2, + "react/no-did-update-set-state": 2, + "react/no-multi-comp": 2, + "react/no-unknown-property": 2, + "react/prop-types": 2, + "react/sort-comp": 0, + "react/wrap-multilines": 2 + } +} diff --git a/web/react/components/activity_log_modal.jsx b/web/react/components/activity_log_modal.jsx index 7cce807a935..90f139e8b18 100644 --- a/web/react/components/activity_log_modal.jsx +++ b/web/react/components/activity_log_modal.jsx @@ -102,8 +102,9 @@ module.exports = React.createClass({
-

Active Devices

+

Active Sessions

+

Sessions are created when you log in with your email and password to a new browser on a device. Sessions let you use Mattermost for up to 30 days without having to log in again. If you want to log out sooner, use the "Logout" button below to end a session.

{ activityList } diff --git a/web/react/components/delete_post_modal.jsx b/web/react/components/delete_post_modal.jsx index 11970bc2b31..f0cb809af02 100644 --- a/web/react/components/delete_post_modal.jsx +++ b/web/react/components/delete_post_modal.jsx @@ -98,7 +98,7 @@ module.exports = React.createClass({ : "" }
- +
diff --git a/web/react/components/file_preview.jsx b/web/react/components/file_preview.jsx index fdd12feec43..7c1db3e10a5 100644 --- a/web/react/components/file_preview.jsx +++ b/web/react/components/file_preview.jsx @@ -24,7 +24,7 @@ module.exports = React.createClass({ if (filename.indexOf("/api/v1/files/get") != -1) { filename = filename.split("/api/v1/files/get")[1]; } - filename = window.location.origin + "/api/v1/files/get" + filename; + filename = utils.getWindowLocationOrigin() + "/api/v1/files/get" + filename; if (type === "image") { previews.push( diff --git a/web/react/components/login.jsx b/web/react/components/login.jsx index 05918650b10..fe0a47777b6 100644 --- a/web/react/components/login.jsx +++ b/web/react/components/login.jsx @@ -103,13 +103,9 @@ module.exports = React.createClass({ return (
-
- { teamDisplayName } -
- /{ teamName }/ -
-
-
+
Sign in to:
+

{ teamDisplayName }

+

on { config.SiteName }

{ server_error } @@ -124,13 +120,13 @@ module.exports = React.createClass({
{ login_message } -
+ -
+
{"Want to create your own " + strings.Team + "?"} Sign up now
diff --git a/web/react/components/post_body.jsx b/web/react/components/post_body.jsx index 7871f52b7d3..641ffeef27a 100644 --- a/web/react/components/post_body.jsx +++ b/web/react/components/post_body.jsx @@ -32,7 +32,7 @@ module.exports = React.createClass({ if (fileInfo.path.indexOf("/api/v1/files/get") != -1) { fileInfo.path = fileInfo.path.split("/api/v1/files/get")[1]; } - fileInfo.path = window.location.origin + "/api/v1/files/get" + fileInfo.path; + fileInfo.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + fileInfo.path; if (type === "image") { $('').attr('src', fileInfo.path+'_thumb.jpg').load(function(path, name){ return function() { @@ -112,7 +112,7 @@ module.exports = React.createClass({ if (fileInfo.path.indexOf("/api/v1/files/get") != -1) { fileInfo.path = fileInfo.path.split("/api/v1/files/get")[1]; } - fileInfo.path = window.location.origin + "/api/v1/files/get" + fileInfo.path; + fileInfo.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + fileInfo.path; if (type === "image") { if (i < Constants.MAX_DISPLAY_FILES) { @@ -126,7 +126,7 @@ module.exports = React.createClass({ } else if (i < Constants.MAX_DISPLAY_FILES) { postFiles.push(
- + diff --git a/web/react/components/post_right.jsx b/web/react/components/post_right.jsx index 567be196210..8097a181e9c 100644 --- a/web/react/components/post_right.jsx +++ b/web/react/components/post_right.jsx @@ -98,7 +98,7 @@ RootPost = React.createClass({ if (fileInfo.path.indexOf("/api/v1/files/get") != -1) { fileInfo.path = fileInfo.path.split("/api/v1/files/get")[1]; } - fileInfo.path = window.location.origin + "/api/v1/files/get" + fileInfo.path; + fileInfo.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + fileInfo.path; if (ftype === "image") { var url = fileInfo.path.replace(re1, '%20').replace(re2, '%28').replace(re3, '%29'); @@ -208,7 +208,7 @@ CommentPost = React.createClass({ if (fileInfo.path.indexOf("/api/v1/files/get") != -1) { fileInfo.path = fileInfo.path.split("/api/v1/files/get")[1]; } - fileInfo.path = window.location.origin + "/api/v1/files/get" + fileInfo.path; + fileInfo.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + fileInfo.path; if (type === "image") { var url = fileInfo.path.replace(re1, '%20').replace(re2, '%28').replace(re3, '%29'); diff --git a/web/react/components/search_bar.jsx b/web/react/components/search_bar.jsx index f21f0cd5883..e39cf5d46f5 100644 --- a/web/react/components/search_bar.jsx +++ b/web/react/components/search_bar.jsx @@ -36,6 +36,9 @@ module.exports = React.createClass({ } } }, + clearFocus: function(e) { + $('.search-bar__container').removeClass('focused'); + }, handleClose: function(e) { e.preventDefault(); @@ -57,6 +60,7 @@ module.exports = React.createClass({ }, handleUserFocus: function(e) { e.target.select(); + $('.search-bar__container').addClass('focused'); }, performSearch: function(terms, isMentionSearch) { if (terms.length) { @@ -92,13 +96,14 @@ module.exports = React.createClass({ render: function() { return (
-
Cancel
- +
+ Cancel
+ Switch to { teamName }); + teams.push(
  • Switch to { teamName }
  • ); } } - teams.push(
  • Create a New Team
  • ); + teams.push(
  • Create a New Team
  • ); return (
      @@ -107,6 +107,10 @@ module.exports = React.createClass({ }; }, + toggleDropdown: function(e) { + $('.team__header').find('.dropdown-toggle').trigger('click'); + }, + render: function() { var me = UserStore.getCurrentUser(); @@ -116,7 +120,7 @@ module.exports = React.createClass({ return ( -
      - - { name_error } -
      { server_error }
      - +
      -
      + diff --git a/web/react/components/signup_team_complete.jsx b/web/react/components/signup_team_complete.jsx index 3e8a57308e4..e7b37ef3962 100644 --- a/web/react/components/signup_team_complete.jsx +++ b/web/react/components/signup_team_complete.jsx @@ -42,11 +42,15 @@ WelcomePage = React.createClass({ state.email_error = ""; } - client.signupTeam(email, this.props.state.team.name, + client.signupTeam(email, function(data) { - this.props.state.wizard = "finished"; - this.props.updateParent(this.props.state); - window.location.href = "/signup_team_confirm/?email=" + encodeURI(email); + if (data["follow_link"]) { + window.location.href = data["follow_link"]; + } else { + this.props.state.wizard = "finished"; + this.props.updateParent(this.props.state); + window.location.href = "/signup_team_confirm/?email=" + encodeURIComponent(team.email); + } }.bind(this), function(err) { this.state.server_error = err.message; @@ -80,19 +84,25 @@ WelcomePage = React.createClass({

      -

      Welcome!

      -

      {"Let's set up your " + strings.Team + " on " + config.SiteName + "."}

      +

      Welcome to:

      +

      {config.SiteName}

      +

      Let's setup 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 }

      -

      If this is not correct, you can switch to a different email. We'll send you a new invite right away.

      @@ -105,7 +115,7 @@ WelcomePage = React.createClass({ { server_error }
      - + Use a different email
      ); } @@ -128,6 +138,7 @@ TeamDisplayNamePage = React.createClass({ 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() { @@ -158,9 +169,11 @@ TeamDisplayNamePage = React.createClass({
      { name_error }
      -

      {"Your " + strings.Team + " name shows in menus and headings. It may include the name of your " + strings.Company + ", but it's not required."}

      -   - +
      {"Name your " + strings.Team + " in any language. Your " + strings.Team + " name shows in menus and headings."}
      + +
      ); @@ -248,17 +261,23 @@ TeamURLPage = React.createClass({
      - { window.location.origin + "/" } + { utils.getWindowLocationOrigin() + "/" }
      { name_error }
    -

    {"Pick something short and memorable for your " + strings.Team + "'s web address."}

    -

    {"Your " + strings.Team + " URL can only contain lowercase letters, numbers and dashes. Also, it needs to start with a letter and cannot end in a dash."}

    -   - +

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

    +
      +
    • Short and memorable is best
    • +
    • Use lower case letters, numbers and dashes
    • +
    • Must start with a letter and can't end in a dash
    • +
    + +
    ); @@ -461,14 +480,16 @@ SendInivtesPage = React.createClass({ return (
    - -

    Send Invitations

    - { emails } -
    -
     
    -
    -

    {"If you'd prefer, you can send invitations after you finish setting up the "+ strings.Team + "."}

    - + +

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

    + { emails } + +
    + +

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

    +
    ); } @@ -512,19 +533,24 @@ UsernamePage = React.createClass({
    -

    Choose a username

    -
    -
    -
    - +

    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 '_'
    +
    +
    + { name_error }
    - { name_error } + + -

    {"Pick something " + strings.Team + "mates will recognize. Your username is how you will appear to others."}

    -

    It can be made of lowercase letters and numbers.

    -   -
    ); @@ -542,15 +568,15 @@ PasswordPage = React.createClass({ var password = this.refs.password.getDOMNode().value.trim(); if (!password || password.length < 5) { - this.setState({name_error: "Please enter at least 5 characters"}); + this.setState({password_error: "Please enter at least 5 characters"}); return; } - this.setState({name_error: ""}); + this.setState({password_error: null, server_error: null}); $('#finish-button').button('loading'); var teamSignup = JSON.parse(JSON.stringify(this.props.state)); teamSignup.user.password = password; - teamSignup.user.allow_marketing = this.refs.email_service.getDOMNode().checked; + teamSignup.user.allow_marketing = true; delete teamSignup.wizard; var ctl = this; @@ -566,7 +592,7 @@ PasswordPage = React.createClass({ props.state.wizard = "finished"; props.updateParent(props.state, true); - window.location.href = window.location.origin + '/' + props.state.team.name + '/login?email=' + encodeURIComponent(teamSignup.team.email); + window.location.href = utils.getWindowLocationOrigin() + '/' + props.state.team.name + '/login?email=' + encodeURIComponent(teamSignup.team.email); // client.loginByEmail(teamSignup.team.domain, teamSignup.team.email, teamSignup.user.password, // function(data) { @@ -582,7 +608,7 @@ PasswordPage = React.createClass({ }, 5000); }.bind(this), function(err) { - this.setState({name_error: err.message}); + this.setState({server_error: err.message}); $('#sign-up-button').button('reset'); }.bind(this) ); @@ -594,30 +620,37 @@ PasswordPage = React.createClass({ client.track('signup', 'signup_team_07_password'); - var name_error = this.state.name_error ? : null; + var password_error = this.state.password_error ?
    : null; + var server_error = this.state.server_error ?
    : null; return (
    -

    Choose a password

    -

    You'll use your email address ({this.props.state.team.email}) and password to log into {config.SiteName}.

    -
    -
    -
    - +

    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.
    +
    +
    + { password_error } + { server_error }
    -
    - { name_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}.

    +
    ); @@ -640,9 +673,6 @@ module.exports = React.createClass({ props.wizard = "welcome"; props.team = {}; props.team.email = this.props.email; - props.team.display_name = this.props.name; - props.team.company_name = this.props.name; - props.team.name = utils.cleanUpUrlable(this.props.name); props.team.allowed_domains = ""; props.invites = []; props.invites.push(""); diff --git a/web/react/components/signup_user_complete.jsx b/web/react/components/signup_user_complete.jsx index bbf1f670c2a..670aab943ed 100644 --- a/web/react/components/signup_user_complete.jsx +++ b/web/react/components/signup_user_complete.jsx @@ -40,7 +40,7 @@ module.exports = React.createClass({ this.setState({name_error: "", email_error: "", password_error: "", server_error: ""}); - this.state.user.allow_marketing = this.refs.email_service.getDOMNode().checked; + this.state.user.allow_marketing = true; client.createUser(this.state.user, this.state.data, this.state.hash, function(data) { @@ -104,8 +104,8 @@ module.exports = React.createClass({ var yourEmailIs = this.state.user.email == "" ? "" : Your email address is { this.state.user.email }. var email = ( -
    - +
    +
    What's your email address?
    { email_error } @@ -124,29 +124,33 @@ module.exports = React.createClass({ return (
    -

    Signup to { config.SiteName }

    -
    - -
    +
    Welcome to:
    +

    { this.props.teamDisplayName }

    +

    on { config.SiteName }

    +

    Let's create your account

    { signup_message } - -
    - - { name_error } -

    Your username can be made of lowercase letters and numbers.

    -

    {"Pick something " + strings.Team + "mates will recognize. Your username is how you will appear to others"}

    -
    - { email } - -
    - - { password_error } -
    -

    { yourEmailIs } You’ll use this address to sign in to {config.SiteName}.

    -
    -

    +
    + { email } +

    { yourEmailIs } You’ll use this address to sign in to {config.SiteName}.

    +
    +
    Choose your username
    +
    + + { name_error } +

    Username must begin with a letter, and contain between 3 to 15 lowercase characters made up of numbers, letters, and the symbols '.', '-' and '_'"

    +
    +
    +
    +
    Choose your password
    +
    + + { 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 creating an account and using Mattermost you are agreeing to our Terms of Service. If you do not agree, you cannot use this service.

    ); } diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx index 2ac9a2371cb..e1ae6da5263 100644 --- a/web/react/components/user_settings.jsx +++ b/web/react/components/user_settings.jsx @@ -617,7 +617,7 @@ var SecurityTab = React.createClass({

    View Access History - View and Logout of Active Devices + View and Logout of Active Sessions
    ); diff --git a/web/react/components/view_image.jsx b/web/react/components/view_image.jsx index c107de4d79a..7b096c6298c 100644 --- a/web/react/components/view_image.jsx +++ b/web/react/components/view_image.jsx @@ -40,7 +40,7 @@ module.exports = React.createClass({ if (fileInfo.path.indexOf("/api/v1/files/get") !== -1) { fileInfo.path = fileInfo.path.split("/api/v1/files/get")[1]; } - fileInfo.path = window.location.origin + "/api/v1/files/get" + fileInfo.path; + fileInfo.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + fileInfo.path; src = fileInfo['path'] + '_preview.jpg'; } @@ -148,7 +148,7 @@ module.exports = React.createClass({ if (info.path.indexOf("/api/v1/files/get") !== -1) { info.path = info.path.split("/api/v1/files/get")[1]; } - info.path = window.location.origin + "/api/v1/files/get" + info.path; + info.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + info.path; preview_filename = info['path'] + '_preview.jpg'; } @@ -166,7 +166,7 @@ module.exports = React.createClass({ if (download_link.indexOf("/api/v1/files/get") !== -1) { download_link = download_link.split("/api/v1/files/get")[1]; } - download_link = window.location.origin + "/api/v1/files/get" + download_link; + download_link = utils.getWindowLocationOrigin() + "/api/v1/files/get" + download_link; return (