@elementor/editor-current-user 3.35.0-447 → 3.35.0-449
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
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -80,12 +80,14 @@ var useSuppressedMessage = (messageKey) => {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
// src/use-current-user-capabilities.ts
|
|
83
|
+
var ADMIN_CAPABILITY = "manage_options";
|
|
83
84
|
var useCurrentUserCapabilities = () => {
|
|
84
85
|
const { data } = useCurrentUser();
|
|
85
86
|
const canUser = (capability) => {
|
|
86
87
|
return Boolean(data?.capabilities.includes(capability));
|
|
87
88
|
};
|
|
88
|
-
|
|
89
|
+
const isAdmin = Boolean(data?.capabilities.includes(ADMIN_CAPABILITY));
|
|
90
|
+
return { canUser, isAdmin, capabilities: data?.capabilities };
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
// src/get-current-user.ts
|
package/dist/index.mjs
CHANGED
|
@@ -48,12 +48,14 @@ var useSuppressedMessage = (messageKey) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
// src/use-current-user-capabilities.ts
|
|
51
|
+
var ADMIN_CAPABILITY = "manage_options";
|
|
51
52
|
var useCurrentUserCapabilities = () => {
|
|
52
53
|
const { data } = useCurrentUser();
|
|
53
54
|
const canUser = (capability) => {
|
|
54
55
|
return Boolean(data?.capabilities.includes(capability));
|
|
55
56
|
};
|
|
56
|
-
|
|
57
|
+
const isAdmin = Boolean(data?.capabilities.includes(ADMIN_CAPABILITY));
|
|
58
|
+
return { canUser, isAdmin, capabilities: data?.capabilities };
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
// src/get-current-user.ts
|
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": "3.35.0-
|
|
4
|
+
"version": "3.35.0-449",
|
|
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": "3.35.0-
|
|
40
|
-
"@elementor/http-client": "3.35.0-
|
|
41
|
-
"@elementor/query": "3.35.0-
|
|
39
|
+
"@elementor/editor-v1-adapters": "3.35.0-449",
|
|
40
|
+
"@elementor/http-client": "3.35.0-449",
|
|
41
|
+
"@elementor/query": "3.35.0-449"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tsup": "^8.3.5"
|
|
@@ -3,19 +3,19 @@ import { renderHook } from '@testing-library/react';
|
|
|
3
3
|
|
|
4
4
|
import { type User } from '../types';
|
|
5
5
|
import { useCurrentUser } from '../use-current-user';
|
|
6
|
-
import { useCurrentUserCapabilities } from '../use-current-user-capabilities';
|
|
6
|
+
import { ADMIN_CAPABILITY, useCurrentUserCapabilities } from '../use-current-user-capabilities';
|
|
7
7
|
|
|
8
8
|
jest.mock( '../use-current-user' );
|
|
9
9
|
|
|
10
10
|
describe( 'useCurrentUserCapabilities', () => {
|
|
11
11
|
it( 'should return true if user has the capability', async () => {
|
|
12
12
|
jest.mocked( useCurrentUser ).mockReturnValue( {
|
|
13
|
-
data: { capabilities: [ '
|
|
13
|
+
data: { capabilities: [ 'some_capability' ] },
|
|
14
14
|
} as UseQueryResult< User, Error > );
|
|
15
15
|
|
|
16
16
|
const { result } = renderHook( () => useCurrentUserCapabilities() );
|
|
17
17
|
|
|
18
|
-
expect( result.current.canUser( '
|
|
18
|
+
expect( result.current.canUser( 'some_capability' ) ).toBe( true );
|
|
19
19
|
} );
|
|
20
20
|
|
|
21
21
|
it( "should return false if user doesn't have the capability", async () => {
|
|
@@ -25,7 +25,8 @@ describe( 'useCurrentUserCapabilities', () => {
|
|
|
25
25
|
|
|
26
26
|
const { result } = renderHook( () => useCurrentUserCapabilities() );
|
|
27
27
|
|
|
28
|
-
expect( result.current.canUser( '
|
|
28
|
+
expect( result.current.canUser( 'some_capability' ) ).toBe( false );
|
|
29
|
+
expect( result.current.isAdmin ).toBe( false );
|
|
29
30
|
} );
|
|
30
31
|
|
|
31
32
|
it( 'should return false if data is undefined', async () => {
|
|
@@ -33,6 +34,16 @@ describe( 'useCurrentUserCapabilities', () => {
|
|
|
33
34
|
|
|
34
35
|
const { result } = renderHook( () => useCurrentUserCapabilities() );
|
|
35
36
|
|
|
36
|
-
expect( result.current.canUser( '
|
|
37
|
+
expect( result.current.canUser( 'some_capability' ) ).toBe( false );
|
|
38
|
+
} );
|
|
39
|
+
|
|
40
|
+
it( 'should return true if user has the admin capability', async () => {
|
|
41
|
+
jest.mocked( useCurrentUser ).mockReturnValue( {
|
|
42
|
+
data: { capabilities: [ ADMIN_CAPABILITY ] },
|
|
43
|
+
} as UseQueryResult< User, Error > );
|
|
44
|
+
|
|
45
|
+
const { result } = renderHook( () => useCurrentUserCapabilities() );
|
|
46
|
+
|
|
47
|
+
expect( result.current.isAdmin ).toBe( true );
|
|
37
48
|
} );
|
|
38
49
|
} );
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useCurrentUser } from './use-current-user';
|
|
2
2
|
|
|
3
|
+
export const ADMIN_CAPABILITY = 'manage_options';
|
|
4
|
+
|
|
3
5
|
export const useCurrentUserCapabilities = () => {
|
|
4
6
|
const { data } = useCurrentUser();
|
|
5
7
|
|
|
@@ -7,5 +9,7 @@ export const useCurrentUserCapabilities = () => {
|
|
|
7
9
|
return Boolean( data?.capabilities.includes( capability ) );
|
|
8
10
|
};
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
const isAdmin = Boolean( data?.capabilities.includes( ADMIN_CAPABILITY ) );
|
|
13
|
+
|
|
14
|
+
return { canUser, isAdmin, capabilities: data?.capabilities };
|
|
11
15
|
};
|