feat: add authorName and editorName attributes to Strapi blog schema for dynamic author display
This commit is contained in:
@@ -14,12 +14,12 @@ export default {
|
||||
const user = ctx?.state?.user;
|
||||
|
||||
if (user) {
|
||||
// Auto-fill author relation if not explicitly set by user
|
||||
if (!data.author) {
|
||||
data.author = user.id;
|
||||
}
|
||||
|
||||
// Auto-fill author designation based on logged-in account
|
||||
if (!data.authorName) {
|
||||
data.authorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username || user.email;
|
||||
}
|
||||
if (!data.authorDesignation && user.email) {
|
||||
data.authorDesignation = designationMap[user.email] || `${user.firstname || ''} ${user.lastname || ''}`.trim();
|
||||
}
|
||||
@@ -32,22 +32,24 @@ export default {
|
||||
const user = ctx?.state?.user;
|
||||
|
||||
if (user && data) {
|
||||
// Auto-fill author relation if empty
|
||||
if (!data.author) {
|
||||
data.author = user.id;
|
||||
}
|
||||
|
||||
// Auto-fill author designation if empty
|
||||
if (!data.authorName && user) {
|
||||
data.authorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username || user.email;
|
||||
}
|
||||
if (!data.authorDesignation && user.email) {
|
||||
data.authorDesignation = designationMap[user.email] || `${user.firstname || ''} ${user.lastname || ''}`.trim();
|
||||
}
|
||||
|
||||
// Auto-fill editor details if an Editor/Admin edits or approves
|
||||
const isEditor = user.roles?.some((r: any) => r.code === 'strapi-editor' || r.code === 'strapi-super-admin');
|
||||
if (isEditor) {
|
||||
if (!data.editor) {
|
||||
data.editor = user.id;
|
||||
}
|
||||
if (!data.editorName && user) {
|
||||
data.editorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username;
|
||||
}
|
||||
if (!data.editorDesignation && user.email) {
|
||||
data.editorDesignation = designationMap[user.email] || 'Senior Editor';
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@
|
||||
"default": "Draft",
|
||||
"required": true
|
||||
},
|
||||
"authorName": {
|
||||
"type": "string"
|
||||
},
|
||||
"author": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
@@ -68,6 +71,9 @@
|
||||
"authorDesignation": {
|
||||
"type": "string"
|
||||
},
|
||||
"editorName": {
|
||||
"type": "string"
|
||||
},
|
||||
"editor": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
|
||||
Reference in New Issue
Block a user