summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/channel.go2
-rw-r--r--api/context.go21
-rw-r--r--api/post.go38
-rw-r--r--api/post_test.go70
-rw-r--r--api/team.go4
-rw-r--r--api/templates/error.html1
-rw-r--r--api/templates/find_teams_body.html2
-rw-r--r--api/web_conn.go5
-rw-r--r--api/web_hub.go8
-rw-r--r--api/web_team_hub.go9
10 files changed, 150 insertions, 10 deletions
diff --git a/api/channel.go b/api/channel.go
index 5f3282072..b40366719 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -391,6 +391,8 @@ func JoinChannel(c *Context, channelId string, role string) {
c.Err = model.NewAppError("joinChannel", "Failed to send join request", "")
return
}
+
+ UpdateChannelAccessCacheAndForget(c.Session.TeamId, c.Session.UserId, channel.Id)
} else {
c.Err = model.NewAppError("joinChannel", "You do not have the appropriate permissions", "")
c.Err.StatusCode = http.StatusForbidden
diff --git a/api/context.go b/api/context.go
index 8babf85f2..aaf304e2c 100644
--- a/api/context.go
+++ b/api/context.go
@@ -4,14 +4,15 @@
package api
import (
- l4g "code.google.com/p/log4go"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/store"
- "github.com/mattermost/platform/utils"
"net"
"net/http"
"net/url"
"strings"
+
+ l4g "code.google.com/p/log4go"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/store"
+ "github.com/mattermost/platform/utils"
)
var sessionCache *utils.Cache = utils.NewLru(model.SESSION_CACHE_SIZE)
@@ -431,10 +432,22 @@ func IsPrivateIpAddress(ipAddress string) bool {
}
func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) {
+
+ protocol := "http"
+ if utils.Cfg.ServiceSettings.UseSSL {
+ forwardProto := r.Header.Get(model.HEADER_FORWARDED_PROTO)
+ if forwardProto != "http" {
+ protocol = "https"
+ }
+ }
+
+ SiteURL := protocol + "://" + r.Host
+
m := make(map[string]string)
m["Message"] = err.Message
m["Details"] = err.DetailedError
m["SiteName"] = utils.Cfg.ServiceSettings.SiteName
+ m["SiteURL"] = SiteURL
w.WriteHeader(err.StatusCode)
ServerTemplates.ExecuteTemplate(w, "error.html", m)
diff --git a/api/post.go b/api/post.go
index c013df87f..5363fdf79 100644
--- a/api/post.go
+++ b/api/post.go
@@ -28,6 +28,7 @@ func InitPost(r *mux.Router) {
sr.Handle("/valet_create", ApiUserRequired(createValetPost)).Methods("POST")
sr.Handle("/update", ApiUserRequired(updatePost)).Methods("POST")
sr.Handle("/posts/{offset:[0-9]+}/{limit:[0-9]+}", ApiUserRequiredActivity(getPosts, false)).Methods("GET")
+ sr.Handle("/posts/{time:[0-9]+}", ApiUserRequiredActivity(getPostsSince, false)).Methods("GET")
sr.Handle("/post/{post_id:[A-Za-z0-9]+}", ApiUserRequired(getPost)).Methods("GET")
sr.Handle("/post/{post_id:[A-Za-z0-9]+}/delete", ApiUserRequired(deletePost)).Methods("POST")
}
@@ -545,9 +546,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
rpost := result.Data.(*model.Post)
message := model.NewMessage(c.Session.TeamId, rpost.ChannelId, c.Session.UserId, model.ACTION_POST_EDITED)
- message.Add("post_id", rpost.Id)
- message.Add("channel_id", rpost.ChannelId)
- message.Add("message", rpost.Message)
+ message.Add("post", rpost.ToJson())
PublishAndForget(message)
@@ -603,6 +602,39 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
}
+func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) {
+ params := mux.Vars(r)
+
+ id := params["id"]
+ if len(id) != 26 {
+ c.SetInvalidParam("getPostsSince", "channelId")
+ return
+ }
+
+ time, err := strconv.ParseInt(params["time"], 10, 64)
+ if err != nil {
+ c.SetInvalidParam("getPostsSince", "time")
+ return
+ }
+
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
+ pchan := Srv.Store.Post().GetPostsSince(id, time)
+
+ if !c.HasPermissionsToChannel(cchan, "getPostsSince") {
+ return
+ }
+
+ if result := <-pchan; result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ list := result.Data.(*model.PostList)
+
+ w.Write([]byte(list.ToJson()))
+ }
+
+}
+
func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
diff --git a/api/post_test.go b/api/post_test.go
index cbba83af6..ac9adf358 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -351,6 +351,76 @@ func TestGetPosts(t *testing.T) {
}
}
+func TestGetPostsSince(t *testing.T) {
+ Setup()
+
+ team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
+
+ user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(user1.Id))
+
+ Client.LoginByEmail(team.Name, user1.Email, "pwd")
+
+ channel1 := &model.Channel{DisplayName: "TestGetPosts", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
+
+ time.Sleep(10 * time.Millisecond)
+ post0 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
+ post0 = Client.Must(Client.CreatePost(post0)).Data.(*model.Post)
+
+ time.Sleep(10 * time.Millisecond)
+ post1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
+ post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
+
+ time.Sleep(10 * time.Millisecond)
+ post1a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post1.Id}
+ post1a1 = Client.Must(Client.CreatePost(post1a1)).Data.(*model.Post)
+
+ time.Sleep(10 * time.Millisecond)
+ post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
+ post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post)
+
+ time.Sleep(10 * time.Millisecond)
+ post3 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
+ post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
+
+ time.Sleep(10 * time.Millisecond)
+ post3a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post3.Id}
+ post3a1 = Client.Must(Client.CreatePost(post3a1)).Data.(*model.Post)
+
+ r1 := Client.Must(Client.GetPostsSince(channel1.Id, post1.CreateAt)).Data.(*model.PostList)
+
+ if r1.Order[0] != post3a1.Id {
+ t.Fatal("wrong order")
+ }
+
+ if r1.Order[1] != post3.Id {
+ t.Fatal("wrong order")
+ }
+
+ if len(r1.Posts) != 5 {
+ t.Fatal("wrong size")
+ }
+
+ now := model.GetMillis()
+ r2 := Client.Must(Client.GetPostsSince(channel1.Id, now)).Data.(*model.PostList)
+
+ if len(r2.Posts) != 0 {
+ t.Fatal("should have been empty")
+ }
+
+ post2.Message = "new message"
+ Client.Must(Client.UpdatePost(post2))
+
+ r3 := Client.Must(Client.GetPostsSince(channel1.Id, now)).Data.(*model.PostList)
+
+ if len(r3.Order) != 2 { // 2 because deleted post is returned as well
+ t.Fatal("missing post update")
+ }
+}
+
func TestSearchPosts(t *testing.T) {
Setup()
diff --git a/api/team.go b/api/team.go
index a331e9e34..8587a6de4 100644
--- a/api/team.go
+++ b/api/team.go
@@ -283,10 +283,10 @@ func emailTeams(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
teams := result.Data.([]*model.Team)
- // the template expects Props to be a map with team names as the keys
+ // the template expects Props to be a map with team names as the keys and the team url as the value
props := make(map[string]string)
for _, team := range teams {
- props[team.Name] = team.Name
+ props[team.Name] = c.GetTeamURLFromTeam(team)
}
bodyPage.Props = props
diff --git a/api/templates/error.html b/api/templates/error.html
index f38bb81a1..3474c9e1e 100644
--- a/api/templates/error.html
+++ b/api/templates/error.html
@@ -14,6 +14,7 @@
<div class="error__icon"><i class="fa fa-exclamation-triangle"></i></div>
<h2>{{ .SiteName }} needs your help:</h2>
<p>{{.Message}}</p>
+ <a href="{{.SiteURL}}">Go back to team site</a>
</div>
</div>
</body>
diff --git a/api/templates/find_teams_body.html b/api/templates/find_teams_body.html
index bd151a819..64bff8126 100644
--- a/api/templates/find_teams_body.html
+++ b/api/templates/find_teams_body.html
@@ -21,7 +21,7 @@
<p>{{ if .Props }}
The following teams were found:<br>
{{range $index, $element := .Props}}
- {{ $index }}<br>
+ <a href="{{ $element }}" style="text-decoration: none; color:#2389D7;">{{ $index }}</a><br>
{{ end }}
{{ else }}
We could not find any teams for the given email.
diff --git a/api/web_conn.go b/api/web_conn.go
index 0990de8ef..4315f5650 100644
--- a/api/web_conn.go
+++ b/api/web_conn.go
@@ -121,6 +121,11 @@ func (c *WebConn) writePump() {
}
}
+func (c *WebConn) updateChannelAccessCache(channelId string) {
+ allowed := hasPermissionsToChannel(Srv.Store.Channel().CheckPermissionsTo(c.TeamId, channelId, c.UserId))
+ c.ChannelAccessCache[channelId] = allowed
+}
+
func hasPermissionsToChannel(sc store.StoreChannel) bool {
if cresult := <-sc; cresult.Err != nil {
return false
diff --git a/api/web_hub.go b/api/web_hub.go
index c7be19cac..44d405283 100644
--- a/api/web_hub.go
+++ b/api/web_hub.go
@@ -30,6 +30,14 @@ func PublishAndForget(message *model.Message) {
}()
}
+func UpdateChannelAccessCacheAndForget(teamId, userId, channelId string) {
+ go func() {
+ if nh, ok := hub.teamHubs[teamId]; ok {
+ nh.UpdateChannelAccessCache(userId, channelId)
+ }
+ }()
+}
+
func (h *Hub) Register(webConn *WebConn) {
h.register <- webConn
}
diff --git a/api/web_team_hub.go b/api/web_team_hub.go
index 7a63b84d1..31c8dfedf 100644
--- a/api/web_team_hub.go
+++ b/api/web_team_hub.go
@@ -77,3 +77,12 @@ func (h *TeamHub) Start() {
}
}()
}
+
+func (h *TeamHub) UpdateChannelAccessCache(userId string, channelId string) {
+ for webCon := range h.connections {
+ if webCon.UserId == userId {
+ webCon.updateChannelAccessCache(channelId)
+ break
+ }
+ }
+}