Merge branch 'master' into advanced-permissions-phase-1

Этот коммит содержится в:
Martin Kraft
2018-03-23 09:08:49 -04:00
родитель 37f0e5e0eb 87762ae62e
Коммит 5fa1b35819
53 изменённых файлов: 2849 добавлений и 164 удалений

Просмотреть файл

@@ -11,6 +11,7 @@ import (
"net"
"net/http"
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
@@ -303,7 +304,11 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
}
utils.DisableDebugLogForTest()
ruser, _ := client.CreateUser(user)
ruser, response := client.CreateUser(user)
if response.Error != nil {
panic(response.Error)
}
ruser.Password = "Password1"
store.Must(me.App.Srv.Store.User().VerifyEmail(ruser.Id))
utils.EnableDebugLogForTest()
@@ -676,7 +681,7 @@ func CheckInternalErrorStatus(t *testing.T, resp *model.Response) {
func readTestFile(name string) ([]byte, error) {
path, _ := utils.FindDir("tests")
file, err := os.Open(path + "/" + name)
file, err := os.Open(filepath.Join(path, name))
if err != nil {
return nil, err
}

Просмотреть файл

@@ -6,6 +6,7 @@ package api4
import (
"net/http"
"net/url"
"path/filepath"
"strings"
l4g "github.com/alecthomas/log4go"
@@ -375,7 +376,7 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, max-age=31556926, public")
staticDir, _ := utils.FindDir(model.CLIENT_DIR)
http.ServeFile(w, r, staticDir+"root.html")
http.ServeFile(w, r, filepath.Join(staticDir, "root.html"))
}
func getAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {

Просмотреть файл

@@ -8,6 +8,7 @@ import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/mattermost/mattermost-server/model"
@@ -53,7 +54,7 @@ func TestPlugin(t *testing.T) {
}()
path, _ := utils.FindDir("tests")
file, err := os.Open(path + "/testplugin.tar.gz")
file, err := os.Open(filepath.Join(path, "testplugin.tar.gz"))
if err != nil {
t.Fatal(err)
}

Просмотреть файл

@@ -17,6 +17,8 @@ import (
func (api *API) InitSystem() {
api.BaseRoutes.System.Handle("/ping", api.ApiHandler(getSystemPing)).Methods("GET")
api.BaseRoutes.System.Handle("/timezones", api.ApiSessionRequired(getSupportedTimezones)).Methods("GET")
api.BaseRoutes.ApiRoot.Handle("/config", api.ApiSessionRequired(getConfig)).Methods("GET")
api.BaseRoutes.ApiRoot.Handle("/config", api.ApiSessionRequired(updateConfig)).Methods("PUT")
api.BaseRoutes.ApiRoot.Handle("/config/reload", api.ApiSessionRequired(configReload)).Methods("POST")
@@ -378,6 +380,18 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(rows.ToJson()))
}
func getSupportedTimezones(c *Context, w http.ResponseWriter, r *http.Request) {
supportedTimezones := c.App.Timezones()
if supportedTimezones != nil {
w.Write([]byte(model.TimezonesToJson(supportedTimezones)))
return
}
emptyTimezones := make([]string, 0)
w.Write([]byte(model.TimezonesToJson(emptyTimezones)))
}
func testS3(c *Context, w http.ResponseWriter, r *http.Request) {
cfg := model.ConfigFromJson(r.Body)
if cfg == nil {

Просмотреть файл

@@ -527,3 +527,15 @@ func TestS3TestConnection(t *testing.T) {
t.Fatal("should return error ")
}
}
func TestSupportedTimezones(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
Client := th.Client
supportedTimezonesFromConfig := th.App.Timezones()
supportedTimezones, resp := Client.GetSupportedTimezone()
CheckNoError(t, resp)
assert.Equal(t, supportedTimezonesFromConfig, supportedTimezones)
}

Просмотреть файл

@@ -285,7 +285,7 @@ func getTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if members, err := c.App.GetTeamMembers(c.Params.TeamId, c.Params.Page, c.Params.PerPage); err != nil {
if members, err := c.App.GetTeamMembers(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
@@ -543,9 +543,9 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
teams, err = c.App.GetAllTeamsPage(c.Params.Page, c.Params.PerPage)
teams, err = c.App.GetAllTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
} else {
teams, err = c.App.GetAllOpenTeamsPage(c.Params.Page, c.Params.PerPage)
teams, err = c.App.GetAllOpenTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
}
if err != nil {

Просмотреть файл

@@ -573,6 +573,10 @@ func TestGetAllTeams(t *testing.T) {
_, resp := Client.CreateTeam(team)
CheckNoError(t, resp)
team2 := &model.Team{DisplayName: "Name2", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: true}
_, resp = Client.CreateTeam(team2)
CheckNoError(t, resp)
rrteams, resp := Client.GetAllTeams("", 0, 1)
CheckNoError(t, resp)
@@ -617,6 +621,17 @@ func TestGetAllTeams(t *testing.T) {
t.Fatal("wrong number of teams - should be 0")
}
rrteams, resp = Client.GetAllTeams("", 0, 2)
CheckNoError(t, resp)
rrteams2, resp = Client.GetAllTeams("", 1, 2)
CheckNoError(t, resp)
for _, t1 := range rrteams {
for _, t2 := range rrteams2 {
assert.NotEqual(t, t1.Id, t2.Id, "different pages should not have the same teams")
}
}
Client.Logout()
_, resp = Client.GetAllTeams("", 1, 10)
CheckUnauthorizedStatus(t, resp)
@@ -1146,6 +1161,17 @@ func TestGetTeamMembers(t *testing.T) {
t.Fatal("should be no member")
}
rmembers, resp = Client.GetTeamMembers(team.Id, 0, 2, "")
CheckNoError(t, resp)
rmembers2, resp := Client.GetTeamMembers(team.Id, 1, 2, "")
CheckNoError(t, resp)
for _, tm1 := range rmembers {
for _, tm2 := range rmembers2 {
assert.NotEqual(t, tm1.UserId+tm1.TeamId, tm2.UserId+tm2.TeamId, "different pages should not have the same members")
}
}
_, resp = Client.GetTeamMembers("junk", 0, 100, "")
CheckBadRequestStatus(t, resp)

Просмотреть файл

@@ -996,6 +996,10 @@ func TestPatchUser(t *testing.T) {
patch.Position = new(string)
patch.NotifyProps = model.StringMap{}
patch.NotifyProps["comment"] = "somethingrandom"
patch.Timezone = model.StringMap{}
patch.Timezone["useAutomaticTimezone"] = "true"
patch.Timezone["automaticTimezone"] = "America/New_York"
patch.Timezone["manualTimezone"] = ""
ruser, resp := Client.PatchUser(user.Id, patch)
CheckNoError(t, resp)
@@ -1019,6 +1023,15 @@ func TestPatchUser(t *testing.T) {
if ruser.NotifyProps["comment"] != "somethingrandom" {
t.Fatal("NotifyProps did not update properly")
}
if ruser.Timezone["useAutomaticTimezone"] != "true" {
t.Fatal("useAutomaticTimezone did not update properly")
}
if ruser.Timezone["automaticTimezone"] != "America/New_York" {
t.Fatal("automaticTimezone did not update properly")
}
if ruser.Timezone["manualTimezone"] != "" {
t.Fatal("manualTimezone did not update properly")
}
patch.Username = model.NewString(th.BasicUser2.Username)
_, resp = Client.PatchUser(user.Id, patch)