-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathapiHelper.js
More file actions
61 lines (59 loc) · 1.69 KB
/
apiHelper.js
File metadata and controls
61 lines (59 loc) · 1.69 KB
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
const fetch = require('node-fetch')
const { config } = require('../config')
const { throwError } = require('@vue/vue2-jest/lib/utils')
const createAdmin = function() {
const url = config.baseUrlOP + '/api/v3/users'
const data = {
login: 'admin2',
password: 'admin2',
firstName: 'Second',
lastName: 'Admin',
email: 'admin@mail.com',
admin: true,
status: 'active',
language: 'en',
}
fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers: {
Authorization: 'Basic ' + Buffer.from(config.openprojectBasicAuthUser + ':' + config.openprojectBasicAuthPass).toString('base64'),
'Content-Type': 'application/json',
},
}).then(function(response) {
if (response.status !== 201) {
throwError('Cannot create the admin user')
}
}).catch(function(error) {
throwError('Cannot create the admin user' + error)
})
}
const resetNextcloudOauthSettings = function() {
const url = config.baseUrlNC + '/index.php/apps/integration_openproject/admin-config'
const data = {
values:
{
client_id: null,
client_secret: null,
default_enable_navigation: false,
default_enable_notifications: false,
default_enable_unified_search: false,
oauth_instance_url: null,
},
}
fetch(url, {
method: 'PUT',
body: JSON.stringify(data),
headers: {
Authorization: 'Basic ' + Buffer.from('admin' + ':' + 'admin').toString('base64'),
'Content-Type': 'application/json; charset=utf-8',
},
}).then(function(response) {
if (response.status !== 200) {
throwError('Error while resetting nextcloud oauth setup')
}
}).catch(function(error) {
throwError('Cannot reset the nextcloud settings' + error)
})
}
module.exports = { createAdmin, resetNextcloudOauthSettings }