Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KPMP-5445_add-package-submitter #397

Merged
merged 20 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/Packages/PackagePanelStateText.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PackagePanelStateText extends Component {
let panelConfig = {};
panelConfig.message = getMessage(this.props.panelState.state, this.props.largeFileUpload, this.props.currentUser.email, this.props.packageSubmitter.email);
if (this.props.handleStateInfoClick) {
panelConfig.icon = getIcon(this.props.panelState.state, this.props.largeFileUpload, this.props.currentUser.email, this.props.packageSubmitter.email, this.props.stateDisplayMap);
panelConfig.icon = getIcon(this.props.panelState.state, this.props.largeFileUpload, this.props.currentUser.email, this.props.currentUser.roles ,this.props.packageSubmitter.email, this.props.stateDisplayMap);
}
return panelConfig;
}
Expand All @@ -52,7 +52,7 @@ class PackagePanelStateText extends Component {
alertClass = 'alert-' + stateDisplayInfo.apps.dlu.alertType;
}

let popoverTargetId = 'popover-' + this.props.panelState.packageId;
let popoverTargetId = 'popover-' + this.props.panelState.packageId;

return <React.Fragment>
<div className='d-flex align-items-start'>
Expand All @@ -78,7 +78,7 @@ class PackagePanelStateText extends Component {
}
</div>
}
{ this.props.currentUser?.roles.includes("uw_rit_kpmp_role_developer") && panelConfig.icon &&
{ panelConfig.icon &&
<span onClick={clickEvent}>
<div className='additional-icon clickable'><FontAwesomeIcon className='float-right' icon={panelConfig.icon} size='lg' inverse/></div>
</span>
Expand Down
12 changes: 10 additions & 2 deletions src/components/Packages/packagePanelStateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,21 @@ const panelConfigIconExists = (panelConfig) => {
return panelConfig && panelConfig.iconInfo;
};

const checkForAdmin = (currentUserEmail, currentUserRoles, packageEmail) => {
if(currentUserRoles.includes("uw_rit_kpmp_role_developer") || currentUserEmail === packageEmail){
return true;
}else {
return false;
}
}

const protectedAndMine = (panelConfig, currentEmail, packageEmail) => {
return panelConfig.iconInfo.isProtected && isMine(currentEmail, packageEmail);
};

export const getIcon = (state, isLargeFile, currentEmail, packageEmail, stateDisplayMap) => {
export const getIcon = (state, isLargeFile, currentUserEmail, currentUserRoles, packageEmail, stateDisplayMap) => {
let panelConfig = PANEL_CONFIGS[state];
if (panelConfigIconExists(panelConfig) && (protectedAndMine(panelConfig ,currentEmail, packageEmail) || !panelConfig.iconInfo.isProtected)) {
if (panelConfigIconExists(panelConfig) && (checkForAdmin(currentUserEmail, currentUserRoles, packageEmail) || !panelConfig.iconInfo.isProtected)) {
if ((panelConfig.iconInfo.isLargeFileOnly && isLargeFile) || !panelConfig.iconInfo.isLargeFileOnly) {
return panelConfig.iconInfo.type;
}
Expand Down
24 changes: 15 additions & 9 deletions src/components/Packages/packagePanelStateHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,55 @@ describe('getIcon', () => {
});

it('should not return an icon for FILES_RECEIVED state', () => {
let icon = getIcon('FILES_RECEIVED', false, 'xyz', 'xyz', stateDisplayMap);
let icon = getIcon('FILES_RECEIVED', false,'xyz', ['role'] ,'xyz', stateDisplayMap);
expect(icon).toBeUndefined();
});

it('should not return an icon for FILES_RECEIVED state, when shibIds do not match', () => {
let icon = getIcon('FILES_RECEIVED', false, 'abc', 'xyz', stateDisplayMap);
let icon = getIcon('FILES_RECEIVED', false, 'abc', ['role'], 'xyz', stateDisplayMap);
expect(icon).toBeUndefined();
});

it('should not return an icon for FILES_RECEIVED state, when large file upload', () => {
let icon = getIcon('FILES_RECEIVED', true, 'xyz', 'xyz', stateDisplayMap);
let icon = getIcon('FILES_RECEIVED', true, 'xyz', ['role'], 'xyz', stateDisplayMap);
expect(icon).toBeUndefined();
});

it('should not return an icon for UPLOAD_FAILED state', () => {
let icon = getIcon('UPLOAD_FAILED', false, 'xyz', 'xyz', stateDisplayMap);
let icon = getIcon('UPLOAD_FAILED', false, 'xyz', ['role'], 'xyz', stateDisplayMap);
expect(icon).toBeUndefined();
});

it('should not return an icon for UPLOAD_FAILED state when shibIds do not match', () => {
let icon = getIcon('UPLOAD_FAILED', false, 'abc', 'xyz', stateDisplayMap);
let icon = getIcon('UPLOAD_FAILED', false, 'abc', ['role'], 'xyz', stateDisplayMap);
expect(icon).toBeUndefined();
});

it('should not return an icon for UPLOAD_FAILED state whenis large file', () => {
let icon = getIcon('UPLOAD_FAILED', true, 'xyz', 'xyz', stateDisplayMap);
let icon = getIcon('UPLOAD_FAILED', true, 'xyz', ['role'], 'xyz', stateDisplayMap);
expect(icon).toBeUndefined();
});

it('should return faclock when METADATA_RECEIVED and it is my large file upload', () => {
let icon = getIcon('METADATA_RECEIVED', true, 'xyz', 'xyz', stateDisplayMap);
let icon = getIcon('METADATA_RECEIVED', true, 'xyz', ['role'], 'xyz', stateDisplayMap);
expect(icon).toBe(faClock);
});

it('should return faclock when METADATA_RECIEVED and role is uw_rit_kpmp_role_developer and package email does not match', () => {
let icon = getIcon('METADATA_RECEIVED', true, 'xyz', ['uw_rit_kpmp_role_developer'], 'xyz', stateDisplayMap);
expect(icon).toBe(faClock);
});

it('should return undefined when METADATA_RECEIVED and shibIds match, but not large file', () => {
let icon = getIcon('METADATA_RECEIVED', false, 'xyz', 'xyz', stateDisplayMap);
let icon = getIcon('METADATA_RECEIVED', false, 'xyz', ['role'], 'xyz', stateDisplayMap);
expect(icon).toBeUndefined();
});

it('should return undefined when METADATA_RECEIVED and shibIds do not match and is large file', () => {
let icon = getIcon('METADATA_RECEIVED', true, 'abc', 'xyz', stateDisplayMap);
let icon = getIcon('METADATA_RECEIVED', true, 'abc', ['role'], 'xyz', stateDisplayMap);
expect(icon).toBeUndefined();
});

});

describe('getMessage', () => {
Expand Down
Loading