mirror of
https://github.com/strapi/strapi.git
synced 2025-10-19 12:02:38 +00:00
chore: build strapi permissions with pack-up (#18309)
This commit is contained in:
parent
3a1cb32f56
commit
82035f18c9
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -121,7 +121,7 @@ jobs:
|
|||||||
- uses: nrwl/nx-set-shas@v3
|
- uses: nrwl/nx-set-shas@v3
|
||||||
- name: Monorepo install
|
- name: Monorepo install
|
||||||
uses: ./.github/actions/yarn-nm-install
|
uses: ./.github/actions/yarn-nm-install
|
||||||
- name: Run build for admin-test-utils
|
- name: Run build:ts for admin-test-utils & helper-plugin
|
||||||
run: yarn build --projects=@strapi/admin-test-utils,@strapi/helper-plugin --skip-nx-cache
|
run: yarn build --projects=@strapi/admin-test-utils,@strapi/helper-plugin --skip-nx-cache
|
||||||
- name: Run test
|
- name: Run test
|
||||||
run: yarn nx affected --target=test:front --nx-ignore-cycles
|
run: yarn nx affected --target=test:front --nx-ignore-cycles
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
export interface Permission {
|
|
||||||
action: string;
|
|
||||||
subject?: string | object | null;
|
|
||||||
properties?: object;
|
|
||||||
conditions?: string[];
|
|
||||||
}
|
|
@ -8,7 +8,9 @@ import { hasPermissions } from '../utils/hasPermissions';
|
|||||||
|
|
||||||
import { LoadingIndicatorPage } from './LoadingIndicatorPage';
|
import { LoadingIndicatorPage } from './LoadingIndicatorPage';
|
||||||
|
|
||||||
import type { Permission } from '@strapi/permissions';
|
import type { domain } from '@strapi/permissions';
|
||||||
|
|
||||||
|
type Permission = domain.permission.Permission;
|
||||||
|
|
||||||
export interface CheckPagePermissions {
|
export interface CheckPagePermissions {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
@ -4,7 +4,9 @@ import { useNotification } from '../features/Notifications';
|
|||||||
import { useRBACProvider } from '../features/RBAC';
|
import { useRBACProvider } from '../features/RBAC';
|
||||||
import { hasPermissions } from '../utils/hasPermissions';
|
import { hasPermissions } from '../utils/hasPermissions';
|
||||||
|
|
||||||
import type { Permission } from '@strapi/permissions';
|
import type { domain } from '@strapi/permissions';
|
||||||
|
|
||||||
|
type Permission = domain.permission.Permission;
|
||||||
|
|
||||||
// NOTE: this component is very similar to the CheckPagePermissions
|
// NOTE: this component is very similar to the CheckPagePermissions
|
||||||
// except that it does not handle redirections nor loading state
|
// except that it does not handle redirections nor loading state
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import type { Permission } from '@strapi/permissions';
|
import type { domain } from '@strapi/permissions';
|
||||||
import type { QueryObserverBaseResult } from 'react-query';
|
import type { QueryObserverBaseResult } from 'react-query';
|
||||||
|
|
||||||
|
type Permission = domain.permission.Permission;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------------------------------
|
||||||
* Context
|
* Context
|
||||||
* -----------------------------------------------------------------------------------------------*/
|
* -----------------------------------------------------------------------------------------------*/
|
||||||
|
@ -2,7 +2,9 @@ import * as React from 'react';
|
|||||||
|
|
||||||
import { TranslationMessage } from '../types';
|
import { TranslationMessage } from '../types';
|
||||||
|
|
||||||
import type { Permission } from '@strapi/permissions';
|
import type { domain } from '@strapi/permissions';
|
||||||
|
|
||||||
|
type Permission = domain.permission.Permission;
|
||||||
|
|
||||||
interface MenuItem {
|
interface MenuItem {
|
||||||
to: string;
|
to: string;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
import { parse, ParsedQs, stringify } from 'qs';
|
import { parse, stringify } from 'qs';
|
||||||
import { useHistory, useLocation } from 'react-router-dom';
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
const useQueryParams = <TQuery extends Record<string, unknown>>(initialParams?: TQuery) => {
|
const useQueryParams = <TQuery extends Record<string, unknown>>(initialParams?: TQuery) => {
|
||||||
|
@ -6,9 +6,11 @@ import { useRBACProvider } from '../features/RBAC';
|
|||||||
|
|
||||||
import { useFetchClient } from './useFetchClient';
|
import { useFetchClient } from './useFetchClient';
|
||||||
|
|
||||||
import type { Permission } from '@strapi/permissions';
|
import type { domain } from '@strapi/permissions';
|
||||||
import type { AxiosResponse } from 'axios';
|
import type { AxiosResponse } from 'axios';
|
||||||
|
|
||||||
|
type Permission = domain.permission.Permission;
|
||||||
|
|
||||||
type AllowedActions = Record<string, boolean>;
|
type AllowedActions = Record<string, boolean>;
|
||||||
|
|
||||||
export const useRBAC = (
|
export const useRBAC = (
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import { getFetchClient } from './getFetchClient';
|
import { getFetchClient } from './getFetchClient';
|
||||||
|
|
||||||
import type { Permission } from '@strapi/permissions';
|
import type { domain } from '@strapi/permissions';
|
||||||
import type { GenericAbortSignal } from 'axios';
|
import type { GenericAbortSignal } from 'axios';
|
||||||
|
|
||||||
|
type Permission = domain.permission.Permission;
|
||||||
|
|
||||||
const findMatchingPermissions = (userPermissions: Permission[], permissions: Permission[]) =>
|
const findMatchingPermissions = (userPermissions: Permission[], permissions: Permission[]) =>
|
||||||
userPermissions.reduce<Permission[]>((acc, curr) => {
|
userPermissions.reduce<Permission[]>((acc, curr) => {
|
||||||
const associatedPermission = permissions.find(
|
const associatedPermission = permissions.find(
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { Permission } from '@strapi/permissions';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
hasPermissions,
|
hasPermissions,
|
||||||
findMatchingPermissions,
|
findMatchingPermissions,
|
||||||
@ -7,6 +5,10 @@ import {
|
|||||||
shouldCheckPermissions,
|
shouldCheckPermissions,
|
||||||
} from '../hasPermissions';
|
} from '../hasPermissions';
|
||||||
|
|
||||||
|
import type { domain } from '@strapi/permissions';
|
||||||
|
|
||||||
|
type Permission = domain.permission.Permission;
|
||||||
|
|
||||||
const hasPermissionsTestData: Record<string, Record<string, Permission[]>> = {
|
const hasPermissionsTestData: Record<string, Record<string, Permission[]>> = {
|
||||||
userPermissions: {
|
userPermissions: {
|
||||||
user1: [
|
user1: [
|
||||||
|
@ -19,20 +19,22 @@
|
|||||||
"url": "https://strapi.io"
|
"url": "https://strapi.io"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"main": "./dist/index.js",
|
||||||
|
"module": "./dist/index.mjs",
|
||||||
|
"source": "./src/index.ts",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"./dist"
|
"./dist"
|
||||||
],
|
],
|
||||||
"main": "./dist/index.js",
|
|
||||||
"types": "./dist/index.d.ts",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "run -T tsc",
|
"build": "pack-up build",
|
||||||
"build:ts": "run build",
|
|
||||||
"watch": "run -T tsc -w --preserveWatchOutput",
|
|
||||||
"clean": "run -T rimraf ./dist",
|
"clean": "run -T rimraf ./dist",
|
||||||
|
"lint": "run -T eslint .",
|
||||||
"prepublishOnly": "yarn clean && yarn build",
|
"prepublishOnly": "yarn clean && yarn build",
|
||||||
|
"test:ts": "run -T tsc --noEmit",
|
||||||
"test:unit": "run -T jest",
|
"test:unit": "run -T jest",
|
||||||
"test:unit:watch": "run -T jest --watch",
|
"test:unit:watch": "run -T jest --watch",
|
||||||
"lint": "run -T eslint ."
|
"watch": "pack-up watch"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@casl/ability": "6.5.0",
|
"@casl/ability": "6.5.0",
|
||||||
@ -42,6 +44,7 @@
|
|||||||
"sift": "16.0.1"
|
"sift": "16.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@strapi/pack-up": "workspace:*",
|
||||||
"eslint-config-custom": "4.14.3",
|
"eslint-config-custom": "4.14.3",
|
||||||
"tsconfig": "4.14.3"
|
"tsconfig": "4.14.3"
|
||||||
},
|
},
|
||||||
|
6
packages/core/permissions/packup.config.ts
Normal file
6
packages/core/permissions/packup.config.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import { defineConfig } from '@strapi/pack-up';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
runtime: 'node',
|
||||||
|
});
|
@ -1,7 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { subject } from '@casl/ability';
|
import { subject } from '@casl/ability';
|
||||||
import { providerFactory } from '@strapi/utils';
|
import { providerFactory } from '@strapi/utils';
|
||||||
import permissions from '..';
|
import * as permissions from '../index';
|
||||||
import type { HookName } from '../engine/hooks';
|
import type { HookName } from '../engine/hooks';
|
||||||
import type { Permission } from '../domain/permission';
|
import type { Permission } from '../domain/permission';
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import * as domain from './domain';
|
import * as domain from './domain';
|
||||||
import * as engine from './engine';
|
import * as engine from './engine';
|
||||||
|
|
||||||
export = {
|
export { domain, engine };
|
||||||
domain,
|
|
||||||
engine,
|
|
||||||
};
|
|
||||||
|
9
packages/core/permissions/tsconfig.build.json
Normal file
9
packages/core/permissions/tsconfig.build.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": "./src",
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["**/__tests__/**"]
|
||||||
|
}
|
@ -3,6 +3,6 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"noEmit": true
|
"noEmit": true
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src", "packup.config.ts"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
"clean": "run -T rimraf ./dist",
|
"clean": "run -T rimraf ./dist",
|
||||||
"lint": "run -T eslint .",
|
"lint": "run -T eslint .",
|
||||||
"prepublishOnly": "yarn clean && yarn build",
|
"prepublishOnly": "yarn clean && yarn build",
|
||||||
|
"test:ts": "run -T tsc --noEmit",
|
||||||
"test:unit": "run -T jest",
|
"test:unit": "run -T jest",
|
||||||
"test:unit:watch": "run -T jest --watch",
|
"test:unit:watch": "run -T jest --watch",
|
||||||
"watch": "run -T pack-up watch"
|
"watch": "run -T pack-up watch"
|
||||||
|
@ -7817,6 +7817,7 @@ __metadata:
|
|||||||
resolution: "@strapi/permissions@workspace:packages/core/permissions"
|
resolution: "@strapi/permissions@workspace:packages/core/permissions"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@casl/ability": 6.5.0
|
"@casl/ability": 6.5.0
|
||||||
|
"@strapi/pack-up": "workspace:*"
|
||||||
"@strapi/utils": 4.14.3
|
"@strapi/utils": 4.14.3
|
||||||
eslint-config-custom: 4.14.3
|
eslint-config-custom: 4.14.3
|
||||||
lodash: 4.17.21
|
lodash: 4.17.21
|
||||||
|
Loading…
x
Reference in New Issue
Block a user