Handle Badge ID in Query String in Export
MODIFY
src/server/rest/service/UserService.ts
src/server/rest/service/UserService.ts
@@ -656,7 +656,8 @@ export default class UserService {
}
public static async handleExportUsers(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Export
+ // Export with tags
+ req.query['WithTag'] = 'true';
await UtilsService.exportToCSV(req, res, 'exported-users.csv',
UserService.getUsers.bind(this), UserService.convertToCSV.bind(this));
}
@@ -1360,22 +1361,17 @@ export default class UserService {
let csv = '';
// Header
if (writeHeader) {
- csv = `Name${Constants.CSV_SEPARATOR}First Name${Constants.CSV_SEPARATOR}Role${Constants.CSV_SEPARATOR}Status${Constants.CSV_SEPARATOR}Email${Constants.CSV_SEPARATOR}Badges${Constants.CSV_SEPARATOR}EULA Accepted On${Constants.CSV_SEPARATOR}Created On${Constants.CSV_SEPARATOR}Changed On${Constants.CSV_SEPARATOR}Changed By\r\n`;
+ csv = `ID${Constants.CSV_SEPARATOR}Name${Constants.CSV_SEPARATOR}First Name${Constants.CSV_SEPARATOR}Role${Constants.CSV_SEPARATOR}Status${Constants.CSV_SEPARATOR}Email${Constants.CSV_SEPARATOR}Badges${Constants.CSV_SEPARATOR}EULA Accepted On${Constants.CSV_SEPARATOR}Created On${Constants.CSV_SEPARATOR}Changed On${Constants.CSV_SEPARATOR}Changed By\r\n`;
}
// Content
for (const user of users) {
+ csv += `${user.id}` + Constants.CSV_SEPARATOR;
csv += `${user.name}` + Constants.CSV_SEPARATOR;
csv += `${user.firstName}` + Constants.CSV_SEPARATOR;
csv += `${user.role}` + Constants.CSV_SEPARATOR;
csv += `${user.status}` + Constants.CSV_SEPARATOR;
csv += `${user.email}` + Constants.CSV_SEPARATOR;
- let tagsString = '';
- if (user.tags) {
- for (const tag of user.tags) {
- tagsString += `${tag.id} `;
- }
- }
- csv += `${tagsString}` + Constants.CSV_SEPARATOR;
+ csv += `${user.tags ? user.tags.map((tag) => tag.id).join(',') : ''}` + Constants.CSV_SEPARATOR;
csv += `${moment(user.eulaAcceptedOn).format('YYYY-MM-DD')}` + Constants.CSV_SEPARATOR;
csv += `${moment(user.createdOn).format('YYYY-MM-DD')}` + Constants.CSV_SEPARATOR;
csv += `${moment(user.lastChangedOn).format('YYYY-MM-DD')}` + Constants.CSV_SEPARATOR;
@@ -1414,6 +1410,7 @@ export default class UserService {
{
search: filteredRequest.Search,
issuer: filteredRequest.Issuer,
+ withTag: filteredRequest.WithTag,
siteIDs: (filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
roles: (filteredRequest.Role ? filteredRequest.Role.split('|') : null),
statuses: (filteredRequest.Status ? filteredRequest.Status.split('|') : null),

MODIFY
src/server/rest/service/security/TransactionSecurity.ts
src/server/rest/service/security/TransactionSecurity.ts
@@ -71,7 +71,7 @@ export default class TransactionSecurity {
}
public static filterTransactionsRequest(request: any): HttpTransactionsRequest {
- const filteredRequest: HttpTransactionsRequest = {} as HttpTransactionsRequest;
+ const filteredRequest = {} as HttpTransactionsRequest;
// Handle picture
if (Utils.objectHasProperty(request, 'Issuer')) {
filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);

MODIFY
src/server/rest/service/security/UserSecurity.ts
src/server/rest/service/security/UserSecurity.ts
@@ -26,46 +26,50 @@ export default class UserSecurity {
}
public static filterUsersRequest(request: any): HttpUsersRequest {
+ const filteredRequest = {} as HttpUsersRequest;
if (request.Issuer) {
- request.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
+ filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
+ }
+ if (request.WithTag) {
+ filteredRequest.WithTag = UtilsSecurity.filterBoolean(request.WithTag);
}
if (request.Search) {
- request.Search = sanitize(request.Search);
+ filteredRequest.Search = sanitize(request.Search);
}
if (request.SiteID) {
- request.SiteID = sanitize(request.SiteID);
+ filteredRequest.SiteID = sanitize(request.SiteID);
}
if (request.Role) {
- request.Role = sanitize(request.Role);
+ filteredRequest.Role = sanitize(request.Role);
}
if (request.Status) {
- request.Status = sanitize(request.Status);
+ filteredRequest.Status = sanitize(request.Status);
}
if (request.ErrorType) {
- request.ErrorType = sanitize(request.ErrorType);
+ filteredRequest.ErrorType = sanitize(request.ErrorType);
}
if (request.ExcludeSiteID) {
- request.ExcludeSiteID = sanitize(request.ExcludeSiteID);
+ filteredRequest.ExcludeSiteID = sanitize(request.ExcludeSiteID);
}
if (request.TagID) {
- request.TagID = sanitize(request.TagID);
+ filteredRequest.TagID = sanitize(request.TagID);
}
if (request.ExcludeUserIDs) {
- request.ExcludeUserIDs = sanitize(request.ExcludeUserIDs);
+ filteredRequest.ExcludeUserIDs = sanitize(request.ExcludeUserIDs);
}
- if (request.IncludeUserIDs) {
- request.IncludeUserIDs = sanitize(request.IncludeUserIDs);
+ if (request.IncludeCarUserIDs) {
+ filteredRequest.IncludeCarUserIDs = sanitize(request.IncludeCarUserIDs);
}
if (request.NotAssignedToCarID) {
- request.NotAssignedToCarID = sanitize(request.NotAssignedToCarID);
+ filteredRequest.NotAssignedToCarID = sanitize(request.NotAssignedToCarID);
}
- UtilsSecurity.filterSkipAndLimit(request, request);
- UtilsSecurity.filterSort(request, request);
- return request as HttpUsersRequest;
+ UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
+ UtilsSecurity.filterSort(request, filteredRequest);
+ return filteredRequest;
}
public static filterUserSitesRequest(request: any): HttpUserSitesRequest {
- const filteredRequest: HttpUserSitesRequest = {} as HttpUserSitesRequest;
+ const filteredRequest = {} as HttpUserSitesRequest;
filteredRequest.UserID = sanitize(request.UserID);
filteredRequest.Search = sanitize(request.Search);
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
@@ -92,7 +96,7 @@ export default class UserSecurity {
}
public static filterTagsRequest(request: any): HttpTagsRequest {
- const filteredRequest: HttpTagsRequest = {
+ const filteredRequest = {
Search: sanitize(request.Search),
UserID: sanitize(request.UserID),
Issuer: Utils.objectHasProperty(request, 'Issuer') ? UtilsSecurity.filterBoolean(request.Issuer) : null
@@ -140,6 +144,9 @@ export default class UserSecurity {
if (user.billingData) {
filteredUser.billingData = user.billingData;
}
+ if (!Utils.isEmptyArray(user.tags)) {
+ filteredUser.tags = user.tags.map((tag) => UserSecurity.filterTagResponse(tag, loggedUser));
+ }
} else {
// Set only necessary info
// Demo user?

MODIFY
src/server/rest/service/security/UtilsSecurity.ts
src/server/rest/service/security/UtilsSecurity.ts
@@ -59,7 +59,7 @@ export default class UtilsSecurity {
}
}
- static filterSkipAndLimit(request, filteredRequest): void {
+ static filterSkipAndLimit(request: any, filteredRequest: any): void {
// Limit
UtilsSecurity.filterLimit(request, filteredRequest);
// Skip
@@ -70,7 +70,7 @@ export default class UtilsSecurity {
}
}
- static filterLimit(request, filteredRequest): void {
+ static filterLimit(request: any, filteredRequest: any): void {
// Exist?
if (!request.Limit) {
// Default
@@ -87,7 +87,7 @@ export default class UtilsSecurity {
}
}
- static filterSkip(request, filteredRequest): void {
+ static filterSkip(request: any, filteredRequest: any): void {
// Exist?
if (!request.Skip) {
// Default

MODIFY
src/types/requests/HttpUserRequest.ts
src/types/requests/HttpUserRequest.ts
@@ -31,6 +31,7 @@ export interface HttpSitesAssignUserRequest {
export interface HttpUsersRequest extends HttpDatabaseRequest {
Issuer: boolean;
+ WithTag?: boolean;
Search: string;
SiteID: string;
Role: string;

Handle Badge ID in Query String in Export