@gudhub/core 1.1.118 → 1.1.120
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/Auth/Auth.js +14 -3
- package/GUDHUB/Storage/ModulesList.js +7 -0
- package/GUDHUB/Utils/sharing/GroupInvitation.js +64 -0
- package/GUDHUB/gudhub.js +2 -0
- package/GUDHUB/invitation.test.js +116 -0
- package/fake_server/fake_java_server.js +54 -0
- package/package.json +1 -1
- package/umd/library.min.js +35 -33
- package/umd/library.min.js.map +1 -1
package/GUDHUB/Auth/Auth.js
CHANGED
|
@@ -5,9 +5,15 @@ export class Auth {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
async login({ username, password } = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
try {
|
|
9
|
+
const user = await this.loginApi(username, password);
|
|
10
|
+
this.storage.updateUser(user);
|
|
11
|
+
return user;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return {
|
|
14
|
+
error: error.response?.data || error.message,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
async loginWithToken(token) {
|
|
@@ -61,6 +67,11 @@ export class Auth {
|
|
|
61
67
|
return user;
|
|
62
68
|
} catch (error) {
|
|
63
69
|
console.log(error);
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
status: error.response?.status,
|
|
73
|
+
message: error.response?.data,
|
|
74
|
+
};
|
|
64
75
|
}
|
|
65
76
|
}
|
|
66
77
|
|
|
@@ -1203,6 +1203,13 @@ export default function generateModulesList(async_modules_path, file_server_url,
|
|
|
1203
1203
|
type: 'automation',
|
|
1204
1204
|
icon: 'automation_item_constructor'
|
|
1205
1205
|
},
|
|
1206
|
+
{
|
|
1207
|
+
data_type: 'InvitationsGenerator',
|
|
1208
|
+
name: 'Invitations Generator',
|
|
1209
|
+
url: file_server_url + '/' + automation_modules_path + 'invitations_generator_node.js',
|
|
1210
|
+
type: 'automation',
|
|
1211
|
+
icon: 'automation_api'
|
|
1212
|
+
},
|
|
1206
1213
|
{
|
|
1207
1214
|
data_type: 'ItemDestructor',
|
|
1208
1215
|
name: 'Item Destructor',
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class GroupInvitation {
|
|
2
|
+
constructor(gudhub, req) {
|
|
3
|
+
this.req = req;
|
|
4
|
+
this.gudhub = gudhub;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async groupInvitationCreate(sharingGroups, actions) {
|
|
8
|
+
try {
|
|
9
|
+
const form = {
|
|
10
|
+
sharing_groups: sharingGroups,
|
|
11
|
+
actions,
|
|
12
|
+
token: await this.gudhub.auth.getToken(),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const groupInventation = await this.req.post({
|
|
16
|
+
url: "/api/invitation/create",
|
|
17
|
+
form,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return groupInventation;
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.log(err);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async groupInvitationGet(invitationId) {
|
|
28
|
+
try {
|
|
29
|
+
const form = {
|
|
30
|
+
invitation_id: invitationId
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const groupInventation = await this.req.post({
|
|
34
|
+
url: "/api/invitation/get",
|
|
35
|
+
form,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return groupInventation;
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.log(err);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async groupInvitationAccept(invitationId) {
|
|
46
|
+
try {
|
|
47
|
+
const form = {
|
|
48
|
+
invitation_id: invitationId
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const groupInventation = await this.req.post({
|
|
52
|
+
url: "/api/invitation/accept",
|
|
53
|
+
form,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return groupInventation;
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.log(err);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default GroupInvitation;
|
package/GUDHUB/gudhub.js
CHANGED
|
@@ -16,6 +16,7 @@ import { Interpritate } from './GHConstructor/interpritate.js'
|
|
|
16
16
|
import { IS_WEB } from "./consts.js";
|
|
17
17
|
import { WebsocketHandler } from './WebSocket/WebsocketHandler.js';
|
|
18
18
|
import { GroupSharing } from './Utils/sharing/GroupSharing.js';
|
|
19
|
+
import { GroupInvitation } from './Utils/sharing/GroupInvitation.js';
|
|
19
20
|
import { Sharing } from './Utils/sharing/Sharing.js';
|
|
20
21
|
import { WebSocketEmitter } from './WebSocket/WebSocketEmitter.js';
|
|
21
22
|
|
|
@@ -46,6 +47,7 @@ export class GudHub {
|
|
|
46
47
|
this.auth = new Auth(this.req, this.storage);
|
|
47
48
|
this.sharing = new Sharing(this, this.req);
|
|
48
49
|
this.groupSharing = new GroupSharing(this, this.req, this.pipeService);
|
|
50
|
+
this.groupInventation = new GroupInvitation(this, this.req);
|
|
49
51
|
|
|
50
52
|
// Login with access token - pass to setUser access token and after it user can make requests with access token
|
|
51
53
|
// This method created for optimize GudHub initialization without auth key
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// import should from "should";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { GroupInvitation } from "../GUDHUB/Utils/sharing/GroupInvitation.js";
|
|
4
|
+
|
|
5
|
+
describe("Invitation API", function () {
|
|
6
|
+
const token = "fgdr5rfd4e5hsjkdrkdemdxm6re5erl";
|
|
7
|
+
|
|
8
|
+
let gudhub;
|
|
9
|
+
let req;
|
|
10
|
+
let api;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
gudhub = {
|
|
14
|
+
auth: {
|
|
15
|
+
getToken: sinon.stub().resolves(token)
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
req = {
|
|
20
|
+
post: sinon.stub()
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
api = new GroupInvitation(gudhub, req);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
sinon.restore();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("groupInvitationCreate should call correct endpoint and return data", async function () {
|
|
31
|
+
const sharingGroups = [
|
|
32
|
+
{ group_id: 7853, permission: 1 },
|
|
33
|
+
{ group_id: 7862, permission: 1 }
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const actions = [
|
|
37
|
+
{ app_id: 36354, field_id: 651748, item_id: 4555415 },
|
|
38
|
+
{ app_id: 54122, field_id: 748122, item_id: 5415122 }
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
req.post.resolves({
|
|
42
|
+
invitation_id: "r5fh587guj7r",
|
|
43
|
+
invitation_status: 0
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const result = await api.groupInvitationCreate(sharingGroups, actions);
|
|
47
|
+
|
|
48
|
+
result.should.have.property("invitation_id", "r5fh587guj7r");
|
|
49
|
+
result.should.have.property("invitation_status", 0);
|
|
50
|
+
|
|
51
|
+
gudhub.auth.getToken.calledOnce.should.be.true();
|
|
52
|
+
req.post.calledOnce.should.be.true();
|
|
53
|
+
|
|
54
|
+
const arg = req.post.firstCall.args[0];
|
|
55
|
+
arg.should.have.property("url", "/api/invitation/create");
|
|
56
|
+
arg.should.have.property("form");
|
|
57
|
+
arg.form.token.should.equal(token);
|
|
58
|
+
arg.form.sharing_groups.should.eql(sharingGroups);
|
|
59
|
+
arg.form.actions.should.eql(actions);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("groupInvitationGet should return full invitation structure", async function () {
|
|
63
|
+
const invitationId = "lknvzl3266bkjbkb";
|
|
64
|
+
|
|
65
|
+
req.post.resolves({
|
|
66
|
+
invitation_id: invitationId,
|
|
67
|
+
invitation_status: 0,
|
|
68
|
+
Inviter_user: {
|
|
69
|
+
fullname: "Andrii Atlas",
|
|
70
|
+
avatar_128: "url128",
|
|
71
|
+
avatar_512: "url512"
|
|
72
|
+
},
|
|
73
|
+
sharing_groups: [
|
|
74
|
+
{ group_name: "3D Rendering Team", group_permission: 1 }
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const result = await api.groupInvitationGet(invitationId);
|
|
79
|
+
|
|
80
|
+
result.should.have.property("invitation_id", invitationId);
|
|
81
|
+
result.should.have.property("invitation_status", 0);
|
|
82
|
+
result.should.have.property("Inviter_user");
|
|
83
|
+
result.should.have.property("sharing_groups");
|
|
84
|
+
|
|
85
|
+
result.Inviter_user.should.have.property("fullname", "Andrii Atlas");
|
|
86
|
+
result.sharing_groups.should.be.Array();
|
|
87
|
+
|
|
88
|
+
req.post.calledOnce.should.be.true();
|
|
89
|
+
|
|
90
|
+
const arg = req.post.firstCall.args[0];
|
|
91
|
+
arg.should.have.property("url", "/api/invitation/get");
|
|
92
|
+
arg.should.have.property("form");
|
|
93
|
+
arg.form.invitation_id.should.equal(invitationId);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("groupInvitationAccept should send invitation id and return accepted status", async function () {
|
|
97
|
+
const invitationId = "lknvzl3266bkjbkb";
|
|
98
|
+
|
|
99
|
+
req.post.resolves({
|
|
100
|
+
invitation_id: invitationId,
|
|
101
|
+
invitation_status: 1
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const result = await api.groupInvitationAccept(invitationId);
|
|
105
|
+
|
|
106
|
+
result.should.have.property("invitation_id", invitationId);
|
|
107
|
+
result.should.have.property("invitation_status", 1);
|
|
108
|
+
|
|
109
|
+
req.post.calledOnce.should.be.true();
|
|
110
|
+
|
|
111
|
+
const arg = req.post.firstCall.args[0];
|
|
112
|
+
arg.should.have.property("url", "/api/invitation/accept");
|
|
113
|
+
arg.should.have.property("form");
|
|
114
|
+
arg.form.invitation_id.should.equal(invitationId);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -193,6 +193,60 @@ export default function (app) {
|
|
|
193
193
|
]);
|
|
194
194
|
})
|
|
195
195
|
|
|
196
|
+
app.post('/api/invitation/create', (req, res) => {
|
|
197
|
+
const { sharing_groups, actions, token } = req.body;
|
|
198
|
+
|
|
199
|
+
if (!sharing_groups || !actions || !token) {
|
|
200
|
+
return res.status(400).json({ error: "Missing required fields" });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
res.status(200).json({
|
|
204
|
+
invitation_id: "r5fh587guj7r",
|
|
205
|
+
invitation_status: 0
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
app.post('/api/invitation/get', (req, res) => {
|
|
210
|
+
const { invitation_id } = req.body;
|
|
211
|
+
|
|
212
|
+
if (!invitation_id) {
|
|
213
|
+
return res.status(400).json({ error: "Missing invitation_id" });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
res.status(200).json({
|
|
217
|
+
invitation_id,
|
|
218
|
+
invitation_status: 0,
|
|
219
|
+
Inviter_user: {
|
|
220
|
+
fullname: "Andrii Atlas",
|
|
221
|
+
avatar_128: "https://gudhub.com/avatars/22_2289_128.jpg",
|
|
222
|
+
avatar_512: "https://gudhub.com/avatars/22_2289_512.jpg"
|
|
223
|
+
},
|
|
224
|
+
sharing_groups: [
|
|
225
|
+
{
|
|
226
|
+
group_name: "3D Rendering Team",
|
|
227
|
+
group_permission: 1
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
group_name: "Design Team",
|
|
231
|
+
group_permission: 2
|
|
232
|
+
}
|
|
233
|
+
]
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
app.post('/api/invitation/accept', (req, res) => {
|
|
238
|
+
const { invitation_id } = req.body;
|
|
239
|
+
|
|
240
|
+
if (!invitation_id) {
|
|
241
|
+
return res.status(400).json({ error: "Missing invitation_id" });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
res.status(200).json({
|
|
245
|
+
invitation_id,
|
|
246
|
+
invitation_status: 1
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
196
250
|
app.post('/api/sharing-group/create-group', (req, res) => {
|
|
197
251
|
res.status(200).send({ group_id: 1, group_name: req.body.group_name });
|
|
198
252
|
})
|