Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.park.utmstack.service;

import com.park.utmstack.config.Constants;
import com.park.utmstack.domain.User;
import com.park.utmstack.domain.UtmConfigurationParameter;
import com.park.utmstack.repository.UtmConfigurationParameterRepository;
import com.park.utmstack.util.CipherUtil;
import com.park.utmstack.util.exceptions.UtmMailException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
Expand All @@ -33,17 +36,23 @@ public class UtmConfigurationParameterService {
private static final String CLASSNAME = "UtmConfigurationParameterService";
private final Logger log = LoggerFactory.getLogger(UtmConfigurationParameterService.class);

private final UtmConfigurationParameterRepository utmConfigurationParameterRepository;
private final UtmConfigurationParameterRepository configParamRepository;
private final UserService userService;
private final MailService mailService;

public UtmConfigurationParameterService(UtmConfigurationParameterRepository utmConfigurationParameterRepository) {
this.utmConfigurationParameterRepository = utmConfigurationParameterRepository;
public UtmConfigurationParameterService(UtmConfigurationParameterRepository configParamRepository,
UserService userService,
MailService mailService) {
this.configParamRepository = configParamRepository;
this.userService = userService;
this.mailService = mailService;
}

@EventListener(ApplicationReadyEvent.class)
public void init() {
final String ctx = CLASSNAME + ".init";
try {
List<UtmConfigurationParameter> params = utmConfigurationParameterRepository.findAll();
List<UtmConfigurationParameter> params = configParamRepository.findAll();
if (CollectionUtils.isEmpty(params))
return;
params.forEach(p -> {
Expand All @@ -57,17 +66,25 @@ public void init() {
}
}

public void saveAll(List<UtmConfigurationParameter> parameters) throws Exception {
public void saveAll(List<UtmConfigurationParameter> params) throws UtmMailException {
final String ctx = CLASSNAME + ".saveAll";
try {
// If the configuration to save is: Enable Two-Factor Authentication then we need to check
// if the email configuration is OK
params.stream().filter(p -> p.getConfParamShort().equals(Constants.PROP_TFA_ENABLE)
&& Boolean.parseBoolean(p.getConfParamValue()))
.findFirst().ifPresent(tfa -> validateMailConfOnMFAActivation());

Map<String, String> cfg = new HashMap<>();
parameters.forEach(p -> {
for (UtmConfigurationParameter p : params) {
cfg.put(p.getConfParamShort(), p.getConfParamValue());
if (StringUtils.hasText(p.getConfParamValue()) && p.getConfParamDatatype().equalsIgnoreCase("password"))
p.setConfParamValue(CipherUtil.encrypt(p.getConfParamValue(), System.getenv(Constants.ENV_ENCRYPTION_KEY)));
});
utmConfigurationParameterRepository.saveAll(parameters);
}
configParamRepository.saveAll(params);
Constants.CFG.putAll(cfg);
} catch (UtmMailException e) {
throw new UtmMailException(ctx + ": " + e.getMessage());
} catch (Exception e) {
throw new RuntimeException(ctx + ": " + e.getMessage());
}
Expand All @@ -82,7 +99,7 @@ public void saveAll(List<UtmConfigurationParameter> parameters) throws Exception
@Transactional(readOnly = true)
public Page<UtmConfigurationParameter> findAll(Pageable pageable) {
log.debug("Request to get all UtmConfigurationParameters");
return utmConfigurationParameterRepository.findAll(pageable);
return configParamRepository.findAll(pageable);
}


Expand All @@ -95,7 +112,7 @@ public Page<UtmConfigurationParameter> findAll(Pageable pageable) {
@Transactional(readOnly = true)
public Optional<UtmConfigurationParameter> findOne(Long id) {
log.debug("Request to get UtmConfigurationParameter : {}", id);
return utmConfigurationParameterRepository.findById(id);
return configParamRepository.findById(id);
}

/**
Expand All @@ -105,18 +122,27 @@ public Optional<UtmConfigurationParameter> findOne(Long id) {
*/
public void delete(Long id) {
log.debug("Request to delete UtmConfigurationParameter : {}", id);
utmConfigurationParameterRepository.deleteById(id);
configParamRepository.deleteById(id);
}

public Map<String, String> getValueMapForDateSetting() throws Exception {
final String ctx = CLASSNAME + ".getValueMapForDateSetting";
try {
return utmConfigurationParameterRepository
.findAllBySectionId(DATE_FORMAT_SETTING_ID).stream()
.collect(Collectors.toMap(UtmConfigurationParameter::getConfParamShort,
UtmConfigurationParameter::getConfParamValue));
return configParamRepository
.findAllBySectionId(DATE_FORMAT_SETTING_ID).stream()
.collect(Collectors.toMap(UtmConfigurationParameter::getConfParamShort,
UtmConfigurationParameter::getConfParamValue));
} catch (Exception e) {
throw new Exception(ctx + ": " + e.getMessage());
}
}

private void validateMailConfOnMFAActivation() throws UtmMailException {
final String ctx = CLASSNAME + ".validateMailConfOnMFAActivation";
try {
mailService.sendCheckEmail(List.of(userService.getCurrentUserLogin().getEmail()));
} catch (Exception e) {
throw new UtmMailException(ctx + ": " + e.getLocalizedMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ public static <T> ResponseEntity<T> buildLockedResponse(String msg) {
public static <T> ResponseEntity<T> buildUnauthorizedResponse(String msg) {
return buildErrorResponse(HttpStatus.UNAUTHORIZED, msg);
}

public static <T> ResponseEntity<T> buildPreconditionFailedResponse(String msg) {
return buildErrorResponse(HttpStatus.PRECONDITION_FAILED, msg);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.park.utmstack.util.exceptions;

public class UtmMailException extends RuntimeException {
public UtmMailException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import com.park.utmstack.service.UtmConfigurationParameterService;
import com.park.utmstack.service.application_events.ApplicationEventService;
import com.park.utmstack.service.dto.UtmConfigurationParameterCriteria;
import com.park.utmstack.web.rest.util.HeaderUtil;
import com.park.utmstack.util.UtilResponse;
import com.park.utmstack.util.exceptions.UtmMailException;
import com.park.utmstack.web.rest.util.PaginationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
Expand All @@ -33,13 +33,10 @@ public class UtmConfigurationParameterResource {

private final Logger log = LoggerFactory.getLogger(UtmConfigurationParameterResource.class);

private static final String ENTITY_NAME = "utmConfigurationParameter";
private static final String CLASSNAME = "UtmConfigurationParameterResource";

private final UtmConfigurationParameterService utmConfigurationParameterService;

private final UtmConfigurationParameterQueryService utmConfigurationParameterQueryService;

private final ApplicationEventService applicationEventService;

public UtmConfigurationParameterResource(UtmConfigurationParameterService utmConfigurationParameterService,
Expand All @@ -64,12 +61,21 @@ public ResponseEntity<Void> updateConfigurationParameters(@Valid @RequestBody Li
Assert.notEmpty(parameters, "There isn't any parameter to update");
utmConfigurationParameterService.saveAll(parameters);
return ResponseEntity.ok().build();
} catch (UtmMailException e) {
String msg = ctx + ": " + e.getMessage();
log.error(msg);
applicationEventService.createEvent(msg, ApplicationEventType.ERROR);
return UtilResponse.buildPreconditionFailedResponse(msg);
} catch (IllegalArgumentException e) {
String msg = ctx + ": " + e.getMessage();
log.error(msg);
applicationEventService.createEvent(msg, ApplicationEventType.ERROR);
return UtilResponse.buildBadRequestResponse(msg);
} catch (Exception e) {
String msg = ctx + ": " + e.getMessage();
log.error(msg);
applicationEventService.createEvent(msg, ApplicationEventType.ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(
HeaderUtil.createFailureAlert("", "", msg)).body(null);
return UtilResponse.buildInternalServerErrorResponse(msg);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<button #tagPopober=ngbPopover *ngIf="typeFormat==='button';else icon"
<button #tagPopoverButton=ngbPopover *ngIf="typeFormat==='button';else icon"
[ngbPopover]="colContent"
[popoverTitle]="colTitle"
autoClose="outside"
class="p-1 text-blue-800 font-weight-light"
container="body"
id="statusId"
placement="auto"
popoverClass="utm-popover"
popoverClass="utm-popover popover-group"
triggers="click">
<span>
<i *ngIf="creating" class="icon-spinner2 spinner"></i>
Expand All @@ -18,7 +18,7 @@
container="body"
placement="auto"
tooltipClass="utm-tooltip-top">
<span #tagPopober=ngbPopover
<span #tagPopoverSpan=ngbPopover
(click)="getGroups($event)"
[ngClass]="{'text-blue-800':group}"
[ngbPopover]="colContent"
Expand All @@ -27,7 +27,7 @@
class="position-relative cursor-pointer small-md-icon"
container="body"
placement="auto"
popoverClass="utm-popover"
popoverClass="utm-popover popover-group"
triggers="click">
<i [ngClass]="creating?'icon-spinner2 spinner':getIcon(group)"></i>
<span *ngIf="showTypeLabel" class="ml-2">
Expand All @@ -38,15 +38,19 @@
</ng-template>

<ng-template #colContent>
<ng-select
<ng-select #select
[(ngModel)]="group"
[clearable]="true"
[clearable]="false"
[items]="groups"
[loadingText]="'Loading groups....'"
[loading]="loading"
bindLabel="groupName"
class="mt-2 mb-2"
id="id" style="min-width: 200px">
<ng-template ng-label-tmp let-item="item" let-clear="clear">
{{item.groupName}}
<span style="position:relative; z-index: 1; cursor: pointer; float: right" (click)="handleClear(select)">&times;</span>
</ng-template>
</ng-select>

<div class="d-flex justify-content-center align-items-center p-1">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
import {NgbModal, NgbPopover} from '@ng-bootstrap/ng-bootstrap';
import {NgSelectComponent} from '@ng-select/ng-select';
import {UtmToastService} from '../../../../shared/alert/utm-toast.service';
import {AssetGroupCreateComponent} from '../../../asset-groups/asset-group-create/asset-group-create.component';
import {AssetGroupType} from '../../../asset-groups/shared/type/asset-group.type';
Expand All @@ -19,6 +20,8 @@ export class AssetGroupAddComponent implements OnInit {
@Input() assets: number[];
@Input() group: AssetGroupType;
@Output() applyGroupEvent = new EventEmitter<AssetGroupType>();
@ViewChild('tagPopoverSpan') tagPopoverSpan: NgbPopover;
@ViewChild('tagPopoverButton') tagPopoverButton: NgbPopover;
groups: AssetGroupType[];
loading = false;
creating = false;
Expand Down Expand Up @@ -58,10 +61,12 @@ export class AssetGroupAddComponent implements OnInit {
this.applyGroupEvent.emit(response.body);
this.assetReloadFilterBehavior.$assetReloadFilter.next(AssetFieldFilterEnum.GROUP);
this.creating = false;
this.closePopover();
}, error => {
this.utmToastService.showError('Error changing group',
'Error changing group, please try again');
this.creating = false;
this.closePopover();
});
}

Expand All @@ -70,8 +75,22 @@ export class AssetGroupAddComponent implements OnInit {
}

addNewGroup() {
this.closePopover();
const modalGroup = this.modalService.open(AssetGroupCreateComponent, {centered: true});
}

protected readonly event = event;
handleClear(select: NgSelectComponent) {
this.group = null;
select.close();
}

closePopover() {
if (this.tagPopoverSpan) {
this.tagPopoverSpan.close();
}

if (this.tagPopoverButton) {
this.tagPopoverButton.close();
}
}
}
6 changes: 6 additions & 0 deletions frontend/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1286,5 +1286,11 @@ $topnav-background-color: #FFFFFF;
}
}

.popover-group{
.ng-select.ng-select-single .ng-select-container .ng-value-container .ng-value{
width: 100%;
}
}



2 changes: 1 addition & 1 deletion installer/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (c *Compose) Populate(conf *Config, stack *StackConfig) *Compose {
}

c.Services["filebrowser"] = Service{
Image: utils.Str("utmstack.azurecr.io/filebrowser:" + conf.Branch),
Image: utils.Str("ghcr.io/utmstack/filebrowser/filebrowser:" + conf.Branch),
Volumes: []string{
stack.Rules + ":/srv",
},
Expand Down