@pristy/pristy-libvue 0.2.3

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.
@@ -0,0 +1,338 @@
1
+ /**
2
+ * Copyright (C) 2022 - Jeci SARL - https://jeci.fr
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as
6
+ * published by the Free Software Foundation, either version 3 of the
7
+ * License, or (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see https://www.gnu.org/licenses/agpl-3.0.html.
16
+ */
17
+
18
+ import {
19
+ sitesApi,
20
+ peopleApi,
21
+ searchApi,
22
+ nodesApi,
23
+ } from "./AlfrescoApi";
24
+
25
+ export default class WorkspaceService {
26
+
27
+ getWorkspaces() {
28
+ const opts = {
29
+ skipCount: 0,
30
+ maxItems: 100,
31
+ };
32
+
33
+ return sitesApi()
34
+ .listSites(opts)
35
+ .then((data) => {
36
+ return data.list.entries.map((data) => data.entry);
37
+ })
38
+ .catch((err) => {
39
+ throw new Error(err.message);
40
+ });
41
+ }
42
+
43
+ searchAllWorkspaces(extraQuery = "") {
44
+ const query = {
45
+ query: {
46
+ //language: "afts",
47
+ query: "TYPE: 'st:site' " + extraQuery,
48
+ },
49
+ include: ["properties"],
50
+ paging: {
51
+ maxItems: 100,
52
+ skipCount: 0,
53
+ },
54
+ localization: { locales: ["fr_FR"] },
55
+ };
56
+
57
+ return searchApi()
58
+ .search(query)
59
+ .then((data) => {
60
+ return data.list.entries.map((data) => {
61
+ let obj = data.entry;
62
+ // add some basic properties to match sitesApi.listSites output
63
+ obj.title = data.entry.properties["cm:title"];
64
+ obj.visibility = data.entry.properties["st:siteVisibility"];
65
+ obj.typeEspace = data.entry.properties["pm:typeEspace"];
66
+ return obj;
67
+ });
68
+ })
69
+ .catch((err) => {
70
+ throw new Error(err.message);
71
+ });
72
+ }
73
+
74
+ getWorkspace(id) {
75
+ const opts = {};
76
+
77
+ return sitesApi()
78
+ .getSite(id, opts)
79
+ .then((data) => {
80
+ return data.entry;
81
+ })
82
+ .catch((err) => {
83
+ throw new Error(err.message);
84
+ });
85
+ }
86
+
87
+ getWorkspaceMemberships(id) {
88
+ const opts = {};
89
+
90
+ return sitesApi()
91
+ .listSiteMemberships(id, opts)
92
+ .then((data) => {
93
+ return data.list.entries.map((data) => data.entry);
94
+ })
95
+ .catch((err) => {
96
+ throw new Error(err.message);
97
+ });
98
+ }
99
+
100
+ createWorkspace(id, title, descr, visibility) {
101
+ const opts = {
102
+ id: id,
103
+ title: title,
104
+ description: descr,
105
+ visibility: visibility,
106
+ };
107
+
108
+ return sitesApi()
109
+ .createSite(opts)
110
+ .then((siteMemberEntry) => {
111
+ return siteMemberEntry;
112
+ })
113
+ .catch((err) => {
114
+ let message;
115
+ switch (err.status) {
116
+ case 400:
117
+ message = "L'identifiant choisi ne respecte pas le format requis.";
118
+ break;
119
+ case 409:
120
+ message = "L'identifiant choisi est déjà existant.";
121
+ break;
122
+ default:
123
+ message = err.message;
124
+ }
125
+ throw new Error(message);
126
+ });
127
+ }
128
+
129
+ async getWorskpaceUuid(id) {
130
+ const opts = {
131
+ skipCount: 0,
132
+ maxItems: 100,
133
+ };
134
+ var uuid = null;
135
+ const list = (await sitesApi.listSiteContainers(id, opts)).list.entries;
136
+ for (let element in list) {
137
+ if (list[element].entry.folderId == "documentLibrary") {
138
+ uuid = list[element].entry.id;
139
+ }
140
+ }
141
+ return uuid;
142
+ }
143
+
144
+ updateWorkspaceMemberRole(siteId, memberId, newRole) {
145
+ const siteMembershipBody = {
146
+ role: newRole,
147
+ };
148
+ const opts = {};
149
+
150
+ return sitesApi()
151
+ .updateSiteMembership(siteId, memberId, siteMembershipBody, opts)
152
+ .then((siteMemberShip) => {
153
+ return siteMemberShip;
154
+ })
155
+ .catch((err) => {
156
+ let message;
157
+ switch (err.status) {
158
+ case 404:
159
+ message = "L'identifiant entré ne correspond à aucun utilisateur.";
160
+ break;
161
+ case 422:
162
+ message =
163
+ "Au moins un utilisateur doit être Gestionnaire. Si ce n'est pas le cas, vous n'avez pas la permission de modifier le rôle de cet utilisateur.";
164
+ break;
165
+ default:
166
+ message = err.message;
167
+ }
168
+ throw new Error(message);
169
+ });
170
+ }
171
+
172
+ deleteWorkspaceMember(siteId, memberId) {
173
+ const opts = {};
174
+
175
+ return sitesApi()
176
+ .deleteSiteMembership(siteId, memberId, opts)
177
+ .then(() => {
178
+ return memberId;
179
+ })
180
+ .catch((err) => {
181
+ let message;
182
+ switch (err.status) {
183
+ case 400:
184
+ message =
185
+ "Impossible de supprimer le seul Gestionnaire de l'espace.";
186
+ break;
187
+ case 404:
188
+ message = "Vous ne pouvez pas supprimer un utilisateur inexistant.";
189
+ break;
190
+ case 422:
191
+ message =
192
+ "Vous n'avez pas la permission de supprimer l'accès à cet utilisateur.";
193
+ break;
194
+ default:
195
+ message = err.message;
196
+ }
197
+ throw new Error(message);
198
+ });
199
+ }
200
+
201
+ addWorkspaceMember(siteId, memberId, role) {
202
+ const memberShipBody = {
203
+ role: role,
204
+ id: memberId,
205
+ };
206
+ const opts = {};
207
+
208
+ return sitesApi()
209
+ .createSiteMembership(siteId, memberShipBody, opts)
210
+ .then((siteMemberShip) => {
211
+ return siteMemberShip;
212
+ })
213
+ .catch((err) => {
214
+ let message;
215
+ switch (err.status) {
216
+ case 403:
217
+ message = "Vous ne pouvez pas inviter sur ce site.";
218
+ break;
219
+ case 404:
220
+ message = "Vous ne pouvez pas ajouter un utilisateur inexistant.";
221
+ break;
222
+ case 409:
223
+ message = "L'utilisateur a déjà accès à cet espace.";
224
+ break;
225
+ default:
226
+ message = err.message;
227
+ }
228
+ throw new Error(message);
229
+ });
230
+ }
231
+
232
+ updateWorkspaceType(id, typeEspace) {
233
+ const opts = {
234
+ properties: {
235
+ "pm:typeEspace": typeEspace,
236
+ },
237
+ };
238
+
239
+ return nodesApi()
240
+ .updateNode(id, opts)
241
+ .then((data) => {
242
+ return data;
243
+ })
244
+ .catch((err) => {
245
+ let message;
246
+ switch (err.status) {
247
+ case 404:
248
+ message = "Vous ne pouvez pas mettre à jour un espace inexistant.";
249
+ break;
250
+ default:
251
+ message = err.message;
252
+ }
253
+ throw new Error(message);
254
+ });
255
+ }
256
+
257
+ async getAllUsers() {
258
+ let userObj = "[";
259
+ let response = await peopleApi().listPeople();
260
+ let usersObject = response.list.entries;
261
+ usersObject.forEach((item) => {
262
+ let firstname = item.entry.firstName;
263
+ let lastname = item.entry.lastName;
264
+ let email = item.entry.email;
265
+ if (email == null) {
266
+ email = "";
267
+ }
268
+ if (firstname == null) {
269
+ if (email == null) {
270
+ firstname = "";
271
+ }
272
+ firstname = email;
273
+ }
274
+ if (lastname == null) {
275
+ if (email == null) {
276
+ lastname = "";
277
+ }
278
+ lastname = email;
279
+ }
280
+ let user =
281
+ '{ "firstname":' +
282
+ '"' +
283
+ firstname +
284
+ '"' +
285
+ ', "lastname":' +
286
+ '"' +
287
+ lastname +
288
+ '"' +
289
+ ', "email":' +
290
+ '"' +
291
+ email +
292
+ '"' +
293
+ ', "id":' +
294
+ '"' +
295
+ item.entry.id +
296
+ '"' +
297
+ ', "label":"' +
298
+ firstname +
299
+ " " +
300
+ lastname +
301
+ '"' +
302
+ ', "label2":"' +
303
+ lastname +
304
+ " " +
305
+ firstname +
306
+ '"},';
307
+ userObj += user;
308
+ });
309
+ userObj = userObj.slice(0, -1);
310
+ userObj += "]";
311
+ let users = JSON.parse(userObj);
312
+ return users;
313
+ }
314
+
315
+ deleteWorkspace(siteId) {
316
+ const opts = {};
317
+
318
+ return sitesApi()
319
+ .deleteSite(siteId, opts)
320
+ .then(() => {
321
+ console.log("Site deletion successful.");
322
+ })
323
+ .catch((err) => {
324
+ throw new Error(err.message);
325
+ });
326
+ }
327
+
328
+ updateWorkspace(id, opts) {
329
+ return sitesApi()
330
+ .updateSite(id, opts)
331
+ .then((data) => {
332
+ return data;
333
+ })
334
+ .catch((err) => {
335
+ throw new Error(err.message);
336
+ });
337
+ }
338
+ }
package/src/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import AlfrescoFileService from "./AlfrescoFileService";
2
+ import AlfrescoNodeService from "./AlfrescoNodeService";
3
+ import AlfrescoPermissionService from "./AlfrescoPermissionService";
4
+ import ErrorService from "./ErrorService";
5
+ import WorkspaceService from "./WorkspaceService"
6
+ import { alfrescoApi, uploadApi, renditionsApi, nodesApi, sitesApi, searchApi, peopleApi, favoritesApi, trashcanApi } from "./AlfrescoApi";
7
+ import { useUserStore } from "./stores/user";
8
+
9
+ export {
10
+ AlfrescoFileService,
11
+ AlfrescoNodeService,
12
+ AlfrescoPermissionService,
13
+ ErrorService,
14
+ uploadApi,
15
+ renditionsApi,
16
+ nodesApi,
17
+ sitesApi,
18
+ searchApi,
19
+ peopleApi,
20
+ alfrescoApi,
21
+ favoritesApi,
22
+ trashcanApi,
23
+ useUserStore,
24
+ WorkspaceService
25
+ }
26
+
27
+ export default class Index {
28
+ constructor() {
29
+ }
30
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Copyright (C) 2022 - Jeci SARL - https://jeci.fr
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as
6
+ * published by the Free Software Foundation, either version 3 of the
7
+ * License, or (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see https://www.gnu.org/licenses/agpl-3.0.html.
16
+ */
17
+
18
+ // @ts-check
19
+ import { defineStore, acceptHMRUpdate } from "pinia";
20
+ import { alfrescoApi, peopleApi } from "../AlfrescoApi";
21
+ import { loginError } from "../ErrorService";
22
+
23
+ export const useUserStore = defineStore({
24
+ id: "user",
25
+ state: () => ({
26
+ displayName: "",
27
+ token: "",
28
+ isAdmin: false,
29
+ person: null,
30
+ apiAlfresco: null,
31
+ }),
32
+ getters: {
33
+ displayName(state) {
34
+ return state.person == null ? "" : state.person.displayName;
35
+ },
36
+ },
37
+ actions: {
38
+ logout() {
39
+ console.log("logout with " + this.email);
40
+
41
+ if (this.apiAlfresco) {
42
+ this.apiAlfresco.logout();
43
+ }
44
+
45
+ this.$patch({
46
+ token: "",
47
+ isAdmin: false,
48
+ person: null,
49
+ apiAlfresco: null,
50
+ });
51
+ },
52
+
53
+ isLoggedIn() {
54
+
55
+ var alfresco;
56
+
57
+ if (!this.apiAlfresco) {
58
+ alfresco = alfrescoApi();
59
+ } else {
60
+ alfresco = this.apiAlfresco;
61
+ }
62
+
63
+ return peopleApi()
64
+ .getPerson("-me-")
65
+ .then((personEntry) => {
66
+ this.$patch({
67
+ person: personEntry.entry,
68
+ apiAlfresco: alfresco,
69
+ });
70
+ return true;
71
+ })
72
+ .catch((data) => {
73
+ return catchLogin(data);
74
+ });
75
+ },
76
+ /**
77
+ * Attempt to login a user
78
+ * @param {string} user
79
+ * @param {string} password
80
+ */
81
+ async login(user, password) {
82
+ if (!user || !password) {
83
+ return false;
84
+ }
85
+
86
+ await this.apiLogin(user, password)
87
+ .then((personEntry) => {
88
+ this.$patch({
89
+ person: personEntry.entry,
90
+ });
91
+ })
92
+ .catch((error) => {
93
+ loginError(error);
94
+ });
95
+ },
96
+ /**
97
+ * Simulate a login
98
+ * @param {string} a
99
+ * @param {string} p
100
+ */
101
+ apiLogin(a, p) {
102
+
103
+ return alfrescoApi()
104
+ .login(a, p)
105
+ .then(() => {
106
+ this.$patch({
107
+ apiAlfresco: alfrescoApi(),
108
+ });
109
+ return peopleApi().getPerson("-me-");
110
+ })
111
+ .catch((err) => {
112
+ return Promise.reject(err);
113
+ });
114
+ },
115
+ async publiclogoff() {
116
+ var userProfile = localStorage.getItem("ACS_USERNAME");
117
+ if (userProfile && userProfile.startsWith("user_publication_")) {
118
+ localStorage.removeItem("ticket-ECM");
119
+ localStorage.removeItem("ACS_USERNAME");
120
+ }
121
+ },
122
+ async publiclogin(espace_id) {
123
+ let ticketECM = window.localStorage.getItem("ticket-ECM");
124
+
125
+ if (typeof ticketECM !== "undefined" && ticketECM != null) {
126
+ // TODO check ticket validity
127
+ } else {
128
+ await fetch(
129
+ window.config["ALFRESCO_HOST"] +
130
+ "/alfresco/s/fr/jeci/pristy/authentication/ticket/publication/site/" +
131
+ espace_id,
132
+ {
133
+ method: "GET",
134
+ headers: {
135
+ "Content-Type": "application/json",
136
+ Accept: "application/json",
137
+ },
138
+ }
139
+ )
140
+ .then((response) => response.json())
141
+ .then((specs) => {
142
+ window.localStorage.setItem("ticket-ECM", specs.ticket);
143
+ window.localStorage.setItem("ACS_USERNAME", specs.login);
144
+ });
145
+ }
146
+ },
147
+ alfrescoApi() {
148
+ return this.apiAlfresco;
149
+ },
150
+ },
151
+ });
152
+
153
+ if (import.meta.hot) {
154
+ import.meta.hot.accept(acceptHMRUpdate(useUserStore, import.meta.hot));
155
+ }
156
+
157
+ /**
158
+ * Traitement de l'erreur de connexion
159
+ */
160
+ function catchLogin(data) {
161
+ let error = JSON.parse(data.message).error;
162
+ if (error.statusCode == 401) {
163
+ return false;
164
+ }
165
+ if (error.statusCode == 403) {
166
+ return false;
167
+ }
168
+ throw new Error(data);
169
+ }