@girder/core 5.0.0-beta.1 → 5.0.0-beta.2
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-lib/Girder_Favicon.png +0 -0
- package/dist-lib/Girder_Mark.png +0 -0
- package/dist-lib/girder-core.js +48560 -0
- package/dist-lib/girder-core.js.map +1 -0
- package/dist-lib/girder-core.umd.cjs +630 -0
- package/dist-lib/girder-core.umd.cjs.map +1 -0
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/src/auth.js +112 -0
- package/dist-lib/src/collections/ApiKeyCollection.js +9 -0
- package/dist-lib/src/collections/AssetstoreCollection.js +9 -0
- package/dist-lib/src/collections/Collection.js +295 -0
- package/dist-lib/src/collections/CollectionCollection.js +9 -0
- package/dist-lib/src/collections/FileCollection.js +11 -0
- package/dist-lib/src/collections/FolderCollection.js +11 -0
- package/dist-lib/src/collections/GroupCollection.js +9 -0
- package/dist-lib/src/collections/ItemCollection.js +11 -0
- package/dist-lib/src/collections/UserCollection.js +24 -0
- package/dist-lib/src/collections/index.js +21 -0
- package/dist-lib/src/constants.js +32 -0
- package/dist-lib/src/dialog.js +128 -0
- package/dist-lib/src/events.js +6 -0
- package/dist-lib/src/index.d.ts +23 -0
- package/dist-lib/src/index.ts +80 -0
- package/dist-lib/src/main.ts +45 -0
- package/dist-lib/src/misc.js +260 -0
- package/dist-lib/src/models/AccessControlledModel.js +76 -0
- package/dist-lib/src/models/ApiKeyModel.js +31 -0
- package/dist-lib/src/models/AssetstoreModel.js +43 -0
- package/dist-lib/src/models/CollectionCreationPolicyModel.js +20 -0
- package/dist-lib/src/models/CollectionModel.js +12 -0
- package/dist-lib/src/models/FileModel.js +310 -0
- package/dist-lib/src/models/FolderModel.js +33 -0
- package/dist-lib/src/models/GroupModel.js +197 -0
- package/dist-lib/src/models/ItemModel.js +72 -0
- package/dist-lib/src/models/MetadataMixin.js +88 -0
- package/dist-lib/src/models/Model.js +187 -0
- package/dist-lib/src/models/UserModel.js +189 -0
- package/dist-lib/src/models/index.js +25 -0
- package/dist-lib/src/pluginUtils.js +11 -0
- package/dist-lib/src/rest.js +221 -0
- package/dist-lib/src/router.js +58 -0
- package/dist-lib/src/routes.js +229 -0
- package/dist-lib/src/stylesheets/apidocs/apidocs.styl +50 -0
- package/dist-lib/src/stylesheets/body/adminConsole.styl +21 -0
- package/dist-lib/src/stylesheets/body/assetstores.styl +46 -0
- package/dist-lib/src/stylesheets/body/collectionList.styl +39 -0
- package/dist-lib/src/stylesheets/body/collectionPage.styl +6 -0
- package/dist-lib/src/stylesheets/body/frontPage.styl +48 -0
- package/dist-lib/src/stylesheets/body/groupList.styl +43 -0
- package/dist-lib/src/stylesheets/body/groupPage.styl +116 -0
- package/dist-lib/src/stylesheets/body/itemPage.styl +81 -0
- package/dist-lib/src/stylesheets/body/plugins.styl +61 -0
- package/dist-lib/src/stylesheets/body/searchResultsList.styl +51 -0
- package/dist-lib/src/stylesheets/body/systemConfig.styl +56 -0
- package/dist-lib/src/stylesheets/body/userAccount.styl +57 -0
- package/dist-lib/src/stylesheets/body/userList.styl +79 -0
- package/dist-lib/src/stylesheets/body/userPage.styl +6 -0
- package/dist-lib/src/stylesheets/layout/footer.styl +19 -0
- package/dist-lib/src/stylesheets/layout/global.styl +154 -0
- package/dist-lib/src/stylesheets/layout/globalNav.styl +89 -0
- package/dist-lib/src/stylesheets/layout/header.styl +29 -0
- package/dist-lib/src/stylesheets/layout/headerUser.styl +33 -0
- package/dist-lib/src/stylesheets/layout/layout.styl +75 -0
- package/dist-lib/src/stylesheets/layout/layoutVars.styl +9 -0
- package/dist-lib/src/stylesheets/layout/loading.styl +37 -0
- package/dist-lib/src/stylesheets/layout/progressArea.styl +17 -0
- package/dist-lib/src/stylesheets/widgets/accessWidget.styl +106 -0
- package/dist-lib/src/stylesheets/widgets/browserWidget.styl +9 -0
- package/dist-lib/src/stylesheets/widgets/hierarchyWidget.styl +188 -0
- package/dist-lib/src/stylesheets/widgets/markdownWidget.styl +92 -0
- package/dist-lib/src/stylesheets/widgets/metadataWidget.styl +92 -0
- package/dist-lib/src/stylesheets/widgets/searchFieldWidget.styl +70 -0
- package/dist-lib/src/stylesheets/widgets/taskProgress.styl +41 -0
- package/dist-lib/src/stylesheets/widgets/timelineWidget.styl +41 -0
- package/dist-lib/src/stylesheets/widgets/uploadWidget.styl +43 -0
- package/dist-lib/src/stylesheets/widgets/userOtpManagementWidget.styl +159 -0
- package/dist-lib/src/templates/body/adminConsole.pug +13 -0
- package/dist-lib/src/templates/body/assetstores.pug +83 -0
- package/dist-lib/src/templates/body/collectionList.pug +40 -0
- package/dist-lib/src/templates/body/collectionPage.pug +36 -0
- package/dist-lib/src/templates/body/filesystemImport.pug +41 -0
- package/dist-lib/src/templates/body/frontPage.pug +84 -0
- package/dist-lib/src/templates/body/groupList.pug +30 -0
- package/dist-lib/src/templates/body/groupPage.pug +116 -0
- package/dist-lib/src/templates/body/itemPage.pug +61 -0
- package/dist-lib/src/templates/body/plugins.pug +20 -0
- package/dist-lib/src/templates/body/s3Import.pug +35 -0
- package/dist-lib/src/templates/body/searchResults.pug +15 -0
- package/dist-lib/src/templates/body/searchResultsType.pug +13 -0
- package/dist-lib/src/templates/body/systemConfiguration.pug +199 -0
- package/dist-lib/src/templates/body/userAccount.pug +83 -0
- package/dist-lib/src/templates/body/userList.pug +43 -0
- package/dist-lib/src/templates/body/userPage.pug +40 -0
- package/dist-lib/src/templates/layout/alert.pug +5 -0
- package/dist-lib/src/templates/layout/layout.pug +12 -0
- package/dist-lib/src/templates/layout/layoutFooter.pug +11 -0
- package/dist-lib/src/templates/layout/layoutGlobalNav.pug +7 -0
- package/dist-lib/src/templates/layout/layoutHeader.pug +8 -0
- package/dist-lib/src/templates/layout/layoutHeaderUser.pug +26 -0
- package/dist-lib/src/templates/layout/layoutProgressArea.pug +1 -0
- package/dist-lib/src/templates/layout/loginDialog.pug +30 -0
- package/dist-lib/src/templates/layout/registerDialog.pug +35 -0
- package/dist-lib/src/templates/layout/resetPasswordDialog.pug +25 -0
- package/dist-lib/src/templates/widgets/accessEditor.pug +23 -0
- package/dist-lib/src/templates/widgets/accessEditorMixins.pug +57 -0
- package/dist-lib/src/templates/widgets/accessEditorNonModal.pug +11 -0
- package/dist-lib/src/templates/widgets/accessEntry.pug +32 -0
- package/dist-lib/src/templates/widgets/apiKeyList.pug +50 -0
- package/dist-lib/src/templates/widgets/browserWidget.pug +32 -0
- package/dist-lib/src/templates/widgets/checkedActionsMenu.pug +46 -0
- package/dist-lib/src/templates/widgets/collectionInfoDialog.pug +37 -0
- package/dist-lib/src/templates/widgets/confirmDialog.pug +14 -0
- package/dist-lib/src/templates/widgets/dateTimeRangeWidget.pug +20 -0
- package/dist-lib/src/templates/widgets/dateTimeWidget.pug +8 -0
- package/dist-lib/src/templates/widgets/editApiKeyWidget.pug +43 -0
- package/dist-lib/src/templates/widgets/editAssetstoreWidget.pug +66 -0
- package/dist-lib/src/templates/widgets/editCollectionWidget.pug +27 -0
- package/dist-lib/src/templates/widgets/editFileWidget.pug +21 -0
- package/dist-lib/src/templates/widgets/editFolderWidget.pug +27 -0
- package/dist-lib/src/templates/widgets/editGroupWidget.pug +54 -0
- package/dist-lib/src/templates/widgets/editItemWidget.pug +27 -0
- package/dist-lib/src/templates/widgets/fileInfoDialog.pug +33 -0
- package/dist-lib/src/templates/widgets/fileList.pug +33 -0
- package/dist-lib/src/templates/widgets/folderInfoDialog.pug +42 -0
- package/dist-lib/src/templates/widgets/folderList.pug +21 -0
- package/dist-lib/src/templates/widgets/groupAdminList.pug +33 -0
- package/dist-lib/src/templates/widgets/groupInviteDialog.pug +76 -0
- package/dist-lib/src/templates/widgets/groupInviteList.pug +14 -0
- package/dist-lib/src/templates/widgets/groupMemberList.pug +39 -0
- package/dist-lib/src/templates/widgets/groupModList.pug +23 -0
- package/dist-lib/src/templates/widgets/hierarchyBreadcrumb.pug +37 -0
- package/dist-lib/src/templates/widgets/hierarchyPaginated.pug +19 -0
- package/dist-lib/src/templates/widgets/hierarchyWidget.pug +96 -0
- package/dist-lib/src/templates/widgets/itemBreadcrumb.pug +16 -0
- package/dist-lib/src/templates/widgets/itemList.pug +27 -0
- package/dist-lib/src/templates/widgets/jsonMetadatumEditWidget.pug +13 -0
- package/dist-lib/src/templates/widgets/jsonMetadatumView.pug +6 -0
- package/dist-lib/src/templates/widgets/loadingAnimation.pug +4 -0
- package/dist-lib/src/templates/widgets/markdownWidget.pug +34 -0
- package/dist-lib/src/templates/widgets/metadataWidget.pug +16 -0
- package/dist-lib/src/templates/widgets/metadatumEditWidget.pug +15 -0
- package/dist-lib/src/templates/widgets/metadatumView.pug +5 -0
- package/dist-lib/src/templates/widgets/newAssetstore.pug +83 -0
- package/dist-lib/src/templates/widgets/paginateWidget.pug +7 -0
- package/dist-lib/src/templates/widgets/pluginConfigBreadcrumb.pug +13 -0
- package/dist-lib/src/templates/widgets/rootSelectorWidget.pug +13 -0
- package/dist-lib/src/templates/widgets/searchField.pug +10 -0
- package/dist-lib/src/templates/widgets/searchHelp.pug +12 -0
- package/dist-lib/src/templates/widgets/searchModeSelect.pug +9 -0
- package/dist-lib/src/templates/widgets/searchResults.pug +14 -0
- package/dist-lib/src/templates/widgets/sortCollectionWidget.pug +14 -0
- package/dist-lib/src/templates/widgets/taskProgress.pug +16 -0
- package/dist-lib/src/templates/widgets/timeline.pug +15 -0
- package/dist-lib/src/templates/widgets/uploadWidget.pug +15 -0
- package/dist-lib/src/templates/widgets/uploadWidgetMixins.pug +31 -0
- package/dist-lib/src/templates/widgets/uploadWidgetNonModal.pug +10 -0
- package/dist-lib/src/templates/widgets/userOtpBegin.pug +4 -0
- package/dist-lib/src/templates/widgets/userOtpDisable.pug +6 -0
- package/dist-lib/src/templates/widgets/userOtpEnable.pug +44 -0
- package/dist-lib/src/utilities/EventStream.js +177 -0
- package/dist-lib/src/utilities/PluginUtils.js +36 -0
- package/dist-lib/src/utilities/S3UploadHandler.js +303 -0
- package/dist-lib/src/utilities/index.js +9 -0
- package/dist-lib/src/utilities/jquery/girderEnable.js +19 -0
- package/dist-lib/src/utilities/jquery/girderModal.js +48 -0
- package/dist-lib/src/version.js +6 -0
- package/dist-lib/src/views/App.js +359 -0
- package/dist-lib/src/views/View.js +79 -0
- package/dist-lib/src/views/body/AdminView.js +29 -0
- package/dist-lib/src/views/body/AssetstoresView.js +234 -0
- package/dist-lib/src/views/body/CollectionView.js +188 -0
- package/dist-lib/src/views/body/CollectionsView.js +120 -0
- package/dist-lib/src/views/body/FilesystemImportView.js +83 -0
- package/dist-lib/src/views/body/FolderView.js +54 -0
- package/dist-lib/src/views/body/FrontPageView.js +47 -0
- package/dist-lib/src/views/body/GroupView.js +336 -0
- package/dist-lib/src/views/body/GroupsView.js +106 -0
- package/dist-lib/src/views/body/ItemView.js +177 -0
- package/dist-lib/src/views/body/PluginsView.js +73 -0
- package/dist-lib/src/views/body/S3ImportView.js +80 -0
- package/dist-lib/src/views/body/SearchResultsView.js +162 -0
- package/dist-lib/src/views/body/SystemConfigurationView.js +182 -0
- package/dist-lib/src/views/body/UserAccountView.js +179 -0
- package/dist-lib/src/views/body/UserView.js +165 -0
- package/dist-lib/src/views/body/UsersView.js +124 -0
- package/dist-lib/src/views/body/index.js +37 -0
- package/dist-lib/src/views/index.js +13 -0
- package/dist-lib/src/views/layout/FooterView.js +29 -0
- package/dist-lib/src/views/layout/GlobalNavView.js +103 -0
- package/dist-lib/src/views/layout/HeaderUserView.js +45 -0
- package/dist-lib/src/views/layout/HeaderView.js +83 -0
- package/dist-lib/src/views/layout/LoginView.js +100 -0
- package/dist-lib/src/views/layout/ProgressListView.js +70 -0
- package/dist-lib/src/views/layout/RegisterView.js +101 -0
- package/dist-lib/src/views/layout/ResetPasswordView.js +70 -0
- package/dist-lib/src/views/layout/index.js +19 -0
- package/dist-lib/src/views/widgets/AccessWidget.js +427 -0
- package/dist-lib/src/views/widgets/ApiKeyListWidget.js +140 -0
- package/dist-lib/src/views/widgets/BrowserWidget.js +317 -0
- package/dist-lib/src/views/widgets/CheckedMenuWidget.js +68 -0
- package/dist-lib/src/views/widgets/CollectionInfoWidget.js +40 -0
- package/dist-lib/src/views/widgets/DateTimeRangeWidget.js +180 -0
- package/dist-lib/src/views/widgets/DateTimeWidget.js +110 -0
- package/dist-lib/src/views/widgets/EditApiKeyWidget.js +122 -0
- package/dist-lib/src/views/widgets/EditAssetstoreWidget.js +133 -0
- package/dist-lib/src/views/widgets/EditCollectionWidget.js +93 -0
- package/dist-lib/src/views/widgets/EditFileWidget.js +56 -0
- package/dist-lib/src/views/widgets/EditFolderWidget.js +116 -0
- package/dist-lib/src/views/widgets/EditGroupWidget.js +125 -0
- package/dist-lib/src/views/widgets/EditItemWidget.js +110 -0
- package/dist-lib/src/views/widgets/FileInfoWidget.js +26 -0
- package/dist-lib/src/views/widgets/FileListWidget.js +151 -0
- package/dist-lib/src/views/widgets/FolderInfoWidget.js +39 -0
- package/dist-lib/src/views/widgets/FolderListWidget.js +106 -0
- package/dist-lib/src/views/widgets/GroupAdminsWidget.js +88 -0
- package/dist-lib/src/views/widgets/GroupInvitesWidget.js +56 -0
- package/dist-lib/src/views/widgets/GroupMembersWidget.js +185 -0
- package/dist-lib/src/views/widgets/GroupModsWidget.js +77 -0
- package/dist-lib/src/views/widgets/HierarchyWidget.js +1097 -0
- package/dist-lib/src/views/widgets/ItemBreadcrumbWidget.js +38 -0
- package/dist-lib/src/views/widgets/ItemListWidget.js +345 -0
- package/dist-lib/src/views/widgets/LoadingAnimation.js +17 -0
- package/dist-lib/src/views/widgets/MarkdownWidget.js +217 -0
- package/dist-lib/src/views/widgets/MetadataWidget.js +508 -0
- package/dist-lib/src/views/widgets/NewAssetstoreWidget.js +71 -0
- package/dist-lib/src/views/widgets/PaginateWidget.js +37 -0
- package/dist-lib/src/views/widgets/PluginConfigBreadcrumbWidget.js +33 -0
- package/dist-lib/src/views/widgets/RootSelectorWidget.js +192 -0
- package/dist-lib/src/views/widgets/SearchFieldWidget.js +365 -0
- package/dist-lib/src/views/widgets/SearchPaginateWidget.js +149 -0
- package/dist-lib/src/views/widgets/SortCollectionWidget.js +53 -0
- package/dist-lib/src/views/widgets/TaskProgressWidget.js +91 -0
- package/dist-lib/src/views/widgets/TimelineWidget.js +155 -0
- package/dist-lib/src/views/widgets/UploadWidget.js +340 -0
- package/dist-lib/src/views/widgets/UserOtpManagementWidget.js +105 -0
- package/dist-lib/src/views/widgets/index.js +75 -0
- package/dist-lib/src/vite-env.d.ts +5 -0
- package/dist-lib/style.css +16 -0
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import _ from 'underscore';
|
|
2
|
+
|
|
3
|
+
import { restRequest } from '@girder/core/rest';
|
|
4
|
+
|
|
5
|
+
var MetadataMixin = {
|
|
6
|
+
_sendMetadata: function (metadata, successCallback, errorCallback, opts) {
|
|
7
|
+
opts = opts || {};
|
|
8
|
+
restRequest({
|
|
9
|
+
url: opts.path ||
|
|
10
|
+
((this.altUrl || this.resourceName) + `/${this.id}/metadata?allowNull=true`),
|
|
11
|
+
contentType: 'application/json',
|
|
12
|
+
data: JSON.stringify(metadata),
|
|
13
|
+
method: 'PUT',
|
|
14
|
+
error: null
|
|
15
|
+
}).done((resp) => {
|
|
16
|
+
this.set(opts.field || 'meta', resp.meta);
|
|
17
|
+
if (_.isFunction(successCallback)) {
|
|
18
|
+
successCallback();
|
|
19
|
+
}
|
|
20
|
+
}).fail((err) => {
|
|
21
|
+
err.message = err.responseJSON.message;
|
|
22
|
+
if (_.isFunction(errorCallback)) {
|
|
23
|
+
errorCallback(err);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
addMetadata: function (key, value, successCallback, errorCallback, opts) {
|
|
29
|
+
opts = opts || {};
|
|
30
|
+
var datum = {};
|
|
31
|
+
datum[key] = value;
|
|
32
|
+
var meta = this.get(opts.field || 'meta');
|
|
33
|
+
if (meta && _.has(meta, key)) {
|
|
34
|
+
if (_.isFunction(errorCallback)) {
|
|
35
|
+
errorCallback({ message: key + ' is already a metadata key' });
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
this._sendMetadata(datum, successCallback, errorCallback, opts);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
removeMetadata: function (key, successCallback, errorCallback, opts) {
|
|
43
|
+
if (!_.isArray(key)) {
|
|
44
|
+
key = [key];
|
|
45
|
+
}
|
|
46
|
+
restRequest({
|
|
47
|
+
url: opts.path ||
|
|
48
|
+
((this.altUrl || this.resourceName) + `/${this.id}/metadata`),
|
|
49
|
+
contentType: 'application/json',
|
|
50
|
+
data: JSON.stringify(key),
|
|
51
|
+
method: 'DELETE',
|
|
52
|
+
error: null
|
|
53
|
+
}).done((resp) => {
|
|
54
|
+
this.set(opts.field || 'meta', resp.meta);
|
|
55
|
+
if (_.isFunction(successCallback)) {
|
|
56
|
+
successCallback();
|
|
57
|
+
}
|
|
58
|
+
}).fail((err) => {
|
|
59
|
+
err.message = err.responseJSON.message;
|
|
60
|
+
if (_.isFunction(errorCallback)) {
|
|
61
|
+
errorCallback(err);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
editMetadata: function (newKey, oldKey, value, successCallback, errorCallback, opts) {
|
|
67
|
+
opts = opts || {};
|
|
68
|
+
|
|
69
|
+
if (newKey === oldKey) {
|
|
70
|
+
var datum = {};
|
|
71
|
+
datum[newKey] = value;
|
|
72
|
+
this._sendMetadata(datum, successCallback, errorCallback, opts);
|
|
73
|
+
} else {
|
|
74
|
+
if (_.has(this.get(opts.field || 'meta'), newKey)) {
|
|
75
|
+
if (_.isFunction(errorCallback)) {
|
|
76
|
+
errorCallback({ message: newKey + ' is already a metadata key' });
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
var metas = {};
|
|
80
|
+
metas[oldKey] = null;
|
|
81
|
+
metas[newKey] = value;
|
|
82
|
+
this._sendMetadata(metas, successCallback, errorCallback, opts);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default MetadataMixin;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import $ from 'jquery';
|
|
2
|
+
import _ from 'underscore';
|
|
3
|
+
import Backbone from 'backbone';
|
|
4
|
+
|
|
5
|
+
import { restRequest, getApiRoot } from '@girder/core/rest';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* All models should descend from this base model, which provides a number
|
|
9
|
+
* of utilities for synchronization.
|
|
10
|
+
*/
|
|
11
|
+
var Model = Backbone.Model.extend({
|
|
12
|
+
resourceName: null,
|
|
13
|
+
altUrl: null,
|
|
14
|
+
idAttribute: '_id',
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Convenience method for incrementing numeric properties.
|
|
18
|
+
* @param {string} attr The attribute to increment.
|
|
19
|
+
* @param {number} [amount] The amount to increment by. Defaults to 1.
|
|
20
|
+
*/
|
|
21
|
+
increment: function (attr, amount) {
|
|
22
|
+
if (amount === undefined) {
|
|
23
|
+
amount = 1;
|
|
24
|
+
}
|
|
25
|
+
if (!amount) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return this.set(attr, this.get(attr) + amount);
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the name for this resource. By default, just the name attribute.
|
|
33
|
+
*/
|
|
34
|
+
name: function () {
|
|
35
|
+
return this.get('name');
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Save this model to the server. If this is a new model, meaning it has no
|
|
40
|
+
* _id attribute, this will create it. If the _id is set, we update the
|
|
41
|
+
* existing model. Triggers g:saved on success, and g:error on error.
|
|
42
|
+
*/
|
|
43
|
+
save: function () {
|
|
44
|
+
if (this.altUrl === null && this.resourceName === null) {
|
|
45
|
+
throw new Error('An altUrl or resourceName must be set on the Model.');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var path, type;
|
|
49
|
+
if (this.has('_id')) {
|
|
50
|
+
path = (this.altUrl || this.resourceName) + '/' + this.get('_id');
|
|
51
|
+
type = 'PUT';
|
|
52
|
+
} else {
|
|
53
|
+
path = (this.altUrl || this.resourceName);
|
|
54
|
+
type = 'POST';
|
|
55
|
+
}
|
|
56
|
+
/* Don't save attributes which are objects using this call. For
|
|
57
|
+
* instance, if the metadata of an item has keys that contain non-ascii
|
|
58
|
+
* values, they won't get handled by the rest call. */
|
|
59
|
+
var data = {};
|
|
60
|
+
_.each(this.keys(), function (key) {
|
|
61
|
+
var value = this.get(key);
|
|
62
|
+
if (!_.isObject(value)) {
|
|
63
|
+
data[key] = value;
|
|
64
|
+
}
|
|
65
|
+
}, this);
|
|
66
|
+
|
|
67
|
+
return restRequest({
|
|
68
|
+
url: path,
|
|
69
|
+
method: type,
|
|
70
|
+
data: data,
|
|
71
|
+
error: null // don't do default error behavior (validation may fail)
|
|
72
|
+
}).done((resp) => {
|
|
73
|
+
this.set(resp);
|
|
74
|
+
this.trigger('g:saved');
|
|
75
|
+
}).fail((err) => {
|
|
76
|
+
this.trigger('g:error', err);
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Fetch a single resource from the server. Triggers g:fetched on success,
|
|
82
|
+
* or g:error on error.
|
|
83
|
+
*
|
|
84
|
+
* @param {object|undefined} opts: additional options, which can include:
|
|
85
|
+
* ignoreError: true - ignore the default error handler
|
|
86
|
+
* extraPath - a string to append to the end of the resource URL
|
|
87
|
+
* data - a dictionary of parameters to pass to the endpoint.
|
|
88
|
+
*/
|
|
89
|
+
fetch: function (opts) {
|
|
90
|
+
if (this.altUrl === null && this.resourceName === null) {
|
|
91
|
+
throw new Error('An altUrl or resourceName must be set on the Model.');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
opts = opts || {};
|
|
95
|
+
var restOpts = {
|
|
96
|
+
url: `${this.altUrl || this.resourceName}/${this.id}`
|
|
97
|
+
};
|
|
98
|
+
if (opts.extraPath) {
|
|
99
|
+
restOpts.url += '/' + opts.extraPath;
|
|
100
|
+
}
|
|
101
|
+
if (opts.ignoreError) {
|
|
102
|
+
restOpts.error = null;
|
|
103
|
+
}
|
|
104
|
+
if (opts.data) {
|
|
105
|
+
restOpts.data = opts.data;
|
|
106
|
+
}
|
|
107
|
+
return restRequest(restOpts).done((resp) => {
|
|
108
|
+
this.set(resp);
|
|
109
|
+
if (opts.extraPath) {
|
|
110
|
+
this.trigger('g:fetched.' + opts.extraPath);
|
|
111
|
+
} else {
|
|
112
|
+
this.trigger('g:fetched');
|
|
113
|
+
}
|
|
114
|
+
}).fail((err) => {
|
|
115
|
+
this.trigger('g:error', err);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get the path for downloading this resource via the API. Can be used
|
|
121
|
+
* as the href property of a direct download link.
|
|
122
|
+
* @param params {Object} list of key-value parameters to include in the
|
|
123
|
+
* query string.
|
|
124
|
+
*/
|
|
125
|
+
downloadUrl: function (params) {
|
|
126
|
+
let url = `${getApiRoot()}/${this.altUrl || this.resourceName}/${this.id}/download`;
|
|
127
|
+
|
|
128
|
+
if (params) {
|
|
129
|
+
url += '?' + $.param(params);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return url;
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* For models that can be downloaded, this method can be used to
|
|
137
|
+
* initiate the download in the browser.
|
|
138
|
+
*/
|
|
139
|
+
download: function () {
|
|
140
|
+
window.location.assign(this.downloadUrl());
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Delete the model on the server.
|
|
145
|
+
* @param opts Options, may contain:
|
|
146
|
+
* throwError Whether to throw an error (bool, default=true)
|
|
147
|
+
* progress Whether to record progress (bool, default=false)
|
|
148
|
+
*/
|
|
149
|
+
destroy: function (opts) {
|
|
150
|
+
if (this.altUrl === null && this.resourceName === null) {
|
|
151
|
+
throw new Error('An altUrl or resourceName must be set on the Model.');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
var args = {
|
|
155
|
+
url: `${this.altUrl || this.resourceName}/${this.id}`,
|
|
156
|
+
method: 'DELETE'
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
opts = opts || {};
|
|
160
|
+
if (opts.progress === true) {
|
|
161
|
+
args.url += '?progress=true';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (opts.throwError !== false) {
|
|
165
|
+
args.error = null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return restRequest(args).done(() => {
|
|
169
|
+
if (this.collection) {
|
|
170
|
+
this.collection.remove(this);
|
|
171
|
+
}
|
|
172
|
+
this.trigger('g:deleted');
|
|
173
|
+
}).fail((err) => {
|
|
174
|
+
this.trigger('g:error', err);
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Return the access level with respect to the current user
|
|
180
|
+
*/
|
|
181
|
+
getAccessLevel: function () {
|
|
182
|
+
return this.get('_accessLevel');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export default Model;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import _ from 'underscore';
|
|
2
|
+
|
|
3
|
+
import { fetchCurrentUser, setCurrentToken, setCurrentUser } from '@girder/core/auth';
|
|
4
|
+
import events from '@girder/core/events';
|
|
5
|
+
import Model from '@girder/core/models/Model';
|
|
6
|
+
import { restRequest } from '@girder/core/rest';
|
|
7
|
+
import eventStream from '@girder/core/utilities/EventStream';
|
|
8
|
+
|
|
9
|
+
var UserModel = Model.extend({
|
|
10
|
+
resourceName: 'user',
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Calling this function mutates the model in one of two ways: (1) if a user
|
|
14
|
+
* is currently logged into Girder, the model will reflect that user; (2) if
|
|
15
|
+
* no user is logged in, the model will become clear. To know which path
|
|
16
|
+
* occurred, you can call this method, then install a one-time event handler
|
|
17
|
+
* for the model's change event. In that handler, calling isNew() on the
|
|
18
|
+
* model will tell if you if a user is logged in (false) or not (true).
|
|
19
|
+
*
|
|
20
|
+
* This is equivalent to invoking fetchCurrentUser(), then calling
|
|
21
|
+
* clear() or set() on the model depending on whether the result of the call
|
|
22
|
+
* is null or not.
|
|
23
|
+
*/
|
|
24
|
+
current: function () {
|
|
25
|
+
fetchCurrentUser()
|
|
26
|
+
.done((user) => {
|
|
27
|
+
if (user) {
|
|
28
|
+
this.set(user);
|
|
29
|
+
} else {
|
|
30
|
+
this.clear();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
name: function () {
|
|
36
|
+
return this.get('firstName') + ' ' + this.get('lastName');
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* When this user is added to a group, call this on the user model.
|
|
41
|
+
*/
|
|
42
|
+
addToGroup: function (groupId) {
|
|
43
|
+
var groups = this.get('groups') || [];
|
|
44
|
+
groups.push(groupId);
|
|
45
|
+
this.set('groups', groups);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* When this user is removed from a group, call this on the user model.
|
|
50
|
+
*/
|
|
51
|
+
removeFromGroup: function (groupId) {
|
|
52
|
+
var groups = this.get('groups') || [];
|
|
53
|
+
var index = groups.indexOf(groupId);
|
|
54
|
+
|
|
55
|
+
while (index >= 0) {
|
|
56
|
+
groups.splice(index, 1);
|
|
57
|
+
index = groups.indexOf(groupId);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.set('groups', groups);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* When this user is invited to a group, call this on the user model.
|
|
65
|
+
*/
|
|
66
|
+
addInvitation: function (groupId, level) {
|
|
67
|
+
var invites = this.get('groupInvites') || [];
|
|
68
|
+
invites.push({
|
|
69
|
+
groupId: groupId,
|
|
70
|
+
level: level
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
this.set('groupInvites', invites);
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* When this user's invitation is deleted, either by joining the group or
|
|
78
|
+
* having the invitation deleted manually, this should be called on the user
|
|
79
|
+
* model.
|
|
80
|
+
*/
|
|
81
|
+
removeInvitation: function (groupId) {
|
|
82
|
+
var invites = this.get('groupInvites') || [];
|
|
83
|
+
var filtered = _.reject(invites, _.matcher({ groupId: groupId }));
|
|
84
|
+
|
|
85
|
+
this.set('groupInvites', filtered);
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Change the password for this user.
|
|
90
|
+
*/
|
|
91
|
+
changePassword: function (oldPassword, newPassword) {
|
|
92
|
+
return restRequest({
|
|
93
|
+
url: `${this.resourceName}/password`,
|
|
94
|
+
data: {
|
|
95
|
+
old: oldPassword,
|
|
96
|
+
new: newPassword
|
|
97
|
+
},
|
|
98
|
+
method: 'PUT',
|
|
99
|
+
error: null
|
|
100
|
+
}).done(() => {
|
|
101
|
+
this.trigger('g:passwordChanged');
|
|
102
|
+
}).fail((err) => {
|
|
103
|
+
this.trigger('g:error', err);
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Change the password for another user (as an admin).
|
|
109
|
+
*/
|
|
110
|
+
adminChangePassword: function (newPassword) {
|
|
111
|
+
return restRequest({
|
|
112
|
+
url: `${this.resourceName}/${this.id}/password`,
|
|
113
|
+
data: {
|
|
114
|
+
password: newPassword
|
|
115
|
+
},
|
|
116
|
+
method: 'PUT',
|
|
117
|
+
error: null
|
|
118
|
+
}).done(() => {
|
|
119
|
+
this.trigger('g:passwordChanged');
|
|
120
|
+
}).fail((err) => {
|
|
121
|
+
this.trigger('g:error', err);
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
initializeEnableOtp: function () {
|
|
126
|
+
return restRequest({
|
|
127
|
+
url: `user/${this.id}/otp`,
|
|
128
|
+
method: 'POST',
|
|
129
|
+
error: null
|
|
130
|
+
})
|
|
131
|
+
.then((resp) => {
|
|
132
|
+
return resp.totpUri;
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
finializeEnableOtp: function (otpToken) {
|
|
137
|
+
return restRequest({
|
|
138
|
+
url: `user/${this.id}/otp`,
|
|
139
|
+
method: 'PUT',
|
|
140
|
+
headers: {
|
|
141
|
+
'Girder-OTP': otpToken
|
|
142
|
+
},
|
|
143
|
+
error: null
|
|
144
|
+
})
|
|
145
|
+
.done(() => {
|
|
146
|
+
this.set('otp', true);
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
disableOtp: function () {
|
|
151
|
+
return restRequest({
|
|
152
|
+
url: `user/${this.id}/otp`,
|
|
153
|
+
method: 'DELETE',
|
|
154
|
+
error: null
|
|
155
|
+
})
|
|
156
|
+
.done(() => {
|
|
157
|
+
this.set('otp', false);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}, {
|
|
161
|
+
fromTemporaryToken: function (userId, token) {
|
|
162
|
+
return restRequest({
|
|
163
|
+
url: `user/password/temporary/${userId}`,
|
|
164
|
+
method: 'GET',
|
|
165
|
+
data: { token: token },
|
|
166
|
+
error: null
|
|
167
|
+
}).done((resp) => {
|
|
168
|
+
resp.user.token = resp.authToken.token;
|
|
169
|
+
eventStream.close();
|
|
170
|
+
setCurrentUser(new UserModel(resp.user));
|
|
171
|
+
setCurrentToken(resp.authToken.token);
|
|
172
|
+
eventStream.open();
|
|
173
|
+
events.trigger('g:login-changed');
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
sendVerificationEmail: function (login) {
|
|
178
|
+
return restRequest({
|
|
179
|
+
url: 'user/verification',
|
|
180
|
+
method: 'POST',
|
|
181
|
+
data: {
|
|
182
|
+
login: login
|
|
183
|
+
},
|
|
184
|
+
error: null
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export default UserModel;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import AccessControlledModel from './AccessControlledModel';
|
|
2
|
+
import ApiKeyModel from './ApiKeyModel';
|
|
3
|
+
import AssetstoreModel from './AssetstoreModel';
|
|
4
|
+
import CollectionModel from './CollectionModel';
|
|
5
|
+
import FileModel from './FileModel';
|
|
6
|
+
import FolderModel from './FolderModel';
|
|
7
|
+
import GroupModel from './GroupModel';
|
|
8
|
+
import ItemModel from './ItemModel';
|
|
9
|
+
import MetadataMixin from './MetadataMixin';
|
|
10
|
+
import Model from './Model';
|
|
11
|
+
import UserModel from './UserModel';
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
AccessControlledModel,
|
|
15
|
+
ApiKeyModel,
|
|
16
|
+
AssetstoreModel,
|
|
17
|
+
CollectionModel,
|
|
18
|
+
FileModel,
|
|
19
|
+
FolderModel,
|
|
20
|
+
GroupModel,
|
|
21
|
+
ItemModel,
|
|
22
|
+
MetadataMixin,
|
|
23
|
+
Model,
|
|
24
|
+
UserModel
|
|
25
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expose the symbols for a girder plugin under the window.girder.plugins
|
|
3
|
+
* namespace. Required since each plugin is loaded dynamically.
|
|
4
|
+
*/
|
|
5
|
+
var registerPluginNamespace = function (pluginName, symbols) {
|
|
6
|
+
window.girder.plugins[pluginName] = symbols;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
registerPluginNamespace
|
|
11
|
+
};
|