@webbio/strapi-plugin-page-builder 0.3.2 → 0.3.3-legacy
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/README.md +21 -6
- package/admin/src/api/collection-type.ts +1 -7
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +11 -14
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +27 -9
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +16 -6
- package/admin/src/components/EditView/Details/index.tsx +1 -1
- package/admin/src/components/EditView/PageSettings/index.tsx +6 -57
- package/admin/src/components/PageTypeFilter/index.tsx +17 -0
- package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -0
- package/admin/src/index.tsx +2 -2
- package/admin/src/utils/sanitizeModules.ts +92 -9
- package/dist/package.json +11 -9
- package/dist/server/bootstrap.js +24 -40
- package/dist/server/content-types/user-categories/schema.json +18 -0
- package/dist/server/content-types/user-category/schema.json +23 -0
- package/dist/server/controllers/index.js +1 -3
- package/dist/server/controllers/platform.js +5 -5
- package/dist/server/controllers/private-content.js +18 -0
- package/dist/server/controllers/sitemap.js +29 -0
- package/dist/server/controllers/user-category.js +4 -0
- package/dist/server/graphql/page-by-path.js +113 -0
- package/dist/server/graphql/pages-by-uid.js +7 -9
- package/dist/server/policies/isAuthorizedPage.js +11 -0
- package/dist/server/routes/index.js +0 -21
- package/dist/server/routes/user-category.js +4 -0
- package/dist/server/schema/page-end.json +0 -5
- package/dist/server/schema/platform-start.json +0 -10
- package/dist/server/schema/template-end.json +40 -0
- package/dist/server/services/builder.js +5 -15
- package/dist/server/services/email.js +160 -0
- package/dist/server/services/index.js +1 -3
- package/dist/server/services/platform.js +6 -11
- package/dist/server/services/private-content/components/admin-email.json +22 -0
- package/dist/server/services/private-content/components/email.json +22 -0
- package/dist/server/services/private-content/components/platform-email.json +33 -0
- package/dist/server/services/private-content/constants/index.js +16 -0
- package/dist/server/services/private-content/graphql/index.js +77 -0
- package/dist/server/services/private-content/graphql/resolvers/findOnePage.js +40 -0
- package/dist/server/services/private-content/graphql/resolvers/findPage.js +44 -0
- package/dist/server/services/private-content/graphql/resolvers/forgot-password.js +29 -0
- package/dist/server/services/private-content/graphql/resolvers/login.js +49 -0
- package/dist/server/services/private-content/graphql/resolvers/register.js +68 -0
- package/dist/server/services/private-content/graphql/resolvers/reset-password.js +41 -0
- package/dist/server/services/private-content/graphql/types/index.js +89 -0
- package/dist/server/services/private-content/index.js +94 -0
- package/dist/server/services/private-content/mail-template/txtMail.email.template.text.js +12 -0
- package/dist/server/services/private-content/page.js +22 -0
- package/dist/server/services/private-content/platform.js +22 -0
- package/dist/server/services/private-content/schemas/index.js +30 -0
- package/dist/server/services/private-content/user.js +170 -0
- package/dist/server/services/sitemap.js +78 -0
- package/dist/server/services/template.js +1 -2
- package/dist/server/services/user-category.js +4 -0
- package/dist/server/utils/strapi.js +1 -4
- package/dist/shared/utils/constants.js +1 -3
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +11 -9
- package/server/bootstrap/collection-type-lifecycles.ts +1 -1
- package/server/bootstrap.ts +24 -43
- package/server/controllers/index.ts +1 -3
- package/server/graphql/pages-by-uid.ts +7 -9
- package/server/routes/index.ts +0 -21
- package/server/schema/page-end.json +0 -5
- package/server/services/builder.ts +6 -18
- package/server/services/index.ts +1 -3
- package/server/services/template.ts +1 -2
- package/server/utils/strapi.ts +1 -5
- package/shared/utils/constants.ts +0 -2
- package/admin/src/api/platform.ts +0 -34
- package/admin/src/components/EditView/Platform/platform-select.tsx +0 -30
- package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +0 -39
- package/admin/src/components/PageFilters/PlatformFilter/index.tsx +0 -28
- package/admin/src/components/PageFilters/filters.tsx +0 -180
- package/admin/src/components/PageFilters/index.tsx +0 -30
- package/server/controllers/platform.ts +0 -21
- package/server/schema/platform-start.json +0 -31
- package/server/services/platform.ts +0 -36
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queries = exports.Mutations = exports.ResetPasswordResponse = exports.ResetPasswordInput = exports.ResetPassword = exports.User = exports.ForgotPasswordResponse = exports.RegisterResponse = exports.LoginResponse = exports.RegisterInput = exports.ForgotPasswordInput = exports.LoginInput = void 0;
|
|
4
|
+
exports.LoginInput = `
|
|
5
|
+
input LoginInput {
|
|
6
|
+
email: String!
|
|
7
|
+
password: String!
|
|
8
|
+
domain: String!
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
exports.ForgotPasswordInput = `
|
|
12
|
+
input ForgotPasswordInput {
|
|
13
|
+
email: String!
|
|
14
|
+
domain: String!
|
|
15
|
+
}`;
|
|
16
|
+
exports.RegisterInput = `
|
|
17
|
+
input RegisterInput {
|
|
18
|
+
email: String!
|
|
19
|
+
password: String!
|
|
20
|
+
firstName: String
|
|
21
|
+
lastName: String
|
|
22
|
+
company: String
|
|
23
|
+
jobTitle: String
|
|
24
|
+
address: String
|
|
25
|
+
postalCode: String
|
|
26
|
+
city: String
|
|
27
|
+
country: String
|
|
28
|
+
phone: String
|
|
29
|
+
subscribeToNewsletter: Boolean
|
|
30
|
+
categories: [ID]
|
|
31
|
+
domain: String!
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
exports.LoginResponse = `
|
|
35
|
+
type LoginResponse {
|
|
36
|
+
jwt: String
|
|
37
|
+
user: User
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
exports.RegisterResponse = `
|
|
41
|
+
type RegisterResponse {
|
|
42
|
+
user: User
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
exports.ForgotPasswordResponse = `
|
|
46
|
+
type ForgotPasswordResponse {
|
|
47
|
+
message: String
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
exports.User = `
|
|
51
|
+
type User {
|
|
52
|
+
id: ID!
|
|
53
|
+
email: String!
|
|
54
|
+
confirmed: Boolean
|
|
55
|
+
blocked: Boolean
|
|
56
|
+
activated: Boolean
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
exports.ResetPassword = `
|
|
60
|
+
type ResetPassword {
|
|
61
|
+
jwt: String
|
|
62
|
+
email: String
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
exports.ResetPasswordInput = `
|
|
66
|
+
input ResetPasswordInput {
|
|
67
|
+
password: String!
|
|
68
|
+
resetPasswordToken: String!
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
exports.ResetPasswordResponse = `
|
|
72
|
+
type ResetPasswordResponse {
|
|
73
|
+
user: User
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
exports.Mutations = `
|
|
77
|
+
type Mutation {
|
|
78
|
+
platformLogin(input: LoginInput!): LoginResponse
|
|
79
|
+
platformRegister(input: RegisterInput!): RegisterResponse
|
|
80
|
+
platformForgotPassword(input: ForgotPasswordInput!): ForgotPasswordResponse
|
|
81
|
+
platformResetPassword(input: ResetPasswordInput!): ResetPasswordResponse
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
exports.Queries = `
|
|
85
|
+
type Query {
|
|
86
|
+
page(id: ID, locale: I18NLocaleCode): PageEntityResponse
|
|
87
|
+
pages(filters: PageFiltersInput pagination: PaginationArg = {} sort: [String] = [] publicationState: PublicationState = LIVE locale: I18NLocaleCode): PageEntityResponseCollection
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const strapi_1 = require("../../utils/strapi");
|
|
4
|
+
const user_1 = require("./user");
|
|
5
|
+
const graphql_1 = require("./graphql");
|
|
6
|
+
const platform_1 = require("./platform");
|
|
7
|
+
const page_1 = require("./page");
|
|
8
|
+
exports.default = {
|
|
9
|
+
async enablePrivateContent() {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
if (this.isPrivateContentEnabled()) {
|
|
12
|
+
await ((_b = (_a = strapi.services) === null || _a === void 0 ? void 0 : _a['plugin::page-builder.builder']) === null || _b === void 0 ? void 0 : _b.buildComponents());
|
|
13
|
+
(0, user_1.extendUser)();
|
|
14
|
+
(0, user_1.extendControllers)();
|
|
15
|
+
(0, graphql_1.extendGraphQL)();
|
|
16
|
+
(0, platform_1.extendPlatform)();
|
|
17
|
+
(0, page_1.extendPage)();
|
|
18
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
19
|
+
extensionService.shadowCRUD('api::page.page').disableActions(['find', 'findOne']);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
isPrivateContentEnabled() {
|
|
23
|
+
const pageBuilderConfig = (0, strapi_1.getConfig)();
|
|
24
|
+
return (pageBuilderConfig === null || pageBuilderConfig === void 0 ? void 0 : pageBuilderConfig.privateContent) === true;
|
|
25
|
+
},
|
|
26
|
+
async activateUser(token) {
|
|
27
|
+
try {
|
|
28
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
29
|
+
const decodedToken = await jwtService.verify(token);
|
|
30
|
+
if (decodedToken) {
|
|
31
|
+
const user = await strapi.query('plugin::users-permissions.user').findOne({
|
|
32
|
+
where: {
|
|
33
|
+
id: decodedToken.userId,
|
|
34
|
+
platform: {
|
|
35
|
+
id: decodedToken.platformId
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
populate: {
|
|
39
|
+
platform: true
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if ((user === null || user === void 0 ? void 0 : user.confirmed) === false && (user === null || user === void 0 ? void 0 : user.confirmationToken) != null && (user === null || user === void 0 ? void 0 : user.confirmationToken) === token) {
|
|
43
|
+
await strapi.entityService.update('plugin::users-permissions.user', user.id, {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
data: { confirmed: true, confirmationToken: null }
|
|
46
|
+
});
|
|
47
|
+
await strapi.service('plugin::page-builder.email').sendAdminMail(user);
|
|
48
|
+
return user;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error("Error activating user. User doesn't exist or is already activated.");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error(error);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
async removeInactiveUsers() {
|
|
61
|
+
const oneDayAgo = new Date();
|
|
62
|
+
oneDayAgo.setHours(oneDayAgo.getHours() - 24);
|
|
63
|
+
const usersToDelete = await (await strapi.query('plugin::users-permissions.user').findMany({
|
|
64
|
+
where: {
|
|
65
|
+
$and: [
|
|
66
|
+
{
|
|
67
|
+
confirmed: {
|
|
68
|
+
$eq: false
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
createdAt: {
|
|
73
|
+
$lt: oneDayAgo
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
})).map((user) => {
|
|
79
|
+
return user.id;
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
await strapi.query('plugin::users-permissions.user').deleteMany({
|
|
83
|
+
where: {
|
|
84
|
+
id: {
|
|
85
|
+
$in: usersToDelete
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.log(error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.txtEmail = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const txtEmail = (text, variables) => {
|
|
9
|
+
const template = handlebars_1.default.compile(text);
|
|
10
|
+
return template(variables);
|
|
11
|
+
};
|
|
12
|
+
exports.txtEmail = txtEmail;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendPage = void 0;
|
|
4
|
+
const constants_1 = require("../../../shared/utils/constants");
|
|
5
|
+
const extendPage = () => {
|
|
6
|
+
const pageContentType = strapi.contentType(constants_1.PAGE_UID);
|
|
7
|
+
pageContentType.attributes = {
|
|
8
|
+
...pageContentType.attributes,
|
|
9
|
+
isPrivate: {
|
|
10
|
+
pluginOptions: {
|
|
11
|
+
i18n: {
|
|
12
|
+
localized: true
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
type: 'boolean',
|
|
16
|
+
required: false,
|
|
17
|
+
default: false
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
delete pageContentType.attributes.username;
|
|
21
|
+
};
|
|
22
|
+
exports.extendPage = extendPage;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendPlatform = void 0;
|
|
4
|
+
const constants_1 = require("../../../shared/utils/constants");
|
|
5
|
+
const extendPlatform = () => {
|
|
6
|
+
const platformContentType = strapi.contentType(constants_1.PLATFORM_UID);
|
|
7
|
+
platformContentType.attributes = {
|
|
8
|
+
...platformContentType.attributes,
|
|
9
|
+
isPrivate: {
|
|
10
|
+
type: 'boolean',
|
|
11
|
+
required: false,
|
|
12
|
+
default: false
|
|
13
|
+
},
|
|
14
|
+
platformEmails: {
|
|
15
|
+
type: 'component',
|
|
16
|
+
repeatable: false,
|
|
17
|
+
component: 'internal.platform-email'
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
delete platformContentType.attributes.username;
|
|
21
|
+
};
|
|
22
|
+
exports.extendPlatform = extendPlatform;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateResetPasswordSchema = exports.validateForgotPasswordSchema = exports.validateLoginSchema = exports.validateRegisterSchema = exports.resetPasswordSchema = exports.forgotPasswordSchema = exports.loginSchema = void 0;
|
|
4
|
+
const utils_1 = require("@strapi/utils");
|
|
5
|
+
const registerSchema = utils_1.yup.object({
|
|
6
|
+
email: utils_1.yup.string().email().required(),
|
|
7
|
+
password: utils_1.yup.string().required(),
|
|
8
|
+
domain: utils_1.yup.string().required()
|
|
9
|
+
});
|
|
10
|
+
exports.loginSchema = utils_1.yup.object({
|
|
11
|
+
email: utils_1.yup.string().email().required(),
|
|
12
|
+
password: utils_1.yup.string().required(),
|
|
13
|
+
domain: utils_1.yup.string().required()
|
|
14
|
+
});
|
|
15
|
+
exports.forgotPasswordSchema = utils_1.yup.object({
|
|
16
|
+
email: utils_1.yup.string().email().required(),
|
|
17
|
+
domain: utils_1.yup.string().required()
|
|
18
|
+
});
|
|
19
|
+
exports.resetPasswordSchema = utils_1.yup.object({
|
|
20
|
+
password: utils_1.yup.string().required(),
|
|
21
|
+
resetPasswordToken: utils_1.yup.string().required()
|
|
22
|
+
});
|
|
23
|
+
const validateRegisterSchema = async (input) => (0, utils_1.validateYupSchema)(input, registerSchema);
|
|
24
|
+
exports.validateRegisterSchema = validateRegisterSchema;
|
|
25
|
+
const validateLoginSchema = async (input) => (0, utils_1.validateYupSchema)(input, exports.loginSchema);
|
|
26
|
+
exports.validateLoginSchema = validateLoginSchema;
|
|
27
|
+
const validateForgotPasswordSchema = async (input) => (0, utils_1.validateYupSchema)(input, exports.forgotPasswordSchema);
|
|
28
|
+
exports.validateForgotPasswordSchema = validateForgotPasswordSchema;
|
|
29
|
+
const validateResetPasswordSchema = async (input) => (0, utils_1.validateYupSchema)(input, exports.resetPasswordSchema);
|
|
30
|
+
exports.validateResetPasswordSchema = validateResetPasswordSchema;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extendControllers = exports.extendUser = void 0;
|
|
7
|
+
const toString_1 = __importDefault(require("lodash/toString"));
|
|
8
|
+
const has_1 = __importDefault(require("lodash/has"));
|
|
9
|
+
const omit_1 = __importDefault(require("lodash/omit"));
|
|
10
|
+
const utils_1 = require("@strapi/utils");
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const { ApplicationError, ValidationError, NotFoundError, ForbiddenError } = utils_1.errors;
|
|
13
|
+
const extendUser = () => {
|
|
14
|
+
const userContentType = strapi.contentType(constants_1.USER_MODEL);
|
|
15
|
+
userContentType.attributes = {
|
|
16
|
+
// Spread previous defined attributes
|
|
17
|
+
...userContentType.attributes,
|
|
18
|
+
// Add new, or override attributes
|
|
19
|
+
platform: {
|
|
20
|
+
type: 'relation',
|
|
21
|
+
relation: 'oneToOne',
|
|
22
|
+
target: 'api::platform.platform',
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
firstName: {
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
28
|
+
lastName: {
|
|
29
|
+
type: 'string'
|
|
30
|
+
},
|
|
31
|
+
company: {
|
|
32
|
+
type: 'string'
|
|
33
|
+
},
|
|
34
|
+
jobTitle: {
|
|
35
|
+
type: 'string'
|
|
36
|
+
},
|
|
37
|
+
address: {
|
|
38
|
+
type: 'string'
|
|
39
|
+
},
|
|
40
|
+
postalCode: {
|
|
41
|
+
type: 'string'
|
|
42
|
+
},
|
|
43
|
+
city: {
|
|
44
|
+
type: 'string'
|
|
45
|
+
},
|
|
46
|
+
country: {
|
|
47
|
+
type: 'string'
|
|
48
|
+
},
|
|
49
|
+
phone: {
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
52
|
+
activateUser: {
|
|
53
|
+
type: 'boolean',
|
|
54
|
+
default: false
|
|
55
|
+
},
|
|
56
|
+
categories: {
|
|
57
|
+
type: 'relation',
|
|
58
|
+
relation: 'oneToMany',
|
|
59
|
+
target: 'plugin::page-builder.user-category'
|
|
60
|
+
},
|
|
61
|
+
filteredCategories: {
|
|
62
|
+
pluginOptions: {
|
|
63
|
+
filteredSelect: {
|
|
64
|
+
targetField: 'categories'
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
type: 'customField',
|
|
69
|
+
customField: 'plugin::page-builder.filtered-select'
|
|
70
|
+
},
|
|
71
|
+
confirmMailSend: {
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
private: true,
|
|
74
|
+
writable: false,
|
|
75
|
+
visible: false,
|
|
76
|
+
default: false
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
delete userContentType.attributes.username;
|
|
80
|
+
};
|
|
81
|
+
exports.extendUser = extendUser;
|
|
82
|
+
const extendControllers = () => {
|
|
83
|
+
const contentController = strapi.controller(constants_1.USER_CONTENT_MANAGER);
|
|
84
|
+
contentController.create = async (ctx) => {
|
|
85
|
+
var _a, _b, _c, _d, _e, _f;
|
|
86
|
+
const { body } = ctx.request;
|
|
87
|
+
const { user: admin, userAbility } = ctx.state;
|
|
88
|
+
const { email } = body;
|
|
89
|
+
const platformId = (_c = (_b = (_a = body === null || body === void 0 ? void 0 : body.platform) === null || _a === void 0 ? void 0 : _a.connect) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.id;
|
|
90
|
+
const pm = (_d = strapi === null || strapi === void 0 ? void 0 : strapi.admin) === null || _d === void 0 ? void 0 : _d.services.permission.createPermissionsManager({
|
|
91
|
+
ability: userAbility,
|
|
92
|
+
action: constants_1.ACTIONS.create,
|
|
93
|
+
model: constants_1.USER_MODEL
|
|
94
|
+
});
|
|
95
|
+
if (!pm.isAllowed) {
|
|
96
|
+
return ctx.forbidden();
|
|
97
|
+
}
|
|
98
|
+
const sanitizedBody = await pm.pickPermittedFieldsOf(body, { subject: constants_1.USER_MODEL });
|
|
99
|
+
const userWithSameEmail = await strapi.query(constants_1.USER_MODEL).findOne({
|
|
100
|
+
where: { $and: [{ email: email.toLowerCase() }, { platform: { id: platformId } }] }
|
|
101
|
+
});
|
|
102
|
+
if (userWithSameEmail) {
|
|
103
|
+
throw new ApplicationError('Email already taken');
|
|
104
|
+
}
|
|
105
|
+
const user = {
|
|
106
|
+
...sanitizedBody,
|
|
107
|
+
provider: 'local',
|
|
108
|
+
[constants_1.CREATED_BY_ATTRIBUTE]: admin.id,
|
|
109
|
+
[constants_1.UPDATED_BY_ATTRIBUTE]: admin.id
|
|
110
|
+
};
|
|
111
|
+
user.email = user.email.toLowerCase();
|
|
112
|
+
const advanced = await (strapi === null || strapi === void 0 ? void 0 : strapi.store({ type: 'plugin', name: 'users-permissions', key: 'advanced' }).get({}));
|
|
113
|
+
if ((((_f = (_e = user === null || user === void 0 ? void 0 : user.role) === null || _e === void 0 ? void 0 : _e.connect) === null || _f === void 0 ? void 0 : _f.length) || 0) === 0) {
|
|
114
|
+
//@ts-ignore strapi types...
|
|
115
|
+
const defaultRole = await strapi.query(constants_1.USER_ROLE).findOne({ where: { type: advanced.default_role } });
|
|
116
|
+
user.role = defaultRole.id;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const data = await strapi.service(constants_1.CONTENT_ENTITY_MANAGER).create(user, constants_1.USER_MODEL);
|
|
120
|
+
const sanitizedData = await pm.sanitizeOutput(data, { action: constants_1.ACTIONS.read });
|
|
121
|
+
ctx.created(sanitizedData);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new ApplicationError(error.message);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
contentController.update = async (ctx) => {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
const { id } = ctx.params;
|
|
130
|
+
const { body } = ctx.request;
|
|
131
|
+
const { user: admin, userAbility } = ctx.state;
|
|
132
|
+
const { email, password } = body;
|
|
133
|
+
const { pm, entity } = await findEntityAndCheckPermissions(userAbility, constants_1.ACTIONS.edit, constants_1.USER_MODEL, id);
|
|
134
|
+
const user = entity;
|
|
135
|
+
const platformId = (((_b = (_a = body === null || body === void 0 ? void 0 : body.platform) === null || _a === void 0 ? void 0 : _a.connect) === null || _b === void 0 ? void 0 : _b.length) || 0) > 0 ? body.platform.connect[0].id : entity.platform.id;
|
|
136
|
+
if ((0, has_1.default)(body, 'password') && !password && user.provider === 'local') {
|
|
137
|
+
throw new ValidationError('password.notNull');
|
|
138
|
+
}
|
|
139
|
+
//@ts-ignore
|
|
140
|
+
if ((0, has_1.default)(body, 'email')) {
|
|
141
|
+
const userWithSameEmail = await strapi
|
|
142
|
+
.query(constants_1.USER_MODEL)
|
|
143
|
+
.findOne({ where: { $and: [{ email: email.toLowerCase() }, { platform: { id: platformId } }] } });
|
|
144
|
+
if (userWithSameEmail && (0, toString_1.default)(userWithSameEmail.id) !== (0, toString_1.default)(id)) {
|
|
145
|
+
throw new ApplicationError('Email already taken');
|
|
146
|
+
}
|
|
147
|
+
body.email = body.email.toLowerCase();
|
|
148
|
+
}
|
|
149
|
+
const sanitizedData = await pm.pickPermittedFieldsOf(body, { subject: pm.toSubject(user) });
|
|
150
|
+
const updateData = (0, omit_1.default)({ ...sanitizedData, updatedBy: admin.id }, 'createdBy');
|
|
151
|
+
const data = await strapi.service('plugin::content-manager.entity-manager').update({ id }, updateData, constants_1.USER_MODEL);
|
|
152
|
+
ctx.body = await pm.sanitizeOutput(data, { action: constants_1.ACTIONS.read });
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
exports.extendControllers = extendControllers;
|
|
156
|
+
const findEntityAndCheckPermissions = async (ability, action, model, id) => {
|
|
157
|
+
const entity = await strapi.query(constants_1.USER_MODEL).findOne({
|
|
158
|
+
where: { id },
|
|
159
|
+
populate: [`${constants_1.CREATED_BY_ATTRIBUTE}.roles`, 'platform']
|
|
160
|
+
});
|
|
161
|
+
if (!entity) {
|
|
162
|
+
throw new NotFoundError();
|
|
163
|
+
}
|
|
164
|
+
const pm = strapi.admin.services.permission.createPermissionsManager({ ability, action, model });
|
|
165
|
+
if (pm.ability.cannot(pm.action, pm.toSubject(entity))) {
|
|
166
|
+
throw new ForbiddenError();
|
|
167
|
+
}
|
|
168
|
+
const entityWithoutCreatorRoles = (0, omit_1.default)(entity, `${constants_1.CREATED_BY_ATTRIBUTE}.roles`);
|
|
169
|
+
return { pm, entity: entityWithoutCreatorRoles };
|
|
170
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sitemap_1 = require("sitemap");
|
|
4
|
+
const constants_1 = require("../../shared/utils/constants");
|
|
5
|
+
exports.default = {
|
|
6
|
+
async generateSitemap(domain) {
|
|
7
|
+
try {
|
|
8
|
+
const entities = await this.fetchPages(domain);
|
|
9
|
+
if (entities.length === 0) {
|
|
10
|
+
throw new Error('Cannot generate a sitemap with 0 pages');
|
|
11
|
+
}
|
|
12
|
+
const sitemapStream = new sitemap_1.SitemapStream();
|
|
13
|
+
for (const entity of entities) {
|
|
14
|
+
const { path, updatedAt } = entity;
|
|
15
|
+
const url = path === '/' ? domain : `${domain}/${path}`;
|
|
16
|
+
sitemapStream.write({
|
|
17
|
+
url,
|
|
18
|
+
changefreq: 'always',
|
|
19
|
+
lastmod: updatedAt,
|
|
20
|
+
priority: 1
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
sitemapStream.end();
|
|
24
|
+
const sitemapPromise = await (0, sitemap_1.streamToPromise)(sitemapStream);
|
|
25
|
+
const sitemap = sitemapPromise.toString();
|
|
26
|
+
return sitemap;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(error);
|
|
30
|
+
throw new Error(`Error generating sitemap for domain ${domain}`);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
async fetchPages(domain) {
|
|
34
|
+
const entities = await strapi.query(constants_1.PAGE_UID).findMany({
|
|
35
|
+
select: ['path', 'updatedAt'],
|
|
36
|
+
where: {
|
|
37
|
+
$and: [
|
|
38
|
+
{
|
|
39
|
+
platform: {
|
|
40
|
+
domain: {
|
|
41
|
+
$eq: domain
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
path: {
|
|
47
|
+
$notNull: true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
publishedAt: {
|
|
52
|
+
$notNull: true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
$or: [
|
|
57
|
+
{
|
|
58
|
+
seo: {
|
|
59
|
+
metaRobots: {
|
|
60
|
+
$notContainsi: 'noindex'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
seo: {
|
|
66
|
+
metaRobots: {
|
|
67
|
+
$null: true
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return entities;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -8,7 +8,6 @@ exports.default = {
|
|
|
8
8
|
return foundTemplates;
|
|
9
9
|
},
|
|
10
10
|
async findOne(id) {
|
|
11
|
-
|
|
12
|
-
return getpopulatedTemplate;
|
|
11
|
+
return await (0, strapi_1.getPopulatedEntity)(constants_1.TEMPLATE_UID, id);
|
|
13
12
|
}
|
|
14
13
|
};
|
|
@@ -11,15 +11,12 @@ const getDeepPopulate = (uid, populate, depth = 0) => {
|
|
|
11
11
|
const { attributes } = strapi.getModel(uid);
|
|
12
12
|
return Object.keys(attributes).reduce((populateAcc, attributeName) => {
|
|
13
13
|
const attribute = attributes[attributeName];
|
|
14
|
-
if (attribute.type === 'relation') {
|
|
15
|
-
return populateAcc;
|
|
16
|
-
}
|
|
17
14
|
if (attribute.type === 'component') {
|
|
18
15
|
populateAcc[attributeName] = {
|
|
19
16
|
populate: (0, exports.getDeepPopulate)(attribute.component, null, depth + 1)
|
|
20
17
|
};
|
|
21
18
|
}
|
|
22
|
-
if (attribute.type === 'media') {
|
|
19
|
+
if (attribute.type === 'relation' || attribute.type === 'media') {
|
|
23
20
|
populateAcc[attributeName] = true;
|
|
24
21
|
}
|
|
25
22
|
if (attribute.type === 'dynamiczone') {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PAGE_TYPE_PAGE = exports.PAGE_TYPE_UID = exports.TEMPLATE_UID = exports.PAGE_UID = void 0;
|
|
4
4
|
exports.PAGE_UID = 'api::page.page';
|
|
5
5
|
exports.TEMPLATE_UID = 'api::template.template';
|
|
6
6
|
exports.PAGE_TYPE_UID = 'api::page-type.page-type';
|
|
7
|
-
exports.PLATFORM_UID = 'api::platform.platform';
|
|
8
7
|
exports.PAGE_TYPE_PAGE = 'page';
|
|
9
|
-
exports.PLATFORM = 'platform';
|