import app from "../../teamwork.app.mjs";
import { parseObject } from "../../common/utils.mjs";
export default {
type: "action",
key: "teamwork-create-user",
version: "0.0.1",
name: "Create User",
description: "Create a new user in Teamwork. [See the docs here](https://apidocs.teamwork.com/docs/teamwork/v1/people/post-people-json)",
props: {
app,
emailAddress: {
type: "string",
label: "Email Address",
description: "The email address of the person",
},
firstName: {
type: "string",
label: "First Name",
description: "The first name of the person",
},
lastName: {
type: "string",
label: "Last Name",
description: "The last name of the person",
},
companyId: {
propDefinition: [
app,
"companyId",
],
},
sendInvite: {
type: "boolean",
label: "Send Invite",
description: "Whether to send an invitation email to the new user",
optional: true,
},
title: {
type: "string",
label: "Title",
description: "The job title of the person",
optional: true,
},
phoneNumberOffice: {
type: "string",
label: "Office Phone",
description: "The office phone number of the person",
optional: true,
},
phoneNumberOfficeExt: {
type: "string",
label: "Office Phone Extension",
description: "The office phone extension of the person",
optional: true,
},
phoneNumberMobileCountrycode: {
type: "string",
label: "Mobile Phone Country Code",
description: "The country code for the mobile phone number",
optional: true,
},
phoneNumberMobilePrefix: {
type: "string",
label: "Mobile Phone Prefix",
description: "The prefix for the mobile phone number",
optional: true,
},
phoneNumberMobile: {
type: "string",
label: "Mobile Phone",
description: "The mobile phone number of the person",
optional: true,
},
phoneNumberHome: {
type: "string",
label: "Home Phone",
description: "The home phone number of the person",
optional: true,
},
phoneNumberFax: {
type: "string",
label: "Fax Number",
description: "The fax number of the person",
optional: true,
},
emailAlt1: {
type: "string",
label: "Alternative Email 1",
description: "First alternative email address",
optional: true,
},
emailAlt2: {
type: "string",
label: "Alternative Email 2",
description: "Second alternative email address",
optional: true,
},
emailAlt3: {
type: "string",
label: "Alternative Email 3",
description: "Third alternative email address",
optional: true,
},
address: {
type: "object",
label: "Address",
description: "Object containing address information. [See the documentation](https://apidocs.teamwork.com/docs/teamwork/v1/people/post-people-json) for more information.",
optional: true,
},
profile: {
type: "string",
label: "Profile",
description: "The profile information of the person",
optional: true,
},
userTwitterName: {
type: "string",
label: "Twitter Name",
description: "The Twitter handle of the person",
optional: true,
},
userLinkedin: {
type: "string",
label: "LinkedIn",
description: "The LinkedIn profile URL of the person",
optional: true,
},
userFacebook: {
type: "string",
label: "Facebook",
description: "The Facebook profile URL of the person",
optional: true,
},
userWebsite: {
type: "string",
label: "Website",
description: "The personal website of the person",
optional: true,
},
imService: {
type: "string",
label: "IM Service",
description: "The instant messaging service used by the person",
optional: true,
},
imHandle: {
type: "string",
label: "IM Handle",
description: "The instant messaging username of the person",
optional: true,
},
language: {
type: "string",
label: "Language",
description: "The language preference for the person",
optional: true,
},
dateFormatId: {
type: "integer",
label: "Date Format ID",
description: "The date format ID for the person",
optional: true,
},
timeFormatId: {
type: "integer",
label: "Time Format ID",
description: "The time format ID for the person",
optional: true,
},
timezoneId: {
type: "integer",
label: "Timezone ID",
description: "The timezone ID for the person",
optional: true,
},
calendarStartsOnSunday: {
type: "string",
label: "Calendar Starts On Sunday",
description: "Whether the calendar starts on Sunday",
optional: true,
},
lengthOfDay: {
type: "integer",
label: "Length of Day",
description: "The length of day in hours",
optional: true,
},
workingHours: {
type: "object",
label: "Working Hours",
description: "Object containing working hours information. . [See the documentation](https://apidocs.teamwork.com/docs/teamwork/v1/people/post-people-json) for more information.",
optional: true,
},
changeForEveryone: {
type: "boolean",
label: "Change For Everyone",
description: "Whether changes apply to everyone",
optional: true,
},
administrator: {
type: "boolean",
label: "Administrator",
description: "Whether the person is an administrator",
optional: true,
},
canAddProjects: {
type: "boolean",
label: "Can Add Projects",
description: "Whether the person can add projects",
optional: true,
},
canManagePeople: {
type: "boolean",
label: "Can Manage People",
description: "Whether the person can manage people",
optional: true,
},
autoGiveProjectAccess: {
type: "boolean",
label: "Auto Give Project Access",
description: "Whether to automatically give the person access to new projects",
optional: true,
},
canAccessCalendar: {
type: "boolean",
label: "Can Access Calendar",
description: "Whether the person can access the calendar",
optional: true,
},
canAccessTemplates: {
type: "boolean",
label: "Can Access Templates",
description: "Whether the person can access templates",
optional: true,
},
canAccessPortfolio: {
type: "boolean",
label: "Can Access Portfolio",
description: "Whether the person can access the portfolio",
optional: true,
},
canManageCustomFields: {
type: "boolean",
label: "Can Manage Custom Fields",
description: "Whether the person can manage custom fields",
optional: true,
},
canManagePortfolio: {
type: "boolean",
label: "Can Manage Portfolio",
description: "Whether the person can manage the portfolio",
optional: true,
},
canManageProjectTemplates: {
type: "boolean",
label: "Can Manage Project Templates",
description: "Whether the person can manage project templates",
optional: true,
},
canViewProjectTemplates: {
type: "boolean",
label: "Can View Project Templates",
description: "Whether the person can view project templates",
optional: true,
},
notifyOnTaskComplete: {
type: "boolean",
label: "Notify On Task Complete",
description: "Whether to notify when tasks are completed",
optional: true,
},
notifyOnAddedAsFollower: {
type: "boolean",
label: "Notify On Added As Follower",
description: "Whether to notify when added as a follower",
optional: true,
},
notifyOnStatusUpdate: {
type: "boolean",
label: "Notify On Status Update",
description: "Whether to notify on status updates",
optional: true,
},
textFormat: {
type: "string",
label: "Text Format",
description: "The text format preference",
optional: true,
},
useShorthandDurations: {
type: "boolean",
label: "Use Shorthand Durations",
description: "Whether to use shorthand durations",
optional: true,
},
userReceiveNotifyWarnings: {
type: "boolean",
label: "User Receive Notify Warnings",
description: "Whether the user receives notification warnings",
optional: true,
},
userReceiveMyNotificationsOnly: {
type: "boolean",
label: "User Receive My Notifications Only",
description: "Whether the user receives only their own notifications",
optional: true,
},
receiveDailyReports: {
type: "boolean",
label: "Receive Daily Reports",
description: "Whether the person should receive daily reports",
optional: true,
},
receiveDailyReportsAtWeekend: {
type: "boolean",
label: "Receive Daily Reports At Weekend",
description: "Whether to receive daily reports on weekends",
optional: true,
},
receiveDailyReportsIfEmpty: {
type: "boolean",
label: "Receive Daily Reports If Empty",
description: "Whether to receive daily reports even if empty",
optional: true,
},
soundAlertsEnabled: {
type: "boolean",
label: "Sound Alerts Enabled",
description: "Whether sound alerts are enabled",
optional: true,
},
dailyReportSort: {
type: "string",
label: "Daily Report Sort",
description: "The sort order for daily reports",
optional: true,
},
receiveDailyReportsAtTime: {
type: "string",
label: "Receive Daily Reports At Time",
description: "The time to receive daily reports",
optional: true,
},
dailyReportEventsType: {
type: "string",
label: "Daily Report Events Type",
description: "The type of events for daily reports",
optional: true,
},
dailyReportDaysFilter: {
type: "integer",
label: "Daily Report Days Filter",
description: "The days filter for daily reports",
optional: true,
},
avatarPendingFileRef: {
type: "string",
label: "Avatar Pending File Ref",
description: "Reference to pending avatar file",
optional: true,
},
removeAvatar: {
type: "boolean",
label: "Remove Avatar",
description: "Whether to remove the avatar",
optional: true,
},
allowEmailNotifications: {
type: "boolean",
label: "Allow Email Notifications",
description: "Whether to allow email notifications",
optional: true,
},
userType: {
type: "string",
label: "User Type",
description: "The type of user (account, collaborator, contact)",
optional: true,
options: [
{
label: "Account",
value: "account",
},
{
label: "Collaborator",
value: "collaborator",
},
{
label: "Contact",
value: "contact",
},
],
},
privateNotes: {
type: "string",
label: "Private Notes",
description: "Private notes about the person",
optional: true,
},
getUserDetails: {
type: "boolean",
label: "Get User Details",
description: "Whether to return user details in the response",
optional: true,
},
},
async run({ $ }) {
const data = {
"email-address": this.emailAddress,
"first-name": this.firstName,
"last-name": this.lastName,
"company-id": this.companyId,
"sendInvite": this.sendInvite,
"title": this.title,
"phone-number-office": this.phoneNumberOffice,
"phone-number-office-ext": this.phoneNumberOfficeExt,
"phone-number-mobile-countrycode": this.phoneNumberMobileCountrycode,
"phone-number-mobile-prefix": this.phoneNumberMobilePrefix,
"phone-number-mobile": this.phoneNumberMobile,
"phone-number-home": this.phoneNumberHome,
"phone-number-fax": this.phoneNumberFax,
"email-alt-1": this.emailAlt1,
"email-alt-2": this.emailAlt2,
"email-alt-3": this.emailAlt3,
"address": parseObject(this.address),
"profile": this.profile,
"userTwitterName": this.userTwitterName,
"userLinkedin": this.userLinkedin,
"userFacebook": this.userFacebook,
"userWebsite": this.userWebsite,
"im-service": this.imService,
"im-handle": this.imHandle,
"language": this.language,
"dateFormatId": this.dateFormatId,
"timeFormatId": this.timeFormatId,
"timezoneId": this.timezoneId,
"calendarStartsOnSunday": this.calendarStartsOnSunday,
"lengthOfDay": this.lengthOfDay,
"workingHours": parseObject(this.workingHours),
"changeForEveryone": this.changeForEveryone,
"administrator": this.administrator,
"canAddProjects": this.canAddProjects,
"canManagePeople": this.canManagePeople,
"autoGiveProjectAccess": this.autoGiveProjectAccess,
"canAccessCalendar": this.canAccessCalendar,
"canAccessTemplates": this.canAccessTemplates,
"canAccessPortfolio": this.canAccessPortfolio,
"canManageCustomFields": this.canManageCustomFields,
"canManagePortfolio": this.canManagePortfolio,
"canManageProjectTemplates": this.canManageProjectTemplates,
"canViewProjectTemplates": this.canViewProjectTemplates,
"notifyOnTaskComplete": this.notifyOnTaskComplete,
"notify-on-added-as-follower": this.notifyOnAddedAsFollower,
"notify-on-status-update": this.notifyOnStatusUpdate,
"textFormat": this.textFormat,
"useShorthandDurations": this.useShorthandDurations,
"userReceiveNotifyWarnings": this.userReceiveNotifyWarnings,
"userReceiveMyNotificationsOnly": this.userReceiveMyNotificationsOnly,
"receiveDailyReports": this.receiveDailyReports,
"receiveDailyReportsAtWeekend": this.receiveDailyReportsAtWeekend,
"receiveDailyReportsIfEmpty": this.receiveDailyReportsIfEmpty,
"soundAlertsEnabled": this.soundAlertsEnabled,
"dailyReportSort": this.dailyReportSort,
"receiveDailyReportsAtTime": this.receiveDailyReportsAtTime,
"dailyReportEventsType": this.dailyReportEventsType,
"dailyReportDaysFilter": this.dailyReportDaysFilter,
"avatarPendingFileRef": this.avatarPendingFileRef,
"removeAvatar": this.removeAvatar,
"allowEmailNotifications": this.allowEmailNotifications,
"user-type": this.userType,
"privateNotes": this.privateNotes,
"getUserDetails": this.getUserDetails,
};
Object.keys(data).forEach((key) => {
if (data[key] === undefined) {
delete data[key];
}
});
const response = await this.app.createPerson(data, $);
$.export("$summary", `User ${this.firstName} ${this.lastName} created successfully`);
return response;
},
};