diff --git a/src/utils/post_utils.js b/src/utils/post_utils.js index 46d438c40..52b8f5d5a 100644 --- a/src/utils/post_utils.js +++ b/src/utils/post_utils.js @@ -76,30 +76,27 @@ export function canEditPost(state, config, license, teamId, channelId, userId, p let canEdit = true; - if (canEdit && license.IsLicensed === 'true') { - if (hasNewPermissions(state)) { - canEdit = canEdit && haveIChannelPermission(state, {team: teamId, channel: channelId, permission: Permissions.EDIT_POST}); - if (!isOwner) { - canEdit = canEdit && haveIChannelPermission(state, {team: teamId, channel: channelId, permission: Permissions.EDIT_OTHERS_POSTS}); - } - if (config.PostEditTimeLimit !== '-1' && config.PostEditTimeLimit !== -1) { - const timeLeft = (post.create_at + (config.PostEditTimeLimit * 1000)) - Date.now(); - if (timeLeft <= 0) { - canEdit = false; - } - } - } else { - canEdit = isOwner && config.AllowEditPost !== 'never'; - if (config.AllowEditPost === General.ALLOW_EDIT_POST_TIME_LIMIT) { - const timeLeft = (post.create_at + (config.PostEditTimeLimit * 1000)) - Date.now(); - if (timeLeft <= 0) { - canEdit = false; - } + if (hasNewPermissions(state)) { + canEdit = canEdit && haveIChannelPermission(state, {team: teamId, channel: channelId, permission: Permissions.EDIT_POST}); + if (!isOwner) { + canEdit = canEdit && haveIChannelPermission(state, {team: teamId, channel: channelId, permission: Permissions.EDIT_OTHERS_POSTS}); + } + if (license.IsLicensed === 'true' && config.PostEditTimeLimit !== '-1' && config.PostEditTimeLimit !== -1) { + const timeLeft = (post.create_at + (config.PostEditTimeLimit * 1000)) - Date.now(); + if (timeLeft <= 0) { + canEdit = false; } } } else { - canEdit = canEdit && isOwner; + canEdit = isOwner && config.AllowEditPost !== 'never'; + if (config.AllowEditPost === General.ALLOW_EDIT_POST_TIME_LIMIT) { + const timeLeft = (post.create_at + (config.PostEditTimeLimit * 1000)) - Date.now(); + if (timeLeft <= 0) { + canEdit = false; + } + } } + return canEdit; } diff --git a/test/utils/post_utils.test.js b/test/utils/post_utils.test.js index f2f1c8f73..24f768c6c 100644 --- a/test/utils/post_utils.test.js +++ b/test/utils/post_utils.test.js @@ -262,13 +262,15 @@ describe('PostUtils', () => { const channelId = 'channel-id'; const userId = 'user-id'; + const state = {entities: {general: {serverVersion: ''}}}; + it('should allow to edit my post without license', () => { // Hasn't license - assert.ok(canEditPost({}, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, {user_id: userId, type: 'normal'})); - assert.ok(!canEditPost({}, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, {user_id: userId, type: 'system_test'})); - assert.ok(!canEditPost({}, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, {user_id: 'other', type: 'normal'})); - assert.ok(!canEditPost({}, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, {user_id: 'other', type: 'system_test'})); - assert.ok(!canEditPost({}, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, null)); + assert.ok(canEditPost(state, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, {user_id: userId, type: 'normal'})); + assert.ok(!canEditPost(state, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, {user_id: userId, type: 'system_test'})); + assert.ok(!canEditPost(state, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, {user_id: 'other', type: 'normal'})); + assert.ok(!canEditPost(state, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, {user_id: 'other', type: 'system_test'})); + assert.ok(!canEditPost(state, {PostEditTimeLimit: -1}, notLicensed, teamId, channelId, userId, null)); }); it('should work with old permissions version', () => {