summaryrefslogtreecommitdiffstats
path: root/webapp/utils
diff options
context:
space:
mode:
authorAmit Yadav <iit.amit@gmail.com>2017-01-18 18:38:31 +0530
committerJoram Wilander <jwawilander@gmail.com>2017-01-18 08:08:31 -0500
commit99cf08ac38bdee25d07f27a3d9bb5d74199d106c (patch)
treee85ca087c2ec1b6bfe859d509b0f9e5c1a991630 /webapp/utils
parent8f0175e15c4d6bd08ca6795851455468811c3dc9 (diff)
downloadchat-99cf08ac38bdee25d07f27a3d9bb5d74199d106c.tar.gz
chat-99cf08ac38bdee25d07f27a3d9bb5d74199d106c.tar.bz2
chat-99cf08ac38bdee25d07f27a3d9bb5d74199d106c.zip
Message Editing and Deleting permissions (#4692)
Diffstat (limited to 'webapp/utils')
-rw-r--r--webapp/utils/constants.jsx7
-rw-r--r--webapp/utils/post_utils.jsx41
2 files changed, 48 insertions, 0 deletions
diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx
index c8ac74a82..6377f27f2 100644
--- a/webapp/utils/constants.jsx
+++ b/webapp/utils/constants.jsx
@@ -860,6 +860,13 @@ export const Constants = {
PERMISSIONS_ALL: 'all',
PERMISSIONS_TEAM_ADMIN: 'team_admin',
PERMISSIONS_SYSTEM_ADMIN: 'system_admin',
+ PERMISSIONS_DELETE_POST_ALL: 'all',
+ PERMISSIONS_DELETE_POST_TEAM_ADMIN: 'team_admin',
+ PERMISSIONS_DELETE_POST_SYSTEM_ADMIN: 'system_admin',
+ ALLOW_EDIT_POST_ALWAYS: 'always',
+ ALLOW_EDIT_POST_NEVER: 'never',
+ ALLOW_EDIT_POST_TIME_LIMIT: 'time_limit',
+ DEFAULT_POST_EDIT_TIME_LIMIT: 300,
MENTION_CHANNELS: 'mention.channels',
MENTION_MORE_CHANNELS: 'mention.morechannels',
MENTION_MEMBERS: 'mention.members',
diff --git a/webapp/utils/post_utils.jsx b/webapp/utils/post_utils.jsx
index 88021c2a5..20993b95c 100644
--- a/webapp/utils/post_utils.jsx
+++ b/webapp/utils/post_utils.jsx
@@ -3,11 +3,19 @@
import Client from 'client/web_client.jsx';
import Constants from 'utils/constants.jsx';
+import * as Utils from 'utils/utils.jsx';
+
+import TeamStore from 'stores/team_store.jsx';
+import UserStore from 'stores/user_store.jsx';
export function isSystemMessage(post) {
return post.type && (post.type.lastIndexOf(Constants.SYSTEM_MESSAGE_PREFIX) === 0);
}
+export function isPostOwner(post) {
+ return UserStore.getCurrentId() === post.user_id;
+}
+
export function isComment(post) {
if ('root_id' in post) {
return post.root_id !== '' && post.root_id != null;
@@ -33,3 +41,36 @@ export function getProfilePicSrcForPost(post, timestamp) {
return src;
}
+
+export function canDeletePost(post) {
+ var isOwner = isPostOwner(post);
+ var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
+ var isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
+
+ if (global.window.mm_license.IsLicensed === 'true') {
+ return (global.window.mm_config.RestrictPostDelete === Constants.PERMISSIONS_DELETE_POST_ALL && (isOwner || isAdmin)) ||
+ (global.window.mm_config.RestrictPostDelete === Constants.PERMISSIONS_DELETE_POST_TEAM_ADMIN && isAdmin) ||
+ (global.window.mm_config.RestrictPostDelete === Constants.PERMISSIONS_DELETE_POST_SYSTEM_ADMIN && isSystemAdmin);
+ }
+ return isOwner || isAdmin;
+}
+
+export function canEditPost(post, editDisableAction) {
+ var isOwner = isPostOwner(post);
+
+ var canEdit = isOwner && !isSystemMessage(post);
+
+ if (canEdit && global.window.mm_license.IsLicensed === 'true') {
+ if (global.window.mm_config.AllowEditPost === Constants.ALLOW_EDIT_POST_NEVER) {
+ canEdit = false;
+ } else if (global.window.mm_config.AllowEditPost === Constants.ALLOW_EDIT_POST_TIME_LIMIT) {
+ var timeLeft = (post.create_at + (global.window.mm_config.PostEditTimeLimit * 1000)) - Utils.getTimestamp();
+ if (timeLeft > 0) {
+ editDisableAction.fireAfter(timeLeft + 1000);
+ } else {
+ canEdit = false;
+ }
+ }
+ }
+ return canEdit;
+} \ No newline at end of file