From 20c15972ce5c7e228b4002c2b52a0010493176b1 Mon Sep 17 00:00:00 2001 From: Wiktork Date: Thu, 8 Dec 2022 11:09:40 +0100 Subject: [PATCH] fix(subscriptions): remove reload button for customers Customers shouldn't be able to reload subscriptions directly. Show an info banner for customer in project-detail. --- frontend/app/services/timed.js | 21 ------------------- .../app/subscriptions/detail/controller.js | 9 ++++---- .../app/subscriptions/detail/template.hbs | 6 ++++++ frontend/app/subscriptions/own/controller.js | 7 ------- frontend/app/subscriptions/own/template.hbs | 6 ------ frontend/app/subscriptions/reload/route.js | 17 ++------------- frontend/translations/de.yaml | 1 + frontend/translations/en.yaml | 1 + 8 files changed, 15 insertions(+), 53 deletions(-) diff --git a/frontend/app/services/timed.js b/frontend/app/services/timed.js index 4161fce4..b0be613b 100644 --- a/frontend/app/services/timed.js +++ b/frontend/app/services/timed.js @@ -62,27 +62,6 @@ export default class TimedService extends Service { }); } - async getReloadPackages(billingType) { - const packages = await this.store.query("subscription-package", { - billing_type: billingType, - }); - - const REGEX_PRICE = /^Fr\./; - - packages.forEach((item) => { - let { price } = item; - - if (REGEX_PRICE.test(price)) { - const price_string = price.replace("Fr.", "").replace(",", ""); - price = parseFloat(price_string); - } - - item.set("price", price); - }); - - return packages; - } - async placeSubscriptionOrder(project, duration, ordered) { const order = this.store.createRecord("subscription-order", { duration, diff --git a/frontend/app/subscriptions/detail/controller.js b/frontend/app/subscriptions/detail/controller.js index 0a955896..d4f4d265 100644 --- a/frontend/app/subscriptions/detail/controller.js +++ b/frontend/app/subscriptions/detail/controller.js @@ -11,10 +11,11 @@ export default class SubscriptionsDetailController extends Controller { @tracked project; get showReloadButton() { - return this.account.isInGroups("one", [ - ENV.auth.adminRole, - ENV.auth.customerRole, - ]); + return this.account.isInGroups("one", [ENV.auth.adminRole]); + } + + get showInfoBanner() { + return this.account.isInGroups("one", [ENV.auth.customerRole]); } get breadcrumbs() { diff --git a/frontend/app/subscriptions/detail/template.hbs b/frontend/app/subscriptions/detail/template.hbs index 58ecec4d..79f0bd0f 100644 --- a/frontend/app/subscriptions/detail/template.hbs +++ b/frontend/app/subscriptions/detail/template.hbs @@ -19,6 +19,12 @@ {{/if}} + {{#if this.showInfoBanner}} +
+ + {{t "page.subscriptions.detail.info"}} +
+ {{/if}} diff --git a/frontend/app/subscriptions/own/controller.js b/frontend/app/subscriptions/own/controller.js index 019b1bba..302699a7 100644 --- a/frontend/app/subscriptions/own/controller.js +++ b/frontend/app/subscriptions/own/controller.js @@ -9,11 +9,4 @@ export default class SubscriptionsOwnController extends Controller { get projects() { return this.model; } - - get showReloadLink() { - return this.account.isInGroups("one", [ - ENV.auth.adminRole, - ENV.auth.customerRole, - ]); - } } diff --git a/frontend/app/subscriptions/own/template.hbs b/frontend/app/subscriptions/own/template.hbs index cd501985..6240fcdf 100644 --- a/frontend/app/subscriptions/own/template.hbs +++ b/frontend/app/subscriptions/own/template.hbs @@ -59,12 +59,6 @@ {{~t "page.subscriptions.own.projects.details"~}} - - {{#if this.showReloadLink}} - - {{~t "page.subscriptions.own.projects.reload"~}} - - {{/if}} diff --git a/frontend/app/subscriptions/reload/route.js b/frontend/app/subscriptions/reload/route.js index 19bd3061..d4a6f367 100644 --- a/frontend/app/subscriptions/reload/route.js +++ b/frontend/app/subscriptions/reload/route.js @@ -11,13 +11,8 @@ export default class SubscriptionsReloadRoute extends Route { beforeModel(transition) { super.beforeModel(transition); - // Employees cannot recharge the subscription. - if ( - !this.account.isInGroups("one", [ - ENV.auth.adminRole, - ENV.auth.customerRole, - ]) - ) { + // Employees and customers cannot recharge the subscription. + if (!this.account.isInGroups("one", [ENV.auth.adminRole])) { this.notify.error(this.intl.t("page.subscriptions.reload.no-access")); this.transitionTo( "subscriptions.detail", @@ -29,16 +24,8 @@ export default class SubscriptionsReloadRoute extends Route { async model(params) { const project = await this.timed.getProjectDetails(params.project_id); - // Customers get a list of packages to choose from. - let packages = []; - if (this.account.isInGroup(ENV.auth.customerRole)) { - const billingType = project.billingType.get("id"); - packages = await this.timed.getReloadPackages(billingType); - } - return { project, - packages, }; } diff --git a/frontend/translations/de.yaml b/frontend/translations/de.yaml index 4a5c86da..4853fbe6 100644 --- a/frontend/translations/de.yaml +++ b/frontend/translations/de.yaml @@ -98,6 +98,7 @@ page: detail: title: Projektdetails reload: Aufladen + info: Um Stunden zu kaufen, melden Sie sich bitte über ihren zuständigen Verkäufer. orders: title: Bestellungen diff --git a/frontend/translations/en.yaml b/frontend/translations/en.yaml index 0ce7f3f8..36aa54d7 100644 --- a/frontend/translations/en.yaml +++ b/frontend/translations/en.yaml @@ -98,6 +98,7 @@ page: detail: title: Project details reload: Recharge + info: To purchase hours, please contact us through your salesperson. orders: title: Past charges