From 0e7a149982f73919badd9d366d06fa699925c89f Mon Sep 17 00:00:00 2001 From: hmhealey Date: Wed, 6 Jan 2016 18:04:24 -0500 Subject: Added the ability to get more channel members from getChannelExtraInfo --- api/channel.go | 21 ++++++++++++++++--- api/channel_benchmark_test.go | 2 +- api/channel_test.go | 48 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 61 insertions(+), 10 deletions(-) (limited to 'api') diff --git a/api/channel.go b/api/channel.go index b85de3071..674293e19 100644 --- a/api/channel.go +++ b/api/channel.go @@ -9,9 +9,14 @@ import ( "github.com/gorilla/mux" "github.com/mattermost/platform/model" "net/http" + "strconv" "strings" ) +const ( + defaultExtraMemberLimit = 100 +) + func InitChannel(r *mux.Router) { l4g.Debug("Initializing channel api routes") @@ -27,6 +32,7 @@ func InitChannel(r *mux.Router) { sr.Handle("/update_notify_props", ApiUserRequired(updateNotifyProps)).Methods("POST") sr.Handle("/{id:[A-Za-z0-9]+}/", ApiUserRequiredActivity(getChannel, false)).Methods("GET") sr.Handle("/{id:[A-Za-z0-9]+}/extra_info", ApiUserRequired(getChannelExtraInfo)).Methods("GET") + sr.Handle("/{id:[A-Za-z0-9]+}/extra_info/{member_limit:-?[0-9]+}", ApiUserRequired(getChannelExtraInfo)).Methods("GET") sr.Handle("/{id:[A-Za-z0-9]+}/join", ApiUserRequired(join)).Methods("POST") sr.Handle("/{id:[A-Za-z0-9]+}/leave", ApiUserRequired(leave)).Methods("POST") sr.Handle("/{id:[A-Za-z0-9]+}/delete", ApiUserRequired(deleteChannel)).Methods("POST") @@ -730,10 +736,19 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) { } func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) id := params["id"] + var memberLimit int + if memberLimitString, ok := params["member_limit"]; !ok { + memberLimit = defaultExtraMemberLimit + } else if memberLimitInt64, err := strconv.ParseInt(memberLimitString, 10, 0); err != nil { + c.Err = model.NewAppError("getChannelExtraInfo", "Failed to parse member limit", err.Error()) + return + } else { + memberLimit = int(memberLimitInt64) + } + sc := Srv.Store.Channel().Get(id) var channel *model.Channel if cresult := <-sc; cresult.Err != nil { @@ -743,13 +758,13 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) { channel = cresult.Data.(*model.Channel) } - extraEtag := channel.ExtraEtag() + extraEtag := channel.ExtraEtag(memberLimit) if HandleEtag(extraEtag, w, r) { return } scm := Srv.Store.Channel().GetMember(id, c.Session.UserId) - ecm := Srv.Store.Channel().GetExtraMembers(id, 100) + ecm := Srv.Store.Channel().GetExtraMembers(id, memberLimit) ccm := Srv.Store.Channel().GetMemberCount(id) if cmresult := <-scm; cmresult.Err != nil { diff --git a/api/channel_benchmark_test.go b/api/channel_benchmark_test.go index fb8dd61bc..d6e1e5a55 100644 --- a/api/channel_benchmark_test.go +++ b/api/channel_benchmark_test.go @@ -189,7 +189,7 @@ func BenchmarkGetChannelExtraInfo(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { for j := range channels { - Client.Must(Client.GetChannelExtraInfo(channels[j].Id, "")) + Client.Must(Client.GetChannelExtraInfo(channels[j].Id, -1, "")) } } } diff --git a/api/channel_test.go b/api/channel_test.go index 4ef164cba..117278378 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -674,7 +674,7 @@ func TestGetChannelExtraInfo(t *testing.T) { channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) - rget := Client.Must(Client.GetChannelExtraInfo(channel1.Id, "")) + rget := Client.Must(Client.GetChannelExtraInfo(channel1.Id, -1, "")) data := rget.Data.(*model.ChannelExtra) if data.Id != channel1.Id { t.Fatal("couldnt't get extra info") @@ -690,7 +690,7 @@ func TestGetChannelExtraInfo(t *testing.T) { currentEtag := rget.Etag - if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil { + if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, -1, currentEtag); err != nil { t.Fatal(err) } else if cache_result.Data.(*model.ChannelExtra) != nil { t.Log(cache_result.Data) @@ -708,7 +708,7 @@ func TestGetChannelExtraInfo(t *testing.T) { Client2.LoginByEmail(team.Name, user2.Email, "pwd") Client2.Must(Client2.JoinChannel(channel1.Id)) - if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil { + if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, -1, currentEtag); err != nil { t.Fatal(err) } else if cache_result.Data.(*model.ChannelExtra) == nil { t.Log(cache_result.Data) @@ -717,7 +717,7 @@ func TestGetChannelExtraInfo(t *testing.T) { currentEtag = cache_result.Etag } - if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil { + if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, -1, currentEtag); err != nil { t.Fatal(err) } else if cache_result.Data.(*model.ChannelExtra) != nil { t.Log(cache_result.Data) @@ -728,7 +728,7 @@ func TestGetChannelExtraInfo(t *testing.T) { Client2.Must(Client2.LeaveChannel(channel1.Id)) - if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil { + if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, -1, currentEtag); err != nil { t.Fatal(err) } else if cache_result.Data.(*model.ChannelExtra) == nil { t.Log(cache_result.Data) @@ -737,7 +737,7 @@ func TestGetChannelExtraInfo(t *testing.T) { currentEtag = cache_result.Etag } - if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, currentEtag); err != nil { + if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, -1, currentEtag); err != nil { t.Fatal(err) } else if cache_result.Data.(*model.ChannelExtra) != nil { t.Log(cache_result.Data) @@ -745,6 +745,42 @@ func TestGetChannelExtraInfo(t *testing.T) { } else { currentEtag = cache_result.Etag } + + Client2.Must(Client2.JoinChannel(channel1.Id)) + + if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, 2, currentEtag); err != nil { + t.Fatal(err) + } else if extra := cache_result.Data.(*model.ChannelExtra); extra == nil { + t.Fatal("response should not be empty") + } else if len(extra.Members) != 2 { + t.Fatal("should've returned 2 members") + } else if extra.MemberCount != 2 { + t.Fatal("should've returned member count of 2") + } else { + currentEtag = cache_result.Etag + } + + if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, 1, currentEtag); err != nil { + t.Fatal(err) + } else if extra := cache_result.Data.(*model.ChannelExtra); extra == nil { + t.Fatal("response should not be empty") + } else if len(extra.Members) != 1 { + t.Fatal("should've returned only 1 member") + } else if extra.MemberCount != 2 { + t.Fatal("should've returned member count of 2") + } else { + currentEtag = cache_result.Etag + } + + if cache_result, err := Client.GetChannelExtraInfo(channel1.Id, 1, currentEtag); err != nil { + t.Fatal(err) + } else if cache_result.Data.(*model.ChannelExtra) != nil { + t.Log(cache_result.Data) + t.Fatal("response should be empty") + } else { + currentEtag = cache_result.Etag + } + } func TestAddChannelMember(t *testing.T) { -- cgit v1.2.3-1-g7c22 From b1251b93932adf616a996725448d0b77fad0d3c1 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Mon, 11 Jan 2016 09:12:51 -0600 Subject: Upgrade logging package --- api/admin.go | 2 +- api/api.go | 2 +- api/channel.go | 2 +- api/command.go | 2 +- api/context.go | 2 +- api/file.go | 2 +- api/import.go | 2 +- api/oauth.go | 2 +- api/post.go | 2 +- api/preference.go | 2 +- api/server.go | 2 +- api/slackimport.go | 2 +- api/team.go | 2 +- api/user.go | 2 +- api/web_conn.go | 2 +- api/web_hub.go | 2 +- api/web_socket.go | 2 +- api/web_team_hub.go | 2 +- api/webhook.go | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) (limited to 'api') diff --git a/api/admin.go b/api/admin.go index 8e0a03e4b..885a95d95 100644 --- a/api/admin.go +++ b/api/admin.go @@ -9,7 +9,7 @@ import ( "os" "strings" - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" diff --git a/api/api.go b/api/api.go index 6c7eda0a2..a6bb22982 100644 --- a/api/api.go +++ b/api/api.go @@ -5,7 +5,7 @@ package api import ( "bytes" - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" "html/template" diff --git a/api/channel.go b/api/channel.go index 674293e19..706baa004 100644 --- a/api/channel.go +++ b/api/channel.go @@ -4,8 +4,8 @@ package api import ( - l4g "code.google.com/p/log4go" "fmt" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" "net/http" diff --git a/api/command.go b/api/command.go index db57f0bae..00293cf16 100644 --- a/api/command.go +++ b/api/command.go @@ -11,7 +11,7 @@ import ( "strings" "time" - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" diff --git a/api/context.go b/api/context.go index b39f03a7d..561884c14 100644 --- a/api/context.go +++ b/api/context.go @@ -11,7 +11,7 @@ import ( "strconv" "strings" - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" "github.com/mattermost/platform/utils" diff --git a/api/file.go b/api/file.go index 67ebc14b7..d023515af 100644 --- a/api/file.go +++ b/api/file.go @@ -5,8 +5,8 @@ package api import ( "bytes" - l4g "code.google.com/p/log4go" "fmt" + l4g "github.com/alecthomas/log4go" "github.com/disintegration/imaging" "github.com/goamz/goamz/aws" "github.com/goamz/goamz/s3" diff --git a/api/import.go b/api/import.go index 81de78975..5c8f99348 100644 --- a/api/import.go +++ b/api/import.go @@ -4,7 +4,7 @@ package api import ( - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" ) diff --git a/api/oauth.go b/api/oauth.go index 5753db8bd..eb5e0e496 100644 --- a/api/oauth.go +++ b/api/oauth.go @@ -4,8 +4,8 @@ package api import ( - l4g "code.google.com/p/log4go" "fmt" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" diff --git a/api/post.go b/api/post.go index 958479427..be1ecd96a 100644 --- a/api/post.go +++ b/api/post.go @@ -4,8 +4,8 @@ package api import ( - l4g "code.google.com/p/log4go" "fmt" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" diff --git a/api/preference.go b/api/preference.go index e9c74aafe..f5c96f1dd 100644 --- a/api/preference.go +++ b/api/preference.go @@ -4,7 +4,7 @@ package api import ( - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" "net/http" diff --git a/api/server.go b/api/server.go index 2bab62fac..33428009f 100644 --- a/api/server.go +++ b/api/server.go @@ -4,7 +4,7 @@ package api import ( - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/braintree/manners" "github.com/gorilla/mux" "github.com/mattermost/platform/store" diff --git a/api/slackimport.go b/api/slackimport.go index cab4c6184..e0a0ff036 100644 --- a/api/slackimport.go +++ b/api/slackimport.go @@ -6,8 +6,8 @@ package api import ( "archive/zip" "bytes" - l4g "code.google.com/p/log4go" "encoding/json" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" "io" "mime/multipart" diff --git a/api/team.go b/api/team.go index fbcb301a9..e2dd8807e 100644 --- a/api/team.go +++ b/api/team.go @@ -5,8 +5,8 @@ package api import ( "bytes" - l4g "code.google.com/p/log4go" "fmt" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" diff --git a/api/user.go b/api/user.go index d4c7fcaf5..6c0ce86d6 100644 --- a/api/user.go +++ b/api/user.go @@ -5,9 +5,9 @@ package api import ( "bytes" - l4g "code.google.com/p/log4go" b64 "encoding/base64" "fmt" + l4g "github.com/alecthomas/log4go" "github.com/disintegration/imaging" "github.com/golang/freetype" "github.com/gorilla/mux" diff --git a/api/web_conn.go b/api/web_conn.go index 50a003ace..2b0e29038 100644 --- a/api/web_conn.go +++ b/api/web_conn.go @@ -4,7 +4,7 @@ package api import ( - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/websocket" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" diff --git a/api/web_hub.go b/api/web_hub.go index f80488824..4361d1035 100644 --- a/api/web_hub.go +++ b/api/web_hub.go @@ -4,7 +4,7 @@ package api import ( - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" ) diff --git a/api/web_socket.go b/api/web_socket.go index 298e44b44..995e2a677 100644 --- a/api/web_socket.go +++ b/api/web_socket.go @@ -4,7 +4,7 @@ package api import ( - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/gorilla/websocket" "github.com/mattermost/platform/model" diff --git a/api/web_team_hub.go b/api/web_team_hub.go index 2c2386317..bb9ed9526 100644 --- a/api/web_team_hub.go +++ b/api/web_team_hub.go @@ -4,7 +4,7 @@ package api import ( - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" ) diff --git a/api/webhook.go b/api/webhook.go index 34c308879..a9a88b7b8 100644 --- a/api/webhook.go +++ b/api/webhook.go @@ -4,7 +4,7 @@ package api import ( - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" -- cgit v1.2.3-1-g7c22 From 1763ff6d72bae7dc57475dc73a03a7c0f12acc90 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Tue, 12 Jan 2016 08:02:38 -0500 Subject: Support old oauth routes --- api/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api') diff --git a/api/user.go b/api/user.go index d4c7fcaf5..00d637ec2 100644 --- a/api/user.go +++ b/api/user.go @@ -1790,7 +1790,7 @@ func GetAuthorizationCode(c *Context, service, teamName string, props map[string props["team"] = teamName state := b64.StdEncoding.EncodeToString([]byte(model.MapToJson(props))) - redirectUri := c.GetSiteURL() + "/" + service + "/complete" + redirectUri := c.GetSiteURL() + "/signup/" + service + "/complete" // Remove /signup after a few releases (~1.8) authUrl := endpoint + "?response_type=code&client_id=" + clientId + "&redirect_uri=" + url.QueryEscape(redirectUri) + "&state=" + url.QueryEscape(state) -- cgit v1.2.3-1-g7c22 From 9110dd54a15f3d0fcf6f60936e01d816b667b93c Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Mon, 4 Jan 2016 12:44:22 -0500 Subject: Added license validation and settings --- api/api.go | 1 + api/context.go | 1 + api/file.go | 20 +++++++++---- api/license.go | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 api/license.go (limited to 'api') diff --git a/api/api.go b/api/api.go index a6bb22982..f29063fe1 100644 --- a/api/api.go +++ b/api/api.go @@ -46,6 +46,7 @@ func InitApi() { InitOAuth(r) InitWebhook(r) InitPreference(r) + InitLicense(r) templatesDir := utils.FindDir("api/templates") l4g.Debug("Parsing server templates at %v", templatesDir) diff --git a/api/context.go b/api/context.go index 561884c14..e8ec6576d 100644 --- a/api/context.go +++ b/api/context.go @@ -35,6 +35,7 @@ type Page struct { TemplateName string Props map[string]string ClientCfg map[string]string + ClientLicense map[string]string User *model.User Team *model.Team Channel *model.Channel diff --git a/api/file.go b/api/file.go index d023515af..46e81691e 100644 --- a/api/file.go +++ b/api/file.go @@ -541,12 +541,8 @@ func writeFile(f []byte, path string) *model.AppError { return model.NewAppError("writeFile", "Encountered an error writing to S3", err.Error()) } } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { - if err := os.MkdirAll(filepath.Dir(utils.Cfg.FileSettings.Directory+path), 0774); err != nil { - return model.NewAppError("writeFile", "Encountered an error creating the directory for the new file", err.Error()) - } - - if err := ioutil.WriteFile(utils.Cfg.FileSettings.Directory+path, f, 0644); err != nil { - return model.NewAppError("writeFile", "Encountered an error writing to local server storage", err.Error()) + if err := writeFileLocally(f, utils.Cfg.FileSettings.Directory+path); err != nil { + return err } } else { return model.NewAppError("writeFile", "File storage not configured properly. Please configure for either S3 or local server file storage.", "") @@ -555,6 +551,18 @@ func writeFile(f []byte, path string) *model.AppError { return nil } +func writeFileLocally(f []byte, path string) *model.AppError { + if err := os.MkdirAll(filepath.Dir(path), 0774); err != nil { + return model.NewAppError("writeFile", "Encountered an error creating the directory for the new file", err.Error()) + } + + if err := ioutil.WriteFile(path, f, 0644); err != nil { + return model.NewAppError("writeFile", "Encountered an error writing to local server storage", err.Error()) + } + + return nil +} + func readFile(path string) ([]byte, *model.AppError) { if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { diff --git a/api/license.go b/api/license.go new file mode 100644 index 000000000..9ed2d2afb --- /dev/null +++ b/api/license.go @@ -0,0 +1,95 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package api + +import ( + "bytes" + l4g "code.google.com/p/log4go" + "github.com/gorilla/mux" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" + "io" + "net/http" + "strings" +) + +func InitLicense(r *mux.Router) { + l4g.Debug("Initializing license api routes") + + sr := r.PathPrefix("/license").Subrouter() + sr.Handle("/add", ApiAdminSystemRequired(addLicense)).Methods("POST") + sr.Handle("/remove", ApiAdminSystemRequired(removeLicense)).Methods("POST") +} + +func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { + c.LogAudit("attempt") + err := r.ParseMultipartForm(model.MAX_FILE_SIZE) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + m := r.MultipartForm + + fileArray, ok := m.File["license"] + if !ok { + c.Err = model.NewAppError("addLicense", "No file under 'license' in request", "") + c.Err.StatusCode = http.StatusBadRequest + return + } + + if len(fileArray) <= 0 { + c.Err = model.NewAppError("addLicense", "Empty array under 'license' in request", "") + c.Err.StatusCode = http.StatusBadRequest + return + } + + fileData := fileArray[0] + + file, err := fileData.Open() + defer file.Close() + if err != nil { + c.Err = model.NewAppError("addLicense", "Could not open license file", err.Error()) + return + } + + buf := bytes.NewBuffer(nil) + io.Copy(buf, file) + + data := buf.Bytes() + + var license *model.License + if success, licenseStr := utils.ValidateLicense(data); success { + license = model.LicenseFromJson(strings.NewReader(licenseStr)) + + if ok := utils.SetLicense(license); !ok { + c.LogAudit("failed - expired or non-started license") + c.Err = model.NewAppError("addLicense", "License is either expired or has not yet started.", "") + return + } + + go func() { + if err := writeFileLocally(data, utils.LICENSE_FILE_LOC); err != nil { + l4g.Error("Could not save license file") + } + }() + } else { + c.LogAudit("failed - invalid license") + c.Err = model.NewAppError("addLicense", "Invalid license file", "") + return + } + + c.LogAudit("success") + w.Write([]byte(license.ToJson())) +} + +func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) { + c.LogAudit("") + + utils.RemoveLicense() + + rdata := map[string]string{} + rdata["status"] = "ok" + w.Write([]byte(model.MapToJson(rdata))) +} -- cgit v1.2.3-1-g7c22 From 874d120535a615afddeb80599b7d2d982959ffdb Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Wed, 13 Jan 2016 10:54:12 -0500 Subject: Add some unit tests --- api/user.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'api') diff --git a/api/user.go b/api/user.go index d014ab995..786414227 100644 --- a/api/user.go +++ b/api/user.go @@ -122,6 +122,11 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) { user.EmailVerified = true } + if !CheckUserDomain(user, utils.Cfg.TeamSettings.RestrictCreationToDomains) { + c.Err = model.NewAppError("createUser", "The email you provided does not belong to an accepted domain. Please contact your administrator or sign up with a different email.", "") + return + } + ruser, err := CreateUser(team, user) if err != nil { c.Err = err @@ -136,19 +141,25 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) { } +func CheckUserDomain(user *model.User, domains string) bool { + domainArray := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(domains, "@", " ", -1), ",", " ", -1)))) + + matched := false + for _, d := range domainArray { + if strings.HasSuffix(user.Email, "@"+d) { + matched = true + break + } + } + + return matched +} + func IsVerifyHashRequired(user *model.User, team *model.Team, hash string) bool { shouldVerifyHash := true if team.Type == model.TEAM_INVITE && len(team.AllowedDomains) > 0 && len(hash) == 0 && user != nil { - domains := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(team.AllowedDomains, "@", " ", -1), ",", " ", -1)))) - - matched := false - for _, d := range domains { - if strings.HasSuffix(user.Email, "@"+d) { - matched = true - break - } - } + matched := CheckUserDomain(user, team.AllowedDomains) if matched { shouldVerifyHash = false -- cgit v1.2.3-1-g7c22 From c26edcf6786fd8aa1535c09e9581fc6417cddda4 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 14 Jan 2016 08:23:48 -0500 Subject: Final updates --- api/license.go | 19 ++++++++++++------- api/user.go | 4 ++++ 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'api') diff --git a/api/license.go b/api/license.go index 9ed2d2afb..06bde2b6c 100644 --- a/api/license.go +++ b/api/license.go @@ -69,14 +69,15 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { return } - go func() { - if err := writeFileLocally(data, utils.LICENSE_FILE_LOC); err != nil { - l4g.Error("Could not save license file") - } - }() + if err := writeFileLocally(data, utils.LicenseLocation()); err != nil { + c.LogAudit("failed - could not save license file") + c.Err = model.NewAppError("addLicense", "License did not save properly.", "path="+utils.LicenseLocation()) + utils.RemoveLicense() + return + } } else { c.LogAudit("failed - invalid license") - c.Err = model.NewAppError("addLicense", "Invalid license file", "") + c.Err = model.NewAppError("addLicense", "Invalid license file.", "") return } @@ -87,7 +88,11 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("") - utils.RemoveLicense() + if ok := utils.RemoveLicense(); !ok { + c.LogAudit("failed - could not remove license file") + c.Err = model.NewAppError("removeLicense", "License did not remove properly.", "") + return + } rdata := map[string]string{} rdata["status"] = "ok" diff --git a/api/user.go b/api/user.go index 786414227..a6b4fb654 100644 --- a/api/user.go +++ b/api/user.go @@ -142,6 +142,10 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) { } func CheckUserDomain(user *model.User, domains string) bool { + if len(domains) == 0 { + return true + } + domainArray := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(domains, "@", " ", -1), ",", " ", -1)))) matched := false -- cgit v1.2.3-1-g7c22 From a341dbad2b8a4564b6f270c79f2f9932e499ac80 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 14 Jan 2016 09:54:15 -0500 Subject: Fix old l4g references --- api/license.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api') diff --git a/api/license.go b/api/license.go index 06bde2b6c..5b3809651 100644 --- a/api/license.go +++ b/api/license.go @@ -5,7 +5,7 @@ package api import ( "bytes" - l4g "code.google.com/p/log4go" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" -- cgit v1.2.3-1-g7c22