Removing fetching updated logs with siteID
MODIFY
src/server/rest/v1/service/LoggingService.ts
src/server/rest/v1/service/LoggingService.ts
@@ -103,7 +103,27 @@ export default class LoggingService {
// Filter
const filteredRequest = LoggingSecurity.filterLogsRequest(req.query);
// Add filter for Site Admins
-
+ if (Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION) && Authorizations.isSiteAdmin(req.user)) {
+ // Optimization: Retrieve Charging Stations to get the logs only for the Site Admin user
+ const chargingStations = await ChargingStationStorage.getChargingStations(req.tenant,
+ { siteIDs: req.user.sitesAdmin, withSiteArea: true }, Constants.DB_PARAMS_MAX_LIMIT);
+ // Check if Charging Station is already filtered
+ if (chargingStations.count === 0) {
+ filteredRequest.Source = '';
+ } else if (filteredRequest.Source && filteredRequest.Source.length > 0) {
+ // Filter only Site Admin Chargers
+ const sources = [];
+ for (const chargingStation of chargingStations.result) {
+ if (filteredRequest.Source.includes(chargingStation.id)) {
+ sources.push(chargingStation.id);
+ }
+ }
+ filteredRequest.Source = sources.join('|');
+ } else {
+ // Add all Site Admin Chargers in filter
+ filteredRequest.Source = chargingStations.result.map((chargingStation) => chargingStation.id).join('|');
+ }
+ }
// Get logs
const loggings = await LoggingStorage.getLogs(req.user.tenantID, {
search: filteredRequest.Search,
@@ -113,7 +133,6 @@ export default class LoggingService {
hosts: filteredRequest.Host ? filteredRequest.Host.split('|') : null,
levels: filteredRequest.Level ? filteredRequest.Level.split('|') : null,
type: filteredRequest.Type,
- siteIDs: req.user.sites,
sources: filteredRequest.Source ? filteredRequest.Source.split('|') : null,
actions: filteredRequest.Action ? filteredRequest.Action.split('|') : null,
}, {
@@ -128,4 +147,3 @@ export default class LoggingService {
return loggings;
}
}
-

MODIFY
src/storage/mongodb/LoggingStorage.ts
src/storage/mongodb/LoggingStorage.ts
@@ -86,7 +86,7 @@ export default class LoggingStorage {
}
public static async getLogs(tenantID: string, params: {
- startDateTime?: Date; endDateTime?: Date; levels?: string[]; sources?: string[]; siteIDs?: string[]; type?: string; actions?: string[];
+ startDateTime?: Date; endDateTime?: Date; levels?: string[]; sources?: string[]; type?: string; actions?: string[];
hosts?: string[]; userIDs?: string[]; search?: string; logIDs?: string[];
} = {}, dbParams: DbParams, projectFields: string[]): Promise<DataResult<Log>> {
// Check Tenant
@@ -119,10 +119,6 @@ export default class LoggingStorage {
if (params.levels && params.levels.length > 0) {
filters.level = { $in: params.levels };
}
- // Filter on site ID
- if (params.siteIDs && params.siteIDs.length > 0) {
- filters.siteID = { $in: params.siteIDs };
- }
// Filter on charging Stations
if (params.sources && params.sources.length > 0) {
filters.source = { $in: params.sources };

Removing fetching updated logs with siteID