Skip to content

Commit

Permalink
fix: display bio, nickname, and statusText in User Info modal; resolv…
Browse files Browse the repository at this point in the history
…e permission issues for viewing full user info (#756)
  • Loading branch information
SinghaAnirban005 authored Jan 1, 2025
1 parent 94e0faf commit 21d6f2d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/react/src/hooks/useFetchChatData.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const useFetchChatData = (showRoles) => {
const isUserAuthenticated = useUserStore(
(state) => state.isUserAuthenticated
);
const setViewUserInfoPermissions = useUserStore(
(state) => state.setViewUserInfoPermissions
);

const getMessagesAndRoles = useCallback(
async (anonymousMode) => {
Expand Down Expand Up @@ -68,6 +71,9 @@ const useFetchChatData = (showRoles) => {

setMemberRoles(rolesObj);
}

const permissions = await RCInstance.permissionInfo();
setViewUserInfoPermissions(permissions.update[70]);
} catch (e) {
console.error(e);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/store/userStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const useUserStore = create((set) => ({
userPinPermissions: {},
setUserPinPermissions: (userPinPermissions) =>
set((state) => ({ ...state, userPinPermissions })),
viewUserInfoPermissions: {},
setViewUserInfoPermissions: (viewUserInfoPermissions) =>
set((state) => ({ ...state, viewUserInfoPermissions })),
showCurrentUserInfo: false,
setShowCurrentUserInfo: (showCurrentUserInfo) =>
set(() => ({ showCurrentUserInfo })),
Expand Down
49 changes: 41 additions & 8 deletions packages/react/src/views/UserInformation/UserInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ const UserInformation = () => {
const [currentUserInfo, setCurrentUserInfo] = useState({});
const [isUserInfoFetched, setIsUserInfoFetched] = useState(false);
const currentUser = useUserStore((state) => state.currentUser);
const authenticatedUserRoles = useUserStore((state) => state.roles);
const currentUserRoles = useUserStore((state) => state.roles);
const viewUserFullInfoRoles = useUserStore(
(state) => state.viewUserInfoPermissions.roles
);
const authenticatedUserId = useUserStore((state) => state.userId);
const isAdmin = authenticatedUserRoles?.includes('admin');
const viewInfoRoles = new Set(viewUserFullInfoRoles);
const isAllowedToViewFullInfo = currentUserRoles.some((role) =>
viewInfoRoles.has(role)
);
const getUserAvatarUrl = (username) => {
const host = RCInstance.getHost();
return `${host}/avatar/${username}`;
Expand Down Expand Up @@ -96,6 +102,24 @@ const UserInformation = () => {
/>
{currentUserInfo?.username}
</Box>
{currentUserInfo?.statusText && (
<Box
css={css`
margin-bottom: 20px;
`}
>
{currentUserInfo?.statusText}
</Box>
)}
{currentUserInfo?.nickname && (
<UserInfoField
label="Nickname"
value={currentUserInfo?.nickname}
isAdmin={isAllowedToViewFullInfo}
authenticatedUserId={authenticatedUserId}
currentUserInfo={currentUserInfo}
/>
)}
{currentUserInfo?.roles?.length && (
<UserInfoField
label="Roles"
Expand All @@ -113,15 +137,15 @@ const UserInformation = () => {
))}
</Box>
}
isAdmin={isAdmin}
isAdmin={isAllowedToViewFullInfo}
authenticatedUserId={authenticatedUserId}
currentUserInfo={currentUserInfo}
/>
)}
<UserInfoField
label="Username"
value={currentUserInfo?.username}
isAdmin={isAdmin}
isAdmin
authenticatedUserId={authenticatedUserId}
currentUserInfo={currentUserInfo}
/>
Expand All @@ -132,17 +156,26 @@ const UserInformation = () => {
? 'Never'
: formatTimestamp(currentUserInfo.lastLogin)
}
isAdmin={isAdmin}
isAdmin={isAllowedToViewFullInfo}
authenticatedUserId={authenticatedUserId}
currentUserInfo={currentUserInfo}
/>
<UserInfoField
label="Full Name"
value={currentUserInfo.name}
isAdmin={isAdmin}
isAdmin={isAllowedToViewFullInfo}
authenticatedUserId={authenticatedUserId}
currentUserInfo={currentUserInfo}
/>
{currentUserInfo?.bio && (
<UserInfoField
label="Bio"
value={currentUserInfo?.bio}
isAdmin={isAllowedToViewFullInfo}
authenticatedUserId={authenticatedUserId}
currentUserInfo={currentUserInfo}
/>
)}
<UserInfoField
label="Email"
value={currentUserInfo.emails?.map((email, index) => (
Expand All @@ -158,14 +191,14 @@ const UserInformation = () => {
</Box>
</Box>
))}
isAdmin={isAdmin}
isAdmin={isAllowedToViewFullInfo}
authenticatedUserId={authenticatedUserId}
currentUserInfo={currentUserInfo}
/>
<UserInfoField
label="Created at"
value={formatTimestamp(currentUserInfo.createdAt)}
isAdmin={isAdmin}
isAdmin={isAllowedToViewFullInfo}
authenticatedUserId={authenticatedUserId}
currentUserInfo={currentUserInfo}
/>
Expand Down

0 comments on commit 21d6f2d

Please sign in to comment.