select users for indicator access by role

This commit is contained in:
CITE\amentis 2024-09-16 11:22:17 +03:00
parent b30f26588d
commit f3e439094b
3 changed files with 47 additions and 25 deletions

View File

@ -9,8 +9,6 @@ import java.util.UUID;
public class KpiProperties { public class KpiProperties {
private UUID id; private UUID id;
private List<UUID> userIds;
private String label; private String label;
private String description; private String description;
@ -19,6 +17,10 @@ public class KpiProperties {
private String code; private String code;
private List<String> roles;
private List<String> tenantRoles;
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -27,14 +29,6 @@ public class KpiProperties {
this.id = id; this.id = id;
} }
public List<UUID> getUserIds() {
return userIds;
}
public void setUserIds(List<UUID> userIds) {
this.userIds = userIds;
}
public String getLabel() { public String getLabel() {
return label; return label;
} }
@ -66,4 +60,20 @@ public class KpiProperties {
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
public List<String> getRoles() {
return roles;
}
public void setRoles(List<String> roles) {
this.roles = roles;
}
public List<String> getTenantRoles() {
return tenantRoles;
}
public void setTenantRoles(List<String> tenantRoles) {
this.tenantRoles = tenantRoles;
}
} }

View File

@ -493,12 +493,20 @@ public class MaintenanceServiceImpl implements MaintenanceService {
public void sendIndicatorAccessEntryEvents() throws InvalidApplicationException { public void sendIndicatorAccessEntryEvents() throws InvalidApplicationException {
try { try {
for (UUID userId: this.kpiProperties.getUserIds()) { List<String> allowedRoles = new ArrayList<>();
this.indicatorAccessEventHandler.handle(this.createIndicatorAccessEvent(userId, this.tenantScope.getDefaultTenantCode()), null); allowedRoles.addAll(this.kpiProperties.getRoles());
} allowedRoles.addAll(this.kpiProperties.getTenantRoles());
UserRoleQuery userRoleQuery = this.queryFactory.query(UserRoleQuery.class).disableTracking().roles(allowedRoles);
this.tenantEntityManager.disableTenantFilters(); this.tenantEntityManager.disableTenantFilters();
List<TenantUserEntity> tenantUserEntities = this.queryFactory.query(TenantUserQuery.class).disableTracking().userIds(this.kpiProperties.getUserIds()).collect(); List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().isActive(IsActive.Active).userRoleSubQuery(userRoleQuery).collectAs(new BaseFieldSet().ensure(User._id).ensure(User._name).ensure(User._createdAt));
if (tenantUserEntities == null || tenantUserEntities.isEmpty()) throw new MyApplicationException("tenant users not found");
if (users != null && !users.isEmpty()) {
for (UserEntity user: users) {
this.indicatorAccessEventHandler.handle(this.createIndicatorAccessEvent(user.getId(), this.tenantScope.getDefaultTenantCode()), null);
}
List<TenantUserEntity> tenantUserEntities = this.queryFactory.query(TenantUserQuery.class).disableTracking().userIds(users.stream().map(UserEntity::getId).distinct().toList()).isActive(IsActive.Active).collect();
if (tenantUserEntities == null || tenantUserEntities.isEmpty()) return;
List<TenantEntity> tenantEntities = this.queryFactory.query(TenantQuery.class).disableTracking().ids(tenantUserEntities.stream().map(TenantUserEntity::getTenantId).distinct().toList()).collectAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code)); List<TenantEntity> tenantEntities = this.queryFactory.query(TenantQuery.class).disableTracking().ids(tenantUserEntities.stream().map(TenantUserEntity::getTenantId).distinct().toList()).collectAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code));
if (tenantEntities != null && !tenantEntities.isEmpty()) { if (tenantEntities != null && !tenantEntities.isEmpty()) {
for (TenantUserEntity user: tenantUserEntities) { for (TenantUserEntity user: tenantUserEntities) {
@ -508,6 +516,8 @@ public class MaintenanceServiceImpl implements MaintenanceService {
} }
} }
} }
}
} finally { } finally {
this.tenantEntityManager.reloadTenantFilters(); this.tenantEntityManager.reloadTenantFilters();
} }

View File

@ -1,10 +1,12 @@
kpi: kpi:
user-indicator: user-indicator:
id: 97c2d685-d7d2-4bd1-a287-ba329ad45d74 id: 97c2d685-d7d2-4bd1-a287-ba329ad45d74
userIds:
- 8552f758-f196-4a51-a3fd-154c088d85c4
- e60876ed-87f8-4a8e-8081-e5620ec839cf
label: test label: test
description: test description: test
url: url test url: url test
code: test code: test
roles:
- Admin
- InstallationAdmin
tenant-roles:
- TenantAdmin