Skip to content

Commit

Permalink
fix(subscriptions): remove reload button for customers
Browse files Browse the repository at this point in the history
Customers shouldn't be able to reload subscriptions directly.
Show an info banner for customer in project-detail.
  • Loading branch information
trowik committed Dec 8, 2022
1 parent a0eba1d commit 20c1597
Showing 8 changed files with 15 additions and 53 deletions.
21 changes: 0 additions & 21 deletions frontend/app/services/timed.js
Original file line number Diff line number Diff line change
@@ -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,
9 changes: 5 additions & 4 deletions frontend/app/subscriptions/detail/controller.js
Original file line number Diff line number Diff line change
@@ -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() {
6 changes: 6 additions & 0 deletions frontend/app/subscriptions/detail/template.hbs
Original file line number Diff line number Diff line change
@@ -19,6 +19,12 @@
</LinkTo>
{{/if}}
</div>
{{#if this.showInfoBanner}}
<div uk-alert class="uk-flex uk-flex-bottom">
<span uk-icon="info" class="uk-margin-right"></span>
{{t "page.subscriptions.detail.info"}}
</div>
{{/if}}

</div>
</section>
7 changes: 0 additions & 7 deletions frontend/app/subscriptions/own/controller.js
Original file line number Diff line number Diff line change
@@ -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,
]);
}
}
6 changes: 0 additions & 6 deletions frontend/app/subscriptions/own/template.hbs
Original file line number Diff line number Diff line change
@@ -59,12 +59,6 @@
<LinkTo @route="subscriptions.detail" @model={{project.id}}>
{{~t "page.subscriptions.own.projects.details"~}}
</LinkTo>

{{#if this.showReloadLink}}
<LinkTo @route="subscriptions.reload" @model={{project.id}}>
{{~t "page.subscriptions.own.projects.reload"~}}
</LinkTo>
{{/if}}
</div>
</div>
</li>
17 changes: 2 additions & 15 deletions frontend/app/subscriptions/reload/route.js
Original file line number Diff line number Diff line change
@@ -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,
};
}

1 change: 1 addition & 0 deletions frontend/translations/de.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions frontend/translations/en.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 20c1597

Please sign in to comment.