[MM-44842] Add restore_group permission (#21806)

* Add restore_group permission

* Fix tests failing due to new permission in groups

* Add new migration to add custom_group_restore permission

* Add mock for new migration function

* Fix tests

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Shivashis Padhi
2022-12-19 22:31:59 +05:30
коммит произвёл GitHub
родитель 5f6fc3150d
Коммит 79193240e9
8 изменённых файлов: 48 добавлений и 2 удалений

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

@@ -1185,8 +1185,8 @@ func restoreGroup(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToGroup(*c.AppContext.Session(), c.Params.GroupId, model.PermissionDeleteCustomGroup) {
c.SetPermissionError(model.PermissionDeleteCustomGroup)
if !c.App.SessionHasPermissionToGroup(*c.AppContext.Session(), c.Params.GroupId, model.PermissionRestoreCustomGroup) {
c.SetPermissionError(model.PermissionRestoreCustomGroup)
return
}

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

@@ -231,7 +231,13 @@ func TestUndeleteGroup(t *testing.T) {
_, response, err := th.Client.DeleteGroup(validGroup.Id)
require.NoError(t, err)
CheckOKStatus(t, response)
th.RemovePermissionFromRole(model.PermissionRestoreCustomGroup.Id, model.SystemUserRoleId)
// shouldn't allow restoring unless user has required permission
_, response, err = th.Client.RestoreGroup(validGroup.Id, "")
require.Error(t, err)
CheckForbiddenStatus(t, response)
th.AddPermissionToRole(model.PermissionRestoreCustomGroup.Id, model.SystemUserRoleId)
_, response, err = th.Client.RestoreGroup(validGroup.Id, "")
require.NoError(t, err)
CheckOKStatus(t, response)