@hestia-earth/api 0.10.1-2 → 0.10.1
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/files/model/model.d.ts +3 -2
- package/dist/files/model/model.js +17 -10
- package/package.json +1 -1
|
@@ -123,8 +123,9 @@ export declare const isGlossary: (path: string) => boolean;
|
|
|
123
123
|
export declare const aggregationFolder = "aggregation";
|
|
124
124
|
export declare const isAggregation: (path: string) => boolean;
|
|
125
125
|
export declare const isFolderUpload: (path: string) => boolean;
|
|
126
|
+
export declare const isOwner: (file: Partial<File>, user: User) => boolean;
|
|
127
|
+
export declare const isAuthorized: ({ authorizedUsers }: Partial<File>, user: User) => boolean;
|
|
126
128
|
export declare const canValidate: ({ status, isPrivate }: Partial<File>, { admin }: Partial<User>) => boolean;
|
|
127
129
|
export declare const isValidated: ({ validatedAt, status }: Partial<File>) => boolean;
|
|
128
|
-
export declare const canSubmit: (
|
|
130
|
+
export declare const canSubmit: (file: Partial<File>, user: User) => boolean;
|
|
129
131
|
export declare const isDraft: ({ filepath, filename }: Partial<File>) => boolean;
|
|
130
|
-
export declare const isAuthorized: ({ authorizedUsers }: Partial<File>, user: any) => boolean;
|
|
@@ -20,7 +20,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
20
20
|
return r;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
23
|
+
exports.isDraft = exports.canSubmit = exports.isValidated = exports.canValidate = exports.isAuthorized = exports.isOwner = exports.isFolderUpload = exports.isAggregation = exports.aggregationFolder = exports.isGlossary = exports.glossaryFolder = exports.filenameFromPath = exports.rootFolderFromPath = exports.folderFromPath = exports.replaceInvalidChars = exports.validPathChars = exports.fileToExt = exports.filepathSearch = exports.filenameSearch = exports.File = exports.FilePipelineError = exports.FilePipelineProgress = exports.FilePipelineStatus = exports.FileError = exports.FileStatus = exports.FileProgress = exports.HestiaExtensions = exports.SupportedExtensions = exports.sizeInMb = exports.MAX_SIZE_MB = exports.MAX_SIZE = exports.mb = void 0;
|
|
24
24
|
var model_base_1 = require("../../db/model.base");
|
|
25
25
|
exports.mb = 1048576;
|
|
26
26
|
exports.MAX_SIZE = 2;
|
|
@@ -153,6 +153,18 @@ exports.isFolderUpload = function (path) { return [
|
|
|
153
153
|
exports.isAggregation,
|
|
154
154
|
exports.isGlossary
|
|
155
155
|
].some(function (f) { return f(path); }); };
|
|
156
|
+
var asString = function (v) {
|
|
157
|
+
return typeof v === 'object' && v._id
|
|
158
|
+
? v._id.toString()
|
|
159
|
+
: typeof v === 'object' && v.id
|
|
160
|
+
? v.id.toString()
|
|
161
|
+
: v.toString();
|
|
162
|
+
};
|
|
163
|
+
exports.isOwner = function (file, user) { return asString(file.user) === asString(user); };
|
|
164
|
+
exports.isAuthorized = function (_a, user) {
|
|
165
|
+
var authorizedUsers = _a.authorizedUsers;
|
|
166
|
+
return (authorizedUsers || []).map(asString).includes(asString(user));
|
|
167
|
+
};
|
|
156
168
|
var validateStatuses = [
|
|
157
169
|
FileStatus.validateDataDone,
|
|
158
170
|
FileStatus.indexJsonDone,
|
|
@@ -161,7 +173,7 @@ var validateStatuses = [
|
|
|
161
173
|
exports.canValidate = function (_a, _b) {
|
|
162
174
|
var status = _a.status, isPrivate = _a.isPrivate;
|
|
163
175
|
var admin = _b.admin;
|
|
164
|
-
return validateStatuses.includes(status) && (
|
|
176
|
+
return validateStatuses.includes(status) && (isPrivate || admin);
|
|
165
177
|
};
|
|
166
178
|
exports.isValidated = function (_a) {
|
|
167
179
|
var validatedAt = _a.validatedAt, status = _a.status;
|
|
@@ -174,16 +186,11 @@ exports.isValidated = function (_a) {
|
|
|
174
186
|
var submitStatuses = [
|
|
175
187
|
FileStatus.validateDataDone
|
|
176
188
|
];
|
|
177
|
-
exports.canSubmit = function (
|
|
178
|
-
|
|
179
|
-
|
|
189
|
+
exports.canSubmit = function (file, user) {
|
|
190
|
+
return submitStatuses.includes(file.status) &&
|
|
191
|
+
!file.userValidatedAt && (exports.isOwner(file, user) || exports.isAuthorized(file, user));
|
|
180
192
|
};
|
|
181
193
|
exports.isDraft = function (_a) {
|
|
182
194
|
var filepath = _a.filepath, filename = _a.filename;
|
|
183
195
|
return (filepath || filename || '').endsWith(SupportedExtensions.draft);
|
|
184
196
|
};
|
|
185
|
-
var asString = function (v) { return typeof v === 'object' && v._id ? v._id.toString() : v.toString(); };
|
|
186
|
-
exports.isAuthorized = function (_a, user) {
|
|
187
|
-
var authorizedUsers = _a.authorizedUsers;
|
|
188
|
-
return (authorizedUsers || []).map(asString).includes(asString(user));
|
|
189
|
-
};
|