Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
},
"dependencies": {
"@payloadcms/db-mongodb": "^3.68.1",
"@payloadcms/next": "^3.68.1",
"@payloadcms/plugin-nested-docs": "^3.68.1",
"@payloadcms/plugin-redirects": "^3.68.1",
"@payloadcms/plugin-seo": "^3.68.1",
"@payloadcms/richtext-slate": "^3.68.1",
"@payloadcms/ui": "^3.68.1",
"@payloadcms/next": "^3.68.3",
"@payloadcms/plugin-nested-docs": "^3.68.3",
"@payloadcms/plugin-redirects": "^3.68.3",
"@payloadcms/plugin-seo": "^3.68.3",
"@payloadcms/richtext-slate": "^3.68.3",
"@payloadcms/ui": "^3.68.3",
"axios": "1.13.2",
"date-fns": "^4.1.0",
"dotenv": "^16.6.1",
"graphql": "^16.12.0",
"lodash-es": "^4.17.21",
"next": "^15.5.7",
"passport": "^0.7.0",
"payload": "^3.68.1",
"payload": "^3.68.3",
"payload-blurhash-plugin": "^3.1.0",
"payload-oauth2": "^1.0.19",
"react": "^19.2.1",
Expand Down
7 changes: 7 additions & 0 deletions src/collections/Administration/ContactForms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CollectionConfig } from 'payload';
import { isAdmin } from '@/access/isAdmin';
import { authorFields, authorFieldsBeforeChangeHook } from '@/fields/authorFields';

const ContactForms: CollectionConfig = {
slug: 'contact-forms',
Expand All @@ -24,6 +25,10 @@ const ContactForms: CollectionConfig = {
delete: isAdmin,
},

hooks: {
beforeChange: [authorFieldsBeforeChangeHook],
},

fields: [
{
name: 'fullName',
Expand All @@ -50,6 +55,8 @@ const ContactForms: CollectionConfig = {
type: 'text',
required: true,
},

...authorFields,
],
};

Expand Down
7 changes: 7 additions & 0 deletions src/collections/Administration/NotFound.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CollectionConfig } from 'payload';
import { isAdmin } from '@/access/isAdmin';
import { authorFields, authorFieldsBeforeChangeHook } from '@/fields/authorFields';

const NotFoundPages: CollectionConfig = {
slug: 'not-found-pages',
Expand All @@ -24,12 +25,18 @@ const NotFoundPages: CollectionConfig = {
delete: isAdmin,
},

hooks: {
beforeChange: [authorFieldsBeforeChangeHook],
},

fields: [
{
name: 'slug',
type: 'text',
required: true,
},

...authorFields,
],
};

Expand Down
7 changes: 7 additions & 0 deletions src/collections/Circles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { hasCircleAccess } from '@/access/hasCircleAccess';
import { isAdmin, isAdminFieldLevel } from '@/access/isAdmin';
import { isUserOrPublished } from '@/access/isUser';
import { CallToAction } from '@/blocks/CallToAction';
import { authorFields, authorFieldsBeforeChangeHook } from '@/fields/authorFields';
import { Content } from '@/blocks/Content';
import { EventOverviewBlock } from '@/blocks/EventOverviewBlock';
import { HeadlineBlock } from '@/blocks/Headline';
Expand Down Expand Up @@ -41,6 +42,10 @@ const Circles: CollectionConfig = {
delete: isAdmin,
},

hooks: {
beforeChange: [authorFieldsBeforeChangeHook],
},

fields: [
{
name: 'name',
Expand Down Expand Up @@ -128,6 +133,8 @@ const Circles: CollectionConfig = {
},
],
},

...authorFields,
],
};

Expand Down
7 changes: 7 additions & 0 deletions src/collections/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CollectionConfig } from 'payload';
import { isAdmin } from '@/access/isAdmin';
import { isEditor, isEditorFieldLevel } from '@/access/isEditor';
import { isUser, isUserOrPublished } from '@/access/isUser';
import { authorFields, authorFieldsBeforeChangeHook } from '@/fields/authorFields';
import richText from '@/fields/richText';
import { slugField } from '@/fields/slug';
import createEventSlug from '@/utilities/createEventSlug';
Expand Down Expand Up @@ -36,6 +37,10 @@ const Events: CollectionConfig = {
delete: isAdmin,
},

hooks: {
beforeChange: [authorFieldsBeforeChangeHook],
},

fields: [
{
type: 'tabs',
Expand Down Expand Up @@ -258,6 +263,8 @@ const Events: CollectionConfig = {
],
},
},

...authorFields,
],
};

Expand Down
7 changes: 7 additions & 0 deletions src/collections/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import type { CollectionConfig } from 'payload';
import { isAdmin } from '@/access/isAdmin';
import { isUser } from '@/access/isUser';
import { authorFields, authorFieldsBeforeChangeHook } from '@/fields/authorFields';
import { fileURLToPath } from 'url';

