Skip to content

Commit

Permalink
Requesting unapproved read-write Google Contacts API results in “App …
Browse files Browse the repository at this point in the history
…Not Verified”

We will have to make Google support read-only until the additional oauth scope is approved…
  • Loading branch information
bengotow committed Oct 14, 2019
1 parent 4d0c8bc commit 6543539
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Features:

**Incoming Message Translation**: Mailspring now offers to translate emails you receive in other languages. When you choose to translate an email, Mailspring sends the text of the message to a translation service (currently Yandex) and displays the result. Free users can translate up to 50 messages a week - Mailspring Pro removes the limit and allows you to "Automatically Translate" all messages in particular languages.

* Note: We're waiting on Google to approve Mailspring for access to the "Read-write Contacts" Oauth scope, so Gmail accounts will be read-only until ~December 2019.

**Contact Management**: Mailspring now includes a full-featured address book available from the `Window` menu! You can create, update, and delete contacts and contact groups in connected Google and CardDAV-compatible accounts (iCloud, FastMail and others.) Mailspring also allows you to turn off automatic suggestions based on your sent mail, and delete individual contact suggestions. When composing an email, you can now type the name of a group to insert all of the contacts in that group as recipients.

Fixes:
Expand Down
5 changes: 5 additions & 0 deletions app/internal_packages/contacts/lib/AddContactToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Store, ContactsPerspective } from './Store';
import { localized, Actions, AccountStore } from 'mailspring-exports';
import * as Icons from './SVGIcons';
import { ListensToFluxStore, BindGlobalCommands } from 'mailspring-component-kit';
import { showGPeopleReadonlyNotice } from './GoogleSupport';

interface AddContactToolbarProps {
editing: string | 'new' | false;
Expand All @@ -16,9 +17,13 @@ class AddContactToolbarWithData extends React.Component<AddContactToolbarProps>
}

onAdd = () => {
if (showGPeopleReadonlyNotice(this.props.perspective.accountId)) {
return;
}
Actions.setFocus({ collection: 'contact', item: null });
Store.setEditing('new');
};

render() {
const { editing, perspective } = this.props;
const enabled = editing === false && perspective && perspective.accountId;
Expand Down
24 changes: 22 additions & 2 deletions app/internal_packages/contacts/lib/ContactDetailToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Contact,
ChangeContactGroupMembershipTask,
} from 'mailspring-exports';
import { showGPeopleReadonlyNotice } from './GoogleSupport';

interface ContactDetailToolbarProps {
editing: string | 'new' | false;
Expand All @@ -32,6 +33,9 @@ class ContactDetailToolbarWithData extends React.Component<ContactDetailToolbarP
throw new Error('Remove from source but perspective is not a group');
return;
}
if (showGPeopleReadonlyNotice(this.props.perspective.accountId)) {
return;
}

const groupId = this.props.perspective.groupId;
const group = Store.groups().find(g => g.id === groupId);
Expand All @@ -45,7 +49,23 @@ class ContactDetailToolbarWithData extends React.Component<ContactDetailToolbarP
);
};

_onEdit = () => {
if (showGPeopleReadonlyNotice(this.props.perspective.accountId)) {
return;
}
const actionSet = this.actionSet();
Store.setEditing(actionSet[0].id);
};

