diff --git a/app/components/canny-feedback-script.js b/app/components/canny-feedback-script.js deleted file mode 100644 index 3a7f8995cb..0000000000 --- a/app/components/canny-feedback-script.js +++ /dev/null @@ -1,29 +0,0 @@ -import Component from '@ember/component'; -import { get } from '@ember/object'; - -export default Component.extend({ - didInsertElement() { - this._super(...arguments); - this._createCannyElement(); - }, - - _createCannyElement() { - const element = document.createElement('script'); - const content = document.createTextNode(` - Canny('render', ${JSON.stringify(this._cannyObject())}); - `); - element.appendChild(content); - get(this, 'element').appendChild(element); - }, - - _cannyObject() { - const baseObject = { - basePath: get(this, 'path'), - boardToken: get(this, 'boardToken') - }; - if (get(this, 'session.hasUser')) { - baseObject.ssoToken = get(this, 'token'); - } - return baseObject; - } -}); diff --git a/app/components/nolt-feedback-script.js b/app/components/nolt-feedback-script.js new file mode 100644 index 0000000000..1dd3ffec08 --- /dev/null +++ b/app/components/nolt-feedback-script.js @@ -0,0 +1,13 @@ +/* eslint no-undef: "off" */ +import Component from '@ember/component'; + +export default Component.extend({ + didInsertElement() { + this._super(...arguments); + + nolt('init', { + selector: '.nolt-button', + url: 'https://kitsu.nolt.io/', + }); + }, +}); diff --git a/app/gql/queries/noltToken.gql b/app/gql/queries/noltToken.gql new file mode 100644 index 0000000000..70891dcec0 --- /dev/null +++ b/app/gql/queries/noltToken.gql @@ -0,0 +1,5 @@ +query noltToken { + session { + noltToken + } +} diff --git a/app/initializers/browser-scripts.js b/app/initializers/browser-scripts.js index c6c58432b9..c822f067fe 100644 --- a/app/initializers/browser-scripts.js +++ b/app/initializers/browser-scripts.js @@ -13,15 +13,14 @@ function adwords() { } /** - * Inject Canny's SDK script into the `head` on initialization. + * Inject Nolt's SDK script into the `head` on initialization. */ -function canny() { - const c = function() { - c.q.push(arguments); +function nolt() { + window.noltQueue = window.noltQueue || []; + window.nolt = function() { + noltQueue.push(arguments); /* eslint no-undef: "off" */ }; - c.q = []; - window.Canny = c; - injectScript('https://canny.io/sdk.js').catch(() => {}); + injectScript('https://cdn.nolt.io/widgets.js').catch(() => {}); } /** @@ -61,7 +60,7 @@ export function initialize() { // Inject scripts adwords(); - canny(); + nolt(); onesignal(); } diff --git a/app/router.js b/app/router.js index d4ffff0cd2..147a661db4 100644 --- a/app/router.js +++ b/app/router.js @@ -116,19 +116,6 @@ RouterInstance.map(function() { this.route('account'); }); - this.route('feedback', function() { - this.route('bugs'); - this.route('bugs-anything', { path: '/bugs/*path' }); - this.route('feature-requests'); - this.route('feature-requests-anything', { path: '/feature-requests/*path' }); - this.route('database-requests'); - this.route('database-requests-anything', { path: '/database-requests/*path' }); - this.route('mobile-bugs'); - this.route('mobile-bugs-anything', { path: '/mobile-bugs/*path' }); - this.route('mobile-features'); - this.route('mobile-features-anything', { path: '/mobile-features/*path' }); - }); - this.route('admin', function() { this.route('reports', function() { this.route('index', { path: '/open' }); diff --git a/app/routes/application.js b/app/routes/application.js index 86a7a37691..03e7fb73a7 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -9,6 +9,7 @@ import preferredLocale from 'preferred-locale'; import { LANGUAGE_CODES } from 'client/utils/languages'; import momentLocale from 'client/utils/languages-moment'; import config from 'client/config/environment'; +import noltTokenQuery from 'client/gql/queries/noltToken'; export default Route.extend(ApplicationRouteMixin, { features: service(), @@ -18,6 +19,7 @@ export default Route.extend(ApplicationRouteMixin, { metrics: service(), moment: service(), raven: service(), + apollo: service(), cache: storageFor('last-used'), local: storageFor('local-cache'), @@ -150,6 +152,9 @@ export default Route.extend(ApplicationRouteMixin, { this._loadTheme(user); get(this, 'moment').changeTimeZone(get(user, 'timeZone') || moment.tz.guess()); + // nolt + this._setupNolt(); + // notifications this._registerNotifications(); @@ -172,6 +177,15 @@ export default Route.extend(ApplicationRouteMixin, { }); }, + _setupNolt() { + get(this, 'apollo').query({ query: noltTokenQuery }, 'session').then(({ noltToken }) => { + // eslint-disable-next-line no-undef + nolt('identify', { + jwt: noltToken, + }); + }).catch(() => {}); + }, + _registerNotifications() { if (get(this, 'session.account.feedCompleted')) { window.OneSignal.push(() => { diff --git a/app/routes/feedback.js b/app/routes/feedback.js deleted file mode 100644 index 8e2236bad4..0000000000 --- a/app/routes/feedback.js +++ /dev/null @@ -1,20 +0,0 @@ -import Route from '@ember/routing/route'; -import { get } from '@ember/object'; -import { inject as service } from '@ember/service'; - -export default Route.extend({ - ajax: service(), - - model() { - if (!get(this, 'session.hasUser')) { - return {}; - } - return get(this, 'ajax').request('/sso/canny'); - }, - - afterModel(_model, transition) { - if (get(transition, 'targetName') === 'feedback.index') { - return this.transitionTo('feedback.bugs'); - } - } -}); diff --git a/app/routes/feedback/bugs-anything.js b/app/routes/feedback/bugs-anything.js deleted file mode 100644 index c2fab0b472..0000000000 --- a/app/routes/feedback/bugs-anything.js +++ /dev/null @@ -1,12 +0,0 @@ -import BugsRoute from 'client/routes/feedback/bugs'; -import { get } from '@ember/object'; -import { inject as service } from '@ember/service'; - -export default BugsRoute.extend({ - templateName: 'feedback/bugs', - intl: service(), - - titleToken() { - return get(this, 'intl').t('titles.feedback.bugs'); - } -}); diff --git a/app/routes/feedback/bugs.js b/app/routes/feedback/bugs.js deleted file mode 100644 index b63b918e20..0000000000 --- a/app/routes/feedback/bugs.js +++ /dev/null @@ -1,7 +0,0 @@ -import Route from '@ember/routing/route'; - -export default Route.extend({ - model() { - return this.modelFor('feedback'); - } -}); diff --git a/app/routes/feedback/database-requests-anything.js b/app/routes/feedback/database-requests-anything.js deleted file mode 100644 index 2e6bc80c6c..0000000000 --- a/app/routes/feedback/database-requests-anything.js +++ /dev/null @@ -1,12 +0,0 @@ -import FeatureRoute from 'client/routes/feedback/feature-requests'; -import { get } from '@ember/object'; -import { inject as service } from '@ember/service'; - -export default FeatureRoute.extend({ - templateName: 'feedback/database-requests', - intl: service(), - - titleToken() { - return get(this, 'intl').t('titles.feedback.database-requests'); - } -}); diff --git a/app/routes/feedback/database-requests.js b/app/routes/feedback/database-requests.js deleted file mode 100644 index b63b918e20..0000000000 --- a/app/routes/feedback/database-requests.js +++ /dev/null @@ -1,7 +0,0 @@ -import Route from '@ember/routing/route'; - -export default Route.extend({ - model() { - return this.modelFor('feedback'); - } -}); diff --git a/app/routes/feedback/feature-requests-anything.js b/app/routes/feedback/feature-requests-anything.js deleted file mode 100644 index d3a1d3599a..0000000000 --- a/app/routes/feedback/feature-requests-anything.js +++ /dev/null @@ -1,12 +0,0 @@ -import FeatureRoute from 'client/routes/feedback/feature-requests'; -import { get } from '@ember/object'; -import { inject as service } from '@ember/service'; - -export default FeatureRoute.extend({ - templateName: 'feedback/feature-requests', - intl: service(), - - titleToken() { - return get(this, 'intl').t('titles.feedback.feature-requests'); - } -}); diff --git a/app/routes/feedback/feature-requests.js b/app/routes/feedback/feature-requests.js deleted file mode 100644 index b63b918e20..0000000000 --- a/app/routes/feedback/feature-requests.js +++ /dev/null @@ -1,7 +0,0 @@ -import Route from '@ember/routing/route'; - -export default Route.extend({ - model() { - return this.modelFor('feedback'); - } -}); diff --git a/app/routes/feedback/mobile-bugs-anything.js b/app/routes/feedback/mobile-bugs-anything.js deleted file mode 100644 index fa0591094d..0000000000 --- a/app/routes/feedback/mobile-bugs-anything.js +++ /dev/null @@ -1,12 +0,0 @@ -import MobileRoute from 'client/routes/feedback/mobile-bugs'; -import { get } from '@ember/object'; -import { inject as service } from '@ember/service'; - -export default MobileRoute.extend({ - templateName: 'feedback/mobile-bugs', - intl: service(), - - titleToken() { - return get(this, 'intl').t('titles.feedback.mobile-bugs'); - } -}); diff --git a/app/routes/feedback/mobile-bugs.js b/app/routes/feedback/mobile-bugs.js deleted file mode 100644 index b63b918e20..0000000000 --- a/app/routes/feedback/mobile-bugs.js +++ /dev/null @@ -1,7 +0,0 @@ -import Route from '@ember/routing/route'; - -export default Route.extend({ - model() { - return this.modelFor('feedback'); - } -}); diff --git a/app/routes/feedback/mobile-features-anything.js b/app/routes/feedback/mobile-features-anything.js deleted file mode 100644 index 447d216c28..0000000000 --- a/app/routes/feedback/mobile-features-anything.js +++ /dev/null @@ -1,12 +0,0 @@ -import MobileRoute from 'client/routes/feedback/mobile-features'; -import { get } from '@ember/object'; -import { inject as service } from '@ember/service'; - -export default MobileRoute.extend({ - templateName: 'feedback/mobile-features', - intl: service(), - - titleToken() { - return get(this, 'intl').t('titles.feedback.mobile-features'); - } -}); diff --git a/app/routes/feedback/mobile-features.js b/app/routes/feedback/mobile-features.js deleted file mode 100644 index b63b918e20..0000000000 --- a/app/routes/feedback/mobile-features.js +++ /dev/null @@ -1,7 +0,0 @@ -import Route from '@ember/routing/route'; - -export default Route.extend({ - model() { - return this.modelFor('feedback'); - } -}); diff --git a/app/services/ajax.js b/app/services/ajax.js index ddf33e7ede..f9d377529c 100644 --- a/app/services/ajax.js +++ b/app/services/ajax.js @@ -13,14 +13,13 @@ export default AjaxService.extend({ set(this, 'host', config.kitsu.APIHost); }, - headers: computed('session.isAuthenticated', function() { + headers: computed('session.token', function() { const headers = { accept: 'application/vnd.api+json' }; - const isAuthenticated = get(this, 'session.isAuthenticated'); - if (isAuthenticated) { - const { access_token: accessToken } = get(this, 'session.data.authenticated'); - headers.Authorization = `Bearer ${accessToken}`; + const token = get(this, 'session.token'); + if (token) { + headers.Authorization = `Bearer ${token}`; } return headers; }).readOnly() diff --git a/app/services/apollo.js b/app/services/apollo.js new file mode 100644 index 0000000000..7133fe1bc7 --- /dev/null +++ b/app/services/apollo.js @@ -0,0 +1,22 @@ +import { computed, get } from '@ember/object'; +import { inject as service } from '@ember/service'; +import ApolloService from 'ember-apollo-client/services/apollo'; +import { setContext } from 'apollo-link-context'; + +export default ApolloService.extend({ + session: service(), + + link: computed('session.token', function() { + const httpLink = this._super(...arguments); + + const token = get(this, 'session.token'); + + const authLink = setContext(() => { + if (!token) return {}; + + return { headers: { Authorization: `Bearer ${token}` } }; + }); + + return authLink.concat(httpLink); + }) +}); diff --git a/app/services/session.js b/app/services/session.js index 292bcbf2a3..3381e2f85c 100644 --- a/app/services/session.js +++ b/app/services/session.js @@ -35,6 +35,15 @@ export default Session.extend({ return sessionId === userId; }, + /** + * Get the access token. Returns undefined when not authenticated. + */ + token: computed('isAuthenticated', 'data.authenticated', function() { + if (!this.isAuthenticated) return; + + return get(this, 'data.authenticated.access_token'); + }), + /** * Get the account information for the sessioned user */ diff --git a/app/templates/components/application/site-header.hbs b/app/templates/components/application/site-header.hbs index a31df8421a..d70da52e79 100644 --- a/app/templates/components/application/site-header.hbs +++ b/app/templates/components/application/site-header.hbs @@ -1,3 +1,5 @@ +{{nolt-feedback-script}} +