Merge pull request #13192 from dashevchenko/customerDataFix

Fixed Customer permission checks
This commit is contained in:
Viacheslav Klimov 2025-04-12 14:18:29 +03:00 committed by GitHub
commit 25c6519545
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View File

@ -1116,6 +1116,29 @@ public class EntityServiceTest extends AbstractControllerTest {
assertThat(deviceName).isEqualTo(devices.get(0).getName()); assertThat(deviceName).isEqualTo(devices.get(0).getName());
} }
@Test
public void testFindCustomerBySingleEntityFilter() {
SingleEntityFilter singleEntityFilter = new SingleEntityFilter();
singleEntityFilter.setSingleEntity(customerId);
List<EntityKey> entityFields = List.of(
new EntityKey(EntityKeyType.ENTITY_FIELD, "name")
);
EntityDataPageLink pageLink = new EntityDataPageLink(1000, 0, null, null);
EntityDataQuery query = new EntityDataQuery(singleEntityFilter, pageLink, entityFields, null, null);
//find by tenant
PageData<EntityData> result = findByQueryAndCheck(query, 1);
String customerName = result.getData().get(0).getLatest().get(EntityKeyType.ENTITY_FIELD).get("name").getValue();
assertThat(customerName).isEqualTo(TEST_CUSTOMER_NAME);
// find by customer user
PageData<EntityData> customerResults = findByQueryAndCheck(customerId, query, 1);
customerName = customerResults.getData().get(0).getLatest().get(EntityKeyType.ENTITY_FIELD).get("name").getValue();
assertThat(customerName).isEqualTo(TEST_CUSTOMER_NAME);
}
@Test @Test
public void testFindEntitiesByRelationEntityTypeFilter() { public void testFindEntitiesByRelationEntityTypeFilter() {
Customer customer = new Customer(); Customer customer = new Customer();

View File

@ -64,8 +64,9 @@ public abstract class AbstractQueryProcessor<T extends EntityFilter> implements
} }
protected static boolean checkCustomerId(UUID customerId, EntityData<?> ed) { protected static boolean checkCustomerId(UUID customerId, EntityData<?> ed) {
return customerId.equals(ed.getCustomerId()) || (ed.getEntityType() == EntityType.DASHBOARD && return customerId.equals(ed.getCustomerId())
ed.getFields().getAssignedCustomerIds().contains(customerId)); || (ed.getEntityType() == EntityType.DASHBOARD && ed.getFields().getAssignedCustomerIds().contains(customerId))
|| (ed.getEntityType() == EntityType.CUSTOMER && customerId.equals(ed.getId()));
} }
protected boolean matches(EntityData<?> ed) { protected boolean matches(EntityData<?> ed) {