Prompt Team Admin before joining private channel (#29955)
* Prompt Team Admin before joining private channel * fix and implement prompt when team admin joins via channel link * update premission check and unit tests * remove comment * clean up some code * update check to fix E2E tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f2af360401
Коммит
369b9fa96b
@@ -1406,7 +1406,9 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
|
||||
// allows team admins to access private channel
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionManageTeam) &&
|
||||
!c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
|
||||
c.Err = model.NewAppError("getChannelByName", "app.channel.get_by_name.missing.app_error", nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
@@ -1436,17 +1438,19 @@ func getChannelByNameForTeamName(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
teamOk := c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionReadPublicChannel)
|
||||
channelOk := c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channel.Id, model.PermissionReadChannel)
|
||||
|
||||
if channel.Type == model.ChannelTypeOpen {
|
||||
teamOk := c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionReadPublicChannel)
|
||||
if !teamOk && !channelOk {
|
||||
c.SetPermissionError(model.PermissionReadPublicChannel)
|
||||
return
|
||||
}
|
||||
} else if !channelOk {
|
||||
c.Err = model.NewAppError("getChannelByNameForTeamName", "app.channel.get_by_name.missing.app_error", nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound)
|
||||
return
|
||||
// allows team admins to access private channel
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionManageTeam) {
|
||||
c.Err = model.NewAppError("getChannelByNameForTeamName", "app.channel.get_by_name.missing.app_error", nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
appErr = c.App.FillInChannelProps(c.AppContext, channel)
|
||||
|
||||
@@ -2487,6 +2487,13 @@ func TestGetChannelByName(t *testing.T) {
|
||||
_, _, err = client.GetChannelByName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
th.SystemAdminClient.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.TeamAdminUser.Id)
|
||||
TeamAdminClient := th.CreateClient()
|
||||
th.LoginTeamAdminWithClient(TeamAdminClient)
|
||||
channel, _, err = TeamAdminClient.GetChannelByName(context.Background(), th.BasicPrivateChannel.Name, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, th.BasicPrivateChannel.Name, channel.Name, "names did not match")
|
||||
}
|
||||
|
||||
func TestGetChannelByNameForTeamName(t *testing.T) {
|
||||
@@ -2498,7 +2505,14 @@ func TestGetChannelByNameForTeamName(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, th.BasicChannel.Name, channel.Name, "names did not match")
|
||||
|
||||
_, _, err = client.GetChannelByNameForTeamName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Name, "")
|
||||
th.SystemAdminClient.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.TeamAdminUser.Id)
|
||||
TeamAdminClient := th.CreateClient()
|
||||
th.LoginTeamAdminWithClient(TeamAdminClient)
|
||||
channel, _, err = TeamAdminClient.GetChannelByNameForTeamName(context.Background(), th.BasicPrivateChannel.Name, th.BasicTeam.Name, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, th.BasicPrivateChannel.Name, channel.Name, "names did not match")
|
||||
|
||||
channel, _, err = client.GetChannelByNameForTeamName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Name, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, th.BasicChannel.Name, channel.Name, "names did not match")
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user