Skip to content

Commit f192216

Browse files
feat: add env variable to display image
1 parent 79a2fa4 commit f192216

File tree

11 files changed

+31
-15
lines changed

11 files changed

+31
-15
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ USER_INFO_COOKIE_NAME=''
2222
SUPPORT_URL=''
2323
LEARNER_FEEDBACK_URL=''
2424
STAFF_FEEDBACK_URL=''
25+
ENABLE_PROFILE_IMAGE=''

.env.development

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ USER_INFO_COOKIE_NAME='edx-user-info'
2323
SUPPORT_URL='https://support.edx.org'
2424
LEARNER_FEEDBACK_URL=''
2525
STAFF_FEEDBACK_URL=''
26+
ENABLE_PROFILE_IMAGE='true'

.env.test

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ USER_INFO_COOKIE_NAME='edx-user-info'
2121
SUPPORT_URL='https://support.edx.org'
2222
LEARNER_FEEDBACK_URL=''
2323
STAFF_FEEDBACK_URL=''
24+
ENABLE_PROFILE_IMAGE=''

src/discussions/data/hooks.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,11 @@ import { ContentSelectors } from './constants';
3333
import {
3434
selectAreThreadsFiltered,
3535
selectEnableInContext,
36-
selectIsCourseAdmin,
37-
selectIsCourseStaff,
3836
selectIsPostingEnabled,
3937
selectIsUserLearner,
4038
selectPostThreadCount,
4139
selectUserHasModerationPrivileges,
4240
selectUserIsGroupTa,
43-
selectUserIsStaff,
4441
} from './selectors';
4542
import fetchCourseConfig from './thunks';
4643

@@ -220,12 +217,9 @@ export const useCurrentDiscussionTopic = () => {
220217

221218
export const useUserPostingEnabled = () => {
222219
const isPostingEnabled = useSelector(selectIsPostingEnabled);
223-
const isUserAdmin = useSelector(selectUserIsStaff);
224220
const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges);
225221
const isUserGroupTA = useSelector(selectUserIsGroupTa);
226-
const isCourseAdmin = useSelector(selectIsCourseAdmin);
227-
const isCourseStaff = useSelector(selectIsCourseStaff);
228-
const isPrivileged = isUserAdmin || userHasModerationPrivileges || isUserGroupTA || isCourseAdmin || isCourseStaff;
222+
const isPrivileged = userHasModerationPrivileges || isUserGroupTA;
229223

230224
return (isPostingEnabled || isPrivileged);
231225
};

src/discussions/data/hooks.test.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const courseConfigApiUrl = getCourseConfigApiUrl();
1919
let store;
2020
let axiosMock;
2121

