revert concept to freeAccess
MODIFY
src/assets/server/rest/v1/schemas/user/user-create.json
src/assets/server/rest/v1/schemas/user/user-create.json
"type": "boolean",
"sanitize": "mongo"
},
- "billable": {
+ "freeAccess": {
"type": "boolean",
"sanitize": "mongo"
}

MODIFY
src/assets/server/rest/v1/schemas/user/user-update.json
src/assets/server/rest/v1/schemas/user/user-update.json
"type": "boolean",
"sanitize": "mongo"
},
- "billable": {
+ "freeAccess": {
"type": "boolean",
"sanitize": "mongo"
}

MODIFY
src/assets/server/rest/v1/schemas/user/users-get.json
src/assets/server/rest/v1/schemas/user/users-get.json
"type": "boolean",
"sanitize": "mongo"
},
- "Billable": {
+ "FreeAccess": {
"type": "boolean",
"sanitize": "mongo"
},

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -70,7 +70,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
attributes: [
'id', 'name', 'firstName', 'email', 'role', 'status', 'issuer', 'createdOn', 'createdBy',
'lastChangedOn', 'lastChangedBy', 'eulaAcceptedOn', 'eulaAcceptedVersion', 'locale',
- 'billingData.customerID', 'billingData.lastChangedOn', 'technical', 'billable'
+ 'billingData.customerID', 'billingData.lastChangedOn', 'technical', 'freeAccess'
]
},
{
@@ -95,7 +95,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
resource: Entity.USER, action: [Action.READ, Action.CREATE, Action.UPDATE],
attributes: [
'id', 'name', 'firstName', 'email', 'role', 'status', 'issuer', 'locale', 'plateID',
- 'notificationsActive', 'notifications', 'phone', 'mobile', 'iNumber', 'costCenter', 'address', 'technical', 'billable'
+ 'notificationsActive', 'notifications', 'phone', 'mobile', 'iNumber', 'costCenter', 'address', 'technical', 'freeAccess'
]
},
{

MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -336,7 +336,7 @@ export default abstract class BillingIntegration {
}
protected isUserInternal(user: User): boolean {
- return !user.billable;
+ return !!user.freeAccess;
}
private async _getUsersWithNoBillingData(): Promise<User[]> {

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
import { ExtractJwt, Strategy } from 'passport-jwt';
import { Handler, NextFunction, Request, RequestHandler, Response } from 'express';
import { HttpLoginRequest, HttpResetPasswordRequest } from '../../../../types/requests/HttpUserRequest';
-import User, { USER_BILLABLE_DEFAULT, UserRole, UserStatus } from '../../../../types/User';
+import User, { USER_FREE_ACCESS_DEFAULT, UserRole, UserStatus } from '../../../../types/User';
import AppError from '../../../../exception/AppError';
import AuthValidator from '../validator/AuthValidator';
@@ -245,7 +245,7 @@ export default class AuthService {
}
}
// Set new user default billable value
- await UserStorage.saveUserAdminData(tenant, newUser.id, { billable: USER_BILLABLE_DEFAULT });
+ await UserStorage.saveUserAdminData(tenant, newUser.id, { freeAccess: USER_FREE_ACCESS_DEFAULT });
// Log
await Logging.logSecurityInfo({
tenantID: tenant.id,

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -755,7 +755,7 @@ export default class UserService {
roles: (filteredRequest.Role ? filteredRequest.Role.split('|') : null),
statuses: (filteredRequest.Status ? filteredRequest.Status.split('|') : null),
technical: Utils.isBoolean(filteredRequest.Technical) ? filteredRequest.Technical : null,
- billable: Utils.isBoolean(filteredRequest.Billable) ? filteredRequest.Billable : null,
+ freeAccess: Utils.isBoolean(filteredRequest.FreeAccess) ? filteredRequest.FreeAccess : null,
excludeSiteID: filteredRequest.ExcludeSiteID,
...authorizationUsersFilters.filters
},
@@ -971,8 +971,8 @@ export default class UserService {
if (projectFields.includes('plateID') ||
projectFields.includes('technical') ||
projectFields.includes('notificationsActive') ||
- projectFields.includes('billable')) {
- const adminData: { plateID?: string; notificationsActive?: boolean; notifications?: UserNotifications, technical?: boolean, billable?: boolean } = {};
+ projectFields.includes('freeAccess')) {
+ const adminData: { plateID?: string; notificationsActive?: boolean; notifications?: UserNotifications, technical?: boolean, freeAccess?: boolean } = {};
if (Utils.objectHasProperty(user, 'plateID') &&
projectFields.includes('plateID')) {
adminData.plateID = user.plateID || null;
@@ -981,9 +981,9 @@ export default class UserService {
projectFields.includes('technical')) {
adminData.technical = user.technical;
}
- if (Utils.objectHasProperty(user, 'billable') &&
- projectFields.includes('billable')) {
- adminData.billable = user.billable;
+ if (Utils.objectHasProperty(user, 'freeAccess') &&
+ projectFields.includes('freeAccess')) {
+ adminData.freeAccess = user.freeAccess;
}
if (Utils.objectHasProperty(user, 'notificationsActive') &&
projectFields.includes('notificationsActive')) {

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -482,7 +482,7 @@ export default class UserStorage {
}
public static async saveUserAdminData(tenant: Tenant, userID: string,
- params: { plateID?: string; notificationsActive?: boolean; notifications?: UserNotifications, technical?: boolean, billable?: boolean }): Promise<void> {
+ params: { plateID?: string; notificationsActive?: boolean; notifications?: UserNotifications, technical?: boolean, freeAccess?: boolean }): Promise<void> {
// Debug
const uniqueTimerID = Logging.traceDatabaseRequestStart();
// Check Tenant
@@ -502,8 +502,8 @@ export default class UserStorage {
if (Utils.objectHasProperty(params, 'technical')) {
updatedUserMDB.technical = params.technical;
}
- if (Utils.objectHasProperty(params, 'billable')) {
- updatedUserMDB.billable = params.billable;
+ if (Utils.objectHasProperty(params, 'freeAccess')) {
+ updatedUserMDB.freeAccess = params.freeAccess;
}
// Modify and return the modified document
await global.database.getCollection<any>(tenant.id, 'users').findOneAndUpdate(
@@ -571,7 +571,7 @@ export default class UserStorage {
notificationsActive?: boolean; siteIDs?: string[]; excludeSiteID?: string; search?: string;
userIDs?: string[]; email?: string; issuer?: boolean; passwordResetHash?: string; roles?: string[];
statuses?: string[]; withImage?: boolean; billingUserID?: string; notSynchronizedBillingData?: boolean;
- withTestBillingData?: boolean; notifications?: any; noLoginSince?: Date; technical?: boolean; billable?: boolean;
+ withTestBillingData?: boolean; notifications?: any; noLoginSince?: Date; technical?: boolean; freeAccess?: boolean;
},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<User>> {
// Debug
@@ -685,21 +685,21 @@ export default class UserStorage {
}
}
}
- // Select (non) billable users
- if (Utils.objectHasProperty(params, 'billable') && Utils.isBoolean(params.billable)) {
- if (params.billable) {
- filters.billable = true;
+ // Select (non) Free users
+ if (Utils.isBoolean(params.freeAccess)) {
+ if (params.freeAccess) {
+ filters.freeAccess = true;
} else {
- const billableFilter = {
+ const freeAccessFilter = {
$or: [
- { billable: { $in: [false, null] } },
- { billable: { $exists: false } }
+ { freeAccess: { $in: [false, null] } },
+ { freeAccess: { $exists: false } }
]
};
if (filters.$and) {
- filters.$and.push(billableFilter);
+ filters.$and.push(freeAccessFilter);
} else {
- filters.$and = [ billableFilter ];
+ filters.$and = [ freeAccessFilter ];
}
}
}

MODIFY
src/types/User.ts
src/types/User.ts
@@ -42,7 +42,7 @@ export default interface User extends CreatedUpdatedProps, AuthorizationActions
autoActivateUserAtImport: boolean;
};
technical?: boolean;
- billable?: boolean;
+ freeAccess?: boolean;
}
export interface UserSite {
@@ -89,4 +89,4 @@ export const UserRequiredImportProperties = [
'name'
];
-export const USER_BILLABLE_DEFAULT = false;
+export const USER_FREE_ACCESS_DEFAULT = false;

MODIFY
src/types/requests/HttpUserRequest.ts
src/types/requests/HttpUserRequest.ts
@@ -39,7 +39,7 @@ export interface HttpUsersRequest extends HttpDatabaseRequest {
Role: string;
Status: string;
Technical?: boolean;
- Billable?: boolean;
+ FreeAccess?: boolean;
ErrorType?: string;
VisualTagID?: string;
ExcludeSiteID: string;

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -27,7 +27,6 @@ import User from '../../src/types/User';
import { UserInErrorType } from '../../src/types/InError';
import chaiSubset from 'chai-subset';
import config from '../config';
-import exp from 'constants';
import global from '../../src/types/GlobalType';
import moment from 'moment';
import responseHelper from '../helpers/responseHelper';
@@ -526,7 +525,7 @@ describe('Billing Service', function() {
testData.createdUsers.shift();
});
- it('Should be able to set billable flag on basic user', async () => {
+ it('Should be able to set freeAccess flag on basic user', async () => {
const fakeUser = {
...Factory.user.build(),
} as User;
@@ -537,21 +536,21 @@ describe('Billing Service', function() {
fakeUser
);
testData.createdUsers.push(fakeUser);
- // Let's check that user exists with no billable flag
+ // Let's check that user exists with no freeAccess flag
const myUser = await testData.userService.userApi.readById(fakeUser.id);
expect(myUser).to.be.not.null;
- expect(myUser.data.billable).to.undefined;
+ expect(myUser.data.freeAccess).to.undefined;
// Let's update the new user
- fakeUser.billable = true;
+ fakeUser.freeAccess = true;
await testData.userService.updateEntity(
testData.userService.userApi,
fakeUser,
false
);
- // Let's check that user exists with billable flag
+ // Let's check that user exists with freeAccess flag
const myUser2 = await testData.userService.userApi.readById(fakeUser.id);
expect(myUser2).to.be.not.null;
- expect(myUser2.data.billable).to.be.eq(true);
+ expect(myUser2.data.freeAccess).to.be.eq(true);
// Let's delete the user
await testData.userService.deleteEntity(
testData.userService.userApi,
@@ -977,7 +976,7 @@ describe('Billing Service', function() {
});
- describe('Where billable basic user', () => {
+ describe('Where freeAccess basic user', () => {
// eslint-disable-next-line @typescript-eslint/require-await
before(async () => {
testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);
@@ -1002,7 +1001,7 @@ describe('Billing Service', function() {
});
});
- describe('Where NON-billable basic user', () => {
+ describe('Where billable basic user', () => {
// eslint-disable-next-line @typescript-eslint/require-await
before(async () => {
testData.userContext = testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER);

MODIFY
test/api/UserTest.ts
test/api/UserTest.ts
@@ -331,19 +331,19 @@ describe('User', function() {
expect(user2.technical).eq(false);
});
- it('Should not be able to set billable flag when billing is inactive', async () => {
- // Check the billable flag can be set
+ it('Should not be able to set freeAccess flag when billing is inactive', async () => {
+ // Check the freeAccess flag canNOT be set
const response = await testData.userService.userApi.exportUsers({});
let users = await testData.userService.userApi.readAll({}, { limit: Constants.DB_RECORD_COUNT_MAX_PAGE_LIMIT, skip: 0 });
expect(response.status).eq(StatusCodes.OK);
expect(response.data).not.null;
expect(users.data.result.length).to.be.greaterThan(1);
const user1 = users.data.result[0];
- user1.billable = true;
+ user1.freeAccess = true;
await testData.userService.userApi.update(user1);
users = await testData.userService.userApi.readAll({}, { limit: Constants.DB_RECORD_COUNT_MAX_PAGE_LIMIT, skip: 0 });
const user2 = users.data.result[0];
- expect(user2.billable).undefined;
+ expect(user2.freeAccess).undefined;
});
});

MODIFY
test/api/context/ContextBuilder.ts
test/api/context/ContextBuilder.ts
@@ -157,8 +157,8 @@ export default class ContextBuilder {
await TagStorage.saveTag(buildTenant, tag);
}
}
- if (Utils.isBoolean(ContextDefinition.TENANT_USER_LIST[0].billable)) {
- await UserStorage.saveUserAdminData(buildTenant, userId, { billable: ContextDefinition.TENANT_USER_LIST[0].billable });
+ if (Utils.isBoolean(ContextDefinition.TENANT_USER_LIST[0].freeAccess)) {
+ await UserStorage.saveUserAdminData(buildTenant, userId, { freeAccess: ContextDefinition.TENANT_USER_LIST[0].freeAccess });
}
const defaultAdminUser = await UserStorage.getUser(buildTenant, ContextDefinition.TENANT_USER_LIST[0].id);
// Create Central Server Service
@@ -252,8 +252,8 @@ export default class ContextBuilder {
if (userDef.assignedToSite) {
userListToAssign.push(userModel);
}
- if (userDef.billable) {
- await UserStorage.saveUserAdminData(buildTenant, user.id, { billable: userDef.billable });
+ if (userDef.freeAccess) {
+ await UserStorage.saveUserAdminData(buildTenant, user.id, { freeAccess: userDef.freeAccess });
}
// Set back password to clear value for login/logout
(userModel as any).passwordClear = config.get('admin.password');

MODIFY
test/api/context/ContextDefinition.ts
test/api/context/ContextDefinition.ts
@@ -387,7 +387,6 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: true,
},
{ // Admin not assigned
id: '5ce249a1a39ae1c056c123ef',
@@ -408,7 +407,6 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: true,
},
{ // Basic user
id: '5ce249a1a39ae1c056c123ab',
@@ -429,28 +427,6 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: true,
- },
- { // Basic user NON BILLABLE
- id: '5ce249a1a39ae1c056c123ff',
- name: 'DOES NOT PAY',
- firstName: 'User',
- locale: 'en-US',
- phone: '66666666666',
- mobile: '66666666666',
- plateID: '666-FB-69',
- issuer: ContextDefinition.USER_CONTEXTS.BASIC_USER.issuer,
- role: ContextDefinition.USER_CONTEXTS.BASIC_USER.role,
- status: ContextDefinition.USER_CONTEXTS.BASIC_USER.status,
- assignedToSite: ContextDefinition.USER_CONTEXTS.BASIC_USER.assignedToSite,
- emailPrefix: 'basic2-',
- tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER.withTags ? [{
- id: 'A1234999',
- visualID: new ObjectId().toString(),
- issuer: false,
- active: true
- }] : null),
- billable: false
},
{ // Demo user
id: '5ce249a1a39ae1c056c123cd',
@@ -471,7 +447,7 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: true,
+ freeAccess: false,
},
{ // Basic user unassigned
id: '5ce249a1a39ae1c056c456ad',
@@ -492,7 +468,6 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: true,
},
{ // Basic user pending
id: '5ce249a1a39ae1c056c456ab',
@@ -513,7 +488,7 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: false,
+ freeAccess: false,
},
{ // Basic user Locked
id: '5ce249a1a39ae1c056c789ef',
@@ -534,7 +509,7 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: true,
+ freeAccess: false,
},
{ // Basic user No Tags
id: '5ce249a1a39ae1c056c567ab',
@@ -555,7 +530,7 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: true,
+ freeAccess: false,
},
{ // External User
id: '5ce249a1a39ae1c056c456ae',
@@ -576,7 +551,7 @@ export default class ContextDefinition {
issuer: false,
active: true
}] : null),
- billable: true,
+ freeAccess: false,
}
];

revert concept to freeAccess