Skip to content

Commit

Permalink
MM-58771 - Make manage_server permission, non updatable (mattermost#2…
Browse files Browse the repository at this point in the history
…7481)

* make manage_server, non updatable

* remove blank line
  • Loading branch information
sbishel authored Jul 3, 2024
1 parent 35dda81 commit 0dbef88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions server/channels/api4/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var notAllowedPermissions = []string{
model.PermissionSysconsoleWriteUserManagementSystemRoles.Id,
model.PermissionSysconsoleReadUserManagementSystemRoles.Id,
model.PermissionManageRoles.Id,
model.PermissionManageSystem.Id,
}

func (api *API) InitRole() {
Expand Down
28 changes: 18 additions & 10 deletions server/channels/api4/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGetRole(t *testing.T) {
Name: model.NewId(),
DisplayName: model.NewId(),
Description: model.NewId(),
Permissions: []string{"manage_system", "create_public_channel"},
Permissions: []string{"create_direct_channel", "create_public_channel"},
SchemeManaged: true,
}

Expand Down Expand Up @@ -85,7 +85,7 @@ func TestGetRoleByName(t *testing.T) {
Name: model.NewId(),
DisplayName: model.NewId(),
Description: model.NewId(),
Permissions: []string{"manage_system", "create_public_channel"},
Permissions: []string{"create_direct_channel", "create_public_channel"},
SchemeManaged: true,
}

Expand Down Expand Up @@ -124,21 +124,21 @@ func TestGetRolesByNames(t *testing.T) {
Name: model.NewId(),
DisplayName: model.NewId(),
Description: model.NewId(),
Permissions: []string{"manage_system", "create_public_channel"},
Permissions: []string{"create_direct_channel", "create_public_channel"},
SchemeManaged: true,
}
role2 := &model.Role{
Name: model.NewId(),
DisplayName: model.NewId(),
Description: model.NewId(),
Permissions: []string{"manage_system", "delete_private_channel"},
Permissions: []string{"create_direct_channel", "delete_private_channel"},
SchemeManaged: true,
}
role3 := &model.Role{
Name: model.NewId(),
DisplayName: model.NewId(),
Description: model.NewId(),
Permissions: []string{"manage_system", "manage_public_channel_properties"},
Permissions: []string{"create_direct_channel", "manage_public_channel_properties"},
SchemeManaged: true,
}

Expand Down Expand Up @@ -207,7 +207,7 @@ func TestPatchRole(t *testing.T) {
Name: model.NewId(),
DisplayName: model.NewId(),
Description: model.NewId(),
Permissions: []string{"manage_system", "create_public_channel", "manage_slash_commands"},
Permissions: []string{"create_direct_channel", "create_public_channel", "manage_slash_commands"},
SchemeManaged: true,
}

Expand All @@ -216,7 +216,7 @@ func TestPatchRole(t *testing.T) {
defer th.App.Srv().Store().Job().Delete(role.Id)

patch := &model.RolePatch{
Permissions: &[]string{"manage_system", "create_public_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"},
Permissions: &[]string{"create_direct_channel", "create_public_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"},
}

th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
Expand Down Expand Up @@ -257,6 +257,14 @@ func TestPatchRole(t *testing.T) {
_, resp, err = client.PatchRole(context.Background(), systemManager.Id, patchManageRoles)
require.Error(t, err)
CheckNotImplementedStatus(t, resp)

patchManageSystem := &model.RolePatch{
Permissions: &[]string{model.PermissionManageSystem.Id},
}

_, resp, err = client.PatchRole(context.Background(), systemManager.Id, patchManageSystem)
require.Error(t, err)
CheckNotImplementedStatus(t, resp)
})

th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
Expand All @@ -267,7 +275,7 @@ func TestPatchRole(t *testing.T) {
assert.Equal(t, received.Name, role.Name)
assert.Equal(t, received.DisplayName, role.DisplayName)
assert.Equal(t, received.Description, role.Description)
perms := []string{"manage_system", "create_public_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"}
perms := []string{"create_direct_channel", "create_public_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"}
sort.Strings(perms)
assert.EqualValues(t, received.Permissions, perms)
assert.Equal(t, received.SchemeManaged, role.SchemeManaged)
Expand All @@ -290,7 +298,7 @@ func TestPatchRole(t *testing.T) {
CheckForbiddenStatus(t, resp)

patch = &model.RolePatch{
Permissions: &[]string{"manage_system", "manage_incoming_webhooks", "manage_outgoing_webhooks"},
Permissions: &[]string{"create_direct_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"},
}

th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
Expand All @@ -301,7 +309,7 @@ func TestPatchRole(t *testing.T) {
assert.Equal(t, received.Name, role.Name)
assert.Equal(t, received.DisplayName, role.DisplayName)
assert.Equal(t, received.Description, role.Description)
perms := []string{"manage_system", "manage_incoming_webhooks", "manage_outgoing_webhooks"}
perms := []string{"create_direct_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"}
sort.Strings(perms)
assert.EqualValues(t, received.Permissions, perms)
assert.Equal(t, received.SchemeManaged, role.SchemeManaged)
Expand Down

0 comments on commit 0dbef88

Please sign in to comment.