MM-15021: Adding new builtin system schema for Guests (#10601)

* MM-15021: Adding new builtin system schema for Guests

* Fixing tests

* Setting properly the permissions

* Adding guests to sampledata

* Restrict more roles updates in the app layer for guests

* Adding comment to explain that permissions migration must go at the end

* Setting the default guest role for custom scheme during migration

* Fixing import and export

* Creating scheme guest roles on migration

* Fixing tests

* Fixing tests

* Fixing tests
Этот коммит содержится в:
Jesús Espino
2019-04-30 20:36:21 +02:00
коммит произвёл GitHub
родитель 987360f325
Коммит 584ec68755
44 изменённых файлов: 1867 добавлений и 110 удалений

Просмотреть файл

@@ -41,8 +41,10 @@ func TestCreateScheme(t *testing.T) {
assert.Equal(t, s1.Scope, scheme1.Scope)
assert.NotZero(t, len(s1.DefaultTeamAdminRole))
assert.NotZero(t, len(s1.DefaultTeamUserRole))
assert.NotZero(t, len(s1.DefaultTeamGuestRole))
assert.NotZero(t, len(s1.DefaultChannelAdminRole))
assert.NotZero(t, len(s1.DefaultChannelUserRole))
assert.NotZero(t, len(s1.DefaultChannelGuestRole))
// Check the default roles have been created.
_, roleRes1 := th.SystemAdminClient.GetRoleByName(s1.DefaultTeamAdminRole)
@@ -53,6 +55,10 @@ func TestCreateScheme(t *testing.T) {
CheckNoError(t, roleRes3)
_, roleRes4 := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
CheckNoError(t, roleRes4)
_, roleRes5 := th.SystemAdminClient.GetRoleByName(s1.DefaultTeamGuestRole)
CheckNoError(t, roleRes5)
_, roleRes6 := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
CheckNoError(t, roleRes6)
// Basic Test of a Channel scheme.
scheme2 := &model.Scheme{
@@ -74,14 +80,18 @@ func TestCreateScheme(t *testing.T) {
assert.Equal(t, s2.Scope, scheme2.Scope)
assert.Zero(t, len(s2.DefaultTeamAdminRole))
assert.Zero(t, len(s2.DefaultTeamUserRole))
assert.Zero(t, len(s2.DefaultTeamGuestRole))
assert.NotZero(t, len(s2.DefaultChannelAdminRole))
assert.NotZero(t, len(s2.DefaultChannelUserRole))
assert.NotZero(t, len(s2.DefaultChannelGuestRole))
// Check the default roles have been created.
_, roleRes5 := th.SystemAdminClient.GetRoleByName(s2.DefaultChannelAdminRole)
CheckNoError(t, roleRes5)
_, roleRes6 := th.SystemAdminClient.GetRoleByName(s2.DefaultChannelUserRole)
CheckNoError(t, roleRes6)
_, roleRes7 := th.SystemAdminClient.GetRoleByName(s2.DefaultChannelAdminRole)
CheckNoError(t, roleRes7)
_, roleRes8 := th.SystemAdminClient.GetRoleByName(s2.DefaultChannelUserRole)
CheckNoError(t, roleRes8)
_, roleRes9 := th.SystemAdminClient.GetRoleByName(s2.DefaultChannelGuestRole)
CheckNoError(t, roleRes9)
// Try and create a scheme with an invalid scope.
scheme3 := &model.Scheme{
@@ -178,8 +188,10 @@ func TestGetScheme(t *testing.T) {
assert.Equal(t, s1.Scope, scheme1.Scope)
assert.NotZero(t, len(s1.DefaultTeamAdminRole))
assert.NotZero(t, len(s1.DefaultTeamUserRole))
assert.NotZero(t, len(s1.DefaultTeamGuestRole))
assert.NotZero(t, len(s1.DefaultChannelAdminRole))
assert.NotZero(t, len(s1.DefaultChannelUserRole))
assert.NotZero(t, len(s1.DefaultChannelGuestRole))
s2, r2 := th.SystemAdminClient.GetScheme(s1.Id)
CheckNoError(t, r2)
@@ -490,8 +502,10 @@ func TestPatchScheme(t *testing.T) {
assert.Equal(t, s1.Scope, scheme1.Scope)
assert.NotZero(t, len(s1.DefaultTeamAdminRole))
assert.NotZero(t, len(s1.DefaultTeamUserRole))
assert.NotZero(t, len(s1.DefaultTeamGuestRole))
assert.NotZero(t, len(s1.DefaultChannelAdminRole))
assert.NotZero(t, len(s1.DefaultChannelUserRole))
assert.NotZero(t, len(s1.DefaultChannelGuestRole))
s2, r2 := th.SystemAdminClient.GetScheme(s1.Id)
CheckNoError(t, r2)
@@ -596,11 +610,17 @@ func TestDeleteScheme(t *testing.T) {
CheckNoError(t, roleRes3)
role4, roleRes4 := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
CheckNoError(t, roleRes4)
role5, roleRes5 := th.SystemAdminClient.GetRoleByName(s1.DefaultTeamGuestRole)
CheckNoError(t, roleRes5)
role6, roleRes6 := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
CheckNoError(t, roleRes6)
assert.Zero(t, role1.DeleteAt)
assert.Zero(t, role2.DeleteAt)
assert.Zero(t, role3.DeleteAt)
assert.Zero(t, role4.DeleteAt)
assert.Zero(t, role5.DeleteAt)
assert.Zero(t, role6.DeleteAt)
// Make sure this scheme is in use by a team.
team, err := th.App.Srv.Store.Team().Save(&model.Team{
@@ -625,11 +645,17 @@ func TestDeleteScheme(t *testing.T) {
CheckNoError(t, roleRes3)
role4, roleRes4 = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
CheckNoError(t, roleRes4)
role5, roleRes5 = th.SystemAdminClient.GetRoleByName(s1.DefaultTeamGuestRole)
CheckNoError(t, roleRes5)
role6, roleRes6 = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
CheckNoError(t, roleRes6)
assert.NotZero(t, role1.DeleteAt)
assert.NotZero(t, role2.DeleteAt)
assert.NotZero(t, role3.DeleteAt)
assert.NotZero(t, role4.DeleteAt)
assert.NotZero(t, role5.DeleteAt)
assert.NotZero(t, role6.DeleteAt)
// Check the team now uses the default scheme
c2, resp := th.SystemAdminClient.GetTeam(team.Id, "")
@@ -658,9 +684,12 @@ func TestDeleteScheme(t *testing.T) {
CheckNoError(t, roleRes3)
role4, roleRes4 := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
CheckNoError(t, roleRes4)
role6, roleRes6 := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
CheckNoError(t, roleRes6)
assert.Zero(t, role3.DeleteAt)
assert.Zero(t, role4.DeleteAt)
assert.Zero(t, role6.DeleteAt)
// Make sure this scheme is in use by a team.
res := <-th.App.Srv.Store.Channel().Save(&model.Channel{
@@ -682,9 +711,12 @@ func TestDeleteScheme(t *testing.T) {
CheckNoError(t, roleRes3)
role4, roleRes4 = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
CheckNoError(t, roleRes4)
role6, roleRes6 = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
CheckNoError(t, roleRes6)
assert.NotZero(t, role3.DeleteAt)
assert.NotZero(t, role4.DeleteAt)
assert.NotZero(t, role6.DeleteAt)
// Check the channel now uses the default scheme
c2, resp := th.SystemAdminClient.GetChannelByName(channel.Name, channel.TeamId, "")