@hestia-earth/api 0.10.1-2 → 0.11.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 +12 -3
- package/dist/files/model/model.js +30 -10
- package/package.json +1 -1
|
@@ -66,6 +66,12 @@ export declare enum FilePipelineError {
|
|
|
66
66
|
calculationEngineError = "calculationEngineError"
|
|
67
67
|
}
|
|
68
68
|
export declare type pipelineStatus = FilePipelineStatus | FilePipelineProgress | FilePipelineError;
|
|
69
|
+
export interface IFileComment {
|
|
70
|
+
content: string;
|
|
71
|
+
date: Date;
|
|
72
|
+
user: User;
|
|
73
|
+
readonly isOwner?: boolean;
|
|
74
|
+
}
|
|
69
75
|
export declare class File extends BaseModel {
|
|
70
76
|
filename: string;
|
|
71
77
|
filepath: string;
|
|
@@ -81,7 +87,7 @@ export declare class File extends BaseModel {
|
|
|
81
87
|
schemaVersion?: string;
|
|
82
88
|
schemaOutdated?: boolean;
|
|
83
89
|
glossaryOutdated?: boolean;
|
|
84
|
-
|
|
90
|
+
comments?: IFileComment[];
|
|
85
91
|
metadata?: {
|
|
86
92
|
slackThreadTs?: string;
|
|
87
93
|
};
|
|
@@ -123,8 +129,11 @@ export declare const isGlossary: (path: string) => boolean;
|
|
|
123
129
|
export declare const aggregationFolder = "aggregation";
|
|
124
130
|
export declare const isAggregation: (path: string) => boolean;
|
|
125
131
|
export declare const isFolderUpload: (path: string) => boolean;
|
|
132
|
+
export declare const isOwner: (file: Partial<File>, user: User) => boolean;
|
|
133
|
+
export declare const isAuthorized: ({ authorizedUsers }: Partial<File>, user: User) => boolean;
|
|
134
|
+
export declare const canRemove: (file: Partial<File>, user: User) => boolean;
|
|
126
135
|
export declare const canValidate: ({ status, isPrivate }: Partial<File>, { admin }: Partial<User>) => boolean;
|
|
127
136
|
export declare const isValidated: ({ validatedAt, status }: Partial<File>) => boolean;
|
|
128
|
-
export declare const canSubmit: (
|
|
137
|
+
export declare const canSubmit: (file: Partial<File>, user: User) => boolean;
|
|
138
|
+
export declare const canFeedback: ({ status }: File) => boolean;
|
|
129
139
|
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.canFeedback = exports.canSubmit = exports.isValidated = exports.canValidate = exports.canRemove = 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,23 @@ 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
|
+
};
|
|
168
|
+
exports.canRemove = function (file, user) {
|
|
169
|
+
return user.admin ||
|
|
170
|
+
!exports.isValidated(file) ||
|
|
171
|
+
file.isPrivate;
|
|
172
|
+
};
|
|
156
173
|
var validateStatuses = [
|
|
157
174
|
FileStatus.validateDataDone,
|
|
158
175
|
FileStatus.indexJsonDone,
|
|
@@ -161,7 +178,7 @@ var validateStatuses = [
|
|
|
161
178
|
exports.canValidate = function (_a, _b) {
|
|
162
179
|
var status = _a.status, isPrivate = _a.isPrivate;
|
|
163
180
|
var admin = _b.admin;
|
|
164
|
-
return validateStatuses.includes(status) && (
|
|
181
|
+
return validateStatuses.includes(status) && (isPrivate || admin);
|
|
165
182
|
};
|
|
166
183
|
exports.isValidated = function (_a) {
|
|
167
184
|
var validatedAt = _a.validatedAt, status = _a.status;
|
|
@@ -174,16 +191,19 @@ exports.isValidated = function (_a) {
|
|
|
174
191
|
var submitStatuses = [
|
|
175
192
|
FileStatus.validateDataDone
|
|
176
193
|
];
|
|
177
|
-
exports.canSubmit = function (
|
|
178
|
-
|
|
179
|
-
|
|
194
|
+
exports.canSubmit = function (file, user) {
|
|
195
|
+
return submitStatuses.includes(file.status) &&
|
|
196
|
+
!file.userValidatedAt && (exports.isOwner(file, user) || exports.isAuthorized(file, user));
|
|
197
|
+
};
|
|
198
|
+
var feedbackStatuses = [
|
|
199
|
+
FileStatus.validateDataDone,
|
|
200
|
+
FileError.validateDataError
|
|
201
|
+
];
|
|
202
|
+
exports.canFeedback = function (_a) {
|
|
203
|
+
var status = _a.status;
|
|
204
|
+
return feedbackStatuses.includes(status);
|
|
180
205
|
};
|
|
181
206
|
exports.isDraft = function (_a) {
|
|
182
207
|
var filepath = _a.filepath, filename = _a.filename;
|
|
183
208
|
return (filepath || filename || '').endsWith(SupportedExtensions.draft);
|
|
184
209
|
};
|
|
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
|
-
};
|