Skip to content

Commit 584da77

Browse files
authored
[ENG-6267] Add the ability to turn off the "add a preprint" feature based on the admin section (#2551)
- Ticket: [ENG-6267] - Feature flag: n/a ## Purpose Updated the branded and non-branded preprint navbar to respect the `allowSubmission` attribute on a preprint provider ## Summary of Changes The Branded Navbar only needed an if statement (this demonstrated that the bug was for all providers and not just the OSF) On the non-branded navbar for just OSF needed the theme service injected to have the if statement work. [ENG-7799]: https://openscience.atlassian.net/browse/ENG-7799?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ [ENG-6267]: https://openscience.atlassian.net/browse/ENG-6267?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent aa39352 commit 584da77

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

lib/app-components/addon/components/branded-navbar/template.hbs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,18 @@
9797
</OsfLink>
9898
</li>
9999
{{/if}}
100-
<li>
101-
<OsfLink
102-
data-test-add-a-preprint-branded-navbar
103-
data-analytics-name='{{this.provider.id}}: add a {{this.provider.preprintWord}} link'
104-
@route='preprints.submit'
105-
@models={{array this.provider.id}}
106-
>
107-
<span role='button'>{{t 'navbar.add_a_preprint' preprintWord=this.provider.preprintWord}}</span>
108-
</OsfLink>
109-
</li>
100+
{{#if this.provider.allowSubmissions}}
101+
<li>
102+
<OsfLink
103+
data-test-add-a-preprint-branded-navbar
104+
data-analytics-name='{{this.provider.id}}: add a {{this.provider.preprintWord}} link'
105+
@route='preprints.submit'
106+
@models={{array this.provider.id}}
107+
>
108+
<span role='button'>{{t 'navbar.add_a_preprint' preprintWord=this.provider.preprintWord}}</span>
109+
</OsfLink>
110+
</li>
111+
{{/if}}
110112
{{/if}}
111113
<li>
112114
<a

lib/osf-components/addon/components/osf-navbar/preprint-links/component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import Component from '@glimmer/component';
22
import { inject as service } from '@ember/service';
33
import CurrentUserService from 'ember-osf-web/services/current-user';
44
import config from 'ember-osf-web/config/environment';
5+
import Theme from 'ember-osf-web/services/theme';
56

67
interface Args {
78
onLinkClicked: () => void;
89
}
910
export default class OsfNavbarPreprintLinks extends Component<Args> {
1011
@service currentUser!: CurrentUserService;
12+
@service theme!: Theme;
1113

1214
donateURL = `${config.OSF.donateUrl}`;
1315
supportURL = `${config.support.faqPageUrl}`;

lib/osf-components/addon/components/osf-navbar/preprint-links/template.hbs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818
</OsfLink>
1919
</li>
2020
{{/if}}
21-
<li data-test-nav-submit-preprint-link>
22-
<OsfLink
23-
data-test-add-a-preprint-osf-navbar
24-
data-analytics-name='Add a preprint'
25-
@route='preprints.select'
26-
{{on 'click' @onLinkClicked}}
27-
>
28-
{{t 'navbar.add_a_preprint' preprintWord=(t 'documentType.preprint.singularCapitalized')}}
29-
</OsfLink>
30-
</li>
21+
{{#if this.theme.provider.allowSubmissions}}
22+
<li data-test-nav-submit-preprint-link>
23+
<OsfLink
24+
data-test-add-a-preprint-osf-navbar
25+
data-analytics-name='Add a preprint'
26+
@route='preprints.select'
27+
{{on 'click' @onLinkClicked}}
28+
>
29+
{{t 'navbar.add_a_preprint' preprintWord=(t 'documentType.preprint.singularCapitalized')}}
30+
</OsfLink>
31+
</li>
32+
{{/if}}
3133
<li data-test-nav-search-link>
3234
<OsfLink
3335
@route='search'

tests/integration/components/osf-navbar/component-test.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const sessionStub = Service.extend({
2323
on: () => { /* stub */ },
2424
});
2525

26+
const themeStub = Service.extend({
27+
provider: {
28+
allowSubmissions: true,
29+
},
30+
});
31+
2632
module('Integration | Component | osf-navbar', hooks => {
2733
setupRenderingTest(hooks);
2834
setupIntl(hooks);
@@ -32,6 +38,7 @@ module('Integration | Component | osf-navbar', hooks => {
3238
this.owner.unregister('service:router');
3339
this.owner.register('service:router', routerStub);
3440
this.owner.register('service:session', sessionStub);
41+
this.owner.register('service:theme', themeStub);
3542
});
3643

3744
test('it renders', async function(assert) {
@@ -78,7 +85,7 @@ module('Integration | Component | osf-navbar', hooks => {
7885
await percySnapshot(assert);
7986
});
8087

81-
test('osf-navbar: preprints, no moderation', async function(assert) {
88+
test('osf-navbar: preprints, no moderation, allow submissions', async function(assert) {
8289
this.owner.lookup('service:session').set('isAuthenticated', true);
8390
this.owner.lookup('service:router').set('currentRouteName', 'preprints.place');
8491

@@ -96,8 +103,27 @@ module('Integration | Component | osf-navbar', hooks => {
96103
assert.dom('[data-test-nav-my-projects-link]').doesNotExist();
97104
});
98105

99-
test('osf-navbar: preprints with moderation', async function(assert) {
106+
test('osf-navbar: preprints, no moderation, submissions turned off', async function(assert) {
107+
this.owner.lookup('service:theme').set('provider', { allowSubmissions: false});
100108
this.owner.lookup('service:session').set('isAuthenticated', true);
109+
this.owner.lookup('service:router').set('currentRouteName', 'preprints.place');
110+
111+
await render(hbs`<OsfNavbar />`);
112+
113+
assert.dom('.service-name').includesText('OSF');
114+
assert.dom('.current-service').hasText('PREPRINTS');
115+
assert.dom('[data-test-nav-my-preprints-link]').exists();
116+
assert.dom('[data-test-nav-submit-preprint-link]').doesNotExist();
117+
assert.dom('[data-test-nav-reviews-link]').doesNotExist();
118+
119+
assert.dom('[data-test-nav-search-link]').exists();
120+
assert.dom('[data-test-nav-donate-link]').hasClass('navbar-donate-button');
121+
122+
assert.dom('[data-test-nav-my-projects-link]').doesNotExist();
123+
});
124+
125+
test('osf-navbar: preprints with moderation, allow submissions', async function(assert) {
126+
this.owner.lookup('service:session').set('isauthenticated', true);
101127
this.owner.lookup('service:router').set('currentRouteName', 'preprints.somewhere');
102128
// this.owner.register('service:current-user', currentUserStub);
103129
this.owner.lookup('service:current-user').set('user', { canViewReviews: true });

0 commit comments

Comments
 (0)