Fixing permissions checks where related to join public channels (#10511)
* Fixing permissions checks where related to join public channels * Addressing PR review comments * Fixing bug * Adding new tests * Addressing PR review comments
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9b73d34eaa
Коммит
9fa6b093f3
@@ -2023,6 +2023,82 @@ func TestAddChannelMember(t *testing.T) {
|
||||
Client.Logout()
|
||||
}
|
||||
|
||||
func TestAddChannelMemberAddMyself(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
user := th.CreateUser()
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
notMemberPublicChannel1 := th.CreatePublicChannel()
|
||||
notMemberPublicChannel2 := th.CreatePublicChannel()
|
||||
notMemberPrivateChannel := th.CreatePrivateChannel()
|
||||
|
||||
memberPublicChannel := th.CreatePublicChannel()
|
||||
memberPrivateChannel := th.CreatePrivateChannel()
|
||||
th.AddUserToChannel(user, memberPublicChannel)
|
||||
th.AddUserToChannel(user, memberPrivateChannel)
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Channel *model.Channel
|
||||
WithJoinPublicPermission bool
|
||||
ExpectedError string
|
||||
}{
|
||||
{
|
||||
"Add myself to a public channel with JOIN_PUBLIC_CHANNEL permission",
|
||||
notMemberPublicChannel1,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"Try to add myself to a private channel with the JOIN_PUBLIC_CHANNEL permission",
|
||||
notMemberPrivateChannel,
|
||||
true,
|
||||
"api.context.permissions.app_error",
|
||||
},
|
||||
{
|
||||
"Try to add myself to a public channel without the JOIN_PUBLIC_CHANNEL permission",
|
||||
notMemberPublicChannel2,
|
||||
false,
|
||||
"api.context.permissions.app_error",
|
||||
},
|
||||
{
|
||||
"Add myself a public channel where I'm already a member, not having JOIN_PUBLIC_CHANNEL or MANAGE MEMBERS permission",
|
||||
memberPublicChannel,
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"Add myself a private channel where I'm already a member, not having JOIN_PUBLIC_CHANNEL or MANAGE MEMBERS permission",
|
||||
memberPrivateChannel,
|
||||
false,
|
||||
"",
|
||||
},
|
||||
}
|
||||
Client.Login(user.Email, user.Password)
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
|
||||
// Check the appropriate permissions are enforced.
|
||||
defaultRolePermissions := th.SaveDefaultRolePermissions()
|
||||
defer func() {
|
||||
th.RestoreDefaultRolePermissions(defaultRolePermissions)
|
||||
}()
|
||||
|
||||
if !tc.WithJoinPublicPermission {
|
||||
th.RemovePermissionFromRole(model.PERMISSION_JOIN_PUBLIC_CHANNELS.Id, model.TEAM_USER_ROLE_ID)
|
||||
}
|
||||
|
||||
_, resp := Client.AddChannelMember(tc.Channel.Id, user.Id)
|
||||
if tc.ExpectedError == "" {
|
||||
CheckNoError(t, resp)
|
||||
} else {
|
||||
CheckErrorMessage(t, resp, tc.ExpectedError)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveChannelMember(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
user1 := th.BasicUser
|
||||
|
||||
Ссылка в новой задаче
Block a user