Cleanup model/utils.go (#17945)
* Cleanup model/utils.go - Removed some functions which were unsued. (The unused linter was somehow failing to catch this). - Moved some functions inside other packages. - Removed two duplicate instances of the same function - RemoveDuplicateStrings and UniqueStrings. - Moved some regexes to global vars to prevent compilation every time. ```release-note NONE ``` * fix lint ```release-note NONE ``` * bring back unused exception ```release-note NONE ``` * fix tests ```release-note NONE ``` * Address review comments ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
77f9620997
Коммит
7454680be5
@@ -847,21 +847,22 @@ func TestPatchPost(t *testing.T) {
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
|
||||
fileIds := make([]string, 3)
|
||||
fileIDs := make([]string, 3)
|
||||
data, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < len(fileIds); i++ {
|
||||
for i := 0; i < len(fileIDs); i++ {
|
||||
fileResp, resp := Client.UploadFile(data, channel.Id, "test.png")
|
||||
CheckNoError(t, resp)
|
||||
fileIds[i] = fileResp.FileInfos[0].Id
|
||||
fileIDs[i] = fileResp.FileInfos[0].Id
|
||||
}
|
||||
sort.Strings(fileIDs)
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: channel.Id,
|
||||
IsPinned: true,
|
||||
Message: "#hashtag a message",
|
||||
Props: model.StringInterface{"channel_header": "old_header"},
|
||||
FileIds: fileIds[0:2],
|
||||
FileIds: fileIDs[0:2],
|
||||
HasReactions: true,
|
||||
}
|
||||
post, _ = Client.CreatePost(post)
|
||||
@@ -873,7 +874,7 @@ func TestPatchPost(t *testing.T) {
|
||||
patch.IsPinned = model.NewBool(false)
|
||||
patch.Message = model.NewString("#otherhashtag other message")
|
||||
patch.Props = &model.StringInterface{"channel_header": "new_header"}
|
||||
patchFileIds := model.StringArray(fileIds) // one extra file
|
||||
patchFileIds := model.StringArray(fileIDs) // one extra file
|
||||
patch.FileIds = &patchFileIds
|
||||
patch.HasReactions = model.NewBool(false)
|
||||
|
||||
@@ -885,7 +886,7 @@ func TestPatchPost(t *testing.T) {
|
||||
assert.Equal(t, "#otherhashtag other message", rpost.Message, "Message did not update properly")
|
||||
assert.Equal(t, *patch.Props, rpost.GetProps(), "Props did not update properly")
|
||||
assert.Equal(t, "#otherhashtag", rpost.Hashtags, "Message did not update properly")
|
||||
assert.Equal(t, model.StringArray(fileIds[0:2]), rpost.FileIds, "FileIds should not update")
|
||||
assert.Equal(t, model.StringArray(fileIDs[0:2]), rpost.FileIds, "FileIds should not update")
|
||||
assert.False(t, rpost.HasReactions, "HasReactions did not update properly")
|
||||
})
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
*patch.Permissions = model.UniqueStrings(*patch.Permissions)
|
||||
*patch.Permissions = model.RemoveDuplicateStrings(*patch.Permissions)
|
||||
}
|
||||
|
||||
if c.App.Srv().License() != nil && isGuest && !*c.App.Srv().License().Features.GuestAccountsPermissions {
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -223,7 +224,9 @@ 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)
|
||||
assert.EqualValues(t, received.Permissions, []string{"manage_system", "create_public_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"})
|
||||
perms := []string{"manage_system", "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)
|
||||
|
||||
// Check a no-op patch succeeds.
|
||||
@@ -252,7 +255,9 @@ 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)
|
||||
assert.EqualValues(t, received.Permissions, []string{"manage_system", "manage_incoming_webhooks", "manage_outgoing_webhooks"})
|
||||
perms := []string{"manage_system", "manage_incoming_webhooks", "manage_outgoing_webhooks"}
|
||||
sort.Strings(perms)
|
||||
assert.EqualValues(t, received.Permissions, perms)
|
||||
assert.Equal(t, received.SchemeManaged, role.SchemeManaged)
|
||||
|
||||
t.Run("Check guest permissions editing without E20 license", func(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user