fix: check the permissions properly to create a discussion and reply in dm (#5217)
* fix: check the permissions properly to create a discussion * add the permission start-discussion-other-user and fix the permission at messagebox --------- Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com>
This commit is contained in:
parent
231057af10
commit
199331f8f6
|
@ -44,6 +44,7 @@ export interface IMessageActionsProps {
|
||||||
deleteOwnMessagePermission?: string[];
|
deleteOwnMessagePermission?: string[];
|
||||||
pinMessagePermission?: string[];
|
pinMessagePermission?: string[];
|
||||||
createDirectMessagePermission?: string[];
|
createDirectMessagePermission?: string[];
|
||||||
|
createDiscussionOtherUserPermission?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMessageActions {
|
export interface IMessageActions {
|
||||||
|
@ -76,6 +77,7 @@ const MessageActions = React.memo(
|
||||||
deleteOwnMessagePermission,
|
deleteOwnMessagePermission,
|
||||||
pinMessagePermission,
|
pinMessagePermission,
|
||||||
createDirectMessagePermission,
|
createDirectMessagePermission,
|
||||||
|
createDiscussionOtherUserPermission,
|
||||||
serverVersion
|
serverVersion
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
|
@ -85,7 +87,9 @@ const MessageActions = React.memo(
|
||||||
hasDeletePermission: false,
|
hasDeletePermission: false,
|
||||||
hasForceDeletePermission: false,
|
hasForceDeletePermission: false,
|
||||||
hasPinPermission: false,
|
hasPinPermission: false,
|
||||||
hasDeleteOwnPermission: false
|
hasDeleteOwnPermission: false,
|
||||||
|
hasCreateDirectMessagePermission: false,
|
||||||
|
hasCreateDiscussionOtherUserPermission: false
|
||||||
};
|
};
|
||||||
const { showActionSheet, hideActionSheet } = useActionSheet();
|
const { showActionSheet, hideActionSheet } = useActionSheet();
|
||||||
|
|
||||||
|
@ -96,7 +100,9 @@ const MessageActions = React.memo(
|
||||||
deleteMessagePermission,
|
deleteMessagePermission,
|
||||||
forceDeleteMessagePermission,
|
forceDeleteMessagePermission,
|
||||||
pinMessagePermission,
|
pinMessagePermission,
|
||||||
deleteOwnMessagePermission
|
deleteOwnMessagePermission,
|
||||||
|
createDirectMessagePermission,
|
||||||
|
createDiscussionOtherUserPermission
|
||||||
];
|
];
|
||||||
const result = await hasPermission(permission, room.rid);
|
const result = await hasPermission(permission, room.rid);
|
||||||
permissions = {
|
permissions = {
|
||||||
|
@ -104,7 +110,9 @@ const MessageActions = React.memo(
|
||||||
hasDeletePermission: result[1],
|
hasDeletePermission: result[1],
|
||||||
hasForceDeletePermission: result[2],
|
hasForceDeletePermission: result[2],
|
||||||
hasPinPermission: result[3],
|
hasPinPermission: result[3],
|
||||||
hasDeleteOwnPermission: result[4]
|
hasDeleteOwnPermission: result[4],
|
||||||
|
hasCreateDirectMessagePermission: result[5],
|
||||||
|
hasCreateDiscussionOtherUserPermission: result[6]
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
@ -385,7 +393,7 @@ const MessageActions = React.memo(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reply in DM
|
// Reply in DM
|
||||||
if (room.t !== 'd' && room.t !== 'l' && createDirectMessagePermission && !videoConfBlock) {
|
if (room.t !== 'd' && room.t !== 'l' && permissions.hasCreateDirectMessagePermission && !videoConfBlock) {
|
||||||
options.push({
|
options.push({
|
||||||
title: I18n.t('Reply_in_direct_message'),
|
title: I18n.t('Reply_in_direct_message'),
|
||||||
icon: 'arrow-back',
|
icon: 'arrow-back',
|
||||||
|
@ -394,11 +402,13 @@ const MessageActions = React.memo(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Discussion
|
// Create Discussion
|
||||||
options.push({
|
if (permissions.hasCreateDiscussionOtherUserPermission) {
|
||||||
title: I18n.t('Start_a_Discussion'),
|
options.push({
|
||||||
icon: 'discussions',
|
title: I18n.t('Start_a_Discussion'),
|
||||||
onPress: () => handleCreateDiscussion(message)
|
icon: 'discussions',
|
||||||
});
|
onPress: () => handleCreateDiscussion(message)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.2.0') && !videoConfBlock) {
|
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.2.0') && !videoConfBlock) {
|
||||||
options.push({
|
options.push({
|
||||||
|
@ -541,7 +551,8 @@ const mapStateToProps = (state: IApplicationState) => ({
|
||||||
deleteOwnMessagePermission: state.permissions['delete-own-message'],
|
deleteOwnMessagePermission: state.permissions['delete-own-message'],
|
||||||
forceDeleteMessagePermission: state.permissions['force-delete-message'],
|
forceDeleteMessagePermission: state.permissions['force-delete-message'],
|
||||||
pinMessagePermission: state.permissions['pin-message'],
|
pinMessagePermission: state.permissions['pin-message'],
|
||||||
createDirectMessagePermission: state.permissions['create-d']
|
createDirectMessagePermission: state.permissions['create-d'],
|
||||||
|
createDiscussionOtherUserPermission: state.permissions['start-discussion-other-user']
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps, null, null, { forwardRef: true })(MessageActions);
|
export default connect(mapStateToProps, null, null, { forwardRef: true })(MessageActions);
|
||||||
|
|
|
@ -112,6 +112,7 @@ export interface IMessageBoxProps extends IBaseScreen<ChatsStackParamList & Mast
|
||||||
isActionsEnabled: boolean;
|
isActionsEnabled: boolean;
|
||||||
usedCannedResponse: string;
|
usedCannedResponse: string;
|
||||||
uploadFilePermission: string[];
|
uploadFilePermission: string[];
|
||||||
|
createDiscussionPermission: string[];
|
||||||
goToCannedResponses: () => void | null;
|
goToCannedResponses: () => void | null;
|
||||||
serverVersion: string;
|
serverVersion: string;
|
||||||
}
|
}
|
||||||
|
@ -130,6 +131,7 @@ interface IMessageBoxState {
|
||||||
tshow: boolean;
|
tshow: boolean;
|
||||||
mentionLoading: boolean;
|
mentionLoading: boolean;
|
||||||
permissionToUpload: boolean;
|
permissionToUpload: boolean;
|
||||||
|
hasCreateDiscussionPermission: boolean;
|
||||||
showEmojiSearchbar: boolean;
|
showEmojiSearchbar: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +186,8 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
tshow: this.sendThreadToChannel,
|
tshow: this.sendThreadToChannel,
|
||||||
mentionLoading: false,
|
mentionLoading: false,
|
||||||
permissionToUpload: true,
|
permissionToUpload: true,
|
||||||
showEmojiSearchbar: false
|
showEmojiSearchbar: false,
|
||||||
|
hasCreateDiscussionPermission: false
|
||||||
};
|
};
|
||||||
this.text = '';
|
this.text = '';
|
||||||
this.selection = { start: 0, end: 0 };
|
this.selection = { start: 0, end: 0 };
|
||||||
|
@ -325,6 +328,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
mentionLoading,
|
mentionLoading,
|
||||||
trackingType,
|
trackingType,
|
||||||
permissionToUpload,
|
permissionToUpload,
|
||||||
|
hasCreateDiscussionPermission,
|
||||||
showEmojiSearchbar
|
showEmojiSearchbar
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
|
@ -337,6 +341,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
theme,
|
theme,
|
||||||
usedCannedResponse,
|
usedCannedResponse,
|
||||||
uploadFilePermission,
|
uploadFilePermission,
|
||||||
|
createDiscussionPermission,
|
||||||
goToCannedResponses
|
goToCannedResponses
|
||||||
} = this.props;
|
} = this.props;
|
||||||
if (nextProps.theme !== theme) {
|
if (nextProps.theme !== theme) {
|
||||||
|
@ -378,6 +383,9 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
if (nextState.permissionToUpload !== permissionToUpload) {
|
if (nextState.permissionToUpload !== permissionToUpload) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (nextState.hasCreateDiscussionPermission !== hasCreateDiscussionPermission) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!dequal(nextState.mentions, mentions)) {
|
if (!dequal(nextState.mentions, mentions)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -390,6 +398,9 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
if (!dequal(nextProps.uploadFilePermission, uploadFilePermission)) {
|
if (!dequal(nextProps.uploadFilePermission, uploadFilePermission)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!dequal(nextProps.createDiscussionPermission, createDiscussionPermission)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (nextProps.usedCannedResponse !== usedCannedResponse) {
|
if (nextProps.usedCannedResponse !== usedCannedResponse) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -400,13 +411,18 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: IMessageBoxProps) {
|
componentDidUpdate(prevProps: IMessageBoxProps) {
|
||||||
const { uploadFilePermission, goToCannedResponses, replyWithMention, threadsEnabled } = this.props;
|
const { uploadFilePermission, goToCannedResponses, replyWithMention, threadsEnabled, createDiscussionPermission } =
|
||||||
|
this.props;
|
||||||
if (prevProps.replyWithMention !== replyWithMention) {
|
if (prevProps.replyWithMention !== replyWithMention) {
|
||||||
if (threadsEnabled && replyWithMention) {
|
if (threadsEnabled && replyWithMention) {
|
||||||
this.setState({ tshow: this.sendThreadToChannel });
|
this.setState({ tshow: this.sendThreadToChannel });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!dequal(prevProps.uploadFilePermission, uploadFilePermission) || prevProps.goToCannedResponses !== goToCannedResponses) {
|
if (
|
||||||
|
!dequal(prevProps.uploadFilePermission, uploadFilePermission) ||
|
||||||
|
!dequal(prevProps.createDiscussionPermission, createDiscussionPermission) ||
|
||||||
|
prevProps.goToCannedResponses !== goToCannedResponses
|
||||||
|
) {
|
||||||
this.setOptions();
|
this.setOptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,7 +457,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
setOptions = async () => {
|
setOptions = async () => {
|
||||||
const { uploadFilePermission, rid } = this.props;
|
const { uploadFilePermission, rid, createDiscussionPermission } = this.props;
|
||||||
|
|
||||||
// Servers older than 4.2
|
// Servers older than 4.2
|
||||||
if (!uploadFilePermission) {
|
if (!uploadFilePermission) {
|
||||||
|
@ -449,8 +465,8 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionToUpload = await hasPermission([uploadFilePermission], rid);
|
const permissions = await hasPermission([uploadFilePermission, createDiscussionPermission], rid);
|
||||||
this.setState({ permissionToUpload: permissionToUpload[0] });
|
this.setState({ permissionToUpload: permissions[0], hasCreateDiscussionPermission: permissions[1] });
|
||||||
};
|
};
|
||||||
|
|
||||||
onChangeText: any = (text: string): void => {
|
onChangeText: any = (text: string): void => {
|
||||||
|
@ -877,7 +893,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
|
|
||||||
showMessageBoxActions = () => {
|
showMessageBoxActions = () => {
|
||||||
logEvent(events.ROOM_SHOW_BOX_ACTIONS);
|
logEvent(events.ROOM_SHOW_BOX_ACTIONS);
|
||||||
const { permissionToUpload } = this.state;
|
const { permissionToUpload, hasCreateDiscussionPermission } = this.state;
|
||||||
const { showActionSheet, goToCannedResponses } = this.props;
|
const { showActionSheet, goToCannedResponses } = this.props;
|
||||||
|
|
||||||
const options: TActionSheetOptionsItem[] = [];
|
const options: TActionSheetOptionsItem[] = [];
|
||||||
|
@ -913,11 +929,13 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
options.push({
|
if (hasCreateDiscussionPermission) {
|
||||||
title: I18n.t('Create_Discussion'),
|
options.push({
|
||||||
icon: 'discussions',
|
title: I18n.t('Create_Discussion'),
|
||||||
onPress: this.createDiscussion
|
icon: 'discussions',
|
||||||
});
|
onPress: this.createDiscussion
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.closeEmojiAndAction(showActionSheet, { options });
|
this.closeEmojiAndAction(showActionSheet, { options });
|
||||||
};
|
};
|
||||||
|
@ -1316,6 +1334,7 @@ const mapStateToProps = (state: IApplicationState) => ({
|
||||||
FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize,
|
FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize,
|
||||||
Message_AudioRecorderEnabled: state.settings.Message_AudioRecorderEnabled,
|
Message_AudioRecorderEnabled: state.settings.Message_AudioRecorderEnabled,
|
||||||
uploadFilePermission: state.permissions['mobile-upload-file'],
|
uploadFilePermission: state.permissions['mobile-upload-file'],
|
||||||
|
createDiscussionPermission: state.permissions['start-discussion'],
|
||||||
serverVersion: state.server.version
|
serverVersion: state.server.version
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ export const SUPPORTED_PERMISSIONS = [
|
||||||
'create-p',
|
'create-p',
|
||||||
'create-d',
|
'create-d',
|
||||||
'start-discussion',
|
'start-discussion',
|
||||||
|
'start-discussion-other-user',
|
||||||
'create-team',
|
'create-team',
|
||||||
'delete-c',
|
'delete-c',
|
||||||
'delete-message',
|
'delete-message',
|
||||||
|
|
Loading…
Reference in New Issue