@gudhub/core 1.1.24 → 1.1.26
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/GUDHUB/PipeService/PipeService.js +5 -3
- package/GUDHUB/Utils/filter/utils.js +2 -1
- package/GUDHUB/Utils/groupManager/GroupManager.js +166 -0
- package/GUDHUB/Utils/groupManager/groupManager.test.js +65 -0
- package/GUDHUB/Utils/sharing/AppGroupSharing.js +111 -0
- package/GUDHUB/Utils/sharing/GroupSharing.js +71 -0
- package/GUDHUB/Utils/sharing/Sharing.js +101 -0
- package/GUDHUB/Utils/sharing/appGroupSharing.test.js +43 -0
- package/GUDHUB/Utils/sharing/sharing.test.js +48 -0
- package/GUDHUB/gudhub.js +4 -0
- package/fake_server/fake_java_server.js +101 -0
- package/package.json +1 -1
- package/umd/library.min.js +15 -7
- package/umd/library.min.js.map +1 -1
|
@@ -200,10 +200,12 @@ export class PipeService {
|
|
|
200
200
|
//-- Emiting messages from the MessageBox
|
|
201
201
|
//We use timeout to emit message after subscriber is created
|
|
202
202
|
setTimeout(() => {
|
|
203
|
-
|
|
203
|
+
if(this.messageBox[listenerName]) {
|
|
204
|
+
this.emit(...this.messageBox[listenerName]);
|
|
204
205
|
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
//we mark message after it was readed as "to be removed" to remove it in next itration
|
|
207
|
+
this.messageBox[listenerName][4] = true;
|
|
208
|
+
}
|
|
207
209
|
}, 0);
|
|
208
210
|
}
|
|
209
211
|
}
|
|
@@ -56,7 +56,8 @@ export function getDate({ type, date = 0, match = true } = {}, itemTime) {
|
|
|
56
56
|
const daysToEnd = date == -2 ? 13 : 6;
|
|
57
57
|
const weekEnd = weekStart + daysToEnd;
|
|
58
58
|
const weekDayStart = newDate.setDate(weekStart + date * 7);
|
|
59
|
-
const
|
|
59
|
+
const currentDate = new Date();
|
|
60
|
+
const weekDayEnd = currentDate.setDate(weekEnd + date * 7);
|
|
60
61
|
|
|
61
62
|
const [sunday, saturday] = getWeek(weekDayStart, weekDayEnd);
|
|
62
63
|
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
export class GroupManager {
|
|
2
|
+
constructor(gudhub, req) {
|
|
3
|
+
this.req = req;
|
|
4
|
+
this.gudhub = gudhub;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
//********************* CREATE GROUP *********************//
|
|
8
|
+
|
|
9
|
+
async createGroupApi(groupName) {
|
|
10
|
+
try {
|
|
11
|
+
const form = {
|
|
12
|
+
token: await this.gudhub.auth.getToken(),
|
|
13
|
+
group_name: groupName,
|
|
14
|
+
};
|
|
15
|
+
const group = await this.req.post({
|
|
16
|
+
url: "/api/sharing-group/create-group",
|
|
17
|
+
form,
|
|
18
|
+
});
|
|
19
|
+
return group;
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.log(err);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//********************* UPDATE GROUP *********************//
|
|
27
|
+
|
|
28
|
+
async updateGroupApi(groupId, groupName) {
|
|
29
|
+
try {
|
|
30
|
+
const form = {
|
|
31
|
+
token: await this.gudhub.auth.getToken(),
|
|
32
|
+
group_name: groupName,
|
|
33
|
+
group_id: groupId
|
|
34
|
+
};
|
|
35
|
+
const group = await this.req.post({
|
|
36
|
+
url: "/api/sharing-group/update-group",
|
|
37
|
+
form,
|
|
38
|
+
});
|
|
39
|
+
return group;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.log(err);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//********************* DELETE GROUP *********************//
|
|
47
|
+
|
|
48
|
+
async deleteGroupApi(groupId) {
|
|
49
|
+
try {
|
|
50
|
+
const form = {
|
|
51
|
+
token: await this.gudhub.auth.getToken(),
|
|
52
|
+
group_id: groupId
|
|
53
|
+
};
|
|
54
|
+
const group = await this.req.post({
|
|
55
|
+
url: "/api/sharing-group/delete-group",
|
|
56
|
+
form,
|
|
57
|
+
});
|
|
58
|
+
return group;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.log(err);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//********************* ADD USER TO GROUP *********************//
|
|
66
|
+
|
|
67
|
+
async addUserToGroupApi(groupId, userId, permission) {
|
|
68
|
+
try {
|
|
69
|
+
const form = {
|
|
70
|
+
token: await this.gudhub.auth.getToken(),
|
|
71
|
+
group_id: groupId,
|
|
72
|
+
user_id: userId,
|
|
73
|
+
group_permission: permission
|
|
74
|
+
};
|
|
75
|
+
const group = await this.req.post({
|
|
76
|
+
url: "/api/sharing-group/add-user-to-group",
|
|
77
|
+
form,
|
|
78
|
+
});
|
|
79
|
+
return group;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.log(err);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//********************* GET USERS BY GROUP *********************//
|
|
87
|
+
|
|
88
|
+
async getUsersByGroupApi(groupId) {
|
|
89
|
+
try {
|
|
90
|
+
const form = {
|
|
91
|
+
token: await this.gudhub.auth.getToken(),
|
|
92
|
+
group_id: groupId,
|
|
93
|
+
};
|
|
94
|
+
const group = await this.req.post({
|
|
95
|
+
url: "/api/sharing-group/get-users-by-group",
|
|
96
|
+
form,
|
|
97
|
+
});
|
|
98
|
+
return group;
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.log(err);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//********************* UPDATE USER IN GROUP *********************//
|
|
106
|
+
|
|
107
|
+
async updateUserInGroupApi(userId, groupId, permission) {
|
|
108
|
+
try {
|
|
109
|
+
const form = {
|
|
110
|
+
token: await this.gudhub.auth.getToken(),
|
|
111
|
+
user_id: userId,
|
|
112
|
+
group_id: groupId,
|
|
113
|
+
group_permission: permission
|
|
114
|
+
};
|
|
115
|
+
const group = await this.req.post({
|
|
116
|
+
url: "/api/sharing-group/update-user-in-group",
|
|
117
|
+
form,
|
|
118
|
+
});
|
|
119
|
+
return group;
|
|
120
|
+
} catch (err) {
|
|
121
|
+
console.log(err);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//********************* REMOVE USER FROM GROUP *********************//
|
|
127
|
+
|
|
128
|
+
async deleteUserFromGroupApi(userId, groupId) {
|
|
129
|
+
try {
|
|
130
|
+
const form = {
|
|
131
|
+
token: await this.gudhub.auth.getToken(),
|
|
132
|
+
user_id: userId,
|
|
133
|
+
group_id: groupId
|
|
134
|
+
};
|
|
135
|
+
const group = await this.req.post({
|
|
136
|
+
url: "/api/sharing-group/delete-user-from-group",
|
|
137
|
+
form,
|
|
138
|
+
});
|
|
139
|
+
return group;
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.log(err);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//********************* GET GROUPS BY USER *********************//
|
|
147
|
+
|
|
148
|
+
async getGroupsByUserApi(userId) {
|
|
149
|
+
try {
|
|
150
|
+
const form = {
|
|
151
|
+
token: await this.gudhub.auth.getToken(),
|
|
152
|
+
user_id: userId
|
|
153
|
+
};
|
|
154
|
+
const group = await this.req.post({
|
|
155
|
+
url: "/api/sharing-group/get-groups-by-user",
|
|
156
|
+
form,
|
|
157
|
+
});
|
|
158
|
+
return group;
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.log(err);
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GudHub } from '../../gudhub.js';
|
|
2
|
+
|
|
3
|
+
describe("GROUP MANAGEMENT", async function() {
|
|
4
|
+
const gudhub = new GudHub();
|
|
5
|
+
|
|
6
|
+
it("CREATE GROUP FOR SHARING / should return object with group name and id", async function () {
|
|
7
|
+
const group = await gudhub.groupSharing.createGroup('Test group');
|
|
8
|
+
group.should.property('group_name').equal('Test group');
|
|
9
|
+
group.should.property('group_id').equal(1);
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it("ADD USER TO GROUP / should return user, group id's and permission for user", async function () {
|
|
13
|
+
// PermissionStatus: 0 - no access, 1 - read and write, 2 - admin, 3 - owner -> default when create group
|
|
14
|
+
const group = await gudhub.groupSharing.addUserToGroup(1, 1695, 1);
|
|
15
|
+
group.should.property('user_id').equal('1695');
|
|
16
|
+
group.should.property('group_id').equal('1');
|
|
17
|
+
group.should.property('group_permission').equal('1');
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("UPDATE GROUP WITH NEW NAME", async function () {
|
|
21
|
+
const group = await gudhub.groupSharing.updateGroup(1, 'New group name');
|
|
22
|
+
group.should.property('group_name').equal('New group name');
|
|
23
|
+
group.should.property('group_id').equal('1');
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it("GET USERS IN GROUP / should return array with users in group", async function () {
|
|
27
|
+
const group = await gudhub.groupSharing.getUsersByGroup(1);
|
|
28
|
+
const groupUsersLength = group.length;
|
|
29
|
+
groupUsersLength.should.equal(2);
|
|
30
|
+
group[0].should.property('group_id').equal(1);
|
|
31
|
+
group[0].should.property('user_id').equal(1695);
|
|
32
|
+
group[0].should.property('group_permission').equal(1);
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it("GET GROUPS BY USER / should return array with groups for specific user", async function () {
|
|
36
|
+
const group = await gudhub.groupSharing.getGroupsByUser(1695);
|
|
37
|
+
const groupUsersLength = group.length;
|
|
38
|
+
groupUsersLength.should.equal(1);
|
|
39
|
+
group[0].should.property('group_id').equal(1);
|
|
40
|
+
group[0].should.property('user_id').equal(1695);
|
|
41
|
+
group[0].should.property('group_permission').equal(1);
|
|
42
|
+
group[0].should.property('group_name').equal('New group name');
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it("UPDATE USER IN GROUP / should return object with user_id, group_id and new permission", async function () {
|
|
46
|
+
const group = await gudhub.groupSharing.updateUserInGroup(1695, 1, 0);
|
|
47
|
+
group.should.property('user_id').equal('1695');
|
|
48
|
+
group.should.property('group_id').equal('1');
|
|
49
|
+
group.should.property('group_permission').equal('0');
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it("DELETE USER FROM GROUP / should return deleted user_id with group_id and permission", async function () {
|
|
53
|
+
const group = await gudhub.groupSharing.deleteUserFromGroup(1695, 1);
|
|
54
|
+
group.should.property('user_id').equal('1695');
|
|
55
|
+
group.should.property('group_id').equal('1');
|
|
56
|
+
group.should.property('group_permission').equal(0);
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it("DELETE GROUP / should return deleted group", async function () {
|
|
60
|
+
const group = await gudhub.groupSharing.deleteGroup(1);
|
|
61
|
+
group.should.property('group_name').equal('New group name');
|
|
62
|
+
group.should.property('group_id').equal('1');
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export class AppGroupSharing {
|
|
2
|
+
|
|
3
|
+
constructor(gudhub, req) {
|
|
4
|
+
this.req = req;
|
|
5
|
+
this.gudhub = gudhub;
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//********************* ADD APP TO GROUP *********************//
|
|
10
|
+
|
|
11
|
+
async addAppToGroupApi(appId, groupId, permission) {
|
|
12
|
+
try {
|
|
13
|
+
const form = {
|
|
14
|
+
token: await this.gudhub.auth.getToken(),
|
|
15
|
+
app_id: appId,
|
|
16
|
+
group_id: groupId,
|
|
17
|
+
app_permission: permission
|
|
18
|
+
};
|
|
19
|
+
const group = await this.req.post({
|
|
20
|
+
url: "/api/sharing-group/add-app-to-group",
|
|
21
|
+
form,
|
|
22
|
+
});
|
|
23
|
+
return group;
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.log(err);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//********************* GET APPS BY GROUP *********************//
|
|
31
|
+
|
|
32
|
+
async getAppsByGroupApi(groupId) {
|
|
33
|
+
try {
|
|
34
|
+
const form = {
|
|
35
|
+
token: await this.gudhub.auth.getToken(),
|
|
36
|
+
group_id: groupId
|
|
37
|
+
};
|
|
38
|
+
const group = await this.req.post({
|
|
39
|
+
url: "/api/sharing-group/get-apps-by-group",
|
|
40
|
+
form,
|
|
41
|
+
});
|
|
42
|
+
return group;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.log(err);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//********************* UPDATE APP IN GROUP *********************//
|
|
50
|
+
|
|
51
|
+
async updateAppInGroupApi(appId, groupId, permission) {
|
|
52
|
+
try {
|
|
53
|
+
const form = {
|
|
54
|
+
token: await this.gudhub.auth.getToken(),
|
|
55
|
+
group_id: groupId,
|
|
56
|
+
app_id: appId,
|
|
57
|
+
app_permission: permission
|
|
58
|
+
};
|
|
59
|
+
const group = await this.req.post({
|
|
60
|
+
url: "/api/sharing-group/update-app-in-group",
|
|
61
|
+
form,
|
|
62
|
+
});
|
|
63
|
+
return group;
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(err);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//********************* DELETE APP FROM GROUP *********************//
|
|
71
|
+
|
|
72
|
+
async deleteAppFromGroupApi(appId, groupId, permission) {
|
|
73
|
+
try {
|
|
74
|
+
const form = {
|
|
75
|
+
token: await this.gudhub.auth.getToken(),
|
|
76
|
+
group_id: groupId,
|
|
77
|
+
app_id: appId,
|
|
78
|
+
app_permission: permission
|
|
79
|
+
};
|
|
80
|
+
const group = await this.req.post({
|
|
81
|
+
url: "/api/sharing-group/delete-app-from-group",
|
|
82
|
+
form,
|
|
83
|
+
});
|
|
84
|
+
return group;
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.log(err);
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//********************* GET GROUPS BY APP *********************//
|
|
92
|
+
|
|
93
|
+
async getGroupsByAppApi(appId) {
|
|
94
|
+
try {
|
|
95
|
+
const form = {
|
|
96
|
+
token: await this.gudhub.auth.getToken(),
|
|
97
|
+
app_id: appId
|
|
98
|
+
};
|
|
99
|
+
const group = await this.req.post({
|
|
100
|
+
url: "/api/sharing-group/get-groups-by-app",
|
|
101
|
+
form,
|
|
102
|
+
});
|
|
103
|
+
return group;
|
|
104
|
+
} catch (err) {
|
|
105
|
+
console.log(err);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { GroupManager } from "../groupManager/GroupManager.js";
|
|
2
|
+
import { AppGroupSharing } from "./AppGroupSharing.js";
|
|
3
|
+
export class GroupSharing {
|
|
4
|
+
constructor(gudhub, req, pipeService) {
|
|
5
|
+
this.req = req;
|
|
6
|
+
this.gudhub = gudhub;
|
|
7
|
+
this.pipeService = pipeService;
|
|
8
|
+
this.groupManager = new GroupManager(gudhub, req);
|
|
9
|
+
this.appGroupSharing = new AppGroupSharing(gudhub, req);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
createGroup(groupName) {
|
|
13
|
+
return this.groupManager.createGroupApi(groupName);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
updateGroup(groupId, groupName) {
|
|
17
|
+
return this.groupManager.updateGroupApi(groupId, groupName);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
deleteGroup(groupId) {
|
|
21
|
+
return this.groupManager.deleteGroupApi(groupId);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async addUserToGroup(userId, groupId, permission) {
|
|
25
|
+
let newUser = await this.groupManager.addUserToGroupApi(userId, groupId, permission);
|
|
26
|
+
this.pipeService.emit("group_members_add", { app_id: "group_sharing"}, newUser);
|
|
27
|
+
return newUser;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getUsersByGroup(groupId) {
|
|
31
|
+
return this.groupManager.getUsersByGroupApi(groupId);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async updateUserInGroup(userId, groupId, permission) {
|
|
35
|
+
let updatedUser = await this.groupManager.updateUserInGroupApi(userId, groupId, permission);
|
|
36
|
+
this.pipeService.emit("group_members_update", { app_id: "group_sharing"}, updatedUser);
|
|
37
|
+
return updatedUser;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async deleteUserFromGroup(userId, groupId) {
|
|
41
|
+
let deletedUser = await this.groupManager.deleteUserFromGroupApi(userId, groupId);
|
|
42
|
+
this.pipeService.emit("group_members_delete", { app_id: "group_sharing"}, deletedUser);
|
|
43
|
+
return deletedUser;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getGroupsByUser(userId) {
|
|
47
|
+
return this.groupManager.getGroupsByUserApi(userId);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
addAppToGroup(appId, groupId, permission) {
|
|
51
|
+
return this.appGroupSharing.addAppToGroupApi(appId, groupId, permission);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getAppsByGroup(groupId) {
|
|
55
|
+
return this.appGroupSharing.getAppsByGroupApi(groupId);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
updateAppInGroup(appId, groupId, permission) {
|
|
59
|
+
return this.appGroupSharing.updateAppInGroupApi(appId, groupId, permission);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
deleteAppFromGroup(appId, groupId, permission) {
|
|
63
|
+
return this.appGroupSharing.deleteAppFromGroupApi(appId, groupId, permission);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getGroupsByApp(appId) {
|
|
67
|
+
return this.appGroupSharing.getGroupsByAppApi(appId);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export class Sharing {
|
|
2
|
+
|
|
3
|
+
constructor(gudhub, req) {
|
|
4
|
+
this.req = req;
|
|
5
|
+
this.gudhub = gudhub;
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async add(appId, userId, permission) {
|
|
10
|
+
try {
|
|
11
|
+
const form = {
|
|
12
|
+
token: await this.gudhub.auth.getToken(),
|
|
13
|
+
app_id: appId,
|
|
14
|
+
user_id: userId,
|
|
15
|
+
sharing_permission: permission
|
|
16
|
+
};
|
|
17
|
+
const response = await this.req.post({
|
|
18
|
+
url: "/sharing/add",
|
|
19
|
+
form,
|
|
20
|
+
});
|
|
21
|
+
return response;
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.log(err);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async update(appId, userId, permission) {
|
|
29
|
+
try {
|
|
30
|
+
const form = {
|
|
31
|
+
token: await this.gudhub.auth.getToken(),
|
|
32
|
+
app_id: appId,
|
|
33
|
+
user_id: userId,
|
|
34
|
+
sharing_permission: permission
|
|
35
|
+
};
|
|
36
|
+
const response = await this.req.post({
|
|
37
|
+
url: "/sharing/update",
|
|
38
|
+
form,
|
|
39
|
+
});
|
|
40
|
+
return response;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.log(err);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async delete(appId, userId) {
|
|
48
|
+
try {
|
|
49
|
+
const form = {
|
|
50
|
+
token: await this.gudhub.auth.getToken(),
|
|
51
|
+
app_id: appId,
|
|
52
|
+
user_id: userId
|
|
53
|
+
};
|
|
54
|
+
const response = await this.req.post({
|
|
55
|
+
url: "/sharing/delete",
|
|
56
|
+
form,
|
|
57
|
+
});
|
|
58
|
+
return response;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.log(err);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getAppUsers(appId) {
|
|
66
|
+
try {
|
|
67
|
+
const form = {
|
|
68
|
+
token: await this.gudhub.auth.getToken(),
|
|
69
|
+
app_id: appId
|
|
70
|
+
};
|
|
71
|
+
const response = await this.req.post({
|
|
72
|
+
url: "/sharing/get-app-users",
|
|
73
|
+
form,
|
|
74
|
+
});
|
|
75
|
+
return response;
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.log(err);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async addInvitation(guestsEmails, apps) {
|
|
83
|
+
try {
|
|
84
|
+
const form = {
|
|
85
|
+
token: await this.gudhub.auth.getToken(),
|
|
86
|
+
guests_emails: guestsEmails,
|
|
87
|
+
apps
|
|
88
|
+
};
|
|
89
|
+
const response = await this.req.post({
|
|
90
|
+
url: "/api/invitation/add",
|
|
91
|
+
form,
|
|
92
|
+
});
|
|
93
|
+
return response;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
console.log(err);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { GudHub } from '../../gudhub.js';
|
|
2
|
+
|
|
3
|
+
describe("SHARING APP TO GROUP OF USERS", async function() {
|
|
4
|
+
// PermissionStatus: 0 - no access, 1 - read, 2 - write, 3 - admin, 4 - owner -> default when create app
|
|
5
|
+
const gudhub = new GudHub();
|
|
6
|
+
|
|
7
|
+
it("SHARE APP TO GROUP / should return object with app id, group id and app permission", async function () {
|
|
8
|
+
const group = await gudhub.groupSharing.addAppToGroup(16259, 1, 1);
|
|
9
|
+
group.should.property('app_id').equal('16259');
|
|
10
|
+
group.should.property('app_permission').equal('1');
|
|
11
|
+
group.should.property('group_id').equal('1');
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it("GET APPS BY GROUP ID / should return array with apps id", async function () {
|
|
15
|
+
const group = await gudhub.groupSharing.getAppsByGroup(1);
|
|
16
|
+
group[0].should.property('app_id').equal('16259');
|
|
17
|
+
group[0].should.property('app_permission').equal('1');
|
|
18
|
+
group[0].should.property('group_id').equal('1');
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it("UPDATE PERMISSION FOR APP IN GROUP / should return object with group id, app id and new permission", async function () {
|
|
22
|
+
const group = await gudhub.groupSharing.updateAppInGroup(16259, 1, 2);
|
|
23
|
+
group.should.property('app_id').equal('16259');
|
|
24
|
+
group.should.property('app_permission').equal('2');
|
|
25
|
+
group.should.property('group_id').equal('1');
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it("DELETE APP FROM GROUP / should return object with group id, app id and permission", async function () {
|
|
29
|
+
const group = await gudhub.groupSharing.deleteAppFromGroup(16259, 1, 2);
|
|
30
|
+
group.should.property('app_id').equal('16259');
|
|
31
|
+
group.should.property('app_permission').equal('2');
|
|
32
|
+
group.should.property('group_id').equal('1');
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it("GET GROUPS BY APP / should return array with groups of current app", async function () {
|
|
36
|
+
const group = await gudhub.groupSharing.getGroupsByApp(16259);
|
|
37
|
+
group[0].should.property('group_name').equal('New group name');
|
|
38
|
+
group[0].should.property('group_id').equal('1');
|
|
39
|
+
group[0].should.property('app_permission').equal('2');
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { GudHub } from '../../gudhub.js';
|
|
2
|
+
|
|
3
|
+
describe("SHARING APP TO USER", async function() {
|
|
4
|
+
// PermissionStatus: 0 - no access, 1 - read, 2 - write, 3 - admin, 4 - owner -> default when create app
|
|
5
|
+
const gudhub = new GudHub();
|
|
6
|
+
|
|
7
|
+
it("SHARE APP TO USER / should return object with app id, user id and app permission", async function () {
|
|
8
|
+
const response = await gudhub.sharing.add(16259, 25, 2);
|
|
9
|
+
response.should.property('app_id').equal('16259');
|
|
10
|
+
response.should.property('permission').equal('2');
|
|
11
|
+
response.should.property('user_id').equal('25');
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it("UPDATE PERMISSION FOR USER / should return object with app id, user id and new permission", async function () {
|
|
15
|
+
const response = await gudhub.sharing.update(16259, 25, 3);
|
|
16
|
+
response.should.property('app_id').equal('16259');
|
|
17
|
+
response.should.property('permission').equal('3');
|
|
18
|
+
response.should.property('user_id').equal('25');
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it("DELETE APP FOR USER / should return object with deleted user", async function () {
|
|
22
|
+
const response = await gudhub.sharing.delete(16259, 25);
|
|
23
|
+
response.should.property('app_id').equal('16259');
|
|
24
|
+
response.should.property('permission').equal('3');
|
|
25
|
+
response.should.property('user_id').equal('25');
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it("GET USERS WHICH HAVE RIGHTS IN APP / should return array with users which have rights to app", async function () {
|
|
29
|
+
const response = await gudhub.sharing.getAppUsers(16259);
|
|
30
|
+
response[0].should.property('app_id').equal('16259');
|
|
31
|
+
response[0].should.property('sharing_permission').equal('4');
|
|
32
|
+
response[0].should.property('user_id').equal('58');
|
|
33
|
+
response[0].should.property('fullname').equal('Vasya Pupkin');
|
|
34
|
+
response[0].should.property('avatar_128');
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it("SEND INVITES TO APPS / should return array with emails and app id's with permission", async function () {
|
|
38
|
+
const response = await gudhub.sharing.addInvitation(['fabricator2@gudhub.com'], [{app_id: 16259, permission: 2}, {app_id: 214, permission: 1}]);
|
|
39
|
+
response.length.should.equal(2);
|
|
40
|
+
response[0].should.property('app_id').equal('16259');
|
|
41
|
+
response[0].should.property('guest_email').equal('fabricator2@gudhub.com');
|
|
42
|
+
response[0].should.property('permission').equal('2');
|
|
43
|
+
response[1].should.property('app_id').equal('214');
|
|
44
|
+
response[1].should.property('guest_email').equal('fabricator2@gudhub.com');
|
|
45
|
+
response[1].should.property('permission').equal('1');
|
|
46
|
+
|
|
47
|
+
})
|
|
48
|
+
});
|
package/GUDHUB/gudhub.js
CHANGED
|
@@ -15,6 +15,8 @@ import { DocumentManager } from "./DocumentManager/DocumentManager.js";
|
|
|
15
15
|
import { Interpritate } from './GHConstructor/interpritate.js'
|
|
16
16
|
import { IS_WEB } from "./consts.js";
|
|
17
17
|
import { WebsocketHandler } from './WebSocket/WebsocketHandler.js';
|
|
18
|
+
import { GroupSharing } from './Utils/sharing/GroupSharing.js';
|
|
19
|
+
import { Sharing } from './Utils/sharing/Sharing.js';
|
|
18
20
|
|
|
19
21
|
export class GudHub {
|
|
20
22
|
constructor(
|
|
@@ -36,6 +38,8 @@ export class GudHub {
|
|
|
36
38
|
this.util = new Utils(this);
|
|
37
39
|
this.req = new GudHubHttpsService(options.server_url);
|
|
38
40
|
this.auth = new Auth(this.req, this.storage);
|
|
41
|
+
this.sharing = new Sharing(this, this.req);
|
|
42
|
+
this.groupSharing = new GroupSharing(this, this.req, this.pipeService);
|
|
39
43
|
if (authKey) this.storage.setUser({ auth_key: authKey });
|
|
40
44
|
this.req.init(this.auth.getToken.bind(this.auth));
|
|
41
45
|
|