Skip to content

Commit 2d81c44

Browse files
authored
feat: Attribute Based Access Control (ABAC) (#6856)
1 parent d019d4b commit 2d81c44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+5826
-409
lines changed
1 KB
Binary file not shown.

app/containers/ActionSheet/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const Item = React.memo(({ item, hide }: IActionSheetItem) => {
2626
hide();
2727
item?.onPress();
2828
} else {
29-
EventEmitter.emit(LISTENER, { message: I18n.t('You_dont_have_permission_to_perform_this_action') });
29+
EventEmitter.emit(LISTENER, { message: item?.disabledReason || I18n.t('You_dont_have_permission_to_perform_this_action') });
3030
}
3131
};
3232

app/containers/ActionSheet/Provider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type TActionSheetOptionsItem = {
1414
onPress: () => void;
1515
right?: () => React.ReactElement;
1616
enabled?: boolean;
17+
disabledReason?: string;
1718
};
1819

1920
export type TActionSheetOptions = {

app/containers/CustomIcon/mappedIcons.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export const mappedIcons = {
106106
'google-monochromatic': 59657,
107107
'group-by-type': 59757,
108108
'hamburguer': 59758,
109+
'hash-shield': 59878,
109110
'history': 59759,
110111
'home': 59760,
111112
'ignore': 59740,
@@ -202,6 +203,7 @@ export const mappedIcons = {
202203
'sun': 59847,
203204
'support': 59848,
204205
'team': 59849,
206+
'team-shield': 59877,
205207
'teams': 59751,
206208
'teams-private': 59750,
207209
'text-format': 59839,

app/containers/CustomIcon/selection.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

app/containers/List/ListItem.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { Icon } from '.';
1818
import { BASE_HEIGHT, ICON_SIZE, PADDING_HORIZONTAL } from './constants';
1919
import { CustomIcon } from '../CustomIcon';
2020
import { useResponsiveLayout } from '../../lib/hooks/useResponsiveLayout/useResponsiveLayout';
21+
import EventEmitter from '../../lib/methods/helpers/events';
22+
import { LISTENER } from '../Toast';
2123

2224
const styles = StyleSheet.create({
2325
container: {
@@ -90,6 +92,7 @@ interface IListItemContent {
9092
left?: () => JSX.Element | null;
9193
right?: () => JSX.Element | null;
9294
disabled?: boolean;
95+
disabledReason?: string;
9396
testID?: string;
9497
color?: string;
9598
translateTitle?: boolean;
@@ -154,7 +157,15 @@ const Content = React.memo(
154157
}
155158
}
156159
return label;
157-
}, [title, subtitle, translateTitle, translateSubtitle, additionalAcessibilityLabel, additionalAcessibilityLabelCheck]);
160+
}, [
161+
accessibilityLabel,
162+
title,
163+
subtitle,
164+
translateTitle,
165+
translateSubtitle,
166+
additionalAcessibilityLabel,
167+
additionalAcessibilityLabelCheck
168+
]);
158169

159170
return (
160171
<View
@@ -205,6 +216,7 @@ interface IListButtonPress extends IListItemButton {
205216
interface IListItemButton {
206217
title: string | (() => JSX.Element | null);
207218
disabled?: boolean;
219+
disabledReason?: string;
208220
backgroundColor?: string;
209221
underlayColor?: string;
210222
}
@@ -214,12 +226,20 @@ const Button = React.memo(({ onPress, backgroundColor, underlayColor, ...props }
214226

215227
const { colors } = useTheme();
216228

229+
const handlePress = () => {
230+
if (props.disabled && props.disabledReason) {
231+
EventEmitter.emit(LISTENER, { message: props.disabledReason });
232+
} else if (!props.disabled) {
233+
onPress(props.title);
234+
}
235+
};
236+
217237
return (
218238
<Touch
219-
onPress={() => onPress(props.title)}
239+
onPress={handlePress}
220240
style={{ backgroundColor: backgroundColor || colors.surfaceRoom }}
221241
underlayColor={underlayColor}
222-
enabled={!props.disabled}>
242+
enabled={!props.disabled || !!props.disabledReason}>
223243
<Content {...props} />
224244
</Touch>
225245
);

app/containers/MessageActions/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ const MessageActions = React.memo(
442442
title: I18n.t('Reply_in_direct_message'),
443443
icon: 'arrow-back',
444444
onPress: () => handleReplyInDM(message),
445-
enabled: permissions.hasCreateDirectMessagePermission
445+
enabled: permissions.hasCreateDirectMessagePermission && !room.abacAttributes,
446+
disabledReason: room.abacAttributes && I18n.t('ABAC_disabled_action_reason')
446447
});
447448
}
448449

@@ -454,19 +455,24 @@ const MessageActions = React.memo(
454455
enabled: permissions.hasCreateDiscussionOtherUserPermission
455456
});
456457

458+
// Forward
457459
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.2.0') && !videoConfBlock) {
458460
options.push({
459461
title: I18n.t('Forward'),
460462
icon: 'arrow-forward',
461-
onPress: () => handleShareMessage(message)
463+
onPress: () => handleShareMessage(message),
464+
enabled: !room.abacAttributes,
465+
disabledReason: room.abacAttributes && I18n.t('ABAC_disabled_action_reason')
462466
});
463467
}
464468

465-
// Permalink
469+
// Get link
466470
options.push({
467471
title: I18n.t('Get_link'),
468472
icon: 'link',
469-
onPress: () => handlePermalink(message)
473+
onPress: () => handlePermalink(message),
474+
enabled: !room.abacAttributes,
475+
disabledReason: room.abacAttributes && I18n.t('ABAC_disabled_action_reason')
470476
});
471477

472478
// Copy

app/containers/RoomHeader/RoomHeader.stories.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ export const Icons = () => (
5555
<HeaderExample title={() => <RoomHeader title='busy dm' type='d' status='busy' />} />
5656
<HeaderExample title={() => <RoomHeader title='loading dm' type='d' status='loading' />} />
5757
<HeaderExample title={() => <RoomHeader title='offline dm' type='d' />} />
58+
<HeaderExample
59+
title={() => (
60+
<RoomHeader title='classified' type='p' abacAttributes={[{ key: 'Attribute', values: ['Value 1', 'Value 2'] }]} />
61+
)}
62+
/>
63+
<HeaderExample
64+
title={() => (
65+
<RoomHeader
66+
title='classified'
67+
type='p'
68+
abacAttributes={[{ key: 'Attribute', values: ['Value 1', 'Value 2'] }]}
69+
teamMain
70+
/>
71+
)}
72+
/>
5873
</>
5974
);
6075

app/containers/RoomHeader/RoomHeader.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import I18n from '../../i18n';
77
import sharedStyles from '../../views/Styles';
88
import { MarkdownPreview } from '../markdown';
99
import RoomTypeIcon from '../RoomTypeIcon';
10-
import { type TUserStatus, type IOmnichannelSource } from '../../definitions';
10+
import { type TUserStatus, type IOmnichannelSource, type ISubscription } from '../../definitions';
1111
import { useTheme } from '../../theme';
1212
import { useAppSelector } from '../../lib/hooks/useAppSelector';
1313
import useStatusAccessibilityLabel from '../../lib/hooks/useStatusAccessibilityLabel';
@@ -80,6 +80,7 @@ interface IRoomHeader {
8080
sourceType?: IOmnichannelSource;
8181
disabled?: boolean;
8282
rightButtonsWidth?: number;
83+
abacAttributes?: ISubscription['abacAttributes'];
8384
}
8485

8586
const SubTitle = React.memo(({ usersTyping, subtitle, renderFunc, scale }: TRoomHeaderSubTitle) => {
@@ -148,7 +149,8 @@ const Header = React.memo(
148149
testID,
149150
usersTyping = [],
150151
sourceType,
151-
disabled
152+
disabled,
153+
abacAttributes
152154
}: IRoomHeader) => {
153155
const statusAccessibilityLabel = useStatusAccessibilityLabel({
154156
isGroupChat,
@@ -182,6 +184,7 @@ const Header = React.memo(
182184
isGroupChat={isGroupChat}
183185
status={status}
184186
teamMain={teamMain}
187+
abacAttributes={abacAttributes}
185188
/>
186189
<Text style={[styles.subtitle, { color: colors.fontSecondaryInfo }]} numberOfLines={1}>
187190
{parentTitle}
@@ -208,6 +211,7 @@ const Header = React.memo(
208211
status={status}
209212
teamMain={teamMain}
210213
sourceType={sourceType}
214+
abacAttributes={abacAttributes}
211215
/>
212216
)}
213217
<HeaderTitle title={title} tmid={tmid} prid={prid} scale={scale} testID={testID} />

0 commit comments

Comments
 (0)