Skip to content

Commit 8a536cf

Browse files
authored
Merge pull request #18 from shefing/readme-update
update packages readme
2 parents 46521d7 + 6aebc0a commit 8a536cf

File tree

22 files changed

+84
-110
lines changed

22 files changed

+84
-110
lines changed

packages/authorization/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ This plugin enables to define roles based on basic permissions per collection. T
77
There is a built-in role named administrator and users assigned to it (aka administrators) can create a Roles collection to define roles that will control access to the content. Each role contains a set of permissions that are composed of operation: read/write/publish and the collection(s) / global(s) they apply to.
88

99
Note that:
10+
1011
- write permission on a collection / global includes read permission on this collection / global
11-
- publish permission on a collection / global does not includes write either read permission on this collection / global
12+
- publish permission on a collection / global includes write either read permission on this collection / global
1213

1314
Example:
1415

@@ -18,7 +19,7 @@ Administrators can set as many permissions he/she wants within a role and as man
1819

1920
![img_1.png](./images/img_1.png)
2021

21-
### Setup
22+
### Setup
2223

2324
- Install the [plugin](https://www.npmjs.com/package/@shefing/authorization) using your node package manager, e.g:
2425

@@ -32,7 +33,7 @@ plugins: [
3233
addAccess({
3334
rolesCollection: 'roles', // name of the collection defining the roles
3435
permissionsField: 'permissions', // name of the field within the role collection
35-
excludedCollections: ['posts', 'media'] // enable to exclude some collections from permission control
36+
excludedCollections: ['posts', 'media'] // enable to exclude some collections from permission control
3637
}),
3738
```
3839
@@ -44,11 +45,11 @@ You need to create the `roles` collection and it must have the following fields:
4445
fields: [
4546
{
4647
name: 'name',
47-
type: 'text'
48+
type: 'text',
4849
},
4950
{
5051
name: 'permissions',
51-
saveToJWT: true,
52+
saveToJWT: true,
5253
interfaceName: 'RolePermissions',
5354
type: 'array',
5455
access: {
@@ -57,14 +58,14 @@ fields: [
5758
},
5859
fields: [
5960
{
60-
type: 'row',
61+
type: 'row',
6162
fields: [
6263
{
6364
name: 'entity',
6465
label: 'Collection or Global',
6566
type: 'select',
6667
hasMany: true,
67-
options: [],
68+
options: [],
6869
required: true,
6970
},
7071
{

packages/authorization/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shefing/authorization",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"private": false,
55
"bugs": "https://github.com/shefing/payload-tools/issues",
66
"repository": "https://github.com/shefing/payload-tools",
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { Access, User, Payload } from 'payload';
22
import { AuthorizationPluginConfig } from '../types.js';
33

4+
const PERMISSION_HIERARCHY: Record<string, string[]> = {
5+
publish: ['write', 'read', 'publish'],
6+
write: ['read', 'write'],
7+
read: ['read'],
8+
};
9+
410
export const canUserAccessAction = async (
511
user: User | null | undefined,
612
slugName: string,
@@ -10,33 +16,31 @@ export const canUserAccessAction = async (
1016
): Promise<boolean> => {
1117
if (!user) return false;
1218

13-
// Admin users always have access
1419
if (user.isAdmin) return true;
1520

16-
// No roles assigned to the user
1721
if (!user.userRoles || user.userRoles.length === 0) return false;
1822

19-
// Fetch roles from the defined collection
2023
const roles = await payload.find({
2124
collection: config.rolesCollection,
2225
where: {
23-
id: { in: user.userRoles.map((role: any) => role.id) }, // Filter by user roles
26+
id: { in: user.userRoles.map((role: any) => role.id) },
2427
},
2528
});
2629

2730
if (!roles.docs || roles.docs.length === 0) return false;
2831

29-
// Check permissions for each role
32+
const userAllowedActions = new Set<string>();
33+
3034
for (const role of roles.docs) {
3135
const permissions = role[config.permissionsField];
3236
if (permissions) {
3337
for (const permission of permissions) {
34-
if (permission.entity.includes(slugName) && permission.type.includes(action)) {
35-
return true;
38+
if (permission.entity.includes(slugName)) {
39+
userAllowedActions.add(permission.type);
40+
PERMISSION_HIERARCHY[permission.type]?.forEach((perm) => userAllowedActions.add(perm));
3641
}
3742
}
3843
}
3944
}
40-
41-
return false;
45+
return userAllowedActions.has(action);
4246
};

packages/authorization/src/utilities/hasAccessToAction.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Access, User } from 'payload';
22
import { canUserAccessAction } from '../access/general.js';
3-
import { config } from 'process';
4-
import { AuthorizationPluginConfig } from '../types.js';
3+
54

65
export const hasAccessToAction =
76
(slugName: string, action: string,pluginConfig:any): Access =>

packages/authors-info/README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
## [Author Info plugin](./src/index.ts)
22

3-
- Payload 3.0 does not store authors informations, so we created this package to automatically store information about who created, updated and publish content, and this for all collections and globals. The package does add a new tab in the authoring user interface "Author Data".
3+
- This plugin provides an automated solution to track and store details about content creators, editors, and publishers across all collections and globals.
4+
It also introduces an "Author Data" tab in the authoring interface.
45
- Payload 3.0 is storing the creation and modification date of each document's collections but does not store publication date. So this package aslo stores the most recent publish date.
56

67
![img_1.png](./images/img_1.png)
78

89
### Setup
910

10-
In order to use this authors-info plugin install it using your prefered node package manager, e.g:
11+
Install the plugin using your node package manager, e.g:
1112

1213
`npm add @shefing/authors-info`
1314

@@ -17,19 +18,11 @@ In the payload.config.ts add the following:
1718
plugins: [
1819
...plugins,
1920
addAuthorsFields({
20-
excludedCollections: [],
21-
usernameField: 'fullName',
21+
excludedCollections: [],//array of collections names to exclude
22+
excludedGlobals:[], // array of globals names to exclude
23+
usernameField: 'fullName', //name field to use from Users collection, 'user' by default
2224
}),
2325
```
2426
25-
### Configuration
26-
27-
- `excludedCollections`: array of collections names to exclude
28-
29-
- `excludedGlobals`: array of globals names to exclude
30-
31-
- `usernameField`: name field to use from Users collection, 'user' by default
32-
33-
34-
The dates are presented relatively using moment.js anywhere using CreatedAtCell type
27+
The dates are presented relatively using moment.js anywhere using CreatedAtCell type
3528
![img_2.png](./images/img_2.png)

packages/authors-info/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shefing/authors-info",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"private": false,
55
"bugs": "https://github.com/shefing/payload-tools/issues",
66
"repository": "https://github.com/shefing/payload-tools",

packages/authors-info/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const processFields = (fields: Field[], hasDraft: boolean): Field[] => {
7878
disableBulkEdit: true,
7979
hidden: true,
8080
components: {
81-
Cell: '@rikifrank/authors-info/client#CreatedAtCell',
81+
Cell: '@shefing/authors-info/client#CreatedAtCell',
8282
},
8383
},
8484
// The default sort for list view is createdAt. Thus, enabling indexing by default, is a major performance improvement, especially for large or a large amount of collections.
@@ -94,7 +94,7 @@ const processFields = (fields: Field[], hasDraft: boolean): Field[] => {
9494
disableBulkEdit: true,
9595
hidden: true,
9696
components: {
97-
Cell: '@rikifrank/authors-info/client#CreatedAtCell',
97+
Cell: '@shefing/authors-info/client#CreatedAtCell',
9898
},
9999
},
100100
label: ({ t }) => t('general:updatedAt'),
@@ -129,7 +129,7 @@ const processFields = (fields: Field[], hasDraft: boolean): Field[] => {
129129
pickerAppearance: 'dayAndTime',
130130
displayFormat: 'd MMM yyy: ,h:mm:ss a',
131131
},
132-
components: { Cell: '@rikifrank/authors-info/client#CreatedAtCell' },
132+
components: { Cell: '@shefing/authors-info/client#CreatedAtCell' },
133133
},
134134
},
135135
{

packages/authors-info/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"target": "ESNext"
2424
},
2525
"paths": {
26-
"@rikifrank/authors-info/client": ["./packages/authors-info/src/exports/client.ts"]
26+
"@shefing/authors-info/client": ["./packages/authors-info/src/exports/client.ts"]
2727
},
2828
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"],
2929
"exclude": ["dist", "build", "node_modules"]

