MM-24595 Migrate API handler getChannelMember(s) to be compatible with local mode (#14533)
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: Miguel de la Cruz <miguel@mcrx.me> Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
cedcb63e83
Коммит
b9309b2af1
@@ -275,6 +275,9 @@ func InitLocal(configservice configservice.ConfigService, globalOptionsFunc app.
|
||||
api.BaseRoutes.TeamMember = api.BaseRoutes.TeamMembers.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter()
|
||||
|
||||
api.BaseRoutes.Channels = api.BaseRoutes.ApiRoot.PathPrefix("/channels").Subrouter()
|
||||
api.BaseRoutes.Channel = api.BaseRoutes.Channels.PathPrefix("/{channel_id:[A-Za-z0-9]+}").Subrouter()
|
||||
api.BaseRoutes.ChannelMembers = api.BaseRoutes.Channel.PathPrefix("/members").Subrouter()
|
||||
api.BaseRoutes.ChannelMember = api.BaseRoutes.ChannelMembers.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter()
|
||||
|
||||
api.BaseRoutes.Plugins = api.BaseRoutes.ApiRoot.PathPrefix("/plugins").Subrouter()
|
||||
api.BaseRoutes.Plugin = api.BaseRoutes.Plugins.PathPrefix("/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}").Subrouter()
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
func (api *API) InitChannelLocal() {
|
||||
api.BaseRoutes.Channels.Handle("", api.ApiLocal(getAllChannels)).Methods("GET")
|
||||
api.BaseRoutes.Channels.Handle("", api.ApiLocal(localCreateChannel)).Methods("POST")
|
||||
api.BaseRoutes.ChannelMember.Handle("", api.ApiLocal(getChannelMember)).Methods("GET")
|
||||
api.BaseRoutes.ChannelMembers.Handle("", api.ApiLocal(getChannelMembers)).Methods("GET")
|
||||
}
|
||||
|
||||
func localCreateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -1634,44 +1634,49 @@ func TestGetChannelByNameForTeamName(t *testing.T) {
|
||||
func TestGetChannelMembers(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
|
||||
members, resp := Client.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, *members, 3, "should only be 3 users in channel")
|
||||
members, resp := client.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, *members, 3, "should only be 3 users in channel")
|
||||
|
||||
members, resp = Client.GetChannelMembers(th.BasicChannel.Id, 0, 2, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, *members, 2, "should only be 2 users")
|
||||
members, resp = client.GetChannelMembers(th.BasicChannel.Id, 0, 2, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, *members, 2, "should only be 2 users")
|
||||
|
||||
members, resp = Client.GetChannelMembers(th.BasicChannel.Id, 1, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, *members, 1, "should only be 1 user")
|
||||
members, resp = client.GetChannelMembers(th.BasicChannel.Id, 1, 1, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, *members, 1, "should only be 1 user")
|
||||
|
||||
members, resp = Client.GetChannelMembers(th.BasicChannel.Id, 1000, 100000, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Empty(t, *members, "should be 0 users")
|
||||
members, resp = client.GetChannelMembers(th.BasicChannel.Id, 1000, 100000, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Empty(t, *members, "should be 0 users")
|
||||
|
||||
_, resp = Client.GetChannelMembers("", 0, 60, "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
_, resp = client.GetChannelMembers("junk", 0, 60, "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = Client.GetChannelMembers("junk", 0, 60, "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
_, resp = client.GetChannelMembers("", 0, 60, "")
|
||||
// NOTE: for some reason, while using the LocalClient, the route /channels//members is not handled
|
||||
if client == th.LocalClient {
|
||||
CheckNotFoundStatus(t, resp)
|
||||
} else {
|
||||
CheckBadRequestStatus(t, resp)
|
||||
}
|
||||
_, resp = client.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
|
||||
_, resp = Client.GetChannelMembers(model.NewId(), 0, 60, "")
|
||||
_, resp := th.Client.GetChannelMembers(model.NewId(), 0, 60, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
|
||||
th.Client.Logout()
|
||||
_, resp = th.Client.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
user := th.CreateUser()
|
||||
Client.Login(user.Email, user.Password)
|
||||
_, resp = Client.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
|
||||
th.Client.Login(user.Email, user.Password)
|
||||
_, resp = th.Client.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
|
||||
CheckNoError(t, resp)
|
||||
}
|
||||
|
||||
func TestGetChannelMembersByIds(t *testing.T) {
|
||||
@@ -1715,42 +1720,42 @@ func TestGetChannelMembersByIds(t *testing.T) {
|
||||
func TestGetChannelMember(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
c := th.Client
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
member, resp := client.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Equal(t, th.BasicChannel.Id, member.ChannelId, "wrong channel id")
|
||||
require.Equal(t, th.BasicUser.Id, member.UserId, "wrong user id")
|
||||
|
||||
member, resp := Client.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
CheckNoError(t, resp)
|
||||
require.Equal(t, th.BasicChannel.Id, member.ChannelId, "wrong channel id")
|
||||
require.Equal(t, th.BasicUser.Id, member.UserId, "wrong user id")
|
||||
_, resp = client.GetChannelMember("", th.BasicUser.Id, "")
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp = Client.GetChannelMember("", th.BasicUser.Id, "")
|
||||
CheckNotFoundStatus(t, resp)
|
||||
_, resp = client.GetChannelMember("junk", th.BasicUser.Id, "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
_, resp = client.GetChannelMember(th.BasicChannel.Id, "", "")
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp = Client.GetChannelMember("junk", th.BasicUser.Id, "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
_, resp = client.GetChannelMember(th.BasicChannel.Id, "junk", "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = Client.GetChannelMember(model.NewId(), th.BasicUser.Id, "")
|
||||
_, resp = client.GetChannelMember(th.BasicChannel.Id, model.NewId(), "")
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp = client.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
CheckNoError(t, resp)
|
||||
})
|
||||
|
||||
_, resp := c.GetChannelMember(model.NewId(), th.BasicUser.Id, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = Client.GetChannelMember(th.BasicChannel.Id, "", "")
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp = Client.GetChannelMember(th.BasicChannel.Id, "junk", "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp = Client.GetChannelMember(th.BasicChannel.Id, model.NewId(), "")
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
c.Logout()
|
||||
_, resp = c.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
user := th.CreateUser()
|
||||
Client.Login(user.Email, user.Password)
|
||||
_, resp = Client.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
c.Login(user.Email, user.Password)
|
||||
_, resp = c.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp = th.SystemAdminClient.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id, "")
|
||||
CheckNoError(t, resp)
|
||||
}
|
||||
|
||||
func TestGetChannelMembersForUser(t *testing.T) {
|
||||
|
||||
@@ -44,7 +44,9 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
||||
if channelId == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if session.IsUnrestricted() {
|
||||
return true
|
||||
}
|
||||
ids, err := a.Srv().Store.Channel().GetAllChannelMembersForUser(session.UserId, true, true)
|
||||
|
||||
var channelRoles []string
|
||||
|
||||
Ссылка в новой задаче
Block a user