Skip to content

Commit 458fdbf

Browse files
authored
fix(preview): Ensure promoted-by field shows correct user (#3414)
* fix(preview): added promoted_by field to version call * fix(preview): added promoted_by field to version call * fix(preview): added promoted_by field to version call * fix(preview): added promoted_by field to version call * fix(preview): added promoted_by field to version call * fix(preview): added promoted_by field to version call
1 parent 45166f4 commit 458fdbf

File tree

7 files changed

+25
-12
lines changed

7 files changed

+25
-12
lines changed

src/common/types/core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ type BoxItemVersion = {
227227
modified_by: ?User,
228228
name?: string,
229229
permissions?: BoxItemVersionPermission,
230+
promoted_by?: ?User,
230231
restored_at?: string,
231232
restored_by?: ?User,
232233
retention?: BoxItemVersionRetention,

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const FIELD_URL = 'url';
121121
export const FIELD_CREATED_BY = 'created_by';
122122
export const FIELD_MODIFIED_BY = 'modified_by';
123123
export const FIELD_OWNED_BY = 'owned_by';
124+
export const FIELD_PROMOTED_BY = 'promoted_by';
124125
export const FIELD_RESTORED_BY = 'restored_by';
125126
export const FIELD_TRASHED_BY = 'trashed_by';
126127
export const FIELD_DESCRIPTION = 'description';

src/elements/common/selectors/__tests__/version.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010

1111
describe('elements/common/selectors/version', () => {
1212
const defaultUser = { name: 'Test User', id: 10 };
13+
const promotedByUser = { name: 'Promote User', id: 13 };
1314
const restoreDate = '2019-04-01T00:00:00';
1415
const restoreUser = { name: 'Restore User', id: 12 };
1516
const trashedDate = '2019-05-01T00:00:00';
@@ -36,20 +37,21 @@ describe('elements/common/selectors/version', () => {
3637

3738
describe('getVersionUser()', () => {
3839
test.each`
39-
modified_by | restored_by | trashed_by | uploader_display_name | expected
40-
${null} | ${null} | ${null} | ${null} | ${PLACEHOLDER_USER}
41-
${null} | ${null} | ${null} | ${FILE_REQUEST_NAME} | ${{ ...PLACEHOLDER_USER, name: FILE_REQUEST_NAME }}
42-
${PLACEHOLDER_USER} | ${null} | ${null} | ${null} | ${PLACEHOLDER_USER}
43-
${PLACEHOLDER_USER} | ${null} | ${null} | ${FILE_REQUEST_NAME} | ${{ ...PLACEHOLDER_USER, name: FILE_REQUEST_NAME }}
44-
${defaultUser} | ${null} | ${null} | ${null} | ${defaultUser}
45-
${defaultUser} | ${restoreUser} | ${null} | ${null} | ${restoreUser}
46-
${defaultUser} | ${restoreUser} | ${trashedUser} | ${null} | ${restoreUser}
47-
${defaultUser} | ${null} | ${trashedUser} | ${null} | ${trashedUser}
40+
description | modified_by | promoted_by | restored_by | trashed_by | uploader_display_name | expected
41+
${'All null values'} | ${null} | ${null} | ${null} | ${null} | ${null} | ${PLACEHOLDER_USER}
42+
${'Uploader Display Name'} | ${null} | ${null} | ${null} | ${null} | ${FILE_REQUEST_NAME} | ${{ ...PLACEHOLDER_USER, name: FILE_REQUEST_NAME }}
43+
${'Placeholder User'} | ${PLACEHOLDER_USER} | ${null} | ${null} | ${null} | ${null} | ${PLACEHOLDER_USER}
44+
${'Placeholder User with Uploader Display Name'} | ${PLACEHOLDER_USER} | ${null} | ${null} | ${null} | ${FILE_REQUEST_NAME} | ${{ ...PLACEHOLDER_USER, name: FILE_REQUEST_NAME }}
45+
${'Default User'} | ${defaultUser} | ${null} | ${null} | ${null} | ${null} | ${defaultUser}
46+
${'Promoted User'} | ${defaultUser} | ${promotedByUser} | ${null} | ${null} | ${null} | ${promotedByUser}
47+
${'Restored User'} | ${defaultUser} | ${promotedByUser} | ${restoreUser} | ${null} | ${null} | ${restoreUser}
48+
${'Trashed User'} | ${defaultUser} | ${promotedByUser} | ${restoreUser} | ${trashedUser} | ${null} | ${restoreUser}
4849
`(
49-
'should return the most relevant user',
50-
({ expected, modified_by, restored_by, trashed_by, uploader_display_name }) => {
50+
'should return the most relevant user - $description',
51+
({ expected, modified_by, promoted_by, restored_by, trashed_by, uploader_display_name }) => {
5152
const version = {
5253
modified_by,
54+
promoted_by,
5355
restored_by,
5456
trashed_by,
5557
uploader_display_name,

src/elements/common/selectors/version.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ const getVersionAction = ({ restored_at, trashed_at, version_promoted }: $Shape<
3434

3535
const getVersionUser = ({
3636
modified_by,
37+
promoted_by,
3738
restored_by,
3839
trashed_by,
3940
uploader_display_name,
4041
}: $Shape<BoxItemVersion>): User => {
41-
const { name, id, ...rest } = restored_by || trashed_by || modified_by || PLACEHOLDER_USER;
42+
const { name, id, ...rest } = restored_by || trashed_by || promoted_by || modified_by || PLACEHOLDER_USER;
4243
const isAnonymous = id === PLACEHOLDER_USER.id;
4344
return { ...rest, id, name: isAnonymous && uploader_display_name ? uploader_display_name : name };
4445
};

src/elements/content-sidebar/versions/__tests__/VersionsItem.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jest.mock('../../../../utils/dom', () => ({
1818
describe('elements/content-sidebar/versions/VersionsItem', () => {
1919
const defaultDate = new Date('2019-03-01T00:00:00');
2020
const defaultUser = { name: 'Test User', id: 10 };
21+
const promotedByUser = { name: 'Promote User', id: 13 };
2122
const restoreDate = new Date('2019-05-01T00:00:00');
2223
const restoreUser = { name: 'Restore User', id: 12 };
2324
const trashedDate = new Date('2019-04-01T00:00:00');
@@ -117,6 +118,7 @@ describe('elements/content-sidebar/versions/VersionsItem', () => {
117118
test.each`
118119
versionUser | expected
119120
${defaultUser} | ${defaultUser.name}
121+
${promotedByUser} | ${promotedByUser.name}
120122
${restoreUser} | ${restoreUser.name}
121123
${trashedUser} | ${trashedUser.name}
122124
${PLACEHOLDER_USER} | ${unknownUser}
@@ -131,6 +133,7 @@ describe('elements/content-sidebar/versions/VersionsItem', () => {
131133
test.each`
132134
versionUser | expected
133135
${defaultUser} | ${defaultUser.name}
136+
${promotedByUser} | ${promotedByUser.name}
134137
${restoreUser} | ${restoreUser.name}
135138
${trashedUser} | ${trashedUser.name}
136139
${{ ...PLACEHOLDER_USER, name: FILE_REQUEST_NAME }} | ${(<FormattedMessage {...messages.fileRequestDisplayName} />)}

src/utils/__tests__/fields.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
FIELD_PARENT,
2020
FIELD_EXTENSION,
2121
FIELD_PERMISSIONS,
22+
FIELD_PROMOTED_BY,
2223
FIELD_ITEM_COLLECTION,
2324
FIELD_ITEM_EXPIRATION,
2425
FIELD_PATH_COLLECTION,
@@ -169,6 +170,7 @@ describe('util/fields', () => {
169170
FIELD_MODIFIED_BY,
170171
FIELD_NAME,
171172
FIELD_PERMISSIONS,
173+
FIELD_PROMOTED_BY,
172174
FIELD_RESTORED_AT,
173175
FIELD_RESTORED_BY,
174176
FIELD_RETENTION,

src/utils/fields.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
FIELD_CREATED_BY,
2929
FIELD_MODIFIED_BY,
3030
FIELD_OWNED_BY,
31+
FIELD_PROMOTED_BY,
3132
FIELD_RESTORED_BY,
3233
FIELD_TRASHED_BY,
3334
FIELD_DESCRIPTION,
@@ -150,6 +151,7 @@ const FILE_VERSION_FIELDS_TO_FETCH = [
150151
FIELD_MODIFIED_BY,
151152
FIELD_RESTORED_FROM,
152153
FIELD_SIZE,
154+
FIELD_PROMOTED_BY,
153155
FIELD_UPLOADER_DISPLAY_NAME,
154156
FIELD_VERSION_NUMBER,
155157
];
@@ -164,6 +166,7 @@ const FILE_VERSIONS_FIELDS_TO_FETCH = [
164166
FIELD_MODIFIED_BY,
165167
FIELD_NAME,
166168
FIELD_PERMISSIONS, // Expensive field to fetch
169+
FIELD_PROMOTED_BY,
167170
FIELD_RESTORED_AT,
168171
FIELD_RESTORED_BY,
169172
FIELD_RETENTION, // Expensive field to fetch

0 commit comments

Comments
 (0)