summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-10-13 12:35:57 +0200
committerGitHub <noreply@github.com>2018-10-13 12:35:57 +0200
commit908ed5555f8a3d37cd057035b2792d66c8b7838a (patch)
tree7ad4248a72a7c3b6e6c3981840c5951c6108fe1d /api4
parente87965f39d2ce6dbd0e7883c387956413c663f6a (diff)
downloadchat-908ed5555f8a3d37cd057035b2792d66c8b7838a.tar.gz
chat-908ed5555f8a3d37cd057035b2792d66c8b7838a.tar.bz2
chat-908ed5555f8a3d37cd057035b2792d66c8b7838a.zip
[APIv4] add getChannelMembersTimezone (#9286)
* add getChannelMembersTimezone * update per feedback review * add delimeter to error
Diffstat (limited to 'api4')
-rw-r--r--api4/channel.go22
-rw-r--r--api4/channel_test.go49
2 files changed, 70 insertions, 1 deletions
diff --git a/api4/channel.go b/api4/channel.go
index 02a7c34b5..e3a5bf703 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -33,7 +33,7 @@ func (api *API) InitChannel() {
api.BaseRoutes.Channel.Handle("", api.ApiSessionRequired(deleteChannel)).Methods("DELETE")
api.BaseRoutes.Channel.Handle("/stats", api.ApiSessionRequired(getChannelStats)).Methods("GET")
api.BaseRoutes.Channel.Handle("/pinned", api.ApiSessionRequired(getPinnedPosts)).Methods("GET")
-
+ api.BaseRoutes.Channel.Handle("/timezones", api.ApiSessionRequired(getChannelMembersTimezones)).Methods("GET")
api.BaseRoutes.ChannelForUser.Handle("/unread", api.ApiSessionRequired(getChannelUnread)).Methods("GET")
api.BaseRoutes.ChannelByName.Handle("", api.ApiSessionRequired(getChannelByName)).Methods("GET")
@@ -821,6 +821,26 @@ func getChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(members.ToJson()))
}
+func getChannelMembersTimezones(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireChannelId()
+ if c.Err != nil {
+ return
+ }
+
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
+ return
+ }
+
+ membersTimezones, err := c.App.GetChannelMembersTimezones(c.Params.ChannelId)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ w.Write([]byte(model.ArrayToJson(membersTimezones)))
+}
+
func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireChannelId()
if c.Err != nil {
diff --git a/api4/channel_test.go b/api4/channel_test.go
index 918b37c0f..d588c0c25 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -2335,3 +2335,52 @@ func TestUpdateChannelScheme(t *testing.T) {
_, resp = th.SystemAdminClient.UpdateChannelScheme(channel.Id, channelScheme.Id)
CheckUnauthorizedStatus(t, resp)
}
+
+func TestGetChannelMembersTimezones(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer th.TearDown()
+ Client := th.Client
+
+ user := th.BasicUser
+ user.Timezone["useAutomaticTimezone"] = "false"
+ user.Timezone["manualTimezone"] = "XOXO/BLABLA"
+ _, resp := Client.UpdateUser(user)
+ CheckNoError(t, resp)
+
+ user2 := th.BasicUser2
+ user2.Timezone["automaticTimezone"] = "NoWhere/Island"
+ _, resp = th.SystemAdminClient.UpdateUser(user2)
+ CheckNoError(t, resp)
+
+ timezone, resp := Client.GetChannelMembersTimezones(th.BasicChannel.Id)
+ CheckNoError(t, resp)
+ if len(timezone) != 2 {
+ t.Fatal("should return 2 timezones")
+ }
+
+ //both users have same timezone
+ user2.Timezone["automaticTimezone"] = "XOXO/BLABLA"
+ _, resp = th.SystemAdminClient.UpdateUser(user2)
+ CheckNoError(t, resp)
+
+ timezone, resp = Client.GetChannelMembersTimezones(th.BasicChannel.Id)
+ CheckNoError(t, resp)
+ if len(timezone) != 1 {
+ t.Fatal("should return 1 timezone")
+ }
+
+ //no timezone set should return empty
+ user2.Timezone["automaticTimezone"] = ""
+ _, resp = th.SystemAdminClient.UpdateUser(user2)
+ CheckNoError(t, resp)
+
+ user.Timezone["manualTimezone"] = ""
+ _, resp = Client.UpdateUser(user)
+
+ timezone, resp = Client.GetChannelMembersTimezones(th.BasicChannel.Id)
+ CheckNoError(t, resp)
+ if len(timezone) > 0 {
+ t.Fatal("should return 0 timezone")
+ }
+
+}