packages/color-picker/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
## [Color Picker Field ](./src/index.ts)
22

3-
In the default Payload CMS, there was no built-in color picker field. We've added a custom Color Picker field that allows users to easily select colors directly within the CMS interface. This field uses the Flowbite color palette, bringing in all available colors from Flowbite. Users can search for a specific color by name or select it from the palette. To use it, simply select a color from the picker, enter a hex code, or search for the color name, and it will be applied to your content.
3+
Payload CMS does not include a built-in color picker, so we added a custom field that integrates Tailwind's color palette. Users can select a color, enter a hex code, or search by name directly within the CMS.
44

5-
This implementation integrates Flowbite with ShadCN UI, combining Flowbite's extensive design system with ShadCN's modern component library for an effective experience
5+
This integrates Tailwind design system with ShadCN's component library for a seamless experience.
66

77
![img1.png](./images/img1.png)
88

99
### Setup
1010

11-
In order to use this color-picker field install it using your prefered node package manager, e.g:
11+
Install the field using your node package manager, e.g:
1212

13-
` npm install @shefing/color-picker`
13+
` npm install @shefing/color-picker`
1414

15-
In the collection add the following:
15+
In the target collection add the following:
1616

1717
```typescript
1818
import { createColorField } from '@shefing/color-picker';
1919

20-
fields: [createColorField({ name: 'color', label: 'font-color' })];
20+
fields: [
21+
createColorField({
22+
name: 'color', //The name of the field.
23+
label: 'font-color', //The label of the field.
24+
}),
25+
];
2126
```
2227

2328
To use this package, make sure Tailwind CSS is installed in your project.
24-
25-
### Configuration
26-
27-
- `name`: The name of the field. This is the key used to store and retrieve the field's value.
28-
- `label`: The label of the field. This is the text displayed in the admin interface to represent the field.

packages/color-picker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shefing/color-picker",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"private": false,
55
"bugs": "https://github.com/shefing/payload-tools/issues",
66
"repository": "https://github.com/shefing/payload-tools",

0 commit comments

Comments
 (0)