Add maxResourceSize to SystemParams
This commit is contained in:
parent
d788b00a69
commit
58cf97f68a
@ -16,8 +16,6 @@
|
||||
package org.thingsboard.server.controller;
|
||||
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -51,7 +49,6 @@ import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.security.Authority;
|
||||
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
|
||||
import org.thingsboard.server.common.data.util.ThrowingSupplier;
|
||||
import org.thingsboard.server.dao.resource.ImageCacheKey;
|
||||
import org.thingsboard.server.dao.resource.ImageService;
|
||||
@ -284,19 +281,6 @@ public class ImageController extends BaseController {
|
||||
return (result.isSuccess() ? ResponseEntity.ok() : ResponseEntity.badRequest()).body(result);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@GetMapping("/api/image/specs")
|
||||
public ImageSpecs getImageUploadSpecs() throws ThingsboardException {
|
||||
SecurityUser user = getCurrentUser();
|
||||
if (user.isSystemAdmin()) {
|
||||
return ImageSpecs.DEFAULT;
|
||||
}
|
||||
DefaultTenantProfileConfiguration tenantProfileConfig = tenantProfileCache.get(user.getTenantId()).getDefaultProfileConfiguration();
|
||||
return ImageSpecs.builder()
|
||||
.maximumSize(tenantProfileConfig.getMaxResourceSize())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ResponseEntity<ByteArrayResource> downloadIfChanged(String type, String key, String etag, boolean preview) throws Exception {
|
||||
ImageCacheKey cacheKey = ImageCacheKey.forImage(getTenantId(type), key, preview);
|
||||
return downloadIfChanged(cacheKey, etag, () -> checkImageInfo(type, key, Operation.READ));
|
||||
@ -359,14 +343,4 @@ public class ImageController extends BaseController {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public static class ImageSpecs {
|
||||
private final long maximumSize;
|
||||
|
||||
public static final ImageSpecs DEFAULT = ImageSpecs.builder()
|
||||
.maximumSize(0)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -35,6 +35,7 @@ import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.settings.UserSettings;
|
||||
import org.thingsboard.server.common.data.settings.UserSettingsType;
|
||||
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
|
||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
import org.thingsboard.server.service.security.model.UserPrincipal;
|
||||
@ -130,6 +131,10 @@ public class SystemInfoController extends BaseController {
|
||||
}
|
||||
systemParams.setUserSettings(userSettingsNode);
|
||||
systemParams.setMaxDatapointsLimit(maxDatapointsLimit);
|
||||
if (!currentUser.isSystemAdmin()) {
|
||||
DefaultTenantProfileConfiguration tenantProfileConfiguration = tenantProfileCache.get(tenantId).getDefaultProfileConfiguration();
|
||||
systemParams.setMaxResourceSize(tenantProfileConfiguration.getMaxResourceSize());
|
||||
}
|
||||
return systemParams;
|
||||
}
|
||||
|
||||
|
||||
@ -30,10 +30,10 @@ import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.ImageDescriptor;
|
||||
import org.thingsboard.server.common.data.ImageExportData;
|
||||
import org.thingsboard.server.common.data.ResourceType;
|
||||
import org.thingsboard.server.common.data.SystemParams;
|
||||
import org.thingsboard.server.common.data.TbResourceInfo;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.controller.ImageController.ImageSpecs;
|
||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||
import org.thingsboard.server.dao.sql.resource.TbResourceRepository;
|
||||
|
||||
@ -243,24 +243,24 @@ public class ImageControllerTest extends AbstractControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetImageUploadSpecs() throws Exception {
|
||||
ImageSpecs specs = doGet("/api/image/specs", ImageSpecs.class);
|
||||
assertThat(specs.getMaximumSize()).isZero();
|
||||
SystemParams systemParams = doGet("/api/system/params", SystemParams.class);
|
||||
assertThat(systemParams.getMaxResourceSize()).isZero();
|
||||
|
||||
loginSysAdmin();
|
||||
updateDefaultTenantProfileConfig(tenantProfileConfig -> {
|
||||
tenantProfileConfig.setMaxResourceSize(100);
|
||||
});
|
||||
loginTenantAdmin();
|
||||
specs = doGet("/api/image/specs", ImageSpecs.class);
|
||||
assertThat(specs.getMaximumSize()).isEqualTo(100);
|
||||
systemParams = doGet("/api/system/params", SystemParams.class);
|
||||
assertThat(systemParams.getMaxResourceSize()).isEqualTo(100);
|
||||
|
||||
loginSysAdmin();
|
||||
updateDefaultTenantProfileConfig(tenantProfileConfig -> {
|
||||
tenantProfileConfig.setMaxResourceSize(0);
|
||||
});
|
||||
loginTenantAdmin();
|
||||
specs = doGet("/api/image/specs", ImageSpecs.class);
|
||||
assertThat(specs.getMaximumSize()).isEqualTo(0);
|
||||
systemParams = doGet("/api/system/params", SystemParams.class);
|
||||
assertThat(systemParams.getMaxResourceSize()).isEqualTo(0);
|
||||
}
|
||||
|
||||
private TbResourceInfo updateImagePublicStatus(String filename, boolean isPublic) throws Exception {
|
||||
|
||||
@ -30,4 +30,5 @@ public class SystemParams {
|
||||
boolean persistDeviceStateToTelemetry;
|
||||
JsonNode userSettings;
|
||||
long maxDatapointsLimit;
|
||||
long maxResourceSize;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user