Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring
This commit is contained in:
commit
0bfaad2906
|
@ -27,7 +27,7 @@ public interface UserService {
|
|||
|
||||
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
||||
|
||||
byte[] exportCsv() throws IOException;
|
||||
byte[] exportCsv(boolean hasTenantAdminMode) throws IOException, InvalidApplicationException;
|
||||
|
||||
User patchRoles(UserRolePatchPersist model, FieldSet fields) throws InvalidApplicationException;
|
||||
|
||||
|
|
|
@ -296,11 +296,18 @@ public class UserServiceImpl implements UserService {
|
|||
//region export
|
||||
|
||||
@Override
|
||||
public byte[] exportCsv() throws IOException {
|
||||
public byte[] exportCsv(boolean hasTenantAdminMode) throws IOException, InvalidApplicationException {
|
||||
this.authorizationService.authorizeForce(Permission.ExportUsers);
|
||||
|
||||
FieldSet fieldSet = new BaseFieldSet().ensure(User._id).ensure(User._name).ensure(User._contacts + "." + UserContactInfo._value).ensure(User._contacts + "." + UserContactInfo._type);
|
||||
List<User> users = this.builderFactory.builder(UserBuilder.class).build(fieldSet, this.queryFactory.query(UserQuery.class).disableTracking().collectAs(fieldSet));
|
||||
List<User> users = null;
|
||||
if (hasTenantAdminMode && !this.tenantScope.getTenantCode().equals(this.tenantScope.getDefaultTenantCode())){
|
||||
if (this.tenantScope.getTenant() == null) throw new MyApplicationException("Tenant not found");
|
||||
TenantUserQuery tenantUserQuery = this.queryFactory.query(TenantUserQuery.class).disableTracking().authorize(AuthorizationFlags.AllExceptPublic).tenantIds(this.tenantScope.getTenant()).isActive(IsActive.Active);
|
||||
users = this.builderFactory.builder(UserBuilder.class).build(fieldSet, this.queryFactory.query(UserQuery.class).tenantUserSubQuery(tenantUserQuery).isActive(IsActive.Active).disableTracking().collectAs(fieldSet));
|
||||
} else {
|
||||
users = this.builderFactory.builder(UserBuilder.class).build(fieldSet, this.queryFactory.query(UserQuery.class).disableTracking().isActive(IsActive.Active).collectAs(fieldSet));
|
||||
}
|
||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
final CSVFormat format = CSVFormat.DEFAULT.withHeader("User Id", "User Name", "User Email").withQuoteMode(QuoteMode.NON_NUMERIC);
|
||||
final CSVPrinter csvPrinter = new CSVPrinter(new PrintWriter(out), format);
|
||||
|
|
|
@ -162,14 +162,15 @@ public class UserController {
|
|||
return model;
|
||||
}
|
||||
|
||||
@GetMapping("/export/csv")
|
||||
public ResponseEntity<byte[]> exportCsv() throws MyApplicationException, MyForbiddenException, MyNotFoundException, IOException {
|
||||
logger.debug(new MapLogEntry("export" + User.class.getSimpleName()));
|
||||
@GetMapping("/export/csv/{hasTenantAdminMode}")
|
||||
public ResponseEntity<byte[]> exportCsv(@PathVariable("hasTenantAdminMode") Boolean hasTenantAdminMode) throws MyApplicationException, MyForbiddenException, MyNotFoundException, IOException, InvalidApplicationException {
|
||||
logger.debug(new MapLogEntry("export" + User.class.getSimpleName()).And("hasTenantAdminMode", hasTenantAdminMode));
|
||||
|
||||
// this.censorFactory.censor(UserCensor.class).censor(fieldSet, null);
|
||||
byte[] bytes = this.userTypeService.exportCsv();
|
||||
byte[] bytes = this.userTypeService.exportCsv(hasTenantAdminMode);
|
||||
|
||||
this.auditService.track(AuditableAction.User_ExportCsv, Map.ofEntries(
|
||||
new AbstractMap.SimpleEntry<String, Object>("hasTenantAdminMode", hasTenantAdminMode)
|
||||
));
|
||||
|
||||
return this.responseUtilsService.buildResponseFileFromText(new String(bytes, StandardCharsets.UTF_8), "Users_dump.csv");
|
||||
|
|
|
@ -314,6 +314,7 @@ permissions:
|
|||
roles:
|
||||
- Admin
|
||||
- InstallationAdmin
|
||||
- TenantAdmin
|
||||
claims: [ ]
|
||||
clients: [ ]
|
||||
allowAnonymous: false
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button mat-raised-button class="create-btn" (click)="export()" *ngIf="authService.hasPermission(authService.permissionEnum.ExportUsers) && !hasTenantAdminMode">
|
||||
<button mat-raised-button class="create-btn" (click)="export()" *ngIf="authService.hasPermission(authService.permissionEnum.ExportUsers)">
|
||||
<mat-icon>download</mat-icon>
|
||||
{{'USER-LISTING.ACTIONS.EXPORT' | translate}}
|
||||
</button>
|
||||
|
|
Loading…
Reference in New Issue