Skip to content

Commit

Permalink
Merge pull request #74 from Zimbra/PREAPPS-1199
Browse files Browse the repository at this point in the history
PREAPPS-1199: Adding external account broken, failed due to "t.zimbra.account.addExternal is not a function" error
  • Loading branch information
silentsakky authored Oct 5, 2018
2 parents 0b065eb + 551ed4c commit 5e8dd6f
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 20 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions src/batch-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import {
CalendarItemInput,
CreateContactInput,
CreateMountpointInput,
ExternalAccountAddInput,
ExternalAccountImportInput,
ExternalAccountTestInput,
FilterInput,
FolderView,
InviteReplyInput,
Expand All @@ -69,6 +72,8 @@ import {
ChangePasswordOptions,
CreateFolderOptions,
CreateSearchFolderOptions,
ExternalAccountDeleteInput,
ExternalAccountModifyInput,
FreeBusyOptions,
GetContactFrequencyOptions,
GetContactOptions,
Expand Down Expand Up @@ -162,6 +167,17 @@ export class ZimbraBatchClient {
});
};

public addExternalAccount = ({
accountType,
...accountInfo
}: ExternalAccountAddInput) =>
this.jsonRequest({
name: 'CreateDataSource',
body: {
[<string>accountType]: mapValuesDeep(accountInfo, coerceBooleanToString)
}
}).then(res => get(res, `${accountType}.0.id`));

public autoComplete = (options: AutoCompleteOptions) =>
this.jsonRequest({
name: 'AutoComplete',
Expand Down Expand Up @@ -295,6 +311,14 @@ export class ZimbraBatchClient {
}
});

public deleteExternalAccount = ({ id }: ExternalAccountDeleteInput) =>
this.jsonRequest({
name: 'DeleteDataSource',
body: {
dsrc: { id }
}
});

public deleteSignature = (options: SignatureInput) =>
this.jsonRequest({
name: 'DeleteSignature',
Expand Down Expand Up @@ -459,6 +483,19 @@ export class ZimbraBatchClient {
namespace: Namespace.Account
});

public importExternalAccount = ({
accountType,
id
}: ExternalAccountImportInput) =>
this.jsonRequest({
name: 'ImportData',
body: {
[<string>accountType]: {
id
}
}
});

public itemAction = (options: ActionOptions) =>
this.action(ActionType.item, options);

Expand Down Expand Up @@ -544,6 +581,21 @@ export class ZimbraBatchClient {
}).then(res => normalize(Contact)(res.cn[0]));
};

public modifyExternalAccount = ({
id,
type: accountType,
attrs
}: ExternalAccountModifyInput) =>
this.jsonRequest({
name: 'ModifyDataSource',
body: {
[<string>accountType]: {
id,
...mapValuesDeep(attrs, coerceBooleanToString)
}
}
});

public modifyFilterRules = (filters: Array<FilterInput>) =>
this.jsonRequest({
name: 'ModifyFilterRules',
Expand Down Expand Up @@ -723,6 +775,19 @@ export class ZimbraBatchClient {
}
}).then(res => normalize(Folder)(res.folder[0].folder));

public testExternalAccount = ({
accountType,
...accountInfo
}: ExternalAccountTestInput) =>
this.jsonRequest({
name: 'TestDataSource',
body: {
[<string>accountType]: mapValuesDeep(accountInfo, coerceBooleanToString)
}
}).then(res =>
mapValuesDeep(get(res, `${accountType}.0`), coerceStringToBoolean)
);

