directus 9.0.1 → 9.2.0
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/app.js +2 -0
- package/dist/auth/drivers/ldap.js +9 -13
- package/dist/auth/drivers/oauth2.d.ts +1 -1
- package/dist/auth/drivers/oauth2.js +2 -2
- package/dist/auth/drivers/openid.d.ts +1 -1
- package/dist/auth/drivers/openid.js +8 -2
- package/dist/auth.js +5 -3
- package/dist/cli/commands/database/install.js +2 -4
- package/dist/cli/commands/schema/apply.js +26 -10
- package/dist/controllers/assets.js +0 -27
- package/dist/controllers/auth.js +7 -2
- package/dist/controllers/extensions.js +1 -1
- package/dist/controllers/notifications.d.ts +2 -0
- package/dist/controllers/notifications.js +147 -0
- package/dist/database/{functions/types.d.ts → helpers/date/dialects/mssql.d.ts} +2 -1
- package/dist/database/{functions → helpers/date}/dialects/mssql.js +4 -6
- package/dist/database/{functions → helpers/date}/dialects/mysql.d.ts +2 -4
- package/dist/database/{functions → helpers/date}/dialects/mysql.js +4 -6
- package/dist/database/{functions/dialects/mssql.d.ts → helpers/date/dialects/oracle.d.ts} +2 -4
- package/dist/database/{functions → helpers/date}/dialects/oracle.js +4 -6
- package/dist/database/helpers/date/dialects/postgres.d.ts +12 -0
- package/dist/database/{functions → helpers/date}/dialects/postgres.js +4 -6
- package/dist/database/{functions → helpers/date}/dialects/sqlite.d.ts +3 -4
- package/dist/database/helpers/date/dialects/sqlite.js +35 -0
- package/dist/database/helpers/date/index.d.ts +6 -0
- package/dist/database/helpers/date/index.js +15 -0
- package/dist/database/helpers/date/types.d.ts +13 -0
- package/dist/database/helpers/date/types.js +10 -0
- package/dist/database/helpers/geometry/dialects/mssql.d.ts +14 -0
- package/dist/database/helpers/geometry/dialects/mssql.js +36 -0
- package/dist/database/helpers/geometry/dialects/mysql.d.ts +7 -0
- package/dist/database/helpers/geometry/dialects/mysql.js +16 -0
- package/dist/database/helpers/geometry/dialects/oracle.d.ts +15 -0
- package/dist/database/helpers/geometry/dialects/oracle.js +39 -0
- package/dist/database/helpers/geometry/dialects/postgres.d.ts +10 -0
- package/dist/database/helpers/geometry/dialects/postgres.js +23 -0
- package/dist/database/helpers/geometry/dialects/redshift.d.ts +7 -0
- package/dist/database/helpers/geometry/dialects/redshift.js +16 -0
- package/dist/database/helpers/geometry/dialects/sqlite.d.ts +6 -0
- package/dist/database/helpers/geometry/dialects/sqlite.js +14 -0
- package/dist/database/helpers/geometry/index.d.ts +6 -0
- package/dist/database/helpers/geometry/index.js +15 -0
- package/dist/database/helpers/{geometry.d.ts → geometry/types.d.ts} +3 -7
- package/dist/database/helpers/geometry/types.js +54 -0
- package/dist/database/helpers/index.d.ts +8 -0
- package/dist/database/helpers/index.js +33 -0
- package/dist/database/helpers/types.d.ts +5 -0
- package/dist/database/helpers/types.js +9 -0
- package/dist/database/index.js +6 -6
- package/dist/database/migrations/20211118A-add-notifications.d.ts +3 -0
- package/dist/database/migrations/20211118A-add-notifications.js +28 -0
- package/dist/database/run-ast.js +5 -5
- package/dist/database/seeds/run.js +3 -3
- package/dist/database/system-data/app-access-permissions/app-access-permissions.yaml +14 -0
- package/dist/database/system-data/collections/collections.yaml +2 -0
- package/dist/database/system-data/fields/notifications.yaml +13 -0
- package/dist/database/system-data/fields/users.yaml +5 -0
- package/dist/database/system-data/relations/relations.yaml +6 -0
- package/dist/env.js +1 -0
- package/dist/extensions.js +17 -2
- package/dist/middleware/get-permissions.js +3 -102
- package/dist/middleware/sanitize-query.js +1 -1
- package/dist/services/activity.d.ts +7 -5
- package/dist/services/activity.js +87 -3
- package/dist/services/assets.js +14 -0
- package/dist/services/collections.js +12 -1
- package/dist/services/fields.d.ts +2 -0
- package/dist/services/fields.js +57 -26
- package/dist/services/files.d.ts +1 -1
- package/dist/services/files.js +13 -11
- package/dist/services/graphql.js +6 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/items.js +18 -29
- package/dist/services/mail/index.js +2 -2
- package/dist/services/mail/templates/base.liquid +153 -85
- package/dist/services/mail/templates/password-reset.liquid +3 -2
- package/dist/services/mail/templates/user-invitation.liquid +4 -4
- package/dist/services/notifications.d.ts +12 -0
- package/dist/services/notifications.js +41 -0
- package/dist/services/payload.d.ts +2 -0
- package/dist/services/payload.js +3 -3
- package/dist/services/users.js +1 -0
- package/dist/types/collection.d.ts +1 -0
- package/dist/utils/apply-query.js +9 -11
- package/dist/utils/apply-snapshot.js +27 -28
- package/dist/utils/get-column.js +2 -2
- package/dist/utils/get-default-index-name.js +2 -2
- package/dist/utils/get-local-type.js +11 -17
- package/dist/utils/get-permissions.d.ts +3 -0
- package/dist/utils/get-permissions.js +106 -0
- package/dist/utils/md.d.ts +4 -0
- package/dist/utils/md.js +15 -0
- package/dist/utils/merge-permissions.js +2 -2
- package/dist/utils/sanitize-query.js +4 -15
- package/dist/utils/user-name.d.ts +2 -0
- package/dist/utils/user-name.js +16 -0
- package/dist/utils/validate-query.js +1 -1
- package/dist/webhooks.js +16 -24
- package/package.json +27 -24
- package/dist/database/functions/dialects/oracle.d.ts +0 -14
- package/dist/database/functions/dialects/postgres.d.ts +0 -14
- package/dist/database/functions/dialects/sqlite.js +0 -33
- package/dist/database/functions/index.d.ts +0 -3
- package/dist/database/functions/index.js +0 -26
- package/dist/database/functions/types.js +0 -2
- package/dist/database/helpers/date.d.ts +0 -8
- package/dist/database/helpers/date.js +0 -44
- package/dist/database/helpers/geometry.js +0 -189
- package/dist/utils/get-simple-hash.d.ts +0 -5
- package/dist/utils/get-simple-hash.js +0 -15
package/dist/app.js
CHANGED
|
@@ -40,6 +40,7 @@ const graphql_1 = __importDefault(require("./controllers/graphql"));
|
|
|
40
40
|
const items_1 = __importDefault(require("./controllers/items"));
|
|
41
41
|
const not_found_1 = __importDefault(require("./controllers/not-found"));
|
|
42
42
|
const panels_1 = __importDefault(require("./controllers/panels"));
|
|
43
|
+
const notifications_1 = __importDefault(require("./controllers/notifications"));
|
|
43
44
|
const permissions_1 = __importDefault(require("./controllers/permissions"));
|
|
44
45
|
const presets_1 = __importDefault(require("./controllers/presets"));
|
|
45
46
|
const relations_1 = __importDefault(require("./controllers/relations"));
|
|
@@ -163,6 +164,7 @@ async function createApp() {
|
|
|
163
164
|
app.use('/files', files_1.default);
|
|
164
165
|
app.use('/folders', folders_1.default);
|
|
165
166
|
app.use('/items', items_1.default);
|
|
167
|
+
app.use('/notifications', notifications_1.default);
|
|
166
168
|
app.use('/panels', panels_1.default);
|
|
167
169
|
app.use('/permissions', permissions_1.default);
|
|
168
170
|
app.use('/presets', presets_1.default);
|
|
@@ -91,21 +91,16 @@ class LDAPAuthDriver extends auth_1.AuthDriver {
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
async fetchUserDn(identifier) {
|
|
94
|
-
const { userDn, userAttribute } = this.config;
|
|
94
|
+
const { userDn, userAttribute, userScope } = this.config;
|
|
95
95
|
return new Promise((resolve, reject) => {
|
|
96
96
|
// Search for the user in LDAP by attribute
|
|
97
|
-
this.bindClient.search(userDn, {
|
|
98
|
-
attributes: ['cn'],
|
|
99
|
-
filter: `(${userAttribute !== null && userAttribute !== void 0 ? userAttribute : 'cn'}=${identifier})`,
|
|
100
|
-
scope: 'one',
|
|
101
|
-
}, (err, res) => {
|
|
97
|
+
this.bindClient.search(userDn, { filter: `(${userAttribute !== null && userAttribute !== void 0 ? userAttribute : 'cn'}=${identifier})`, scope: userScope !== null && userScope !== void 0 ? userScope : 'one' }, (err, res) => {
|
|
102
98
|
if (err) {
|
|
103
99
|
reject(handleError(err));
|
|
104
100
|
return;
|
|
105
101
|
}
|
|
106
102
|
res.on('searchEntry', ({ object }) => {
|
|
107
|
-
|
|
108
|
-
resolve(`cn=${userCn},${userDn}`.toLowerCase());
|
|
103
|
+
resolve(object.dn.toLowerCase());
|
|
109
104
|
});
|
|
110
105
|
res.on('error', (err) => {
|
|
111
106
|
reject(handleError(err));
|
|
@@ -147,7 +142,7 @@ class LDAPAuthDriver extends auth_1.AuthDriver {
|
|
|
147
142
|
});
|
|
148
143
|
}
|
|
149
144
|
async fetchUserGroups(userDn) {
|
|
150
|
-
const { groupDn, groupAttribute } = this.config;
|
|
145
|
+
const { groupDn, groupAttribute, groupScope } = this.config;
|
|
151
146
|
if (!groupDn) {
|
|
152
147
|
return Promise.resolve([]);
|
|
153
148
|
}
|
|
@@ -157,7 +152,7 @@ class LDAPAuthDriver extends auth_1.AuthDriver {
|
|
|
157
152
|
this.bindClient.search(groupDn, {
|
|
158
153
|
attributes: ['cn'],
|
|
159
154
|
filter: `(${groupAttribute !== null && groupAttribute !== void 0 ? groupAttribute : 'member'}=${userDn})`,
|
|
160
|
-
scope: 'one',
|
|
155
|
+
scope: groupScope !== null && groupScope !== void 0 ? groupScope : 'one',
|
|
161
156
|
}, (err, res) => {
|
|
162
157
|
if (err) {
|
|
163
158
|
reject(handleError(err));
|
|
@@ -244,12 +239,13 @@ class LDAPAuthDriver extends auth_1.AuthDriver {
|
|
|
244
239
|
reject(handleError(err));
|
|
245
240
|
});
|
|
246
241
|
client.bind(user.external_identifier, password, (err) => {
|
|
247
|
-
client.destroy();
|
|
248
242
|
if (err) {
|
|
249
243
|
reject(handleError(err));
|
|
250
|
-
return;
|
|
251
244
|
}
|
|
252
|
-
|
|
245
|
+
else {
|
|
246
|
+
resolve();
|
|
247
|
+
}
|
|
248
|
+
client.destroy();
|
|
253
249
|
});
|
|
254
250
|
});
|
|
255
251
|
}
|
|
@@ -13,7 +13,7 @@ export declare class OAuth2AuthDriver extends LocalAuthDriver {
|
|
|
13
13
|
generateAuthUrl(codeVerifier: string): string;
|
|
14
14
|
private fetchUserId;
|
|
15
15
|
getUserID(payload: Record<string, any>): Promise<string>;
|
|
16
|
-
login(user: User
|
|
16
|
+
login(user: User): Promise<SessionData>;
|
|
17
17
|
refresh(user: User, sessionData: SessionData): Promise<SessionData>;
|
|
18
18
|
}
|
|
19
19
|
export declare function createOAuth2AuthRouter(providerName: string): Router;
|
|
@@ -123,8 +123,8 @@ class OAuth2AuthDriver extends local_1.LocalAuthDriver {
|
|
|
123
123
|
});
|
|
124
124
|
return (await this.fetchUserId(identifier));
|
|
125
125
|
}
|
|
126
|
-
async login(user
|
|
127
|
-
return this.refresh(user,
|
|
126
|
+
async login(user) {
|
|
127
|
+
return this.refresh(user, null);
|
|
128
128
|
}
|
|
129
129
|
async refresh(user, sessionData) {
|
|
130
130
|
let authData = user.auth_data;
|
|
@@ -13,7 +13,7 @@ export declare class OpenIDAuthDriver extends LocalAuthDriver {
|
|
|
13
13
|
generateAuthUrl(codeVerifier: string): Promise<string>;
|
|
14
14
|
private fetchUserId;
|
|
15
15
|
getUserID(payload: Record<string, any>): Promise<string>;
|
|
16
|
-
login(user: User
|
|
16
|
+
login(user: User): Promise<SessionData>;
|
|
17
17
|
refresh(user: User, sessionData: SessionData): Promise<SessionData>;
|
|
18
18
|
}
|
|
19
19
|
export declare function createOpenIDAuthRouter(providerName: string): Router;
|
|
@@ -31,6 +31,12 @@ class OpenIDAuthDriver extends local_1.LocalAuthDriver {
|
|
|
31
31
|
this.client = new Promise((resolve, reject) => {
|
|
32
32
|
openid_client_1.Issuer.discover(issuerUrl)
|
|
33
33
|
.then((issuer) => {
|
|
34
|
+
const supportedTypes = issuer.metadata.response_types_supported;
|
|
35
|
+
if (!(supportedTypes === null || supportedTypes === void 0 ? void 0 : supportedTypes.includes('code'))) {
|
|
36
|
+
reject(new exceptions_1.InvalidConfigException('OpenID provider does not support required code flow', {
|
|
37
|
+
provider: additionalConfig.provider,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
34
40
|
resolve(new issuer.Client({
|
|
35
41
|
client_id: clientId,
|
|
36
42
|
client_secret: clientSecret,
|
|
@@ -125,8 +131,8 @@ class OpenIDAuthDriver extends local_1.LocalAuthDriver {
|
|
|
125
131
|
});
|
|
126
132
|
return (await this.fetchUserId(identifier));
|
|
127
133
|
}
|
|
128
|
-
async login(user
|
|
129
|
-
return this.refresh(user,
|
|
134
|
+
async login(user) {
|
|
135
|
+
return this.refresh(user, null);
|
|
130
136
|
}
|
|
131
137
|
async refresh(user, sessionData) {
|
|
132
138
|
let authData = user.auth_data;
|
package/dist/auth.js
CHANGED
|
@@ -24,9 +24,11 @@ function getAuthProvider(provider) {
|
|
|
24
24
|
exports.getAuthProvider = getAuthProvider;
|
|
25
25
|
async function registerAuthProviders() {
|
|
26
26
|
const options = { knex: (0, database_1.default)(), schema: await (0, get_schema_1.getSchema)() };
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
// Register default provider if not disabled
|
|
28
|
+
if (!env_1.default.AUTH_DISABLE_DEFAULT) {
|
|
29
|
+
const defaultProvider = getProviderInstance('local', options);
|
|
30
|
+
providers.set(constants_1.DEFAULT_AUTH_PROVIDER, defaultProvider);
|
|
31
|
+
}
|
|
30
32
|
if (!env_1.default.AUTH_PROVIDERS) {
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
@@ -3,15 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const run_1 = __importDefault(require("../../../database/
|
|
7
|
-
const run_2 = __importDefault(require("../../../database/seeds/run"));
|
|
6
|
+
const run_1 = __importDefault(require("../../../database/seeds/run"));
|
|
8
7
|
const database_1 = __importDefault(require("../../../database"));
|
|
9
8
|
const logger_1 = __importDefault(require("../../../logger"));
|
|
10
9
|
async function start() {
|
|
11
10
|
const database = (0, database_1.default)();
|
|
12
11
|
try {
|
|
13
|
-
await (0,
|
|
14
|
-
await (0, run_1.default)(database, 'latest');
|
|
12
|
+
await (0, run_1.default)(database);
|
|
15
13
|
database.destroy();
|
|
16
14
|
process.exit(0);
|
|
17
15
|
}
|
|
@@ -35,7 +35,7 @@ const get_snapshot_diff_1 = require("../../../utils/get-snapshot-diff");
|
|
|
35
35
|
const apply_snapshot_1 = require("../../../utils/apply-snapshot");
|
|
36
36
|
const cache_1 = require("../../../cache");
|
|
37
37
|
async function apply(snapshotPath, options) {
|
|
38
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
38
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
39
39
|
const filename = path_1.default.resolve(process.cwd(), snapshotPath);
|
|
40
40
|
const database = (0, database_1.default)();
|
|
41
41
|
await (0, database_1.validateDatabaseConnection)(database);
|
|
@@ -83,12 +83,15 @@ async function apply(snapshotPath, options) {
|
|
|
83
83
|
else if (((_c = diff[0]) === null || _c === void 0 ? void 0 : _c.kind) === 'N') {
|
|
84
84
|
message += `\n - ${chalk_1.default.green('Create')} ${collection}`;
|
|
85
85
|
}
|
|
86
|
+
else if (((_d = diff[0]) === null || _d === void 0 ? void 0 : _d.kind) === 'A') {
|
|
87
|
+
message += `\n - ${chalk_1.default.blue('Update')} ${collection}`;
|
|
88
|
+
}
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
if (snapshotDiff.fields.length > 0) {
|
|
89
92
|
message += '\n\n' + chalk_1.default.black.underline.bold('Fields:');
|
|
90
93
|
for (const { collection, field, diff } of snapshotDiff.fields) {
|
|
91
|
-
if (((
|
|
94
|
+
if (((_e = diff[0]) === null || _e === void 0 ? void 0 : _e.kind) === 'E') {
|
|
92
95
|
message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}`;
|
|
93
96
|
for (const change of diff) {
|
|
94
97
|
if (change.kind === 'E') {
|
|
@@ -97,19 +100,22 @@ async function apply(snapshotPath, options) {
|
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
|
-
else if (((
|
|
103
|
+
else if (((_f = diff[0]) === null || _f === void 0 ? void 0 : _f.kind) === 'D') {
|
|
101
104
|
message += `\n - ${chalk_1.default.red('Delete')} ${collection}.${field}`;
|
|
102
105
|
}
|
|
103
|
-
else if (((
|
|
106
|
+
else if (((_g = diff[0]) === null || _g === void 0 ? void 0 : _g.kind) === 'N') {
|
|
104
107
|
message += `\n - ${chalk_1.default.green('Create')} ${collection}.${field}`;
|
|
105
108
|
}
|
|
109
|
+
else if (((_h = diff[0]) === null || _h === void 0 ? void 0 : _h.kind) === 'A') {
|
|
110
|
+
message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}`;
|
|
111
|
+
}
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
if (snapshotDiff.relations.length > 0) {
|
|
109
115
|
message += '\n\n' + chalk_1.default.black.underline.bold('Relations:');
|
|
110
116
|
for (const { collection, field, related_collection, diff } of snapshotDiff.relations) {
|
|
111
|
-
if (((
|
|
112
|
-
message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}
|
|
117
|
+
if (((_j = diff[0]) === null || _j === void 0 ? void 0 : _j.kind) === 'E') {
|
|
118
|
+
message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}`;
|
|
113
119
|
for (const change of diff) {
|
|
114
120
|
if (change.kind === 'E') {
|
|
115
121
|
const path = change.path.slice(1).join('.');
|
|
@@ -117,11 +123,21 @@ async function apply(snapshotPath, options) {
|
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
|
-
else if (((
|
|
121
|
-
message += `\n - ${chalk_1.default.red('Delete')} ${collection}.${field}
|
|
126
|
+
else if (((_k = diff[0]) === null || _k === void 0 ? void 0 : _k.kind) === 'D') {
|
|
127
|
+
message += `\n - ${chalk_1.default.red('Delete')} ${collection}.${field}`;
|
|
128
|
+
}
|
|
129
|
+
else if (((_l = diff[0]) === null || _l === void 0 ? void 0 : _l.kind) === 'N') {
|
|
130
|
+
message += `\n - ${chalk_1.default.green('Create')} ${collection}.${field}`;
|
|
131
|
+
}
|
|
132
|
+
else if (((_m = diff[0]) === null || _m === void 0 ? void 0 : _m.kind) === 'A') {
|
|
133
|
+
message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}`;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
continue;
|
|
122
137
|
}
|
|
123
|
-
|
|
124
|
-
|
|
138
|
+
// Related collection doesn't exist for m2a relationship types
|
|
139
|
+
if (related_collection) {
|
|
140
|
+
message += `-> ${related_collection}`;
|
|
125
141
|
}
|
|
126
142
|
}
|
|
127
143
|
}
|
|
@@ -6,44 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const express_1 = require("express");
|
|
7
7
|
const lodash_1 = require("lodash");
|
|
8
8
|
const ms_1 = __importDefault(require("ms"));
|
|
9
|
-
const uuid_validate_1 = __importDefault(require("uuid-validate"));
|
|
10
9
|
const constants_1 = require("../constants");
|
|
11
10
|
const database_1 = __importDefault(require("../database"));
|
|
12
11
|
const env_1 = __importDefault(require("../env"));
|
|
13
12
|
const exceptions_1 = require("../exceptions");
|
|
14
13
|
const use_collection_1 = __importDefault(require("../middleware/use-collection"));
|
|
15
14
|
const services_1 = require("../services");
|
|
16
|
-
const storage_1 = __importDefault(require("../storage"));
|
|
17
15
|
const assets_1 = require("../types/assets");
|
|
18
16
|
const async_handler_1 = __importDefault(require("../utils/async-handler"));
|
|
19
17
|
const router = (0, express_1.Router)();
|
|
20
18
|
router.use((0, use_collection_1.default)('directus_files'));
|
|
21
19
|
router.get('/:pk',
|
|
22
|
-
// Check if file exists and if you have permission to read it
|
|
23
|
-
(0, async_handler_1.default)(async (req, res, next) => {
|
|
24
|
-
var _a;
|
|
25
|
-
/**
|
|
26
|
-
* We ignore everything in the id after the first 36 characters (uuid length). This allows the
|
|
27
|
-
* user to add an optional extension, or other identifier for use in external software (#4067)
|
|
28
|
-
*/
|
|
29
|
-
const id = (_a = req.params.pk) === null || _a === void 0 ? void 0 : _a.substring(0, 36);
|
|
30
|
-
/**
|
|
31
|
-
* This is a little annoying. Postgres will error out if you're trying to search in `where`
|
|
32
|
-
* with a wrong type. In case of directus_files where id is a uuid, we'll have to verify the
|
|
33
|
-
* validity of the uuid ahead of time.
|
|
34
|
-
*/
|
|
35
|
-
const isValidUUID = (0, uuid_validate_1.default)(id, 4);
|
|
36
|
-
if (isValidUUID === false)
|
|
37
|
-
throw new exceptions_1.ForbiddenException();
|
|
38
|
-
const database = (0, database_1.default)();
|
|
39
|
-
const file = await database.select('id', 'storage', 'filename_disk').from('directus_files').where({ id }).first();
|
|
40
|
-
if (!file)
|
|
41
|
-
throw new exceptions_1.ForbiddenException();
|
|
42
|
-
const { exists } = await storage_1.default.disk(file.storage).exists(file.filename_disk);
|
|
43
|
-
if (!exists)
|
|
44
|
-
throw new exceptions_1.ForbiddenException();
|
|
45
|
-
return next();
|
|
46
|
-
}),
|
|
47
20
|
// Validate query params
|
|
48
21
|
(0, async_handler_1.default)(async (req, res, next) => {
|
|
49
22
|
const payloadService = new services_1.PayloadService('directus_settings', { schema: req.schema });
|
package/dist/controllers/auth.js
CHANGED
|
@@ -38,7 +38,9 @@ for (const authProvider of authProviders) {
|
|
|
38
38
|
}
|
|
39
39
|
router.use(`/login/${authProvider.name}`, authRouter);
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
if (!env_1.default.AUTH_DISABLE_DEFAULT) {
|
|
42
|
+
router.use('/login', (0, drivers_1.createLocalAuthRouter)(constants_1.DEFAULT_AUTH_PROVIDER));
|
|
43
|
+
}
|
|
42
44
|
router.post('/refresh', (0, async_handler_1.default)(async (req, res, next) => {
|
|
43
45
|
var _a;
|
|
44
46
|
const accountability = {
|
|
@@ -141,7 +143,10 @@ router.post('/password/reset', (0, async_handler_1.default)(async (req, res, nex
|
|
|
141
143
|
return next();
|
|
142
144
|
}), respond_1.respond);
|
|
143
145
|
router.get('/', (0, async_handler_1.default)(async (req, res, next) => {
|
|
144
|
-
res.locals.payload = {
|
|
146
|
+
res.locals.payload = {
|
|
147
|
+
data: (0, get_auth_providers_1.getAuthProviders)(),
|
|
148
|
+
disableDefault: env_1.default.AUTH_DISABLE_DEFAULT,
|
|
149
|
+
};
|
|
145
150
|
return next();
|
|
146
151
|
}), respond_1.respond);
|
|
147
152
|
exports.default = router;
|
|
@@ -33,7 +33,7 @@ router.get('/:type/index.js', (0, async_handler_1.default)(async (req, res) => {
|
|
|
33
33
|
throw new exceptions_1.RouteNotFoundException(req.path);
|
|
34
34
|
}
|
|
35
35
|
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
|
36
|
-
res.setHeader('Cache-Control', 'no-
|
|
36
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
37
37
|
res.setHeader('Vary', 'Origin, Cache-Control');
|
|
38
38
|
res.end(extensionSource);
|
|
39
39
|
}));
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
const express_1 = __importDefault(require("express"));
|
|
7
|
+
const exceptions_1 = require("../exceptions");
|
|
8
|
+
const respond_1 = require("../middleware/respond");
|
|
9
|
+
const use_collection_1 = __importDefault(require("../middleware/use-collection"));
|
|
10
|
+
const validate_batch_1 = require("../middleware/validate-batch");
|
|
11
|
+
const services_1 = require("../services");
|
|
12
|
+
const async_handler_1 = __importDefault(require("../utils/async-handler"));
|
|
13
|
+
const router = express_1.default.Router();
|
|
14
|
+
router.use((0, use_collection_1.default)('directus_notifications'));
|
|
15
|
+
router.post('/', (0, async_handler_1.default)(async (req, res, next) => {
|
|
16
|
+
const service = new services_1.NotificationsService({
|
|
17
|
+
accountability: req.accountability,
|
|
18
|
+
schema: req.schema,
|
|
19
|
+
});
|
|
20
|
+
const savedKeys = [];
|
|
21
|
+
if (Array.isArray(req.body)) {
|
|
22
|
+
const keys = await service.createMany(req.body);
|
|
23
|
+
savedKeys.push(...keys);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const key = await service.createOne(req.body);
|
|
27
|
+
savedKeys.push(key);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
if (Array.isArray(req.body)) {
|
|
31
|
+
const records = await service.readMany(savedKeys, req.sanitizedQuery);
|
|
32
|
+
res.locals.payload = { data: records };
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const record = await service.readOne(savedKeys[0], req.sanitizedQuery);
|
|
36
|
+
res.locals.payload = { data: record };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof exceptions_1.ForbiddenException) {
|
|
41
|
+
return next();
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
return next();
|
|
46
|
+
}), respond_1.respond);
|
|
47
|
+
const readHandler = (0, async_handler_1.default)(async (req, res, next) => {
|
|
48
|
+
const service = new services_1.NotificationsService({
|
|
49
|
+
accountability: req.accountability,
|
|
50
|
+
schema: req.schema,
|
|
51
|
+
});
|
|
52
|
+
const metaService = new services_1.MetaService({
|
|
53
|
+
accountability: req.accountability,
|
|
54
|
+
schema: req.schema,
|
|
55
|
+
});
|
|
56
|
+
let result;
|
|
57
|
+
if (req.singleton) {
|
|
58
|
+
result = await service.readSingleton(req.sanitizedQuery);
|
|
59
|
+
}
|
|
60
|
+
else if (req.body.keys) {
|
|
61
|
+
result = await service.readMany(req.body.keys, req.sanitizedQuery);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
result = await service.readByQuery(req.sanitizedQuery);
|
|
65
|
+
}
|
|
66
|
+
const meta = await metaService.getMetaForQuery('directus_presets', req.sanitizedQuery);
|
|
67
|
+
res.locals.payload = { data: result, meta };
|
|
68
|
+
return next();
|
|
69
|
+
});
|
|
70
|
+
router.get('/', (0, validate_batch_1.validateBatch)('read'), readHandler, respond_1.respond);
|
|
71
|
+
router.search('/', (0, validate_batch_1.validateBatch)('read'), readHandler, respond_1.respond);
|
|
72
|
+
router.get('/:pk', (0, async_handler_1.default)(async (req, res, next) => {
|
|
73
|
+
const service = new services_1.NotificationsService({
|
|
74
|
+
accountability: req.accountability,
|
|
75
|
+
schema: req.schema,
|
|
76
|
+
});
|
|
77
|
+
const record = await service.readOne(req.params.pk, req.sanitizedQuery);
|
|
78
|
+
res.locals.payload = { data: record || null };
|
|
79
|
+
return next();
|
|
80
|
+
}), respond_1.respond);
|
|
81
|
+
router.patch('/', (0, validate_batch_1.validateBatch)('update'), (0, async_handler_1.default)(async (req, res, next) => {
|
|
82
|
+
const service = new services_1.NotificationsService({
|
|
83
|
+
accountability: req.accountability,
|
|
84
|
+
schema: req.schema,
|
|
85
|
+
});
|
|
86
|
+
let keys = [];
|
|
87
|
+
if (req.body.keys) {
|
|
88
|
+
keys = await service.updateMany(req.body.keys, req.body.data);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
keys = await service.updateByQuery(req.body.query, req.body.data);
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const result = await service.readMany(keys, req.sanitizedQuery);
|
|
95
|
+
res.locals.payload = { data: result };
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error instanceof exceptions_1.ForbiddenException) {
|
|
99
|
+
return next();
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
return next();
|
|
104
|
+
}), respond_1.respond);
|
|
105
|
+
router.patch('/:pk', (0, async_handler_1.default)(async (req, res, next) => {
|
|
106
|
+
const service = new services_1.NotificationsService({
|
|
107
|
+
accountability: req.accountability,
|
|
108
|
+
schema: req.schema,
|
|
109
|
+
});
|
|
110
|
+
const primaryKey = await service.updateOne(req.params.pk, req.body);
|
|
111
|
+
try {
|
|
112
|
+
const record = await service.readOne(primaryKey, req.sanitizedQuery);
|
|
113
|
+
res.locals.payload = { data: record };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (error instanceof exceptions_1.ForbiddenException) {
|
|
117
|
+
return next();
|
|
118
|
+
}
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
return next();
|
|
122
|
+
}), respond_1.respond);
|
|
123
|
+
router.delete('/', (0, validate_batch_1.validateBatch)('delete'), (0, async_handler_1.default)(async (req, res, next) => {
|
|
124
|
+
const service = new services_1.NotificationsService({
|
|
125
|
+
accountability: req.accountability,
|
|
126
|
+
schema: req.schema,
|
|
127
|
+
});
|
|
128
|
+
if (Array.isArray(req.body)) {
|
|
129
|
+
await service.deleteMany(req.body);
|
|
130
|
+
}
|
|
131
|
+
else if (req.body.keys) {
|
|
132
|
+
await service.deleteMany(req.body.keys);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
await service.deleteByQuery(req.body.query);
|
|
136
|
+
}
|
|
137
|
+
return next();
|
|
138
|
+
}), respond_1.respond);
|
|
139
|
+
router.delete('/:pk', (0, async_handler_1.default)(async (req, res, next) => {
|
|
140
|
+
const service = new services_1.NotificationsService({
|
|
141
|
+
accountability: req.accountability,
|
|
142
|
+
schema: req.schema,
|
|
143
|
+
});
|
|
144
|
+
await service.deleteOne(req.params.pk);
|
|
145
|
+
return next();
|
|
146
|
+
}), respond_1.respond);
|
|
147
|
+
exports.default = router;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DateHelper } from '../types';
|
|
1
2
|
import { Knex } from 'knex';
|
|
2
|
-
export
|
|
3
|
+
export declare class DateHelperMSSQL extends DateHelper {
|
|
3
4
|
year(table: string, column: string): Knex.Raw;
|
|
4
5
|
month(table: string, column: string): Knex.Raw;
|
|
5
6
|
week(table: string, column: string): Knex.Raw;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.knex = knex;
|
|
7
|
-
}
|
|
3
|
+
exports.DateHelperMSSQL = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class DateHelperMSSQL extends types_1.DateHelper {
|
|
8
6
|
year(table, column) {
|
|
9
7
|
return this.knex.raw('DATEPART(year, ??.??)', [table, column]);
|
|
10
8
|
}
|
|
@@ -30,4 +28,4 @@ class HelperMSSQL {
|
|
|
30
28
|
return this.knex.raw('DATEPART(second, ??.??)', [table, column]);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
exports.
|
|
31
|
+
exports.DateHelperMSSQL = DateHelperMSSQL;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import { DateHelper } from '../types';
|
|
1
2
|
import { Knex } from 'knex';
|
|
2
|
-
|
|
3
|
-
export declare class HelperMySQL implements HelperFn {
|
|
4
|
-
private knex;
|
|
5
|
-
constructor(knex: Knex);
|
|
3
|
+
export declare class DateHelperMySQL extends DateHelper {
|
|
6
4
|
year(table: string, column: string): Knex.Raw;
|
|
7
5
|
month(table: string, column: string): Knex.Raw;
|
|
8
6
|
week(table: string, column: string): Knex.Raw;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.knex = knex;
|
|
7
|
-
}
|
|
3
|
+
exports.DateHelperMySQL = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class DateHelperMySQL extends types_1.DateHelper {
|
|
8
6
|
year(table, column) {
|
|
9
7
|
return this.knex.raw('YEAR(??.??)', [table, column]);
|
|
10
8
|
}
|
|
@@ -30,4 +28,4 @@ class HelperMySQL {
|
|
|
30
28
|
return this.knex.raw('SECOND(??.??)', [table, column]);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
exports.
|
|
31
|
+
exports.DateHelperMySQL = DateHelperMySQL;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import { DateHelper } from '../types';
|
|
1
2
|
import { Knex } from 'knex';
|
|
2
|
-
|
|
3
|
-
export declare class HelperMSSQL implements HelperFn {
|
|
4
|
-
private knex;
|
|
5
|
-
constructor(knex: Knex);
|
|
3
|
+
export declare class DateHelperOracle extends DateHelper {
|
|
6
4
|
year(table: string, column: string): Knex.Raw;
|
|
7
5
|
month(table: string, column: string): Knex.Raw;
|
|
8
6
|
week(table: string, column: string): Knex.Raw;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.knex = knex;
|
|
7
|
-
}
|
|
3
|
+
exports.DateHelperOracle = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class DateHelperOracle extends types_1.DateHelper {
|
|
8
6
|
year(table, column) {
|
|
9
7
|
return this.knex.raw("TO_CHAR(??.??, 'IYYY')", [table, column]);
|
|
10
8
|
}
|
|
@@ -30,4 +28,4 @@ class HelperOracle {
|
|
|
30
28
|
return this.knex.raw("TO_CHAR(??.??, 'SS')", [table, column]);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
exports.
|
|
31
|
+
exports.DateHelperOracle = DateHelperOracle;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DateHelper } from '../types';
|
|
2
|
+
import { Knex } from 'knex';
|
|
3
|
+
export declare class DateHelperPostgres extends DateHelper {
|
|
4
|
+
year(table: string, column: string): Knex.Raw;
|
|
5
|
+
month(table: string, column: string): Knex.Raw;
|
|
6
|
+
week(table: string, column: string): Knex.Raw;
|
|
7
|
+
day(table: string, column: string): Knex.Raw;
|
|
8
|
+
weekday(table: string, column: string): Knex.Raw;
|
|
9
|
+
hour(table: string, column: string): Knex.Raw;
|
|
10
|
+
minute(table: string, column: string): Knex.Raw;
|
|
11
|
+
second(table: string, column: string): Knex.Raw;
|
|
12
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.knex = knex;
|
|
7
|
-
}
|
|
3
|
+
exports.DateHelperPostgres = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class DateHelperPostgres extends types_1.DateHelper {
|
|
8
6
|
year(table, column) {
|
|
9
7
|
return this.knex.raw('EXTRACT(YEAR FROM ??.??)', [table, column]);
|
|
10
8
|
}
|
|
@@ -30,4 +28,4 @@ class HelperPostgres {
|
|
|
30
28
|
return this.knex.raw('EXTRACT(SECOND FROM ??.??)', [table, column]);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
exports.
|
|
31
|
+
exports.DateHelperPostgres = DateHelperPostgres;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import { DateHelper } from '../types';
|
|
1
2
|
import { Knex } from 'knex';
|
|
2
|
-
|
|
3
|
-
export declare class HelperSQLite implements HelperFn {
|
|
4
|
-
private knex;
|
|
5
|
-
constructor(knex: Knex);
|
|
3
|
+
export declare class DateHelperSQLite extends DateHelper {
|
|
6
4
|
year(table: string, column: string): Knex.Raw;
|
|
7
5
|
month(table: string, column: string): Knex.Raw;
|
|
8
6
|
week(table: string, column: string): Knex.Raw;
|
|
@@ -11,4 +9,5 @@ export declare class HelperSQLite implements HelperFn {
|
|
|
11
9
|
hour(table: string, column: string): Knex.Raw;
|
|
12
10
|
minute(table: string, column: string): Knex.Raw;
|
|
13
11
|
second(table: string, column: string): Knex.Raw;
|
|
12
|
+
parse(date: string): string;
|
|
14
13
|
}
|