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 {
private UUID id;
private List<UUID> userIds;
private String label;
private String description;
@ -19,6 +17,10 @@ public class KpiProperties {
private String code;
private List<String> roles;
private List<String> tenantRoles;
public UUID getId() {
return id;
}
@ -27,14 +29,6 @@ public class KpiProperties {
this.id = id;
}
public List<UUID> getUserIds() {
return userIds;
}
public void setUserIds(List<UUID> userIds) {
this.userIds = userIds;
}
public String getLabel() {
return label;
}
@ -66,4 +60,20 @@ public class KpiProperties {
public void setCode(String 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,21 +493,31 @@ public class MaintenanceServiceImpl implements MaintenanceService {
public void sendIndicatorAccessEntryEvents() throws InvalidApplicationException {
try {
for (UUID userId: this.kpiProperties.getUserIds()) {
this.indicatorAccessEventHandler.handle(this.createIndicatorAccessEvent(userId, this.tenantScope.getDefaultTenantCode()), null);
}
List<String> allowedRoles = new ArrayList<>();
allowedRoles.addAll(this.kpiProperties.getRoles());
allowedRoles.addAll(this.kpiProperties.getTenantRoles());
UserRoleQuery userRoleQuery = this.queryFactory.query(UserRoleQuery.class).disableTracking().roles(allowedRoles);
this.tenantEntityManager.disableTenantFilters();
List<TenantUserEntity> tenantUserEntities = this.queryFactory.query(TenantUserQuery.class).disableTracking().userIds(this.kpiProperties.getUserIds()).collect();
if (tenantUserEntities == null || tenantUserEntities.isEmpty()) throw new MyApplicationException("tenant users not found");
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()) {
for (TenantUserEntity user: tenantUserEntities) {
TenantEntity tenant = tenantEntities.stream().filter(x -> x.getId().equals(user.getTenantId())).findFirst().orElse(null);
if (tenant != null){
this.indicatorAccessEventHandler.handle(this.createIndicatorAccessEvent(user.getUserId(), tenant.getCode()), tenant.getId());
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 (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));
if (tenantEntities != null && !tenantEntities.isEmpty()) {
for (TenantUserEntity user: tenantUserEntities) {
TenantEntity tenant = tenantEntities.stream().filter(x -> x.getId().equals(user.getTenantId())).findFirst().orElse(null);
if (tenant != null){
this.indicatorAccessEventHandler.handle(this.createIndicatorAccessEvent(user.getUserId(), tenant.getCode()), tenant.getId());
}
}
}
}
} finally {
this.tenantEntityManager.reloadTenantFilters();
}

View File

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