Skip to content

Commit 8ae748c

Browse files
authored
fix: hide 'View My Records' button if no credentials service (#421)
This hides the 'View My Records' button from users profile page if `CREDENTIALS_BASE_URL` is not configured.
1 parent 00b2dee commit 8ae748c

File tree

3 files changed

+973
-2
lines changed

3 files changed

+973
-2
lines changed

src/profile/ProfilePage.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ ensureConfig(['CREDENTIALS_BASE_URL', 'LMS_BASE_URL'], 'ProfilePage');
4444
class ProfilePage extends React.Component {
4545
constructor(props, context) {
4646
super(props, context);
47+
const credentialsBaseUrl = context.config.CREDENTIALS_BASE_URL;
4748

4849
this.state = {
49-
viewMyRecordsUrl: `${context.config.CREDENTIALS_BASE_URL}/records`,
50+
viewMyRecordsUrl: credentialsBaseUrl ? `${credentialsBaseUrl}/records` : null,
5051
accountSettingsUrl: `${context.config.LMS_BASE_URL}/account/settings`,
5152
};
5253

@@ -95,7 +96,7 @@ class ProfilePage extends React.Component {
9596

9697
// Inserted into the DOM in two places (for responsive layout)
9798
renderViewMyRecordsButton() {
98-
if (!this.isAuthenticatedUserProfile()) {
99+
if (!(this.state.viewMyRecordsUrl && this.isAuthenticatedUserProfile())) {
99100
return null;
100101
}
101102

src/profile/ProfilePage.test.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,28 @@ describe('<ProfilePage />', () => {
145145
const tree = renderer.create(component).toJSON();
146146
expect(tree).toMatchSnapshot();
147147
});
148+
149+
it('without credentials service', () => {
150+
const config = getConfig();
151+
config.CREDENTIALS_BASE_URL = '';
152+
153+
const component = (
154+
<AppContext.Provider
155+
value={{
156+
authenticatedUser: { userId: 123, username: 'staff', administrator: true },
157+
config,
158+
}}
159+
>
160+
<IntlProvider locale="en">
161+
<Provider store={mockStore(storeMocks.viewOwnProfile)}>
162+
<ProfilePage {...requiredProfilePageProps} />
163+
</Provider>
164+
</IntlProvider>
165+
</AppContext.Provider>
166+
);
167+
const tree = renderer.create(component).toJSON();
168+
expect(tree).toMatchSnapshot();
169+
});
148170
});
149171

150172
describe('handles analytics', () => {

0 commit comments

Comments
 (0)