diff --git a/front/lib/api/assistant/conversation.ts b/front/lib/api/assistant/conversation.ts index a60913a50d8a..32cffac3054c 100644 --- a/front/lib/api/assistant/conversation.ts +++ b/front/lib/api/assistant/conversation.ts @@ -219,7 +219,9 @@ async function renderUserMessage( providerId: user.providerId, username: user.username, email: user.email, - name: user.name, + firstName: user.firstName, + lastName: user.lastName, + fullName: user.firstName + (user.lastName ? ` ${user.lastName}` : ""), image: null, workspaces: [], isDustSuperUser: false, diff --git a/front/lib/api/assistant/global_agents.ts b/front/lib/api/assistant/global_agents.ts index b429226e928a..b3a69715b6d2 100644 --- a/front/lib/api/assistant/global_agents.ts +++ b/front/lib/api/assistant/global_agents.ts @@ -66,7 +66,7 @@ async function _getHelperGlobalAgent( const user = auth.user(); if (user) { const role = auth.role(); - prompt = `The user you're interacting with is granted with the role ${role}. Their name is ${user.name}. `; + prompt = `The user you're interacting with is granted with the role ${role}. Their name is ${user.fullName}. `; } const helperAssistantPromptInstance = HelperAssistantPrompt.getInstance(); diff --git a/front/lib/api/workspace.ts b/front/lib/api/workspace.ts index bd21395b6593..10090bfb401b 100644 --- a/front/lib/api/workspace.ts +++ b/front/lib/api/workspace.ts @@ -78,7 +78,9 @@ export async function getMembers(auth: Authenticator): Promise { providerId: u.providerId, username: u.username, email: u.email, - name: u.name, + fullName: u.firstName + (u.lastName ? ` ${u.lastName}` : ""), + firstName: u.firstName, + lastName: u.lastName, image: null, workspaces: [{ ...owner, role }], isDustSuperUser: u.isDustSuperUser, diff --git a/front/lib/auth.ts b/front/lib/auth.ts index bbb4e5c475bd..f6bd85352876 100644 --- a/front/lib/auth.ts +++ b/front/lib/auth.ts @@ -268,7 +268,11 @@ export class Authenticator { providerId: this._user.providerId, username: this._user.username, email: this._user.email, - name: this._user.name, + fullName: + this._user.firstName + + (this._user.lastName ? ` ${this._user.lastName}` : ""), + firstName: this._user.firstName, + lastName: this._user.lastName || null, // Not available from this method image: null, workspaces: [], @@ -332,7 +336,9 @@ export async function getUserFromSession( providerId: user.providerId, username: user.username, email: user.email, - name: user.name, + firstName: user.firstName, + lastName: user.lastName, + fullName: user.firstName + (user.lastName ? ` ${user.lastName}` : ""), image: session.user ? session.user.image : null, workspaces: workspaces.map((w) => { const m = memberships.find((m) => m.workspaceId === w.id); diff --git a/front/lib/models/user.ts b/front/lib/models/user.ts index 45fb4ff52545..b1b445895cfc 100644 --- a/front/lib/models/user.ts +++ b/front/lib/models/user.ts @@ -21,7 +21,7 @@ export class User extends Model< declare username: string; declare email: string; declare name: string; - declare firstName: string | null; + declare firstName: string; declare lastName: string | null; declare isDustSuperUser: CreationOptional; @@ -65,7 +65,7 @@ User.init( }, firstName: { type: DataTypes.STRING, - allowNull: true, + allowNull: false, }, lastName: { type: DataTypes.STRING, diff --git a/front/lib/user.ts b/front/lib/user.ts index 85396c6037c0..d5488006471a 100644 --- a/front/lib/user.ts +++ b/front/lib/user.ts @@ -61,15 +61,14 @@ export function setUserMetadataFromClient(metadata: UserMetadataType) { export const guessFirstandLastNameFromFullName = ( fullName: string -): { firstName: string | null; lastName: string | null } => { - if (!fullName) return { firstName: null, lastName: null }; - +): { firstName: string; lastName: string | null } => { const nameParts = fullName.split(" "); - if (nameParts.length === 1) return { firstName: fullName, lastName: null }; - - const firstName = nameParts.shift() || null; - const lastName = nameParts.join(" "); - - return { firstName, lastName }; + if (nameParts.length > 1) { + const firstName = nameParts.shift() || fullName; + const lastName = nameParts.join(" "); + return { firstName, lastName }; + } else { + return { firstName: fullName, lastName: null }; + } }; diff --git a/front/migrations/20231017_user_first_and_last_name.ts b/front/migrations/20231017_user_first_and_last_name.ts index dc6c1632f19d..2665976a0f60 100644 --- a/front/migrations/20231017_user_first_and_last_name.ts +++ b/front/migrations/20231017_user_first_and_last_name.ts @@ -1,15 +1,14 @@ -import { Op } from "sequelize"; - import { User } from "@app/lib/models"; import { guessFirstandLastNameFromFullName } from "@app/lib/user"; async function main() { - const users = await User.findAll({ - where: { - firstName: { - [Op.or]: [null, ""], - }, - }, + const users: User[] = await User.findAll({ + // Was run with this were but then we make first name non nullable and linter is not happy + // where: { + // firstName: { + // [Op.or]: [null, ""], + // }, + // }, }); console.log(`Found ${users.length} users to update`); @@ -23,7 +22,7 @@ async function main() { console.log(`Processing chunk ${i}/${chunks.length}...`); const chunk = chunks[i]; await Promise.all( - chunk.map((u) => { + chunk.map((u: User) => { return (async () => { if (!u.firstName) { const { firstName, lastName } = guessFirstandLastNameFromFullName( diff --git a/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/[mId]/reactions/index.ts b/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/[mId]/reactions/index.ts index 4945702ed8b2..5ad9f93a6077 100644 --- a/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/[mId]/reactions/index.ts +++ b/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/[mId]/reactions/index.ts @@ -118,7 +118,7 @@ async function handler( user: user, context: { username: user.username, - fullName: user.name, + fullName: user.fullName, }, reaction: bodyValidation.right.reaction, }); @@ -142,7 +142,7 @@ async function handler( user: user, context: { username: user.username, - fullName: user.name, + fullName: user.fullName, }, reaction: bodyValidation.right.reaction, }); diff --git a/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/index.ts b/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/index.ts index 124c4f0fc6de..66e21bc36ef8 100644 --- a/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/index.ts +++ b/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/index.ts @@ -118,7 +118,7 @@ async function handler( context: { timezone: context.timezone, username: user.username, - fullName: user.name, + fullName: user.fullName, email: user.email, profilePictureUrl: context.profilePictureUrl, }, diff --git a/front/pages/api/w/[wId]/assistant/conversations/index.ts b/front/pages/api/w/[wId]/assistant/conversations/index.ts index 79c1ebdee3e7..405ad68a1ef1 100644 --- a/front/pages/api/w/[wId]/assistant/conversations/index.ts +++ b/front/pages/api/w/[wId]/assistant/conversations/index.ts @@ -133,7 +133,7 @@ async function handler( context: { timezone: message.context.timezone, username: user.username, - fullName: user.name, + fullName: user.fullName, email: user.email, profilePictureUrl: message.context.profilePictureUrl, }, diff --git a/front/pages/api/w/[wId]/members/[userId]/index.ts b/front/pages/api/w/[wId]/members/[userId]/index.ts index 243024e48ee7..b2a99b13d03a 100644 --- a/front/pages/api/w/[wId]/members/[userId]/index.ts +++ b/front/pages/api/w/[wId]/members/[userId]/index.ts @@ -115,7 +115,9 @@ async function handler( providerId: user.providerId, username: user.username, email: user.email, - name: user.name, + firstName: user.firstName, + lastName: user.lastName, + fullName: user.firstName + (user.lastName ? ` ${user.lastName}` : ""), image: null, workspaces: [w], isDustSuperUser: user.isDustSuperUser, diff --git a/front/pages/poke/[wId]/memberships.tsx b/front/pages/poke/[wId]/memberships.tsx index 78fdfa767df2..94de9c276777 100644 --- a/front/pages/poke/[wId]/memberships.tsx +++ b/front/pages/poke/[wId]/memberships.tsx @@ -105,7 +105,7 @@ const MembershipsPage = ({ >

- {m.username} ({m.name}) + {m.username} ({m.fullName})

diff --git a/front/pages/w/[wId]/assistant/new.tsx b/front/pages/w/[wId]/assistant/new.tsx index 220f5d20c5d8..9e4c7a81446d 100644 --- a/front/pages/w/[wId]/assistant/new.tsx +++ b/front/pages/w/[wId]/assistant/new.tsx @@ -167,7 +167,7 @@ export default function AssistantNew({

{/* FEATURED AGENTS */} diff --git a/front/pages/w/[wId]/members/index.tsx b/front/pages/w/[wId]/members/index.tsx index e9e97321d11b..681bb7b4bcec 100644 --- a/front/pages/w/[wId]/members/index.tsx +++ b/front/pages/w/[wId]/members/index.tsx @@ -187,12 +187,12 @@ export default function WorkspaceAdmin({ | MembershipInvitationType )[] = [ ...members - .sort((a, b) => a.name.localeCompare(b.name)) + .sort((a, b) => a.fullName.localeCompare(b.fullName)) .filter((m) => m.workspaces[0].role !== "none") .filter( (m) => !searchText || - m.name.toLowerCase().includes(searchText.toLowerCase()) || + m.fullName.toLowerCase().includes(searchText.toLowerCase()) || m.email?.toLowerCase().includes(searchText.toLowerCase()) || m.username?.toLowerCase().includes(searchText.toLowerCase()) ), @@ -271,13 +271,17 @@ export default function WorkspaceAdmin({ {isInvitation(item) ? ( ) : ( - + )}
{!isInvitation(item) && (
- {item.name} + {item.fullName}
)} @@ -630,7 +634,7 @@ function ChangeMemberModal({ hasChanged={ selectedRole !== null && selectedRole !== member.workspaces[0].role } - title={member.name || "Unreachable"} + title={member.fullName || "Unreachable"} type="right-side" onSave={async () => { setIsSaving(true); @@ -647,9 +651,11 @@ function ChangeMemberModal({ >
- +
-
{member.name}
+
+ {member.fullName} +
{member.email}
@@ -706,7 +712,7 @@ function ChangeMemberModal({
Revoke access for user{" "} - {member.name}? + {member.fullName}?