public uploadMessage = (message: string) => {
const contentDisposition = 'attachment';
const filename = 'message.eml';
Expand Down
12 changes: 12 additions & 0 deletions src/batch-client/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
AccountType,
Cursor,
ExternalAccountModifyAttrsInput,
FolderView,
SearchType,
SortBy
Expand Down Expand Up @@ -209,3 +211,13 @@ export interface RecoverAccountOptions {
export interface ResetPasswordOptions {
password: string;
}

export interface ExternalAccountModifyInput {
attrs: ExternalAccountModifyAttrsInput;
id: string;
type?: AccountType;
}

export interface ExternalAccountDeleteInput {
id: string;
}
33 changes: 31 additions & 2 deletions src/schema/generated-schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ export interface ShareInfo {

export interface Mutation {
action?: boolean | null;
testExternalAccount?: ExternalAccountTestResponse | null;
addExternalAccount?: string | null;
cancelTask?: boolean | null;
changeCalendarColor?: boolean | null;
Expand All @@ -987,14 +988,15 @@ export interface Mutation {
createSignature?: SignatureResponse | null;
createTask?: boolean | null;
deleteAppointment?: boolean | null;
deleteExternalAccount?: string | null;
deleteExternalAccount?: boolean | null;
deleteSignature?: string | null;
folderAction?: boolean | null;
itemAction?: boolean | null;
importExternalAccount?: boolean | null;
logout?: boolean | null;
login?: AuthResponse | null;
messageAction?: boolean | null;
modifyExternalAccount?: string | null;
modifyExternalAccount?: boolean | null;
modifyAppointment?: ModifyAppointmentResponse | null;
modifyIdentity?: string | null;
modifyPrefs?: boolean | null;
Expand Down Expand Up @@ -1024,6 +1026,11 @@ export interface Mutation {
setRecoveryAccount?: boolean | null;
}

export interface ExternalAccountTestResponse {
success: boolean;
error?: string | null;
}

export interface SignatureResponse {
signature?: NameId[] | null;
}
Expand Down Expand Up @@ -1122,6 +1129,17 @@ export interface Cursor {
includeOffset?: boolean | null;
}

export interface ExternalAccountTestInput {
accountType?: AccountType | null;
connectionType?: ConnectionType | null;
emailAddress?: string | null;
host: string;
leaveOnServer?: boolean | null;
port: string;
username: string;
password: string;
}

export interface ExternalAccountAddInput {
accountType?: AccountType | null;
connectionType?: ConnectionType | null;
Expand Down Expand Up @@ -1401,6 +1419,11 @@ export interface GrantInput {
zimbraId?: string | null;
}

export interface ExternalAccountImportInput {
accountType?: AccountType | null;
id: string;
}

export interface ExternalAccountModifyAttrsInput {
id?: string | null;
accountType?: AccountType | null;
Expand Down Expand Up @@ -1872,6 +1895,9 @@ export interface ActionMutationArgs {
tagNames?: string | null;
name?: string | null;
}
export interface TestExternalAccountMutationArgs {
externalAccount: ExternalAccountTestInput;
}
export interface AddExternalAccountMutationArgs {
externalAccount: ExternalAccountAddInput;
}
Expand Down Expand Up @@ -1965,6 +1991,9 @@ export interface ItemActionMutationArgs {
folderId?: string | null;
op: string;
}
export interface ImportExternalAccountMutationArgs {
externalAccount: ExternalAccountImportInput;
}
export interface LoginMutationArgs {
username: string;
password?: string | null;
Expand Down
29 changes: 26 additions & 3 deletions src/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,11 @@ type CalendarItemHitInfo { # <appt>; aka AppointmentHitInfo
aid: String
}

type ExternalAccountTestResponse {
success: Boolean!
error: String
}

input ExternalAccount {
id: ID!
name: String!
Expand Down Expand Up @@ -1855,6 +1860,17 @@ input ExternalAccountAddInput {
username: String!
}

input ExternalAccountTestInput {
accountType: AccountType
connectionType: ConnectionType
emailAddress: String
host: String!
leaveOnServer: Boolean
port: String!
username: String!
password: String!
}

input ExternalAccountModifyAttrsInput {
id: ID
accountType: AccountType
Expand All @@ -1879,6 +1895,11 @@ input ExternalAccountModifyAttrsInput {
smtpPort: String
}

input ExternalAccountImportInput {
accountType: AccountType
id: ID!
}

# Include one of these fields to query for a folder
input GetFolderFolderInput {
uuid: ID
Expand Down Expand Up @@ -2074,7 +2095,8 @@ type Mutation {
tagNames: String,
name: String
): Boolean
addExternalAccount(externalAccount: ExternalAccountAddInput!): String
testExternalAccount(externalAccount: ExternalAccountTestInput!): ExternalAccountTestResponse
addExternalAccount(externalAccount: ExternalAccountAddInput!): ID
cancelTask(inviteId: ID!): Boolean
changeCalendarColor(id: String!, color: Int!): Boolean
changePassword(
Expand Down Expand Up @@ -2118,10 +2140,11 @@ type Mutation {
): SignatureResponse
createTask(task: CalendarItemInput!): Boolean
deleteAppointment(inviteId: String!): Boolean
deleteExternalAccount(id: ID!): String
deleteExternalAccount(id: ID!): Boolean
deleteSignature(signature: NameIdInput!): String
folderAction(action: FolderActionInput!): Boolean
itemAction(id: ID, ids: [ID], folderId: ID, op: String!): Boolean
importExternalAccount(externalAccount: ExternalAccountImportInput!): Boolean
logout: Boolean
login(username: String!, password: String, recoveryCode: String, tokenType: String): AuthResponse
messageAction(
Expand All @@ -2132,7 +2155,7 @@ type Mutation {
id: ID!
type: AccountType
attrs: ExternalAccountModifyAttrsInput!
): String
): Boolean
modifyAppointment(accountName: String, appointment: CalendarItemInput!): ModifyAppointmentResponse
modifyIdentity(id: ID!, attrs: IdentityAttrsInput!): String
modifyPrefs(prefs: PreferencesInput!): Boolean
Expand Down
31 changes: 19 additions & 12 deletions src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
CalendarItemInput,
CreateContactInput,
CreateMountpointInput,
ExternalAccountAddInput,
ExternalAccountImportInput,
ExternalAccountTestInput,
FilterInput,
FolderView,
InviteReplyInput,
Expand Down Expand Up @@ -33,6 +36,8 @@ import {
ChangePasswordOptions,
CreateFolderOptions,
CreateSearchFolderOptions,
ExternalAccountDeleteInput,
ExternalAccountModifyInput,
FreeBusyOptions,
GetContactFrequencyOptions,
GetContactOptions,
Expand Down Expand Up @@ -230,18 +235,20 @@ export function createZimbraSchema(
client.sendShareNotification(
shareNotification as ShareNotificationInput
),
addExternalAccount: (_, { externalAccount }, { zimbra }) =>
zimbra.account
.addExternal({
externalAccount
})
.then((id?: string) => {
if (id !== undefined) return id;
}),
modifyExternalAccount: (_, { id, type, attrs }, { zimbra }) =>
zimbra.account.modifyExternal(id, type, attrs),
deleteExternalAccount: (_, { id }, { zimbra }) =>
zimbra.account.deleteExternal({ id }),
testExternalAccount: (_, { externalAccount }) =>
client.testExternalAccount(
externalAccount as ExternalAccountTestInput
),
addExternalAccount: (_, { externalAccount }) =>
client.addExternalAccount(externalAccount as ExternalAccountAddInput),
modifyExternalAccount: (_, variables) =>
client.modifyExternalAccount(variables as ExternalAccountModifyInput),
deleteExternalAccount: (_, variables) =>
client.deleteExternalAccount(variables as ExternalAccountDeleteInput),
importExternalAccount: (_, { externalAccount }) =>
client.importExternalAccount(
externalAccount as ExternalAccountImportInput
),
prefEnableOutOfOfficeAlertOnLogin: (_, { value }) =>
client
.modifyPrefs({
Expand Down

0 comments on commit 5e8dd6f

Please sign in to comment.