@elementor/editor-current-user 4.4.0-1092 → 4.4.0-1093
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/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +18 -11
- package/dist/index.mjs +17 -11
- package/package.json +4 -4
- package/src/__tests__/is-content-only-user.test.ts +45 -0
- package/src/index.ts +1 -0
- package/src/is-content-only-user.ts +6 -0
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,8 @@ type UserModel = {
|
|
|
23
23
|
|
|
24
24
|
declare const getCurrentUser: () => UserModel | undefined;
|
|
25
25
|
|
|
26
|
+
declare const isContentOnlyUser: () => boolean;
|
|
27
|
+
|
|
26
28
|
declare function ensureUser(): Promise<{
|
|
27
29
|
capabilities: string[];
|
|
28
30
|
suppressedMessages: string[];
|
|
@@ -47,4 +49,4 @@ declare const useUserRestrictions: () => {
|
|
|
47
49
|
|
|
48
50
|
declare const useHasContentOnlyAccess: () => boolean;
|
|
49
51
|
|
|
50
|
-
export { DESIGN_RESTRICTION, ensureUser, getCurrentUser, onSetUser, useCurrentUser, useCurrentUserCapabilities, useHasContentOnlyAccess, useSuppressedMessage, useUpdateCurrentUser, useUserRestrictions };
|
|
52
|
+
export { DESIGN_RESTRICTION, ensureUser, getCurrentUser, isContentOnlyUser, onSetUser, useCurrentUser, useCurrentUserCapabilities, useHasContentOnlyAccess, useSuppressedMessage, useUpdateCurrentUser, useUserRestrictions };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ type UserModel = {
|
|
|
23
23
|
|
|
24
24
|
declare const getCurrentUser: () => UserModel | undefined;
|
|
25
25
|
|
|
26
|
+
declare const isContentOnlyUser: () => boolean;
|
|
27
|
+
|
|
26
28
|
declare function ensureUser(): Promise<{
|
|
27
29
|
capabilities: string[];
|
|
28
30
|
suppressedMessages: string[];
|
|
@@ -47,4 +49,4 @@ declare const useUserRestrictions: () => {
|
|
|
47
49
|
|
|
48
50
|
declare const useHasContentOnlyAccess: () => boolean;
|
|
49
51
|
|
|
50
|
-
export { DESIGN_RESTRICTION, ensureUser, getCurrentUser, onSetUser, useCurrentUser, useCurrentUserCapabilities, useHasContentOnlyAccess, useSuppressedMessage, useUpdateCurrentUser, useUserRestrictions };
|
|
52
|
+
export { DESIGN_RESTRICTION, ensureUser, getCurrentUser, isContentOnlyUser, onSetUser, useCurrentUser, useCurrentUserCapabilities, useHasContentOnlyAccess, useSuppressedMessage, useUpdateCurrentUser, useUserRestrictions };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
DESIGN_RESTRICTION: () => DESIGN_RESTRICTION,
|
|
24
24
|
ensureUser: () => ensureUser,
|
|
25
25
|
getCurrentUser: () => getCurrentUser,
|
|
26
|
+
isContentOnlyUser: () => isContentOnlyUser,
|
|
26
27
|
onSetUser: () => onSetUser,
|
|
27
28
|
useCurrentUser: () => useCurrentUser,
|
|
28
29
|
useCurrentUserCapabilities: () => useCurrentUserCapabilities,
|
|
@@ -100,6 +101,22 @@ var getCurrentUser = () => {
|
|
|
100
101
|
return queryClient.getQueryData([EDITOR_CURRENT_USER_QUERY_KEY]);
|
|
101
102
|
};
|
|
102
103
|
|
|
104
|
+
// src/use-user-restrictions.ts
|
|
105
|
+
var DESIGN_RESTRICTION = "design";
|
|
106
|
+
var useUserRestrictions = () => {
|
|
107
|
+
const { data } = useCurrentUser();
|
|
108
|
+
const isRestricted = (restriction) => Boolean(data?.restrictions?.includes(restriction));
|
|
109
|
+
return {
|
|
110
|
+
isRestricted,
|
|
111
|
+
restrictions: data?.restrictions
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/is-content-only-user.ts
|
|
116
|
+
var isContentOnlyUser = () => {
|
|
117
|
+
return Boolean(getCurrentUser()?.restrictions?.includes(DESIGN_RESTRICTION));
|
|
118
|
+
};
|
|
119
|
+
|
|
103
120
|
// src/ensure-current-user.ts
|
|
104
121
|
var import_query4 = require("@elementor/query");
|
|
105
122
|
async function ensureUser() {
|
|
@@ -130,17 +147,6 @@ function onSetUser(callback) {
|
|
|
130
147
|
};
|
|
131
148
|
}
|
|
132
149
|
|
|
133
|
-
// src/use-user-restrictions.ts
|
|
134
|
-
var DESIGN_RESTRICTION = "design";
|
|
135
|
-
var useUserRestrictions = () => {
|
|
136
|
-
const { data } = useCurrentUser();
|
|
137
|
-
const isRestricted = (restriction) => Boolean(data?.restrictions?.includes(restriction));
|
|
138
|
-
return {
|
|
139
|
-
isRestricted,
|
|
140
|
-
restrictions: data?.restrictions
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
|
|
144
150
|
// src/use-has-content-only-access.ts
|
|
145
151
|
var useHasContentOnlyAccess = () => useUserRestrictions().isRestricted(DESIGN_RESTRICTION);
|
|
146
152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -148,6 +154,7 @@ var useHasContentOnlyAccess = () => useUserRestrictions().isRestricted(DESIGN_RE
|
|
|
148
154
|
DESIGN_RESTRICTION,
|
|
149
155
|
ensureUser,
|
|
150
156
|
getCurrentUser,
|
|
157
|
+
isContentOnlyUser,
|
|
151
158
|
onSetUser,
|
|
152
159
|
useCurrentUser,
|
|
153
160
|
useCurrentUserCapabilities,
|
package/dist/index.mjs
CHANGED
|
@@ -65,6 +65,22 @@ var getCurrentUser = () => {
|
|
|
65
65
|
return queryClient.getQueryData([EDITOR_CURRENT_USER_QUERY_KEY]);
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
// src/use-user-restrictions.ts
|
|
69
|
+
var DESIGN_RESTRICTION = "design";
|
|
70
|
+
var useUserRestrictions = () => {
|
|
71
|
+
const { data } = useCurrentUser();
|
|
72
|
+
const isRestricted = (restriction) => Boolean(data?.restrictions?.includes(restriction));
|
|
73
|
+
return {
|
|
74
|
+
isRestricted,
|
|
75
|
+
restrictions: data?.restrictions
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/is-content-only-user.ts
|
|
80
|
+
var isContentOnlyUser = () => {
|
|
81
|
+
return Boolean(getCurrentUser()?.restrictions?.includes(DESIGN_RESTRICTION));
|
|
82
|
+
};
|
|
83
|
+
|
|
68
84
|
// src/ensure-current-user.ts
|
|
69
85
|
import { getQueryClient as getQueryClient2 } from "@elementor/query";
|
|
70
86
|
async function ensureUser() {
|
|
@@ -95,23 +111,13 @@ function onSetUser(callback) {
|
|
|
95
111
|
};
|
|
96
112
|
}
|
|
97
113
|
|
|
98
|
-
// src/use-user-restrictions.ts
|
|
99
|
-
var DESIGN_RESTRICTION = "design";
|
|
100
|
-
var useUserRestrictions = () => {
|
|
101
|
-
const { data } = useCurrentUser();
|
|
102
|
-
const isRestricted = (restriction) => Boolean(data?.restrictions?.includes(restriction));
|
|
103
|
-
return {
|
|
104
|
-
isRestricted,
|
|
105
|
-
restrictions: data?.restrictions
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
114
|
// src/use-has-content-only-access.ts
|
|
110
115
|
var useHasContentOnlyAccess = () => useUserRestrictions().isRestricted(DESIGN_RESTRICTION);
|
|
111
116
|
export {
|
|
112
117
|
DESIGN_RESTRICTION,
|
|
113
118
|
ensureUser,
|
|
114
119
|
getCurrentUser,
|
|
120
|
+
isContentOnlyUser,
|
|
115
121
|
onSetUser,
|
|
116
122
|
useCurrentUser,
|
|
117
123
|
useCurrentUserCapabilities,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-current-user",
|
|
3
3
|
"description": "Elementor Editor Current User",
|
|
4
|
-
"version": "4.4.0-
|
|
4
|
+
"version": "4.4.0-1093",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"react": "^18.3.1"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@elementor/editor-v1-adapters": "4.4.0-
|
|
40
|
-
"@elementor/http-client": "4.4.0-
|
|
41
|
-
"@elementor/query": "4.4.0-
|
|
39
|
+
"@elementor/editor-v1-adapters": "4.4.0-1093",
|
|
40
|
+
"@elementor/http-client": "4.4.0-1093",
|
|
41
|
+
"@elementor/query": "4.4.0-1093"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tsup": "^8.3.5"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type UserModel } from '../api';
|
|
2
|
+
import { getCurrentUser } from '../get-current-user';
|
|
3
|
+
import { isContentOnlyUser } from '../is-content-only-user';
|
|
4
|
+
import { DESIGN_RESTRICTION } from '../use-user-restrictions';
|
|
5
|
+
|
|
6
|
+
jest.mock( '../get-current-user' );
|
|
7
|
+
|
|
8
|
+
describe( 'isContentOnlyUser', () => {
|
|
9
|
+
it( 'should return true when the design restriction is present', () => {
|
|
10
|
+
// Arrange
|
|
11
|
+
jest.mocked( getCurrentUser ).mockReturnValue( {
|
|
12
|
+
restrictions: [ DESIGN_RESTRICTION ],
|
|
13
|
+
} as UserModel );
|
|
14
|
+
|
|
15
|
+
// Act
|
|
16
|
+
const result = isContentOnlyUser();
|
|
17
|
+
|
|
18
|
+
// Assert
|
|
19
|
+
expect( result ).toBe( true );
|
|
20
|
+
} );
|
|
21
|
+
|
|
22
|
+
it( 'should return false when the design restriction is absent', () => {
|
|
23
|
+
// Arrange
|
|
24
|
+
jest.mocked( getCurrentUser ).mockReturnValue( {
|
|
25
|
+
restrictions: [ 'json-upload' ],
|
|
26
|
+
} as UserModel );
|
|
27
|
+
|
|
28
|
+
// Act
|
|
29
|
+
const result = isContentOnlyUser();
|
|
30
|
+
|
|
31
|
+
// Assert
|
|
32
|
+
expect( result ).toBe( false );
|
|
33
|
+
} );
|
|
34
|
+
|
|
35
|
+
it( 'should return false when there is no cached user', () => {
|
|
36
|
+
// Arrange
|
|
37
|
+
jest.mocked( getCurrentUser ).mockReturnValue( undefined );
|
|
38
|
+
|
|
39
|
+
// Act
|
|
40
|
+
const result = isContentOnlyUser();
|
|
41
|
+
|
|
42
|
+
// Assert
|
|
43
|
+
expect( result ).toBe( false );
|
|
44
|
+
} );
|
|
45
|
+
} );
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { useSuppressedMessage } from './use-suppressed-message';
|
|
2
2
|
export { useCurrentUserCapabilities } from './use-current-user-capabilities';
|
|
3
3
|
export { getCurrentUser } from './get-current-user';
|
|
4
|
+
export { isContentOnlyUser } from './is-content-only-user';
|
|
4
5
|
export { ensureUser } from './ensure-current-user';
|
|
5
6
|
export { onSetUser } from './on-set-user';
|
|
6
7
|
export { useCurrentUser } from './use-current-user';
|