forked from parse-community/parse-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppsManager.js
122 lines (111 loc) · 3.21 KB
/
AppsManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (c) 2016-present, Parse, LLC
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
import Parse from 'parse';
import ParseApp from 'lib/ParseApp';
import { get, post, del } from 'lib/AJAX';
import { unescape } from 'lib/StringEscaping';
let appsStore = [];
const AppsManager = {
addApp(raw) {
appsStore.push(new ParseApp(raw));
},
apps() {
appsStore.sort(function(app1, app2) {
return app1.name.localeCompare(app2.name);
});
return appsStore;
},
findAppBySlugOrName(slugOrName) {
let apps = this.apps();
for (let i = apps.length; i--;) {
if (apps[i].slug === slugOrName || apps[i].name === slugOrName) {
return apps[i];
}
}
return null;
},
create(name, connectionURL) {
let payload = {
parse_app: { name }
};
if (connectionURL) {
payload.parse_app.connectionString = connectionURL;
}
return post('/apps', payload).then((response) => {
let newApp = new ParseApp(response.app);
appsStore.push(newApp);
return newApp;
});
},
deleteApp(slug, password) {
return del('/apps/' + slug + '?password_confirm_delete=' + password).then(() => {
for (let i = 0; i < appsStore.length; i++) {
if (appsStore[i].slug == slug) {
appsStore.splice(i, 1);
return;
}
}
});
},
// Fetch the latest usage and request info for the apps index
getAllAppsIndexStats() {
return Parse.Promise.when(this.apps().map(app => {
return Parse.Promise.when(
app.getClassCount('_Installation').then(count => app.installations = count),
app.getClassCount('_User').then(count => app.users = count)
);
}));
},
// Options should be a list containing a subset of
// ["schema", "app_settings", "config", "cloud_code", "background_jobs"]
// indicating which parts of the app to clone.
cloneApp(slug, name, options) {
//Clone nothing by default
let optionsForRuby = {
cloud_code: false,
background_jobs: false,
config: false,
schema: false,
app_settings: false,
data: false,
};
options.forEach((option) => {
if (option !== 'data') { //Data cloning not supported yet, but api_server still requires the key to be present
optionsForRuby[option] = true;
}
});
let path = '/apps/' + slug + '/clone_app';
let request = post(path, {
app_name: name,
options: optionsForRuby,
});
request.then(({ app }) => {
if (!appsStore) {
AppsManager.seed();
}
appsStore.push(new ParseApp(app));
});
return request;
},
transferApp(slug, newOwner, password) {
let payload = {
new_owner_email: newOwner,
}
if (password) {
// Users who log in with oauth don't have a password,
// and don't require one to transfer their app.
payload.password_confirm_transfer = password;
}
let promise = post('/apps/' + slug + '/transfer', payload);
promise.then((response) => {
//TODO modify appsStore to reflect transfer
});
return promise;
}
}
export default AppsManager;