const filename = fileURLToPath(import.meta.url);
Expand All @@ -28,6 +29,10 @@ const Media: CollectionConfig = {
group: 'Medien',
},

hooks: {
beforeChange: [authorFieldsBeforeChangeHook],
},

upload: {
// from the imageSizes below, the admin UI will show this size for previewing
adminThumbnail: 'thumbnail',
Expand Down Expand Up @@ -67,6 +72,8 @@ const Media: CollectionConfig = {
description: 'Gib "-" ein, falls es sich um ein rein dekoratives Element handelt',
},
},

...authorFields,
],
};

Expand Down
7 changes: 7 additions & 0 deletions src/collections/News.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CollectionConfig } from 'payload';
import { isAdmin } from '@/access/isAdmin';
import { isUser, isUserFieldLevel, isUserOrPublished } from '@/access/isUser';
import { CallToAction } from '@/blocks/CallToAction';
import { authorFields, authorFieldsBeforeChangeHook } from '@/fields/authorFields';
import { Content } from '@/blocks/Content';
import { EventOverviewBlock } from '@/blocks/EventOverviewBlock';
import { HeadlineBlock } from '@/blocks/Headline';
Expand Down Expand Up @@ -41,6 +42,10 @@ const News: CollectionConfig = {
delete: isAdmin,
},

hooks: {
beforeChange: [authorFieldsBeforeChangeHook],
},

fields: [
{
name: 'title',
Expand Down Expand Up @@ -192,6 +197,8 @@ const News: CollectionConfig = {
],
},
},

...authorFields,
],
};

Expand Down
7 changes: 7 additions & 0 deletions src/collections/Organisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isAdmin, isAdminFieldLevel } from '@/access/isAdmin';
import { isEditor } from '@/access/isEditor';
import { isUserOrPublished } from '@/access/isUser';
import { CallToAction } from '@/blocks/CallToAction';
import { authorFields, authorFieldsBeforeChangeHook } from '@/fields/authorFields';
import { CircleOverviewBlock } from '@/blocks/CircleOverviewBlock';
import { Content } from '@/blocks/Content';
import { EventOverviewBlock } from '@/blocks/EventOverviewBlock';
Expand Down Expand Up @@ -36,6 +37,10 @@ const Organisation: CollectionConfig = {
delete: isAdmin,
},

hooks: {
beforeChange: [authorFieldsBeforeChangeHook],
},

fields: [
{
type: 'tabs',
Expand Down Expand Up @@ -97,6 +102,8 @@ const Organisation: CollectionConfig = {
hidden: true,
defaultValue: 'organisation',
},

...authorFields,
],
};

Expand Down
7 changes: 7 additions & 0 deletions src/collections/Pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isAdmin, isAdminFieldLevel } from '@/access/isAdmin';
import { isEditor } from '@/access/isEditor';
import { isUserOrPublished } from '@/access/isUser';
import { CallToAction } from '@/blocks/CallToAction';
import { authorFields, authorFieldsBeforeChangeHook } from '@/fields/authorFields';
import { Content } from '@/blocks/Content';
import { EventOverviewBlock } from '@/blocks/EventOverviewBlock';
import { HeadlineBlock } from '@/blocks/Headline';
Expand Down Expand Up @@ -42,6 +43,10 @@ const Pages: CollectionConfig = {
delete: isAdmin,
},

hooks: {
beforeChange: [authorFieldsBeforeChangeHook],
},

fields: [
{
name: 'title',
Expand All @@ -65,6 +70,8 @@ const Pages: CollectionConfig = {
initCollapsed: true,
},
},

...authorFields,
],
};

Expand Down
49 changes: 49 additions & 0 deletions src/fields/authorFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { Field, CollectionBeforeChangeHook } from 'payload';
import Users from '@/collections/Users/Users';

export const authorFields: Field[] = [
{
name: 'createdBy',
type: 'relationship',
relationTo: Users.slug,
label: 'Erstellt von',
admin: {
readOnly: true,
position: 'sidebar',
description: 'Wird automatisch beim Erstellen gesetzt.',
},
access: {
create: () => true,
update: () => false,
},
},
{
name: 'updatedBy',
type: 'relationship',
relationTo: Users.slug,
label: 'Aktualisiert von',
admin: {
readOnly: true,
position: 'sidebar',
description: 'Wird automatisch beim Speichern gesetzt.',
},
access: {
create: () => true,
update: () => false,
},
},
];

export const authorFieldsBeforeChangeHook: CollectionBeforeChangeHook = async ({ data, operation, req }) => {
const userId = req.user?.id;

if (!userId) {
return data;
}

if (operation === 'create') {
return { ...data, createdBy: userId, updatedBy: userId };
}

return { ...data, updatedBy: userId };
};
Loading