Merge pull request #6875 from YevhenBondarenko/fix/device-profile
[3.4] added device-profile read permissions for the customer
This commit is contained in:
commit
28858f0f83
@ -42,6 +42,7 @@ public class CustomerUserPermissions extends AbstractPermissions {
|
|||||||
put(Resource.WIDGET_TYPE, widgetsPermissionChecker);
|
put(Resource.WIDGET_TYPE, widgetsPermissionChecker);
|
||||||
put(Resource.EDGE, customerEntityPermissionChecker);
|
put(Resource.EDGE, customerEntityPermissionChecker);
|
||||||
put(Resource.RPC, rpcPermissionChecker);
|
put(Resource.RPC, rpcPermissionChecker);
|
||||||
|
put(Resource.DEVICE_PROFILE, deviceProfilePermissionChecker);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final PermissionChecker customerAlarmPermissionChecker = new PermissionChecker() {
|
private static final PermissionChecker customerAlarmPermissionChecker = new PermissionChecker() {
|
||||||
@ -152,4 +153,19 @@ public class CustomerUserPermissions extends AbstractPermissions {
|
|||||||
return user.getTenantId().equals(entity.getTenantId());
|
return user.getTenantId().equals(entity.getTenantId());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final PermissionChecker deviceProfilePermissionChecker = new PermissionChecker.GenericPermissionChecker(Operation.READ) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) {
|
||||||
|
if (!super.hasPermission(user, operation, entityId, entity)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (entity.getTenantId() == null || entity.getTenantId().isNullUid()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return user.getTenantId().equals(entity.getTenantId());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import org.junit.Assert;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.thingsboard.server.common.data.Customer;
|
||||||
import org.thingsboard.server.common.data.Device;
|
import org.thingsboard.server.common.data.Device;
|
||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
import org.thingsboard.server.common.data.DeviceProfileInfo;
|
||||||
@ -170,6 +171,25 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
|
|||||||
Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId());
|
Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId());
|
||||||
Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName());
|
Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName());
|
||||||
Assert.assertEquals(savedDeviceProfile.getType(), foundDeviceProfileInfo.getType());
|
Assert.assertEquals(savedDeviceProfile.getType(), foundDeviceProfileInfo.getType());
|
||||||
|
|
||||||
|
Customer customer = new Customer();
|
||||||
|
customer.setTitle("Customer");
|
||||||
|
customer.setTenantId(savedTenant.getId());
|
||||||
|
Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
|
||||||
|
|
||||||
|
User customerUser = new User();
|
||||||
|
customerUser.setAuthority(Authority.CUSTOMER_USER);
|
||||||
|
customerUser.setTenantId(savedTenant.getId());
|
||||||
|
customerUser.setCustomerId(savedCustomer.getId());
|
||||||
|
customerUser.setEmail("customer2@thingsboard.org");
|
||||||
|
|
||||||
|
createUserAndLogin(customerUser, "customer");
|
||||||
|
|
||||||
|
foundDeviceProfileInfo = doGet("/api/deviceProfileInfo/" + savedDeviceProfile.getId().getId().toString(), DeviceProfileInfo.class);
|
||||||
|
Assert.assertNotNull(foundDeviceProfileInfo);
|
||||||
|
Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId());
|
||||||
|
Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName());
|
||||||
|
Assert.assertEquals(savedDeviceProfile.getType(), foundDeviceProfileInfo.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user