codebase-models 2.1.23 → 2.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -4
- package/dist/src/constant.d.ts +2 -1
- package/dist/src/constant.js +14 -3
- package/dist/src/models/ClientScript.d.ts +1 -3
- package/dist/src/models/ClientScript.js +4 -14
- package/dist/src/models/Role.js +16 -7
- package/index.ts +6 -5
- package/package.json +1 -1
- package/src/constant.ts +19 -4
- package/src/models/ClientScript.ts +5 -17
- package/src/models/Role.ts +51 -39
package/dist/index.d.ts
CHANGED
|
@@ -72,9 +72,9 @@ import Environment from "./src/models/Environment";
|
|
|
72
72
|
import PrecalculationFilters from "./src/models/PrecalculationFilters";
|
|
73
73
|
import BqPreCompiledData from "./src/models/BqPreCompiledData";
|
|
74
74
|
import CustomQuery from "./src/models/CustomQuery";
|
|
75
|
-
import { generateRandomIID } from "./src/constant";
|
|
75
|
+
import { generateRandomIID, RolesConstants } from "./src/constant";
|
|
76
76
|
import TestTimeline from "./src/models/TestTimeline";
|
|
77
77
|
import CronData from "./src/models/CronData";
|
|
78
78
|
import CronConfig from "./src/models/CronConfig";
|
|
79
79
|
export declare function connect(uri: string, options?: mongoose.ConnectOptions | undefined): Promise<typeof mongoose>;
|
|
80
|
-
export { generateRandomIID, Client, ClientReportsTemp, QueryLog, Report, Test, TestSequentialValue, User, AppEvent, Announcement, ClientAdditionalRevenue, ClientLearning, ClientLinks, ClientNextStep, ClientNote, ClientRetention, ClientStrategy, ClientSurvey, CVRReport, Faq, Feedback, Goal, Hypothesis, HypothesisSheet, LandingPages, NewIdeas, Notification, Page, PageElement, PageTestType, Portfolio, ReadNotification, Role, CustomQuery, SavedSegment, TestTimeline, Segment, SegmentCombination, Snippet, StageInCustomerJourney, Tag, Temp, Tier, Trigger, ClientScript, Audience, Environment, Organization, PrecalculationFilters, BqPreCompiledData, CronData, CronConfig, UserPermission };
|
|
80
|
+
export { generateRandomIID, RolesConstants, Client, ClientReportsTemp, QueryLog, Report, Test, TestSequentialValue, User, AppEvent, Announcement, ClientAdditionalRevenue, ClientLearning, ClientLinks, ClientNextStep, ClientNote, ClientRetention, ClientStrategy, ClientSurvey, CVRReport, Faq, Feedback, Goal, Hypothesis, HypothesisSheet, LandingPages, NewIdeas, Notification, Page, PageElement, PageTestType, Portfolio, ReadNotification, Role, CustomQuery, SavedSegment, TestTimeline, Segment, SegmentCombination, Snippet, StageInCustomerJourney, Tag, Temp, Tier, Trigger, ClientScript, Audience, Environment, Organization, PrecalculationFilters, BqPreCompiledData, CronData, CronConfig, UserPermission, };
|
package/dist/index.js
CHANGED
|
@@ -12,8 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
exports.UserPermission = exports.CronConfig = exports.CronData = exports.BqPreCompiledData = void 0;
|
|
15
|
+
exports.Organization = exports.Environment = exports.Audience = exports.ClientScript = exports.Trigger = exports.Tier = exports.Temp = exports.Tag = exports.StageInCustomerJourney = exports.Snippet = exports.SegmentCombination = exports.Segment = exports.TestTimeline = exports.SavedSegment = exports.CustomQuery = exports.Role = exports.ReadNotification = exports.Portfolio = exports.PageTestType = exports.PageElement = exports.Page = exports.Notification = exports.NewIdeas = exports.LandingPages = exports.HypothesisSheet = exports.Hypothesis = exports.Goal = exports.Feedback = exports.Faq = exports.CVRReport = exports.ClientSurvey = exports.ClientStrategy = exports.ClientRetention = exports.ClientNote = exports.ClientNextStep = exports.ClientLinks = exports.ClientLearning = exports.ClientAdditionalRevenue = exports.Announcement = exports.AppEvent = exports.User = exports.TestSequentialValue = exports.Test = exports.Report = exports.QueryLog = exports.ClientReportsTemp = exports.Client = exports.RolesConstants = exports.generateRandomIID = exports.connect = void 0;
|
|
16
|
+
exports.UserPermission = exports.CronConfig = exports.CronData = exports.BqPreCompiledData = exports.PrecalculationFilters = void 0;
|
|
17
17
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
18
18
|
const Client_1 = __importDefault(require("./src/models/Client"));
|
|
19
19
|
exports.Client = Client_1.default;
|
|
@@ -115,6 +115,7 @@ const CustomQuery_1 = __importDefault(require("./src/models/CustomQuery"));
|
|
|
115
115
|
exports.CustomQuery = CustomQuery_1.default;
|
|
116
116
|
const constant_1 = require("./src/constant");
|
|
117
117
|
Object.defineProperty(exports, "generateRandomIID", { enumerable: true, get: function () { return constant_1.generateRandomIID; } });
|
|
118
|
+
Object.defineProperty(exports, "RolesConstants", { enumerable: true, get: function () { return constant_1.RolesConstants; } });
|
|
118
119
|
const TestTimeline_1 = __importDefault(require("./src/models/TestTimeline"));
|
|
119
120
|
exports.TestTimeline = TestTimeline_1.default;
|
|
120
121
|
const CronData_1 = __importDefault(require("./src/models/CronData"));
|
|
@@ -124,8 +125,8 @@ exports.CronConfig = CronConfig_1.default;
|
|
|
124
125
|
function seedRoles() {
|
|
125
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
127
|
const checkRoles = yield Role_1.default.countDocuments();
|
|
127
|
-
if (checkRoles <
|
|
128
|
-
Promise.all(
|
|
128
|
+
if (checkRoles < constant_1.RolesConstants.length) {
|
|
129
|
+
Promise.all(constant_1.RolesConstants.map((name) => {
|
|
129
130
|
Role_1.default.bulkWrite([
|
|
130
131
|
{
|
|
131
132
|
updateOne: {
|
package/dist/src/constant.d.ts
CHANGED
|
@@ -8,11 +8,12 @@ declare const HypothesisSheetConstants: {
|
|
|
8
8
|
MEDIUM: number;
|
|
9
9
|
GOOD: number;
|
|
10
10
|
};
|
|
11
|
+
declare const RolesConstants: string[];
|
|
11
12
|
/**
|
|
12
13
|
* Generates a random unique identifier
|
|
13
14
|
* @returns A 12-character uppercase string (increased from 8 for better uniqueness)
|
|
14
15
|
* @throws Error if UUID generation fails
|
|
15
16
|
*/
|
|
16
17
|
declare const generateRandomIID: () => string;
|
|
17
|
-
export { generateRandomIID };
|
|
18
|
+
export { generateRandomIID, RolesConstants };
|
|
18
19
|
export default HypothesisSheetConstants;
|
package/dist/src/constant.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateRandomIID = void 0;
|
|
3
|
+
exports.RolesConstants = exports.generateRandomIID = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const HypothesisSheetConstants = {
|
|
6
6
|
NO: 0,
|
|
@@ -14,6 +14,17 @@ const HypothesisSheetConstants = {
|
|
|
14
14
|
MEDIUM: 1,
|
|
15
15
|
GOOD: 2,
|
|
16
16
|
};
|
|
17
|
+
const RolesConstants = [
|
|
18
|
+
"USER",
|
|
19
|
+
"ADMIN",
|
|
20
|
+
// "EDITOR",
|
|
21
|
+
// "COLLABORATOR",
|
|
22
|
+
"CLIENT",
|
|
23
|
+
"EXTERNAL",
|
|
24
|
+
"QA",
|
|
25
|
+
"OPTIMIZER",
|
|
26
|
+
];
|
|
27
|
+
exports.RolesConstants = RolesConstants;
|
|
17
28
|
/**
|
|
18
29
|
* Generates a random unique identifier
|
|
19
30
|
* @returns A 12-character uppercase string (increased from 8 for better uniqueness)
|
|
@@ -22,10 +33,10 @@ const HypothesisSheetConstants = {
|
|
|
22
33
|
const generateRandomIID = () => {
|
|
23
34
|
try {
|
|
24
35
|
// Take first 12 characters instead of 8 for better uniqueness
|
|
25
|
-
return (0, uuid_1.v4)().replace(/-/g,
|
|
36
|
+
return (0, uuid_1.v4)().replace(/-/g, "").substring(0, 12).toUpperCase();
|
|
26
37
|
}
|
|
27
38
|
catch (error) {
|
|
28
|
-
throw new Error(`Failed to generate random IID: ${error instanceof Error ? error.message :
|
|
39
|
+
throw new Error(`Failed to generate random IID: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
29
40
|
}
|
|
30
41
|
};
|
|
31
42
|
exports.generateRandomIID = generateRandomIID;
|
|
@@ -29,15 +29,12 @@ export interface IClientScript extends Document {
|
|
|
29
29
|
client?: mongoose.Schema.Types.ObjectId;
|
|
30
30
|
adhere_dnt: Boolean;
|
|
31
31
|
allow_in_iframes: Boolean;
|
|
32
|
-
viewId?: string;
|
|
33
|
-
clientScriptURL: string;
|
|
34
32
|
jquery_include: string;
|
|
35
33
|
debug: Boolean;
|
|
36
34
|
restrict_debug: Boolean;
|
|
37
35
|
max_cookie_lifetime: Number;
|
|
38
36
|
activation_mode: string;
|
|
39
37
|
use_antiflicker: Boolean;
|
|
40
|
-
snippet_revision: Number;
|
|
41
38
|
snippet_version: Number;
|
|
42
39
|
rules: string;
|
|
43
40
|
rules_tracking: string;
|
|
@@ -60,6 +57,7 @@ export interface IClientScript extends Document {
|
|
|
60
57
|
goalsEnabled: Boolean;
|
|
61
58
|
optedOut: Boolean;
|
|
62
59
|
liveEventListenersSet: Boolean;
|
|
60
|
+
active: Boolean;
|
|
63
61
|
}
|
|
64
62
|
declare const ClientScript: mongoose.Model<any, {}, {}, {}, any, any>;
|
|
65
63
|
export default ClientScript;
|
|
@@ -48,13 +48,6 @@ const ClientScriptSchema = new mongoose_1.Schema({
|
|
|
48
48
|
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
49
49
|
ref: "client",
|
|
50
50
|
},
|
|
51
|
-
viewId: {
|
|
52
|
-
type: String,
|
|
53
|
-
},
|
|
54
|
-
clientScriptURL: {
|
|
55
|
-
type: String,
|
|
56
|
-
trim: true,
|
|
57
|
-
},
|
|
58
51
|
jquery_include: {
|
|
59
52
|
type: String,
|
|
60
53
|
default: "false",
|
|
@@ -83,10 +76,6 @@ const ClientScriptSchema = new mongoose_1.Schema({
|
|
|
83
76
|
type: Boolean,
|
|
84
77
|
default: false,
|
|
85
78
|
},
|
|
86
|
-
snippet_revision: {
|
|
87
|
-
type: Number,
|
|
88
|
-
default: 1,
|
|
89
|
-
},
|
|
90
79
|
rules: {
|
|
91
80
|
type: String,
|
|
92
81
|
default: "return true;",
|
|
@@ -175,6 +164,10 @@ const ClientScriptSchema = new mongoose_1.Schema({
|
|
|
175
164
|
type: Boolean,
|
|
176
165
|
default: false,
|
|
177
166
|
},
|
|
167
|
+
active: {
|
|
168
|
+
type: Boolean,
|
|
169
|
+
default: true,
|
|
170
|
+
},
|
|
178
171
|
}, {
|
|
179
172
|
timestamps: true,
|
|
180
173
|
});
|
|
@@ -197,8 +190,5 @@ ClientScriptSchema.pre('save', function (next) {
|
|
|
197
190
|
ClientScriptSchema.index({ iid: 1 }, { unique: true });
|
|
198
191
|
// Compound indexes for common query patterns
|
|
199
192
|
ClientScriptSchema.index({ client: 1 });
|
|
200
|
-
// Sparse indexes for optional fields
|
|
201
|
-
ClientScriptSchema.index({ organisationId: 1 }, { sparse: true });
|
|
202
|
-
ClientScriptSchema.index({ asset_url: 1 }, { sparse: true });
|
|
203
193
|
const ClientScript = mongoose_1.default.models.clientscript || (0, mongoose_1.model)("clientscript", ClientScriptSchema);
|
|
204
194
|
exports.default = ClientScript;
|
package/dist/src/models/Role.js
CHANGED
|
@@ -29,7 +29,16 @@ const RoleSchema = new mongoose_1.Schema({
|
|
|
29
29
|
type: String,
|
|
30
30
|
unique: true,
|
|
31
31
|
required: true,
|
|
32
|
-
enum: [
|
|
32
|
+
enum: [
|
|
33
|
+
"USER",
|
|
34
|
+
"ADMIN",
|
|
35
|
+
"EDITOR",
|
|
36
|
+
"COLLABORATOR",
|
|
37
|
+
"CLIENT",
|
|
38
|
+
"EXTERNAL",
|
|
39
|
+
"QA",
|
|
40
|
+
"OPTIMIZER",
|
|
41
|
+
],
|
|
33
42
|
trim: true,
|
|
34
43
|
uppercase: true,
|
|
35
44
|
},
|
|
@@ -56,12 +65,12 @@ const RoleSchema = new mongoose_1.Schema({
|
|
|
56
65
|
cvrReports: { type: Boolean, default: true },
|
|
57
66
|
manageExperiments: { type: Boolean, default: true },
|
|
58
67
|
dashboard: { type: Boolean, default: true },
|
|
59
|
-
}
|
|
68
|
+
},
|
|
60
69
|
}, {
|
|
61
|
-
timestamps: true
|
|
70
|
+
timestamps: true,
|
|
62
71
|
});
|
|
63
72
|
// IF role is CLIENT then defaultPermissions should be false for all modules except reporting, insights, documentsAndLinks, cvrReports, dashboard
|
|
64
|
-
RoleSchema.pre(
|
|
73
|
+
RoleSchema.pre("save", function (next) {
|
|
65
74
|
const allTrue = {
|
|
66
75
|
abTestingDefault: true,
|
|
67
76
|
abTesting: true,
|
|
@@ -73,7 +82,7 @@ RoleSchema.pre('save', function (next) {
|
|
|
73
82
|
cvrReports: true,
|
|
74
83
|
dashboard: true,
|
|
75
84
|
};
|
|
76
|
-
if (this.name ===
|
|
85
|
+
if (this.name === "CLIENT") {
|
|
77
86
|
this.defaultPermissions = Object.assign(Object.assign({}, allTrue), { abTesting: false });
|
|
78
87
|
}
|
|
79
88
|
else {
|
|
@@ -86,8 +95,8 @@ RoleSchema.index({ name: 1, isActive: 1 });
|
|
|
86
95
|
RoleSchema.index({ organizationId: 1, name: 1 });
|
|
87
96
|
// Add text index for search
|
|
88
97
|
RoleSchema.index({
|
|
89
|
-
name:
|
|
90
|
-
description:
|
|
98
|
+
name: "text",
|
|
99
|
+
description: "text",
|
|
91
100
|
});
|
|
92
101
|
const Role = mongoose_1.default.models.role || (0, mongoose_1.model)("role", RoleSchema);
|
|
93
102
|
exports.default = Role;
|
package/index.ts
CHANGED
|
@@ -49,15 +49,15 @@ import Environment from "./src/models/Environment";
|
|
|
49
49
|
import PrecalculationFilters from "./src/models/PrecalculationFilters";
|
|
50
50
|
import BqPreCompiledData from "./src/models/BqPreCompiledData";
|
|
51
51
|
import CustomQuery from "./src/models/CustomQuery";
|
|
52
|
-
import { generateRandomIID } from "./src/constant";
|
|
52
|
+
import { generateRandomIID, RolesConstants } from "./src/constant";
|
|
53
53
|
import TestTimeline from "./src/models/TestTimeline";
|
|
54
54
|
import CronData from "./src/models/CronData";
|
|
55
55
|
import CronConfig from "./src/models/CronConfig";
|
|
56
56
|
async function seedRoles() {
|
|
57
57
|
const checkRoles = await Role.countDocuments();
|
|
58
|
-
if (checkRoles <
|
|
58
|
+
if (checkRoles < RolesConstants.length) {
|
|
59
59
|
Promise.all(
|
|
60
|
-
|
|
60
|
+
RolesConstants.map((name: string) => {
|
|
61
61
|
Role.bulkWrite([
|
|
62
62
|
{
|
|
63
63
|
updateOne: {
|
|
@@ -102,6 +102,7 @@ export async function connect(
|
|
|
102
102
|
|
|
103
103
|
export {
|
|
104
104
|
generateRandomIID,
|
|
105
|
+
RolesConstants,
|
|
105
106
|
Client,
|
|
106
107
|
ClientReportsTemp,
|
|
107
108
|
QueryLog,
|
|
@@ -153,5 +154,5 @@ export {
|
|
|
153
154
|
BqPreCompiledData,
|
|
154
155
|
CronData,
|
|
155
156
|
CronConfig,
|
|
156
|
-
UserPermission
|
|
157
|
-
};
|
|
157
|
+
UserPermission,
|
|
158
|
+
};
|
package/package.json
CHANGED
package/src/constant.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
2
|
|
|
3
3
|
const HypothesisSheetConstants = {
|
|
4
4
|
NO: 0,
|
|
@@ -13,6 +13,17 @@ const HypothesisSheetConstants = {
|
|
|
13
13
|
GOOD: 2,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
const RolesConstants = [
|
|
17
|
+
"USER",
|
|
18
|
+
"ADMIN",
|
|
19
|
+
// "EDITOR",
|
|
20
|
+
// "COLLABORATOR",
|
|
21
|
+
"CLIENT",
|
|
22
|
+
"EXTERNAL",
|
|
23
|
+
"QA",
|
|
24
|
+
"OPTIMIZER",
|
|
25
|
+
];
|
|
26
|
+
|
|
16
27
|
/**
|
|
17
28
|
* Generates a random unique identifier
|
|
18
29
|
* @returns A 12-character uppercase string (increased from 8 for better uniqueness)
|
|
@@ -21,11 +32,15 @@ const HypothesisSheetConstants = {
|
|
|
21
32
|
const generateRandomIID = (): string => {
|
|
22
33
|
try {
|
|
23
34
|
// Take first 12 characters instead of 8 for better uniqueness
|
|
24
|
-
return uuidv4().replace(/-/g,
|
|
35
|
+
return uuidv4().replace(/-/g, "").substring(0, 12).toUpperCase();
|
|
25
36
|
} catch (error) {
|
|
26
|
-
throw new Error(
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Failed to generate random IID: ${
|
|
39
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
40
|
+
}`
|
|
41
|
+
);
|
|
27
42
|
}
|
|
28
43
|
};
|
|
29
44
|
|
|
30
|
-
export { generateRandomIID };
|
|
45
|
+
export { generateRandomIID, RolesConstants };
|
|
31
46
|
export default HypothesisSheetConstants;
|
|
@@ -7,15 +7,12 @@ export interface IClientScript extends Document {
|
|
|
7
7
|
client?: mongoose.Schema.Types.ObjectId;
|
|
8
8
|
adhere_dnt: Boolean;
|
|
9
9
|
allow_in_iframes: Boolean;
|
|
10
|
-
viewId?: string;
|
|
11
|
-
clientScriptURL: string;
|
|
12
10
|
jquery_include: string;
|
|
13
11
|
debug: Boolean;
|
|
14
12
|
restrict_debug: Boolean;
|
|
15
13
|
max_cookie_lifetime: Number;
|
|
16
14
|
activation_mode: string;
|
|
17
15
|
use_antiflicker: Boolean;
|
|
18
|
-
snippet_revision: Number;
|
|
19
16
|
snippet_version: Number;
|
|
20
17
|
rules: string;
|
|
21
18
|
rules_tracking: string;
|
|
@@ -38,6 +35,7 @@ export interface IClientScript extends Document {
|
|
|
38
35
|
goalsEnabled: Boolean;
|
|
39
36
|
optedOut: Boolean;
|
|
40
37
|
liveEventListenersSet: Boolean;
|
|
38
|
+
active: Boolean;
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
const ClientScriptSchema = new Schema<IClientScript>(
|
|
@@ -55,13 +53,6 @@ const ClientScriptSchema = new Schema<IClientScript>(
|
|
|
55
53
|
type: mongoose.Schema.Types.ObjectId,
|
|
56
54
|
ref: "client",
|
|
57
55
|
},
|
|
58
|
-
viewId: {
|
|
59
|
-
type: String,
|
|
60
|
-
},
|
|
61
|
-
clientScriptURL: {
|
|
62
|
-
type: String,
|
|
63
|
-
trim: true,
|
|
64
|
-
},
|
|
65
56
|
jquery_include: {
|
|
66
57
|
type: String,
|
|
67
58
|
default: "false",
|
|
@@ -90,10 +81,6 @@ const ClientScriptSchema = new Schema<IClientScript>(
|
|
|
90
81
|
type: Boolean,
|
|
91
82
|
default: false,
|
|
92
83
|
},
|
|
93
|
-
snippet_revision: {
|
|
94
|
-
type: Number,
|
|
95
|
-
default: 1,
|
|
96
|
-
},
|
|
97
84
|
rules: {
|
|
98
85
|
type: String,
|
|
99
86
|
default: "return true;",
|
|
@@ -182,6 +169,10 @@ const ClientScriptSchema = new Schema<IClientScript>(
|
|
|
182
169
|
type: Boolean,
|
|
183
170
|
default: false,
|
|
184
171
|
},
|
|
172
|
+
active: {
|
|
173
|
+
type: Boolean,
|
|
174
|
+
default: true,
|
|
175
|
+
},
|
|
185
176
|
},
|
|
186
177
|
{
|
|
187
178
|
timestamps: true,
|
|
@@ -206,9 +197,6 @@ ClientScriptSchema.pre('save', async function(next) {
|
|
|
206
197
|
ClientScriptSchema.index({ iid: 1 }, { unique: true });
|
|
207
198
|
// Compound indexes for common query patterns
|
|
208
199
|
ClientScriptSchema.index({ client: 1 });
|
|
209
|
-
// Sparse indexes for optional fields
|
|
210
|
-
ClientScriptSchema.index({ organisationId: 1 }, { sparse: true });
|
|
211
|
-
ClientScriptSchema.index({ asset_url: 1 }, { sparse: true });
|
|
212
200
|
|
|
213
201
|
|
|
214
202
|
const ClientScript = mongoose.models.clientscript || model<IClientScript>("clientscript", ClientScriptSchema);
|
package/src/models/Role.ts
CHANGED
|
@@ -20,44 +20,56 @@ export interface IRole extends Document {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const RoleSchema = new Schema<IRole>(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const RoleSchema = new Schema<IRole>(
|
|
24
|
+
{
|
|
25
|
+
name: {
|
|
26
|
+
type: String,
|
|
27
|
+
unique: true,
|
|
28
|
+
required: true,
|
|
29
|
+
enum: [
|
|
30
|
+
"USER",
|
|
31
|
+
"ADMIN",
|
|
32
|
+
"EDITOR",
|
|
33
|
+
"COLLABORATOR",
|
|
34
|
+
"CLIENT",
|
|
35
|
+
"EXTERNAL",
|
|
36
|
+
"QA",
|
|
37
|
+
"OPTIMIZER",
|
|
38
|
+
],
|
|
39
|
+
trim: true,
|
|
40
|
+
uppercase: true,
|
|
41
|
+
},
|
|
42
|
+
description: {
|
|
43
|
+
type: String,
|
|
44
|
+
trim: true,
|
|
45
|
+
},
|
|
46
|
+
organizationId: {
|
|
47
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
48
|
+
ref: "organization",
|
|
49
|
+
default: null,
|
|
50
|
+
},
|
|
51
|
+
isActive: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: true,
|
|
54
|
+
},
|
|
55
|
+
defaultPermissions: {
|
|
56
|
+
abTestingDefault: { type: Boolean, default: true },
|
|
57
|
+
abTesting: { type: Boolean, default: false },
|
|
58
|
+
preCalculations: { type: Boolean, default: true },
|
|
59
|
+
reporting: { type: Boolean, default: true },
|
|
60
|
+
insights: { type: Boolean, default: true },
|
|
61
|
+
documentsAndLinks: { type: Boolean, default: true },
|
|
62
|
+
cvrReports: { type: Boolean, default: true },
|
|
63
|
+
manageExperiments: { type: Boolean, default: true },
|
|
64
|
+
dashboard: { type: Boolean, default: true },
|
|
65
|
+
},
|
|
31
66
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
trim: true,
|
|
35
|
-
},
|
|
36
|
-
organizationId: {
|
|
37
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
38
|
-
ref: "organization",
|
|
39
|
-
default: null,
|
|
40
|
-
},
|
|
41
|
-
isActive: {
|
|
42
|
-
type: Boolean,
|
|
43
|
-
default: true,
|
|
44
|
-
},
|
|
45
|
-
defaultPermissions: {
|
|
46
|
-
abTestingDefault: { type: Boolean, default: true },
|
|
47
|
-
abTesting: { type: Boolean, default: false },
|
|
48
|
-
preCalculations: { type: Boolean, default: true },
|
|
49
|
-
reporting: { type: Boolean, default: true },
|
|
50
|
-
insights: { type: Boolean, default: true },
|
|
51
|
-
documentsAndLinks: { type: Boolean, default: true },
|
|
52
|
-
cvrReports: { type: Boolean, default: true },
|
|
53
|
-
manageExperiments: { type: Boolean, default: true },
|
|
54
|
-
dashboard: { type: Boolean, default: true },
|
|
67
|
+
{
|
|
68
|
+
timestamps: true,
|
|
55
69
|
}
|
|
56
|
-
|
|
57
|
-
timestamps: true
|
|
58
|
-
});
|
|
70
|
+
);
|
|
59
71
|
// IF role is CLIENT then defaultPermissions should be false for all modules except reporting, insights, documentsAndLinks, cvrReports, dashboard
|
|
60
|
-
RoleSchema.pre(
|
|
72
|
+
RoleSchema.pre("save", function (next) {
|
|
61
73
|
const allTrue = {
|
|
62
74
|
abTestingDefault: true,
|
|
63
75
|
abTesting: true,
|
|
@@ -69,7 +81,7 @@ RoleSchema.pre('save', function(next) {
|
|
|
69
81
|
cvrReports: true,
|
|
70
82
|
dashboard: true,
|
|
71
83
|
};
|
|
72
|
-
if (this.name ===
|
|
84
|
+
if (this.name === "CLIENT") {
|
|
73
85
|
this.defaultPermissions = {
|
|
74
86
|
...allTrue,
|
|
75
87
|
abTesting: false, // only this one is false
|
|
@@ -88,9 +100,9 @@ RoleSchema.index({ name: 1, isActive: 1 });
|
|
|
88
100
|
RoleSchema.index({ organizationId: 1, name: 1 });
|
|
89
101
|
|
|
90
102
|
// Add text index for search
|
|
91
|
-
RoleSchema.index({
|
|
92
|
-
name:
|
|
93
|
-
description:
|
|
103
|
+
RoleSchema.index({
|
|
104
|
+
name: "text",
|
|
105
|
+
description: "text",
|
|
94
106
|
});
|
|
95
107
|
|
|
96
108
|
const Role = mongoose.models.role || model<IRole>("role", RoleSchema);
|