Enable updates of devices and assets by assigned customer itself.
This commit is contained in:
parent
f7f6a59163
commit
3ca0288f3d
@ -28,8 +28,10 @@ import org.thingsboard.server.common.data.id.TenantId;
|
|||||||
import org.thingsboard.server.common.data.page.TextPageData;
|
import org.thingsboard.server.common.data.page.TextPageData;
|
||||||
import org.thingsboard.server.common.data.page.TextPageLink;
|
import org.thingsboard.server.common.data.page.TextPageLink;
|
||||||
import org.thingsboard.server.common.data.asset.AssetSearchQuery;
|
import org.thingsboard.server.common.data.asset.AssetSearchQuery;
|
||||||
|
import org.thingsboard.server.common.data.security.Authority;
|
||||||
import org.thingsboard.server.dao.exception.IncorrectParameterException;
|
import org.thingsboard.server.dao.exception.IncorrectParameterException;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
|
import org.thingsboard.server.exception.ThingsboardErrorCode;
|
||||||
import org.thingsboard.server.exception.ThingsboardException;
|
import org.thingsboard.server.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
|
|
||||||
@ -54,12 +56,21 @@ public class AssetController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/asset", method = RequestMethod.POST)
|
@RequestMapping(value = "/asset", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Asset saveAsset(@RequestBody Asset asset) throws ThingsboardException {
|
public Asset saveAsset(@RequestBody Asset asset) throws ThingsboardException {
|
||||||
try {
|
try {
|
||||||
asset.setTenantId(getCurrentUser().getTenantId());
|
asset.setTenantId(getCurrentUser().getTenantId());
|
||||||
|
if (getCurrentUser().getAuthority() == Authority.CUSTOMER_USER) {
|
||||||
|
if (asset.getId() == null || asset.getId().isNullUid() ||
|
||||||
|
asset.getCustomerId() == null || asset.getCustomerId().isNullUid()) {
|
||||||
|
throw new ThingsboardException("You don't have permission to perform this operation!",
|
||||||
|
ThingsboardErrorCode.PERMISSION_DENIED);
|
||||||
|
} else {
|
||||||
|
checkCustomerId(asset.getCustomerId());
|
||||||
|
}
|
||||||
|
}
|
||||||
return checkNotNull(assetService.saveAsset(asset));
|
return checkNotNull(assetService.saveAsset(asset));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
|
|||||||
@ -27,10 +27,12 @@ import org.thingsboard.server.common.data.id.DeviceId;
|
|||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.page.TextPageData;
|
import org.thingsboard.server.common.data.page.TextPageData;
|
||||||
import org.thingsboard.server.common.data.page.TextPageLink;
|
import org.thingsboard.server.common.data.page.TextPageLink;
|
||||||
|
import org.thingsboard.server.common.data.security.Authority;
|
||||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||||
import org.thingsboard.server.common.data.device.DeviceSearchQuery;
|
import org.thingsboard.server.common.data.device.DeviceSearchQuery;
|
||||||
import org.thingsboard.server.dao.exception.IncorrectParameterException;
|
import org.thingsboard.server.dao.exception.IncorrectParameterException;
|
||||||
import org.thingsboard.server.dao.model.ModelConstants;
|
import org.thingsboard.server.dao.model.ModelConstants;
|
||||||
|
import org.thingsboard.server.exception.ThingsboardErrorCode;
|
||||||
import org.thingsboard.server.exception.ThingsboardException;
|
import org.thingsboard.server.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
|
|
||||||
@ -55,12 +57,21 @@ public class DeviceController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/device", method = RequestMethod.POST)
|
@RequestMapping(value = "/device", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Device saveDevice(@RequestBody Device device) throws ThingsboardException {
|
public Device saveDevice(@RequestBody Device device) throws ThingsboardException {
|
||||||
try {
|
try {
|
||||||
device.setTenantId(getCurrentUser().getTenantId());
|
device.setTenantId(getCurrentUser().getTenantId());
|
||||||
|
if (getCurrentUser().getAuthority() == Authority.CUSTOMER_USER) {
|
||||||
|
if (device.getId() == null || device.getId().isNullUid() ||
|
||||||
|
device.getCustomerId() == null || device.getCustomerId().isNullUid()) {
|
||||||
|
throw new ThingsboardException("You don't have permission to perform this operation!",
|
||||||
|
ThingsboardErrorCode.PERMISSION_DENIED);
|
||||||
|
} else {
|
||||||
|
checkCustomerId(device.getCustomerId());
|
||||||
|
}
|
||||||
|
}
|
||||||
Device savedDevice = checkNotNull(deviceService.saveDevice(device));
|
Device savedDevice = checkNotNull(deviceService.saveDevice(device));
|
||||||
actorService
|
actorService
|
||||||
.onDeviceNameOrTypeUpdate(
|
.onDeviceNameOrTypeUpdate(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user