@mapomodule/core 1.0.0-alpha.8 → 1.0.0
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/CHANGELOG.md +224 -0
- package/api/crud.js +43 -9
- package/api/multipart.js +19 -23
- package/index.js +18 -8
- package/interceptor/auth.js +13 -13
- package/middleware/auth.js +5 -4
- package/middleware/permissions.js +35 -18
- package/module.js +5 -1
- package/package.json +3 -3
- package/templates/options.js +1 -0
- package/LICENSE.md +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,230 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.60...v1.0.0) (2026-07-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [1.0.0-alpha.49](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.48...v1.0.0-alpha.49) (2023-07-27)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [1.0.0-alpha.45](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.44...v1.0.0-alpha.45) (2023-06-10)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [1.0.0-alpha.44](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.43...v1.0.0-alpha.44) (2023-06-10)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# [1.0.0-alpha.43](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.42...v1.0.0-alpha.43) (2023-02-02)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# [1.0.0-alpha.41](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.40...v1.0.0-alpha.41) (2022-12-20)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Features
|
|
50
|
+
|
|
51
|
+
* handle all_permissions prop in user ([14d4252](https://github.com/lotrekagency/mapo/commit/14d425215434e29f82093fc96e53b172bf247b8f))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# [1.0.0-alpha.40](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.39...v1.0.0-alpha.40) (2022-12-20)
|
|
58
|
+
|
|
59
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# [1.0.0-alpha.39](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.38...v1.0.0-alpha.39) (2022-12-03)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
### Features
|
|
69
|
+
|
|
70
|
+
* give the option to rewrite form fields components defaults in nuxt.config.js ([c4e76b1](https://github.com/lotrekagency/mapo/commit/c4e76b153b145cc670ef988e9501e1a8fbc0005e))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# [1.0.0-alpha.34](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.33...v1.0.0-alpha.34) (2022-11-11)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
### Features
|
|
80
|
+
|
|
81
|
+
* default upload in multipart autodiscover ([b153307](https://github.com/lotrekagency/mapo/commit/b15330725a64a0931d2de49929a01e3a7319b382))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# [1.0.0-alpha.31](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.30...v1.0.0-alpha.31) (2022-09-14)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
### Bug Fixes
|
|
91
|
+
|
|
92
|
+
* **interceptor:** remove token injection for axios requests ([59b2f5c](https://github.com/lotrekagency/mapo/commit/59b2f5cb3dfd0becd78df02f30bc32967643e276))
|
|
93
|
+
* **middleware:** fix auth middleware to correclty redirect based on router base ([1d49cd7](https://github.com/lotrekagency/mapo/commit/1d49cd72e141888ef7aae91ac0ddb13f8d0fce7a))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# [1.0.0-alpha.30](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.29...v1.0.0-alpha.30) (2022-09-13)
|
|
100
|
+
|
|
101
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# [1.0.0-alpha.27](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.26...v1.0.0-alpha.27) (2022-08-25)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### Bug Fixes
|
|
111
|
+
|
|
112
|
+
* remove unused options plugin ([45004bb](https://github.com/lotrekagency/mapo/commit/45004bb158267c7e2f7795c1d12cf568f9d7ded2))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# [1.0.0-alpha.23](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.22...v1.0.0-alpha.23) (2022-05-04)
|
|
119
|
+
|
|
120
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# [1.0.0-alpha.22](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.21...v1.0.0-alpha.22) (2022-05-01)
|
|
127
|
+
|
|
128
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
# [1.0.0-alpha.19](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.18...v1.0.0-alpha.19) (2022-04-06)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### Bug Fixes
|
|
138
|
+
|
|
139
|
+
* fix logout loop ([3177cca](https://github.com/lotrekagency/mapo/commit/3177ccaf4be6151feec379c4241f8784b79d4361))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# [1.0.0-alpha.18](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.17...v1.0.0-alpha.18) (2022-04-04)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### Bug Fixes
|
|
149
|
+
|
|
150
|
+
* fix core interceptor syntax ([c546a48](https://github.com/lotrekagency/mapo/commit/c546a48f22bf689d4b679aaab82b2b9ed62f26cc))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
# [1.0.0-alpha.17](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.16...v1.0.0-alpha.17) (2022-04-03)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
### Bug Fixes
|
|
160
|
+
|
|
161
|
+
* various fixes to auth loops ([58cdb58](https://github.com/lotrekagency/mapo/commit/58cdb586e88df8e595876ba4dd4d4cc11865f7e3))
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
# [1.0.0-alpha.16](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.15...v1.0.0-alpha.16) (2022-04-03)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
### Features
|
|
171
|
+
|
|
172
|
+
* Added mapo integrations module! 🎉 ([76d2c80](https://github.com/lotrekagency/mapo/commit/76d2c805245b4cf49a33696339da52e4c17f4053))
|
|
173
|
+
* added mapo options to mapo helper ([38dcbf2](https://github.com/lotrekagency/mapo/commit/38dcbf28d286eb02c2a6785a883a14edaa0837b1))
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
### BREAKING CHANGES
|
|
177
|
+
|
|
178
|
+
* This change removes all the camomilla cms references moving the compatibility layer in a detached package [mapo-integrations-camomilla](https://github.com/lotrekagency/mapo-integrations-camomilla). The guidelines to make mapo work with camomilla will be provided in the package readme.
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# [1.0.0-alpha.15](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.14...v1.0.0-alpha.15) (2022-03-11)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
### Features
|
|
188
|
+
|
|
189
|
+
* **ordering:** added sortablejs to drag and reorder list ([eb8bf21](https://github.com/lotrekagency/mapo/commit/eb8bf21c3178c3ad62db5aa7c06c0562e944dea6))
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# [1.0.0-alpha.13](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.12...v1.0.0-alpha.13) (2022-03-01)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
### Features
|
|
199
|
+
|
|
200
|
+
* added snack message in the requst interceptor ([acf9cd1](https://github.com/lotrekagency/mapo/commit/acf9cd1efbabc13eb99af7f4bfe0dcf096112ec0))
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
# [1.0.0-alpha.10](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2022-02-11)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
### Bug Fixes
|
|
210
|
+
|
|
211
|
+
* fix crud requests without multipart policy ([5875833](https://github.com/lotrekagency/mapo/commit/5875833209872a2609b653a089fff80c447b14e9))
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
### Features
|
|
215
|
+
|
|
216
|
+
* **core:** Completely rewritten multipart capabilities, now the crud helper autodiscovers whet to use a multipart request. ([0a6546c](https://github.com/lotrekagency/mapo/commit/0a6546c9adeaf1fcf57a88105101e476b8b786dc))
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# [1.0.0-alpha.9](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2022-02-08)
|
|
223
|
+
|
|
224
|
+
**Note:** Version bump only for package @mapomodule/core
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
6
230
|
# [1.0.0-alpha.8](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2022-01-23)
|
|
7
231
|
|
|
8
232
|
|
package/api/crud.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
const transformRequestInMultipart = require('@mapomodule/core/api/multipart')
|
|
1
2
|
const trimslashes = (str) => (str || "").replace(/^\/|\/$/g, '')
|
|
3
|
+
const preparePayload = (payload, options) => {
|
|
4
|
+
const { multipart } = (options || {})
|
|
5
|
+
if (!(payload instanceof FormData) && multipart !== 'disable') {
|
|
6
|
+
payload = transformRequestInMultipart(payload, multipart || 'auto');
|
|
7
|
+
}
|
|
8
|
+
return payload
|
|
9
|
+
}
|
|
2
10
|
const endpointError = "This crud is badly configured. No endpoint was passed"
|
|
3
11
|
|
|
4
12
|
/**
|
|
@@ -26,10 +34,12 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
|
|
|
26
34
|
* @alias $api.crud.create
|
|
27
35
|
* @param {Object} payload The payload containing the data that we want to send.
|
|
28
36
|
* @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
|
|
37
|
+
* @param {MapoRequestConfig} options Additional option configuration. Here you can configure some mapo reserved options. Like the multipart autodiscover politic.
|
|
29
38
|
* @returns {Promise<external:AxiosResponse>}
|
|
30
39
|
*/
|
|
31
|
-
create(payload, config) {
|
|
32
|
-
|
|
40
|
+
create(payload, config, options) {
|
|
41
|
+
|
|
42
|
+
const func = $axios.$post(`/${trimslashes(endpoint)}/`, preparePayload(payload, options), { ...higherConf, ...config })
|
|
33
43
|
return endpoint !== null ? func : Promise.reject(endpointError)
|
|
34
44
|
},
|
|
35
45
|
|
|
@@ -50,10 +60,11 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
|
|
|
50
60
|
* @alias $api.crud.updateOrCreate
|
|
51
61
|
* @param {Object} payload The payload containing the data that we want to send.
|
|
52
62
|
* @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
|
|
63
|
+
* @param {MapoRequestConfig} options Additional option configuration. Here you can configure some mapo reserved options. Like the multipart autodiscover politic.
|
|
53
64
|
* @returns {Promise<external:AxiosResponse>}
|
|
54
65
|
*/
|
|
55
|
-
updateOrCreate(payload, config) {
|
|
56
|
-
const func = payload.id ? this.update(payload.id, payload, { ...higherConf, ...config }) : this.create(payload, { ...higherConf, ...config })
|
|
66
|
+
updateOrCreate(payload, config, options) {
|
|
67
|
+
const func = payload.id ? this.update(payload.id, payload, { ...higherConf, ...config }, options) : this.create(payload, { ...higherConf, ...config }, options)
|
|
57
68
|
return endpoint !== null ? func : Promise.reject(endpointError)
|
|
58
69
|
},
|
|
59
70
|
|
|
@@ -63,10 +74,11 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
|
|
|
63
74
|
* @param {String} id The id of the data we want to update.
|
|
64
75
|
* @param {Object} payload The payload containing the data that we want to send.
|
|
65
76
|
* @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
|
|
77
|
+
* @param {MapoRequestConfig} options Additional option configuration. Here you can configure some mapo reserved options. Like the multipart autodiscover politic.
|
|
66
78
|
* @returns {Promise<external:AxiosResponse>}
|
|
67
79
|
*/
|
|
68
|
-
update(id, payload, config) {
|
|
69
|
-
const func = $axios.$put(`/${trimslashes(endpoint)}/${id}/`, payload, { ...higherConf, ...config })
|
|
80
|
+
update(id, payload, config, options) {
|
|
81
|
+
const func = $axios.$put(`/${trimslashes(endpoint)}/${id}/`, preparePayload(payload, options), { ...higherConf, ...config })
|
|
70
82
|
return endpoint !== null ? func : Promise.reject(endpointError)
|
|
71
83
|
},
|
|
72
84
|
|
|
@@ -76,10 +88,11 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
|
|
|
76
88
|
* @param {String} id The id of the data we want to partially update.
|
|
77
89
|
* @param {Object} payload The payload containing the data that we want to send.
|
|
78
90
|
* @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
|
|
91
|
+
* @param {MapoRequestConfig} options Additional option configuration. Here you can configure some mapo reserved options. Like the multipart autodiscover politic.
|
|
79
92
|
* @returns {Promise<external:AxiosResponse>}
|
|
80
93
|
*/
|
|
81
|
-
partialUpdate(id, payload, config) {
|
|
82
|
-
const func = $axios.$patch(`/${trimslashes(endpoint)}/${id}/`, payload, { ...higherConf, ...config })
|
|
94
|
+
partialUpdate(id, payload, config, options) {
|
|
95
|
+
const func = $axios.$patch(`/${trimslashes(endpoint)}/${id}/`, preparePayload(payload, options), { ...higherConf, ...config })
|
|
83
96
|
return endpoint !== null ? func : Promise.reject(endpointError)
|
|
84
97
|
},
|
|
85
98
|
/**
|
|
@@ -92,7 +105,22 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
|
|
|
92
105
|
delete(id, config) {
|
|
93
106
|
const func = $axios.$delete(`/${trimslashes(endpoint)}/${id}/`, { ...higherConf, ...config })
|
|
94
107
|
return endpoint !== null ? func : Promise.reject(endpointError)
|
|
95
|
-
}
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* This makes a POST http call to the crud endpoint slash update_order. Returns as a promise the server response.
|
|
111
|
+
* Use this endpoint to change the order of the items in the list.
|
|
112
|
+
* @alias $api.crud.update_order
|
|
113
|
+
* @param {String} startId The id of the item we want to move in the list.
|
|
114
|
+
* @param {String} endId The id of the item in the position where we want to move.
|
|
115
|
+
* @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
|
|
116
|
+
* @returns {Promise<external:AxiosResponse>}
|
|
117
|
+
*/
|
|
118
|
+
update_order(startId, endId, config) {
|
|
119
|
+
const func = $axios.$post(`/${trimslashes(endpoint)}/update_order/`, { startId, endId }, { ...higherConf, ...config })
|
|
120
|
+
return endpoint !== null ? func : Promise.reject(endpointError)
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
|
|
96
124
|
})
|
|
97
125
|
/**
|
|
98
126
|
* @external AxiosResponse
|
|
@@ -104,4 +132,10 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
|
|
|
104
132
|
* @see https://axios-http.com/docs/req_config
|
|
105
133
|
*/
|
|
106
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Additional option configuration. Here you can configure some mapo reserved options.
|
|
137
|
+
* @typedef {MapoRequestConfig} MapoRequestConfig
|
|
138
|
+
* @property {string} multipart - Set the multipart politic. Accepts `'auto'|'force|'disable'`. If auto is set the request is transformed in multipart if any file is in the payload. If set to force the request is transformed in multipart no matter if files are found. If set to `'disable'` the request is never transformed in multipart.
|
|
139
|
+
*/
|
|
140
|
+
|
|
107
141
|
module.exports = createRepository
|
package/api/multipart.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const deepClone = require('@mapomodule/utils/helpers/objHelpers')
|
|
1
|
+
const { deepClone, getPointed, setPointed, filesInObject } = require('@mapomodule/utils/helpers/objHelpers')
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This lets you transform a js object containing files in a multipart request with all the classic data in a single attribute (data)
|
|
@@ -6,33 +6,29 @@ const deepClone = require('@mapomodule/utils/helpers/objHelpers').deepClone
|
|
|
6
6
|
*
|
|
7
7
|
* @alias $api.multipart
|
|
8
8
|
* @param {Object} payload The payload of the request that needs to be trasformed.
|
|
9
|
-
* @param {String[]} file_attributes The list of dotted path of all the file attributes that need to be attached to the request.
|
|
9
|
+
* @param {String | String[]} file_attributes The list of dotted path of all the file attributes that need to be attached to the request. If unset autodiscovery is applyed. If set to 'fallback' if no files are found it returns the payload as it is.
|
|
10
10
|
* @returns {external:FormData}
|
|
11
11
|
*/
|
|
12
|
-
function transformRequestInMultipart(payload, file_attributes =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
delete object[key];
|
|
19
|
-
}
|
|
20
|
-
if (typeof object[key] == 'object') {
|
|
21
|
-
cleanObject(object[key], file_attributes, base + key + '.', files);
|
|
22
|
-
}
|
|
23
|
-
if (file_attributes.includes(key) && object[key] && typeof object[key] == 'string') {
|
|
24
|
-
delete object[key];
|
|
25
|
-
}
|
|
12
|
+
function transformRequestInMultipart(payload, file_attributes = "auto") {
|
|
13
|
+
var file_paths = []
|
|
14
|
+
if (["auto", "force"].includes(file_attributes)) {
|
|
15
|
+
file_paths = filesInObject(payload)
|
|
16
|
+
if (file_attributes == "auto" && !file_paths.length){
|
|
17
|
+
return payload
|
|
26
18
|
}
|
|
27
|
-
|
|
19
|
+
} else if (Array.isArray(file_attributes)) {
|
|
20
|
+
file_paths = file_attributes
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
22
|
+
const data = deepClone(payload);
|
|
23
|
+
const files = file_paths.reduce((acc, path) => {
|
|
24
|
+
const file = getPointed(data, path, undefined)
|
|
25
|
+
setPointed(data, path, undefined);
|
|
26
|
+
return { [path]: file, ...acc }
|
|
27
|
+
}, {})
|
|
32
28
|
const formData = new FormData();
|
|
33
|
-
formData.append('data', JSON.stringify(
|
|
34
|
-
for (const key in
|
|
35
|
-
formData.append(key,
|
|
29
|
+
formData.append('data', JSON.stringify(data));
|
|
30
|
+
for (const key in files) {
|
|
31
|
+
formData.append(key, files[key]);
|
|
36
32
|
}
|
|
37
33
|
return formData;
|
|
38
34
|
}
|
package/index.js
CHANGED
|
@@ -2,9 +2,15 @@ import createRepository from '@mapomodule/core/api/crud'
|
|
|
2
2
|
import transformRequestInMultipart from '@mapomodule/core/api/multipart'
|
|
3
3
|
import initInterceptors from '@mapomodule/core/interceptor'
|
|
4
4
|
|
|
5
|
+
try {
|
|
6
|
+
var options = require('./options').default;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
var options = {};
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
function getRouteMiddlewares(route) {
|
|
6
12
|
const meta = Array.isArray(route?.meta) ? route.meta[0] : route.meta
|
|
7
|
-
const { middleware } = meta
|
|
13
|
+
const { middleware } = meta || {}
|
|
8
14
|
return (typeof middleware === "string" ? [middleware] : middleware) || []
|
|
9
15
|
}
|
|
10
16
|
|
|
@@ -13,13 +19,13 @@ export default (ctx, inject) => {
|
|
|
13
19
|
|
|
14
20
|
initInterceptors(ctx)
|
|
15
21
|
|
|
16
|
-
|
|
22
|
+
const mapo = {
|
|
17
23
|
/**
|
|
18
24
|
* From here you can reach some utilities that simplify the interaction with the backend api.
|
|
19
25
|
*/
|
|
20
26
|
$api: {
|
|
21
27
|
crud: createRepository(ctx.$axios),
|
|
22
|
-
multipart: transformRequestInMultipart
|
|
28
|
+
multipart: transformRequestInMultipart,
|
|
23
29
|
},
|
|
24
30
|
/**
|
|
25
31
|
* From here you can reach some utilities that simplify the interaction with the user authentication flow.
|
|
@@ -35,7 +41,7 @@ export default (ctx, inject) => {
|
|
|
35
41
|
*
|
|
36
42
|
* This simply commits a logout to the vuex store.
|
|
37
43
|
*/
|
|
38
|
-
logout: () => ctx.store.dispatch("mapo/user/
|
|
44
|
+
logout: () => ctx.store.dispatch("mapo/user/logout"),
|
|
39
45
|
/**
|
|
40
46
|
* This refresh user informations present in vuex store and returns them.
|
|
41
47
|
* @returns {UserData}
|
|
@@ -46,7 +52,7 @@ export default (ctx, inject) => {
|
|
|
46
52
|
get token() { return ctx.store.getters['mapo/user/token'] },
|
|
47
53
|
get info() { return ctx.store.getters['mapo/user/info'] },
|
|
48
54
|
get username() { return ctx.store.getters['mapo/user/username'] },
|
|
49
|
-
get permissions() { return ctx.store.getters['mapo/user/pagePermission'](ctx.app
|
|
55
|
+
get permissions() { return ctx.store.getters['mapo/user/pagePermission'](ctx.app?.context?.route?.name || "") },
|
|
50
56
|
get role() { return ctx.store.getters['mapo/user/role'] }
|
|
51
57
|
},
|
|
52
58
|
/**
|
|
@@ -54,7 +60,7 @@ export default (ctx, inject) => {
|
|
|
54
60
|
* This returns the current route middlewares if routemeta is enabled.
|
|
55
61
|
*/
|
|
56
62
|
get routeMiddlewares() {
|
|
57
|
-
return getRouteMiddlewares(ctx.app
|
|
63
|
+
return getRouteMiddlewares(ctx.app?.context?.route || {})
|
|
58
64
|
},
|
|
59
65
|
/**
|
|
60
66
|
*
|
|
@@ -102,8 +108,12 @@ export default (ctx, inject) => {
|
|
|
102
108
|
* @function
|
|
103
109
|
*/
|
|
104
110
|
close: null
|
|
105
|
-
}
|
|
106
|
-
|
|
111
|
+
},
|
|
112
|
+
$options: options
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
inject('mapo', mapo);
|
|
116
|
+
ctx.$mapo = mapo;
|
|
107
117
|
}
|
|
108
118
|
|
|
109
119
|
/**
|
package/interceptor/auth.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
module.exports = ({ $axios, store }) => {
|
|
2
|
-
if ($axios && store){
|
|
3
|
-
$axios.onRequest((config) => {
|
|
4
|
-
const token = store.getters['mapo/user/token']
|
|
5
|
-
if (token && token !== 'undefined') {
|
|
6
|
-
config.headers['Authorization'] = `Token ${token}`
|
|
7
|
-
}
|
|
8
|
-
return config
|
|
9
|
-
})
|
|
10
|
-
|
|
2
|
+
if ($axios && store) {
|
|
11
3
|
$axios.onResponse((response) => {
|
|
12
4
|
if (response.status === 401) {
|
|
13
5
|
store.dispatch('mapo/user/logout');
|
|
14
6
|
}
|
|
7
|
+
if (response.status == 403) {
|
|
8
|
+
store.dispatch("mapo/app/showSnackMessage", { message: "Permission denied..", color: "error" })
|
|
9
|
+
}
|
|
15
10
|
return response
|
|
16
11
|
})
|
|
17
|
-
|
|
12
|
+
|
|
18
13
|
$axios.onError((error) => {
|
|
19
|
-
const { status } = error.response || {}
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const { status, request } = error.response || {}
|
|
15
|
+
const baseURL = ($axios.defaults.baseURL || "").replace(/https?:\/\/[^\/]+/i, "")
|
|
16
|
+
const logoutPath = `${baseURL.endsWith("/") ? baseURL : baseURL + "/"}${process.env.AUTH_LOGIN_URL || "api/auth/logout"}`
|
|
17
|
+
if (status === 401 && (request || {}).path !== logoutPath) {
|
|
18
|
+
store.dispatch('mapo/user/logout')
|
|
19
|
+
}
|
|
20
|
+
if (status == 403) {
|
|
21
|
+
store.dispatch("mapo/app/showSnackMessage", { message: "Permission denied..", color: "error" })
|
|
22
22
|
}
|
|
23
23
|
return Promise.reject(error)
|
|
24
24
|
})
|
package/middleware/auth.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import Middleware from '../../middleware' // little hack to inject middleware in root project :P
|
|
2
2
|
|
|
3
|
-
Middleware.auth = Middleware.auth || function ({ route, redirect, query, store }) {
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
Middleware.auth = Middleware.auth || function ({ route, redirect, query, store, app }) {
|
|
4
|
+
const { router: { options } } = app;
|
|
5
|
+
const isLoggedIn = store.getters['mapo/user/isLoggedIn']
|
|
6
|
+
if (!isLoggedIn) {
|
|
6
7
|
query['redirect'] = route.path
|
|
7
|
-
return redirect('/login
|
|
8
|
+
return redirect(`${options.base || '/'}login`, query)
|
|
8
9
|
}
|
|
9
10
|
}
|
|
@@ -1,19 +1,36 @@
|
|
|
1
|
-
import Middleware from
|
|
1
|
+
import Middleware from "../../middleware"; // little hack to inject middleware in root project :P
|
|
2
2
|
|
|
3
|
-
Middleware.permissions =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
Middleware.permissions =
|
|
4
|
+
Middleware.permissions ||
|
|
5
|
+
async function ({ route, error, store }) {
|
|
6
|
+
route.meta = Array.isArray(route.meta) ? route.meta[0] : route.meta;
|
|
7
|
+
if (!route.meta.permissions) return;
|
|
8
|
+
const userInfo = store.getters["mapo/user/info"];
|
|
9
|
+
if (userInfo.is_superuser) {
|
|
10
|
+
await store.dispatch("mapo/user/addPagePermission", {
|
|
11
|
+
key: route.name,
|
|
12
|
+
value: ["add", "change", "delete", "view"],
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const { model } = route.meta.permissions;
|
|
17
|
+
const userPermission = (
|
|
18
|
+
userInfo.all_permissions ||
|
|
19
|
+
userInfo.user_permissions ||
|
|
20
|
+
[]
|
|
21
|
+
)
|
|
22
|
+
.filter((perm) => perm.codename.endsWith(model))
|
|
23
|
+
.map(({ codename }) => codename.replace(`_${model}`, ""));
|
|
24
|
+
if (!userPermission.includes("view")) {
|
|
25
|
+
return error({
|
|
26
|
+
statusCode: 404,
|
|
27
|
+
message: "This page could not be found",
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
await store.dispatch("mapo/user/addPagePermission", {
|
|
31
|
+
key: route.name,
|
|
32
|
+
value: userPermission,
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
};
|
package/module.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/core",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "This is part of Mapo nuxt module. Injects the core mapo plugin helpers.",
|
|
5
5
|
"author": "bnznamco <gabriele.baldi.01@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"repository": "https://github.com/lotrekagency/mapo",
|
|
14
14
|
"main": "./module.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@mapomodule/utils": "^1.0.0
|
|
16
|
+
"@mapomodule/utils": "^1.0.0"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "1e825711fb068d6195fe6dda607d1fb0e05109ec"
|
|
22
22
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default <%= serializeFunction(options) %>;
|
package/LICENSE.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) Lotrek 2021
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|