summaryrefslogtreecommitdiffstats
path: root/api4/channel.go
diff options
context:
space:
mode:
Diffstat (limited to 'api4/channel.go')
-rw-r--r--api4/channel.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go
index 10e59f49b..09ed4b571 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -17,6 +17,10 @@ func InitChannel() {
BaseRoutes.Channels.Handle("", ApiSessionRequired(createChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/direct", ApiSessionRequired(createDirectChannel)).Methods("POST")
+
+ BaseRoutes.ChannelMembers.Handle("", ApiSessionRequired(getChannelMembers)).Methods("GET")
+ BaseRoutes.ChannelMembersForUser.Handle("", ApiSessionRequired(getChannelMembersForUser)).Methods("GET")
+ BaseRoutes.ChannelMember.Handle("", ApiSessionRequired(getChannelMember)).Methods("GET")
}
func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -83,3 +87,65 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(sc.ToJson()))
}
}
+
+func getChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireChannelId()
+ if c.Err != nil {
+ return
+ }
+
+ if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
+ return
+ }
+
+ if members, err := app.GetChannelMembersPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage); err != nil {
+ c.Err = err
+ return
+ } else {
+ w.Write([]byte(members.ToJson()))
+ }
+}
+
+func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireChannelId().RequireUserId()
+ if c.Err != nil {
+ return
+ }
+
+ if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
+ return
+ }
+
+ if member, err := app.GetChannelMember(c.Params.ChannelId, c.Params.UserId); err != nil {
+ c.Err = err
+ return
+ } else {
+ w.Write([]byte(member.ToJson()))
+ }
+}
+
+func getChannelMembersForUser(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireUserId().RequireTeamId()
+ if c.Err != nil {
+ return
+ }
+
+ if !app.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
+ c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
+ return
+ }
+
+ if c.Session.UserId != c.Params.UserId && !app.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_MANAGE_SYSTEM) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
+ return
+ }
+
+ if members, err := app.GetChannelMembersForUser(c.Params.TeamId, c.Params.UserId); err != nil {
+ c.Err = err
+ return
+ } else {
+ w.Write([]byte(members.ToJson()))
+ }
+}