Skip to content

Commit ff7b6e8

Browse files
BrandonNgoranNtamchrisbobbe
authored andcommitted
AccountDetails: Add user's role in the profile
The user's profile wasn't diplaying the user's role which could either be "Owner", "Moderator", "Admin", "Member" or "Guest". Now the role is displayed. Fixes: #5534 Co-authored-by: Chris Bobbe <[email protected]>
1 parent 3c9da46 commit ff7b6e8

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/account-info/AccountDetails.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { View } from 'react-native';
55

66
import Emoji from '../emoji/Emoji';
77
import { emojiTypeFromReactionType } from '../emoji/data';
8-
import type { UserOrBot } from '../types';
8+
import type { LocalizableText, UserOrBot } from '../types';
99
import styles, { createStyleSheet } from '../styles';
1010
import { useSelector } from '../react-redux';
1111
import UserAvatar from '../common/UserAvatar';
@@ -14,6 +14,10 @@ import ZulipText from '../common/ZulipText';
1414
import { getUserStatus } from '../user-statuses/userStatusesModel';
1515
import PresenceStatusIndicator from '../common/PresenceStatusIndicator';
1616
import { getDisplayEmailForUser } from '../selectors';
17+
import { Role } from '../api/permissionsTypes';
18+
import ZulipTextIntl from '../common/ZulipTextIntl';
19+
import { getOwnUserId } from '../users/userSelectors';
20+
import { getOwnUserRole } from '../permissionSelectors';
1721

1822
const componentStyles = createStyleSheet({
1923
componentListItem: {
@@ -42,6 +46,21 @@ type Props = $ReadOnly<{|
4246
showEmail: boolean,
4347
|}>;
4448

49+
const getRoleText = (role: Role): LocalizableText => {
50+
switch (role) {
51+
case Role.Owner:
52+
return 'Owner';
53+
case Role.Admin:
54+
return 'Admin';
55+
case Role.Moderator:
56+
return 'Moderator';
57+
case Role.Member:
58+
return 'Member';
59+
case Role.Guest:
60+
return 'Guest';
61+
}
62+
};
63+
4564
export default function AccountDetails(props: Props): Node {
4665
const { user, showEmail } = props;
4766

@@ -51,6 +70,16 @@ export default function AccountDetails(props: Props): Node {
5170
);
5271
const realm = useSelector(state => state.realm);
5372
const displayEmail = getDisplayEmailForUser(realm, user);
73+
const ownUserId = useSelector(getOwnUserId);
74+
const ownUserRole = useSelector(getOwnUserRole);
75+
76+
// user.role will be missing when the server has feature level <59. For
77+
// those old servers, we can use getOwnUserRole for the "own" (or "self")
78+
// user's role, but nothing will give us the role of a non-"own" user, so
79+
// we just won't show any role in that case.
80+
// TODO(server-4.0): user.role will never be missing; use that for "own"
81+
// and non-"own" users.
82+
const role = user.user_id === ownUserId ? ownUserRole : user.role;
5483

5584
return (
5685
<ComponentList outerSpacing itemStyle={componentStyles.componentListItem}>
@@ -79,6 +108,14 @@ export default function AccountDetails(props: Props): Node {
79108
/>
80109
</View>
81110
)}
111+
{
112+
// TODO(server-4.0): Remove conditional; we'll always know the role.
113+
role != null && (
114+
<View>
115+
<ZulipTextIntl selectable style={styles.largerText} text={getRoleText(role)} />
116+
</View>
117+
)
118+
}
82119
<View style={componentStyles.statusWrapper}>
83120
{userStatusEmoji && (
84121
<Emoji

static/translations/messages_en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,10 @@
351351
"Copy link to stream": "Copy link to stream",
352352
"Failed to copy stream link": "Failed to copy stream link",
353353
"A stream with this name already exists.": "A stream with this name already exists.",
354-
"Streams": "Streams"
354+
"Streams": "Streams",
355+
"Owner": "Owner",
356+
"Admin": "Admin",
357+
"Moderator": "Moderator",
358+
"Member": "Member",
359+
"Guest": "Guest"
355360
}

0 commit comments

Comments
 (0)