22-
const generateApiResponse = (isPostingEnabled, isCourseAdmin = false) => ({
22+
const generateApiResponse = (isPostingEnabled, hasModerationPrivileges = false) => ({
2323
isPostingEnabled,
24-
hasModerationPrivileges: false,
24+
hasModerationPrivileges,
2525
isGroupTa: false,
26-
isCourseAdmin,
26+
isCourseAdmin: false,
2727
isCourseStaff: false,
2828
isUserAdmin: false,
2929
});
@@ -160,7 +160,7 @@ describe('Hooks', () => {
160160
expect(queryByText('false')).toBeInTheDocument();
161161
});
162162

163-
test('when posting is not disabled and Role is not Learner return true', async () => {
163+
test('when posting is disabled and Role is not Learner return true', async () => {
164164
axiosMock.onGet(`${courseConfigApiUrl}${courseId}/`)
165165
.reply(200, generateApiResponse(false, true));
166166
await executeThunk(fetchCourseConfig(courseId), store.dispatch, store.getState);

src/discussions/post-comments/comments/comment/Comment.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const Comment = ({
4343
const {
4444
id, parentId, childCount, abuseFlagged, endorsed, threadId, endorsedAt, endorsedBy, endorsedByLabel, renderedBody,
4545
voted, following, voteCount, authorLabel, author, createdAt, lastEdit, rawBody, closed, closedBy, closeReason,
46-
editByLabel, closedByLabel,
46+
editByLabel, closedByLabel, users: postUsers,
4747
} = comment;
4848
const intl = useIntl();
4949
const hasChildren = childCount > 0;
@@ -203,6 +203,7 @@ const Comment = ({
203203
closed={closed}
204204
createdAt={createdAt}
205205
lastEdit={lastEdit}
206+
postUsers={postUsers}
206207
/>
207208
{isEditing ? (
208209
<CommentEditor

src/discussions/post-comments/comments/comment/CommentHeader.jsx

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
44
import { Avatar } from '@openedx/paragon';
55
import classNames from 'classnames';
66

7+
import { getConfig } from '@edx/frontend-platform';
8+
79
import { AvatarOutlineAndLabelColors } from '../../../../data/constants';
810
import { AuthorLabel } from '../../../common';
911
import { useAlertBannerVisible } from '../../../data/hooks';
@@ -15,6 +17,7 @@ const CommentHeader = ({
1517
closed,
1618
createdAt,
1719
lastEdit,
20+
postUsers,
1821
}) => {
1922
const colorClass = AvatarOutlineAndLabelColors[authorLabel];
2023
const hasAnyAlert = useAlertBannerVisible({
@@ -24,6 +27,8 @@ const CommentHeader = ({
2427
closed,
2528
});
2629

30+
const profileImage = getConfig().ENABLE_PROFILE_IMAGE === 'true' && postUsers && Object.values(postUsers)[0].profile.image;
31+
2732
return (
2833
<div className={classNames('d-flex flex-row justify-content-between', {
2934
'mt-2': hasAnyAlert,
@@ -33,6 +38,7 @@ const CommentHeader = ({
3338
<Avatar
3439
className={`border-0 ml-0.5 mr-2.5 ${colorClass ? `outline-${colorClass}` : 'outline-anonymous'}`}
3540
alt={author}
41+
src={profileImage?.hasImage ? profileImage?.imageUrlSmall : undefined}
3642
style={{
3743
width: '32px',
3844
height: '32px',
@@ -61,6 +67,7 @@ CommentHeader.propTypes = {
6167
editorUsername: PropTypes.string,
6268
reason: PropTypes.string,
6369
}),
70+
postUsers: PropTypes.shape({}).isRequired,
6471
};
6572

6673
CommentHeader.defaultProps = {

src/discussions/posts/post/Post.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Post = ({ handleAddResponseButton }) => {
3232
const {
3333
topicId, abuseFlagged, closed, pinned, voted, hasEndorsed, following, closedBy, voteCount, groupId, groupName,
3434
closeReason, authorLabel, type: postType, author, title, createdAt, renderedBody, lastEdit, editByLabel,
35-
closedByLabel,
35+
closedByLabel, users: postUsers,
3636
} = useSelector(selectThread(postId));
3737
const intl = useIntl();
3838
const location = useLocation();
@@ -182,6 +182,7 @@ const Post = ({ handleAddResponseButton }) => {
182182
lastEdit={lastEdit}
183183
postType={postType}
184184
title={title}
185+
postUsers={postUsers}
185186
/>
186187
<div className="d-flex mt-14px text-break font-style text-primary-500">
187188
<HTMLLoader htmlNode={renderedBody} componentId="post" cssClassName="html-loader w-100" testId={postId} />

src/discussions/posts/post/PostHeader.jsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Avatar, Badge, Icon } from '@openedx/paragon';
55
import { Question } from '@openedx/paragon/icons';
66
import classNames from 'classnames';
77

8+
import { getConfig } from '@edx/frontend-platform';
89
import { useIntl } from '@edx/frontend-platform/i18n';
910

1011
import { AvatarOutlineAndLabelColors, ThreadType } from '../../../data/constants';
@@ -13,7 +14,7 @@ import { useAlertBannerVisible } from '../../data/hooks';
1314
import messages from './messages';
1415

1516
export const PostAvatar = React.memo(({
16-
author, postType, authorLabel, fromPostLink, read,
17+
author, postType, authorLabel, fromPostLink, read, postUsers,
1718
}) => {
1819
const outlineColor = AvatarOutlineAndLabelColors[authorLabel];
1920

@@ -37,6 +38,8 @@ export const PostAvatar = React.memo(({
3738
return spacing;
3839
}, [postType]);
3940

41+
const profileImage = getConfig().ENABLE_PROFILE_IMAGE === 'true' && postUsers && Object.values(postUsers)[0].profile.image;
42+
4043
return (
4144
<div className={avatarSpacing}>
4245
{postType === ThreadType.QUESTION && (
@@ -59,6 +62,7 @@ export const PostAvatar = React.memo(({
5962
height: avatarSize,
6063
width: avatarSize,
6164
}}
65+
src={profileImage?.hasImage ? profileImage?.imageUrlSmall : undefined}
6266
alt={author}
6367
/>
6468
</div>
@@ -71,6 +75,7 @@ PostAvatar.propTypes = {
7175
authorLabel: PropTypes.string,
7276
fromPostLink: PropTypes.bool,
7377
read: PropTypes.bool,
78+
postUsers: PropTypes.shape({}).isRequired,
7479
};
7580

7681
PostAvatar.defaultProps = {
@@ -90,6 +95,7 @@ const PostHeader = ({
9095
title,
9196
postType,
9297
preview,
98+
postUsers,
9399
}) => {
94100
const intl = useIntl();
95101
const showAnsweredBadge = preview && hasEndorsed && postType === ThreadType.QUESTION;
@@ -101,7 +107,7 @@ const PostHeader = ({
101107
return (
102108
<div className={classNames('d-flex flex-fill mw-100', { 'mt-10px': hasAnyAlert && !preview })}>
103109
<div className="flex-shrink-0">
104-
<PostAvatar postType={postType} author={author} authorLabel={authorLabel} />
110+
<PostAvatar postType={postType} author={author} authorLabel={authorLabel} postUsers={postUsers} />
105111
</div>
106112
<div className="align-items-center d-flex flex-row">
107113
<div className="d-flex flex-column justify-content-start mw-100">
@@ -151,6 +157,7 @@ PostHeader.propTypes = {
151157
reason: PropTypes.string,
152158
}),
153159
closed: PropTypes.bool,
160+
postUsers: PropTypes.shape({}).isRequired,
154161
};
155162

156163
PostHeader.defaultProps = {

src/discussions/posts/post/PostLink.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const PostLink = ({
3636
const {
3737
topicId, hasEndorsed, type, author, authorLabel, abuseFlagged, abuseFlaggedCount, read, commentCount,
3838
unreadCommentCount, id, pinned, previewBody, title, voted, voteCount, following, groupId, groupName, createdAt,
39+
users: postUsers,
3940
} = useSelector(selectThread(postId));
4041
const { pathname } = discussionsPath(Routes.COMMENTS.PAGES[page], {
4142
0: enableInContextSidebar ? 'in-context' : undefined,
@@ -83,6 +84,7 @@ const PostLink = ({
8384
authorLabel={authorLabel}
8485
fromPostLink
8586
read={isPostRead}
87+
postUsers={postUsers}
8688
/>
8789
<div className="d-flex flex-column flex-fill" style={{ minWidth: 0 }}>
8890
<div className="d-flex flex-column justify-content-start mw-100 flex-fill" style={{ marginBottom: '-3px' }}>

src/index.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ initialize({
4040
LEARNING_BASE_URL: process.env.LEARNING_BASE_URL,
4141
LEARNER_FEEDBACK_URL: process.env.LEARNER_FEEDBACK_URL,
4242
STAFF_FEEDBACK_URL: process.env.STAFF_FEEDBACK_URL,
43+
ENABLE_PROFILE_IMAGE: process.env.ENABLE_PROFILE_IMAGE,
4344
}, 'DiscussionsConfig');
4445
},
4546
},

0 commit comments

Comments
 (0)