@elementor/editor-styles-repository 4.4.0-1092 → 4.4.0-1094

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.js CHANGED
@@ -88,9 +88,19 @@ var DEFAULT_CAPABILITIES = {
88
88
  update: true,
89
89
  updateProps: true
90
90
  };
91
+ var DENIED_CAPABILITIES = {
92
+ create: false,
93
+ delete: false,
94
+ update: false,
95
+ updateProps: false
96
+ };
91
97
  var useUserStylesCapability = () => {
92
98
  const { capabilities } = (0, import_editor_current_user.useCurrentUserCapabilities)();
99
+ const hasContentOnlyAccess = (0, import_editor_current_user.useHasContentOnlyAccess)();
93
100
  const userCan = (providerKey) => {
101
+ if (hasContentOnlyAccess) {
102
+ return DENIED_CAPABILITIES;
103
+ }
94
104
  const provider = stylesRepository.getProviderByKey(providerKey);
95
105
  if (!provider?.capabilities) {
96
106
  return DEFAULT_CAPABILITIES;
package/dist/index.mjs CHANGED
@@ -45,16 +45,26 @@ function useProviders() {
45
45
  import { useMemo } from "react";
46
46
 
47
47
  // src/hooks/use-user-styles-capability.ts
48
- import { useCurrentUserCapabilities } from "@elementor/editor-current-user";
48
+ import { useCurrentUserCapabilities, useHasContentOnlyAccess } from "@elementor/editor-current-user";
49
49
  var DEFAULT_CAPABILITIES = {
50
50
  create: true,
51
51
  delete: true,
52
52
  update: true,
53
53
  updateProps: true
54
54
  };
55
+ var DENIED_CAPABILITIES = {
56
+ create: false,
57
+ delete: false,
58
+ update: false,
59
+ updateProps: false
60
+ };
55
61
  var useUserStylesCapability = () => {
56
62
  const { capabilities } = useCurrentUserCapabilities();
63
+ const hasContentOnlyAccess = useHasContentOnlyAccess();
57
64
  const userCan = (providerKey) => {
65
+ if (hasContentOnlyAccess) {
66
+ return DENIED_CAPABILITIES;
67
+ }
58
68
  const provider = stylesRepository.getProviderByKey(providerKey);
59
69
  if (!provider?.capabilities) {
60
70
  return DEFAULT_CAPABILITIES;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-styles-repository",
3
3
  "description": "Elementor Editor Styles Repository",
4
- "version": "4.4.0-1092",
4
+ "version": "4.4.0-1094",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -33,13 +33,13 @@
33
33
  "dev": "tsup --config=../../tsup.dev.ts"
34
34
  },
35
35
  "dependencies": {
36
- "@elementor/editor-current-user": "4.4.0-1092",
37
- "@elementor/editor-elements": "4.4.0-1092",
38
- "@elementor/editor-props": "4.4.0-1092",
39
- "@elementor/editor-styles": "4.4.0-1092",
40
- "@elementor/editor-v1-adapters": "4.4.0-1092",
41
- "@elementor/schema": "4.4.0-1092",
42
- "@elementor/utils": "4.4.0-1092",
36
+ "@elementor/editor-current-user": "4.4.0-1094",
37
+ "@elementor/editor-elements": "4.4.0-1094",
38
+ "@elementor/editor-props": "4.4.0-1094",
39
+ "@elementor/editor-styles": "4.4.0-1094",
40
+ "@elementor/editor-v1-adapters": "4.4.0-1094",
41
+ "@elementor/schema": "4.4.0-1094",
42
+ "@elementor/utils": "4.4.0-1094",
43
43
  "@wordpress/i18n": "^5.13.0"
44
44
  },
45
45
  "peerDependencies": {
@@ -0,0 +1,68 @@
1
+ import { useCurrentUserCapabilities, useHasContentOnlyAccess } from '@elementor/editor-current-user';
2
+ import { renderHook } from '@testing-library/react';
3
+
4
+ import { documentElementsStylesProvider } from '../../providers/document-elements-styles-provider';
5
+ import { stylesRepository } from '../../styles-repository';
6
+ import { type StylesProvider } from '../../types';
7
+ import { useUserStylesCapability } from '../use-user-styles-capability';
8
+
9
+ jest.mock( '@elementor/editor-current-user' );
10
+ jest.mock( '../../styles-repository' );
11
+
12
+ const UPDATE_CAPABILITY = 'update_style';
13
+ const PROVIDER_WITH_CAPABILITIES_KEY = 'provider-with-capabilities';
14
+
15
+ const providerWithCapabilities: Pick< StylesProvider, 'getKey' | 'capabilities' > = {
16
+ getKey: () => PROVIDER_WITH_CAPABILITIES_KEY,
17
+ capabilities: {
18
+ create: UPDATE_CAPABILITY,
19
+ delete: UPDATE_CAPABILITY,
20
+ update: UPDATE_CAPABILITY,
21
+ updateProps: UPDATE_CAPABILITY,
22
+ },
23
+ };
24
+
25
+ const deniedCapabilities = {
26
+ create: false,
27
+ delete: false,
28
+ update: false,
29
+ updateProps: false,
30
+ };
31
+
32
+ describe( 'useUserStylesCapability', () => {
33
+ beforeEach( () => {
34
+ jest.mocked( useHasContentOnlyAccess ).mockReturnValue( false );
35
+
36
+ jest.mocked( useCurrentUserCapabilities ).mockReturnValue( {
37
+ capabilities: [ UPDATE_CAPABILITY ],
38
+ canUser: ( capability ) => capability === UPDATE_CAPABILITY,
39
+ isAdmin: false,
40
+ } );
41
+ } );
42
+
43
+ it( 'should deny all capabilities for content-only users on a provider without capabilities', () => {
44
+ // Arrange
45
+ jest.mocked( useHasContentOnlyAccess ).mockReturnValue( true );
46
+
47
+ jest.mocked( stylesRepository.getProviderByKey ).mockReturnValue( documentElementsStylesProvider );
48
+
49
+ // Act
50
+ const { result } = renderHook( () => useUserStylesCapability() );
51
+
52
+ // Assert
53
+ expect( result.current.userCan( 'document-elements-42' ) ).toEqual( deniedCapabilities );
54
+ } );
55
+
56
+ it( 'should deny all capabilities for content-only users on a provider with capabilities', () => {
57
+ // Arrange
58
+ jest.mocked( useHasContentOnlyAccess ).mockReturnValue( true );
59
+
60
+ jest.mocked( stylesRepository.getProviderByKey ).mockReturnValue( providerWithCapabilities as StylesProvider );
61
+
62
+ // Act
63
+ const { result } = renderHook( () => useUserStylesCapability() );
64
+
65
+ // Assert
66
+ expect( result.current.userCan( PROVIDER_WITH_CAPABILITIES_KEY ) ).toEqual( deniedCapabilities );
67
+ } );
68
+ } );
@@ -1,4 +1,4 @@
1
- import { useCurrentUserCapabilities } from '@elementor/editor-current-user';
1
+ import { useCurrentUserCapabilities, useHasContentOnlyAccess } from '@elementor/editor-current-user';
2
2
 
3
3
  import { stylesRepository } from '../styles-repository';
4
4
  import { type UserCapabilities } from '../types';
@@ -14,10 +14,22 @@ const DEFAULT_CAPABILITIES: UserCan = {
14
14
  updateProps: true,
15
15
  };
16
16
 
17
+ const DENIED_CAPABILITIES: UserCan = {
18
+ create: false,
19
+ delete: false,
20
+ update: false,
21
+ updateProps: false,
22
+ };
23
+
17
24
  export const useUserStylesCapability = () => {
18
25
  const { capabilities } = useCurrentUserCapabilities();
26
+ const hasContentOnlyAccess = useHasContentOnlyAccess();
19
27
 
20
28
  const userCan = ( providerKey: string ): UserCan => {
29
+ if ( hasContentOnlyAccess ) {
30
+ return DENIED_CAPABILITIES;
31
+ }
32
+
21
33
  const provider = stylesRepository.getProviderByKey( providerKey );
22
34
 
23
35
  if ( ! provider?.capabilities ) {