-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENG-4648] Opt out of SHARE indexing (#1998)
* Add allowIndexing attr to user model * Add opt-out panel to user-settings * Add test * Update wording * Use constructor; Match mirage default with BE default
- Loading branch information
1 parent
261ea17
commit 9722d5d
Showing
7 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Component from '@glimmer/component'; | ||
import { inject as service } from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import CurrentUserService from 'ember-osf-web/services/current-user'; | ||
import { restartableTask } from 'ember-concurrency'; | ||
import { waitFor } from '@ember/test-waiters'; | ||
import config from 'ember-get-config'; | ||
import IntlService from 'ember-intl/services/intl'; | ||
|
||
import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception'; | ||
|
||
const { support: { supportEmail } } = config; | ||
|
||
export default class OptOutComponent extends Component { | ||
@service currentUser!: CurrentUserService; | ||
@service intl!: IntlService; | ||
@service toast!: Toastr; | ||
|
||
@tracked indexingPreference?: boolean; | ||
|
||
get allowIndexingIsFalse() { | ||
// allowIndexing is null by default | ||
return this.currentUser.user?.allowIndexing === false; | ||
} | ||
|
||
constructor(owner: unknown, args: any) { | ||
super(owner, args); | ||
this.indexingPreference = this.currentUser.user?.allowIndexing; | ||
} | ||
|
||
@restartableTask | ||
@waitFor | ||
async updateIndexingPreference() { | ||
if (!this.currentUser.user) { | ||
return; | ||
} | ||
try { | ||
this.currentUser.user.allowIndexing = this.indexingPreference; | ||
await this.currentUser.user.save(); | ||
this.toast.success(this.intl.t('settings.account.opt-out.success')); | ||
} catch (e) { | ||
const errorMessage = this.intl.t( | ||
'settings.account.opt-out.error', | ||
{ supportEmail, htmlSafe: true }, | ||
); | ||
captureException(e, { errorMessage: errorMessage.toString() }); | ||
this.toast.error(getApiErrorMessage(e), errorMessage as string); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<Panel | ||
data-test-opt-out-panel | ||
data-analytics-scope='Indexing opt out panel' | ||
as |panel| | ||
> | ||
<panel.heading @title={{t 'settings.account.opt-out.title'}} /> | ||
<panel.body> | ||
<p data-test-opt-out-help-text> | ||
{{t 'settings.account.opt-out.description' htmlSafe=true}} | ||
</p> | ||
<label data-test-indexing-opt-out-label> | ||
<input | ||
name='indexingPreference' | ||
type='radio' | ||
value={{false}} | ||
checked={{this.allowIndexingIsFalse}} | ||
{{on 'click' (action (mut this.indexingPreference) false)}} | ||
/> | ||
{{t 'settings.account.opt-out.opt-out-label'}} | ||
</label> | ||
<br /> | ||
<label data-test-indexing-opt-in-label> | ||
<input | ||
name='indexingPreference' | ||
type='radio' | ||
value={{true}} | ||
checked={{this.indexingPreference}} | ||
{{on 'click' (action (mut this.indexingPreference) true)}} | ||
/> | ||
{{t 'settings.account.opt-out.opt-in-label'}} | ||
</label> | ||
<br /> | ||
<Button | ||
data-test-update-indexing-preference-button | ||
data-analytics-name='Submit' | ||
{{on 'click' (perform this.updateIndexingPreference)}} | ||
> | ||
{{t 'settings.account.opt-out.button-label'}} | ||
</Button> | ||
</panel.body> | ||
</Panel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/integration/routes/settings/account/-components/opt-out-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { TestContext } from 'ember-test-helpers'; | ||
import Service from '@ember/service'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { percySnapshot } from 'ember-percy'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { module, test } from 'qunit'; | ||
|
||
const currentUserStub = Service.extend({ | ||
user: { | ||
allowIndexing: null, | ||
}, | ||
}); | ||
|
||
module('Integration | routes | settings | account | -components | opt-out', hooks => { | ||
setupRenderingTest(hooks); | ||
|
||
test('default allowIndexing: null', async function(this: TestContext, assert) { | ||
this.owner.register('service:currentUser', currentUserStub); | ||
await render(hbs`<Settings::Account::-Components::OptOut />`); | ||
|
||
assert.dom('[data-test-opt-out-panel]').exists('opt-out panel exists'); | ||
assert.dom('[data-test-opt-out-panel] [data-test-panel-heading]') | ||
.hasText( | ||
'Opt out of SHARE indexing', | ||
'title is correct', | ||
); | ||
assert.dom('[data-test-opt-out-help-text]').exists('description exists'); | ||
assert.dom('[data-test-indexing-opt-out-label]').containsText( | ||
'Opt out of SHARE indexing', 'opt out label is correct', | ||
); | ||
assert.dom('[data-test-indexing-opt-in-label]').containsText( | ||
'Opt in to SHARE indexing', 'opt in label is correct', | ||
); | ||
assert.dom('[data-test-indexing-opt-out-label] input').isNotChecked('Opt out radio button is not checked'); | ||
assert.dom('[data-test-indexing-opt-in-label] input').isNotChecked('Opt in radio button is not checked'); | ||
assert.dom('[data-test-update-indexing-preference-button]').containsText( | ||
'Update', 'update button is correct', | ||
); | ||
await percySnapshot(assert); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters