Skip to content

Commit

Permalink
added delete account button
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkonecn committed Mar 7, 2024
1 parent 18d4bcd commit 308c937
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 30 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import org.mskcc.cbio.oncokb.service.CompanyService;
import org.mskcc.cbio.oncokb.config.cache.CacheNameResolver;
import org.mskcc.cbio.oncokb.domain.Company;
import org.mskcc.cbio.oncokb.domain.User;
import org.mskcc.cbio.oncokb.domain.UserDetails;
import org.mskcc.cbio.oncokb.domain.enumeration.LicenseStatus;
import org.mskcc.cbio.oncokb.domain.enumeration.LicenseType;
import org.mskcc.cbio.oncokb.repository.CompanyRepository;
import org.mskcc.cbio.oncokb.repository.UserDetailsRepository;
import org.mskcc.cbio.oncokb.repository.UserRepository;
import org.mskcc.cbio.oncokb.service.dto.CompanyDTO;
import org.mskcc.cbio.oncokb.service.dto.UserDTO;
import org.mskcc.cbio.oncokb.service.mapper.CompanyDomainMapper;
Expand All @@ -16,6 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -49,6 +55,10 @@ public class CompanyServiceImpl implements CompanyService {

private final CacheNameResolver cacheNameResolver;

private final UserRepository userRepository;

private final UserDetailsRepository userDetailsRepository;

public CompanyServiceImpl(
CompanyRepository companyRepository,
CompanyMapper companyMapper,
Expand All @@ -57,14 +67,18 @@ public CompanyServiceImpl(
UserService userService,
UserMapper userMapper,
CacheManager cacheManager,
CacheNameResolver cacheNameResolver
CacheNameResolver cacheNameResolver,
UserRepository userRepository,
UserDetailsRepository userDetailsRepository
) {
this.companyRepository = companyRepository;
this.companyMapper = companyMapper;
this.userMapper = userMapper;
this.userService = userService;
this.cacheManager = cacheManager;
this.cacheNameResolver = cacheNameResolver;
this.userRepository = userRepository;
this.userDetailsRepository = userDetailsRepository;
}

@Override
Expand Down Expand Up @@ -168,8 +182,30 @@ public Optional<CompanyDTO> findOneByNameIgnoreCase(String name) {
}

@Override
@Transactional()
public void delete(Long id) {
log.debug("Request to delete Company : {}", id);
Optional<CompanyDTO> maybeCompanyDTO = this.findOne(id);
if (!maybeCompanyDTO.isPresent()) {
throw new EmptyResultDataAccessException("No class org.mskcc.cbio.oncokb.domain.Company entity with id " + id + " exists!", 0);
}

CompanyDTO companyDTO = maybeCompanyDTO.get();
Boolean isCommercial = companyDTO.getLicenseType().equals(LicenseType.COMMERCIAL);
List<UserDetails> userDetails = userDetailsRepository.findByCompanyId(id);
for (UserDetails userDetail : userDetails) {
userDetail.setCompany(null);
}

if (isCommercial) {
List<User> users = userDetails.stream().map(UserDetails::getUser).collect(Collectors.toList());
for (User user : users) {
user.setActivated(false);
}
userRepository.saveAll(users);
}

userDetailsRepository.saveAll(userDetails);
companyRepository.deleteById(id);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.mskcc.cbio.oncokb.web.rest;

import org.mskcc.cbio.oncokb.domain.Company;
import org.mskcc.cbio.oncokb.domain.User;
import org.mskcc.cbio.oncokb.domain.UserDetails;
import org.mskcc.cbio.oncokb.domain.enumeration.LicenseType;
import org.mskcc.cbio.oncokb.repository.CompanyRepository;
import org.mskcc.cbio.oncokb.repository.UserDetailsRepository;
import org.mskcc.cbio.oncokb.repository.UserRepository;
import org.mskcc.cbio.oncokb.security.AuthoritiesConstants;
import org.mskcc.cbio.oncokb.service.CompanyService;
import org.mskcc.cbio.oncokb.service.UserDetailsService;
import org.mskcc.cbio.oncokb.service.UserService;
import org.mskcc.cbio.oncokb.web.rest.errors.BadRequestAlertException;
import org.mskcc.cbio.oncokb.web.rest.vm.CompanyVM;
Expand Down Expand Up @@ -47,7 +52,10 @@ public class CompanyResource {

private final CompanyRepository companyRepository;

public CompanyResource(CompanyService companyService, UserService userService, CompanyRepository companyRepository) {
public CompanyResource(
CompanyService companyService,
UserService userService,
CompanyRepository companyRepository) {
this.companyService = companyService;
this.userService = userService;
this.companyRepository = companyRepository;
Expand Down Expand Up @@ -174,4 +182,17 @@ public ResponseEntity<Boolean> verifyCompanyName(@Valid @RequestBody VerifyCompa
}
return new ResponseEntity<>(isValid, HttpStatus.OK);
}

/**
* {@code DELETE /companies/:id} : delete the "id" company.
*
* @param id the id of the companyDTO to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/companies/{id}")
public ResponseEntity<Void> deleteCompany(@PathVariable Long id) {
log.debug("REST request to delete Company : {}", id);
companyService.delete(id);
return ResponseEntity.ok().build();
}
}
141 changes: 113 additions & 28 deletions src/main/webapp/app/pages/companyPage/CompanyPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { observer } from 'mobx-react';
import { inject, observer } from 'mobx-react';
import { getSectionClassName } from 'app/pages/account/AccountUtils';
import { AvField, AvForm } from 'availity-reactstrap-validation';
import {
Expand All @@ -10,6 +10,7 @@ import {
LicenseModel,
LicenseStatus,
PAGE_ROUTE,
REDIRECT_TIMEOUT_MILLISECONDS,
} from 'app/config/constants';
import { Alert, Button, Col, Row } from 'react-bootstrap';
import {
Expand Down Expand Up @@ -67,11 +68,16 @@ import {
import UsageText from 'app/shared/texts/UsageText';
import { DateSelector } from 'app/components/dateSelector/DateSelector';
import { DownloadButton } from 'app/components/downloadButton/DownloadButton';
import { RouterStore } from 'mobx-react-router';

interface MatchParams {
id: string;
}

interface ICompanyPage extends RouteComponentProps<MatchParams> {
routing: RouterStore;
}

type SelectOptionType = {
label: string;
value: string;
Expand All @@ -97,18 +103,23 @@ const LICENSE_STATUS_UPDATE_MESSAGES = {
},
};

enum SimpleConfirmModalType {
NA,
DELETE_COMPANY,
UPDATE_COMPANY,
}

@inject('routing')
@observer
export default class CompanyPage extends React.Component<
RouteComponentProps<MatchParams>
> {
export default class CompanyPage extends React.Component<ICompanyPage> {
@observable getCompanyStatus = PromiseStatus.pending;
@observable getCompanyUsersStatus = PromiseStatus.pending;
@observable getDropdownUsersStatus = PromiseStatus.pending;

@observable selectedLicenseStatus: LicenseStatus;
@observable conflictingDomains: string[] = [];

@observable showLicenseChangeModal = false;
@observable showModal = false;
@observable confirmLicenseChangeModalText = '';
@observable formValues: any;

Expand All @@ -118,10 +129,13 @@ export default class CompanyPage extends React.Component<
@observable dropDownUsers: SelectOptionType[] = [];
@observable selectedUsersOptions: SelectOptionType[] = [];

@observable simpleConfirmModalType: SimpleConfirmModalType =
SimpleConfirmModalType.NA;

@observable resourcesTypeToggleValue: ToggleValue =
ToggleValue.PUBLIC_RESOURCES;

constructor(props: RouteComponentProps<MatchParams>) {
constructor(props: ICompanyPage) {
super(props);
this.getCompany();
this.getDropdownUsers();
Expand Down Expand Up @@ -182,8 +196,8 @@ export default class CompanyPage extends React.Component<
}

@action.bound
updateCompany() {
this.showLicenseChangeModal = false;
onConfirmUpdateCompany() {
this.showModal = false;
this.getCompanyStatus = PromiseStatus.pending;
this.getCompanyUsersStatus = PromiseStatus.pending;
this.getDropdownUsersStatus = PromiseStatus.pending;
Expand Down Expand Up @@ -218,6 +232,38 @@ export default class CompanyPage extends React.Component<
});
}

@autobind
onConfirmDeleteAccountButton() {
this.showModal = false;
client.deleteCompanyUsingDELETE({ id: this.company.id }).then(
() => {
notifySuccess(
'Deleted company, we will redirect you to the company details page.'
);
setTimeout(() => {
this.props.routing.history.push(PAGE_ROUTE.ADMIN_COMPANY_DETAILS);
}, REDIRECT_TIMEOUT_MILLISECONDS);
},
(error: Error) => notifyError(error)
);
}

@autobind
onConfirmSimpleConfirmModal() {
switch (this.simpleConfirmModalType) {
case SimpleConfirmModalType.UPDATE_COMPANY:
this.onConfirmUpdateCompany();
break;
case SimpleConfirmModalType.DELETE_COMPANY:
this.onConfirmDeleteAccountButton();
break;
case SimpleConfirmModalType.NA:
default:
break;
}
this.simpleConfirmModalType = SimpleConfirmModalType.NA;
}

@action.bound
async verifyUserEmail(user: UserDTO) {
try {
Expand Down Expand Up @@ -247,13 +293,13 @@ export default class CompanyPage extends React.Component<
this.company.licenseStatus !== this.selectedLicenseStatus &&
this.companyUsers.length > 0
) {
this.showLicenseChangeModal = true;
this.showModal = true;
this.confirmLicenseChangeModalText =
LICENSE_STATUS_UPDATE_MESSAGES[this.company.licenseStatus][
this.selectedLicenseStatus
];
} else {
this.updateCompany();
this.onConfirmUpdateCompany();
}
}

Expand Down Expand Up @@ -323,23 +369,41 @@ export default class CompanyPage extends React.Component<
option => !hideOptions.includes(option.value)
);
}
@computed
get licenseChangeModalTitle() {
if (this.simpleConfirmModalType === SimpleConfirmModalType.UPDATE_COMPANY) {
return 'Review Company Changes';
} else if (
this.simpleConfirmModalType === SimpleConfirmModalType.DELETE_COMPANY
) {
return 'Confirm Deleting Company';
}
}

@computed
get licenseChangeModalBody() {
return (
<>
<div>
Are you sure you want to change the company's license status from{' '}
<span className="font-weight-bold">{this.company.licenseStatus}</span>{' '}
to{' '}
<span className="font-weight-bold">{this.selectedLicenseStatus}</span>
?
</div>
<Alert variant={'warning'} style={{ marginTop: '20px' }}>
Warning: {this.confirmLicenseChangeModalText}
</Alert>
</>
);
if (this.simpleConfirmModalType === SimpleConfirmModalType.UPDATE_COMPANY) {
return (
<>
<div>
Are you sure you want to change the company's license status from{' '}
<span className="font-weight-bold">
{this.company.licenseStatus}
</span>{' '}
to{' '}
<span className="font-weight-bold">
{this.selectedLicenseStatus}
</span>
?
</div>
<Alert variant={'warning'} style={{ marginTop: '20px' }}>
Warning: {this.confirmLicenseChangeModalText}
</Alert>
</>
);
} else {
return undefined;
}
}

@computed
Expand Down Expand Up @@ -876,13 +940,34 @@ export default class CompanyPage extends React.Component<
</Button>
</Col>
</Row>
<Row>
<Col className={getSectionClassName()}>
<div className={'my-2 text-danger'}>Danger Zone</div>
<div>
<Button
variant="danger"
onClick={() => {
this.showModal = true;
this.simpleConfirmModalType =
SimpleConfirmModalType.DELETE_COMPANY;
}}
>
Delete Account
</Button>
</div>
</Col>
</Row>
</AvForm>
<SimpleConfirmModal
show={this.showLicenseChangeModal}
title={'Review Company Changes'}
key="company-page-simple-confirm-modal"
show={this.showModal}
title={this.licenseChangeModalTitle}
body={this.licenseChangeModalBody}
onCancel={() => (this.showLicenseChangeModal = false)}
onConfirm={this.updateCompany}
onCancel={() => {
this.showModal = false;
this.simpleConfirmModalType = SimpleConfirmModalType.NA;
}}
onConfirm={this.onConfirmSimpleConfirmModal}
/>
</>
</DocumentTitle>
Expand Down
Loading

0 comments on commit 308c937

Please sign in to comment.