_onDelete = () => {
const contacts = this.actionSet();
if (
contacts.some(c => c.source === 'gpeople') &&
showGPeopleReadonlyNotice(this.props.perspective.accountId)
) {
return;
}

Actions.queueTask(
DestroyContactTask.forRemoving({
contacts: this.actionSet(),
Expand Down Expand Up @@ -77,7 +97,7 @@ class ContactDetailToolbarWithData extends React.Component<ContactDetailToolbarP
commands['core:delete-item'] = this._onDelete;
}
if (editable) {
commands['core:edit-item'] = () => Store.setEditing(actionSet[0].id);
commands['core:edit-item'] = this._onEdit;
}

return (
Expand Down Expand Up @@ -105,7 +125,7 @@ class ContactDetailToolbarWithData extends React.Component<ContactDetailToolbarP
tabIndex={-1}
title={localized('Edit')}
className={`btn btn-toolbar ${!editable && 'btn-disabled'}`}
onClick={editable ? () => Store.setEditing(actionSet[0].id) : undefined}
onClick={editable ? this._onEdit : undefined}
>
{localized('Edit')}
</button>
Expand Down
21 changes: 19 additions & 2 deletions app/internal_packages/contacts/lib/ContactPerspectivesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
IOutlineViewItem,
} from 'mailspring-component-kit';
import { isEqual } from 'underscore';
import { showGPeopleReadonlyNotice } from './GoogleSupport';

interface ContactsPerspectivesProps {
accounts: Account[];
Expand Down Expand Up @@ -81,14 +82,26 @@ const OutlineViewForAccount = ({
selected: isEqual(selected, perspective),
onSelect: () => onSelect(perspective),
onEdited: (item, value: string) => {
if (showGPeopleReadonlyNotice(account.id)) {
return false;
}
Actions.queueTask(SyncbackContactGroupTask.forRenaming(group, value));
},
onDelete: () => {
if (showGPeopleReadonlyNotice(account.id)) {
return false;
}
Actions.queueTask(DestroyContactGroupTask.forRemoving(group));
},
onDrop: (item, { dataTransfer }) => {
const data = JSON.parse(dataTransfer.getData('mailspring-contacts-data'));
const contacts = data.ids.map(i => Store.filteredContacts().find(c => c.id === i));
if (!contacts.length) {
return false;
}
if (showGPeopleReadonlyNotice(contacts[0].accountId)) {
return false;
}
Actions.queueTask(
ChangeContactGroupMembershipTask.forMoving({
direction: 'add',
Expand All @@ -104,7 +117,6 @@ const OutlineViewForAccount = ({
if (isEqual(selected, perspective)) {
return false;
}

// We can't inspect the drag payload until drop, so we use a dataTransfer
// type to encode the account IDs of threads currently being dragged.
const accountsType = dataTransfer.types.find(t => t.startsWith('mailspring-accounts='));
Expand Down Expand Up @@ -138,7 +150,12 @@ const OutlineViewForAccount = ({
items={items}
onItemCreated={
books.length > 0
? name => Actions.queueTask(SyncbackContactGroupTask.forCreating(account.id, name))
? name => {
if (showGPeopleReadonlyNotice(account.id)) {
return false;
}
Actions.queueTask(SyncbackContactGroupTask.forCreating(account.id, name));
}
: undefined
}
/>
Expand Down
15 changes: 15 additions & 0 deletions app/internal_packages/contacts/lib/GoogleSupport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AccountStore } from 'mailspring-exports';
import { remote } from 'electron';

export const showGPeopleReadonlyNotice = (accountId: string) => {
const acct = AccountStore.accountForId(accountId);
if (acct && acct.provider === 'gmail') {
remote.dialog.showMessageBox({
message: 'Coming Soon for Google Accounts',
detail:
"We've added support for creating, updating and deleting contacts in Google accounts, but Google is still reviewing Mailspring's use of the Google People API so we're unable to sync these changes back to their servers. Stay tuned!",
});
return true;
}
return false;
};
1 change: 1 addition & 0 deletions app/internal_packages/contacts/lib/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class ContactsWindowStore extends MailspringStore {

this._filtered = null;
this._perspective = perspective;
this._search = '';

if (q.sql() !== this._contactsSubscription.query().sql()) {
this._contacts = [];
Expand Down
2 changes: 1 addition & 1 deletion app/internal_packages/onboarding/lib/onboarding-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const GMAIL_SCOPES = [
'https://www.googleapis.com/auth/userinfo.email', // email address
'https://www.googleapis.com/auth/userinfo.profile', // G+ profile
'https://mail.google.com/', // email
'https://www.googleapis.com/auth/contacts', // contacts
'https://www.googleapis.com/auth/contacts.readonly', // contacts
'https://www.googleapis.com/auth/calendar', // calendar
];

Expand Down

0 comments on commit 6543539

Please sign in to comment.