8000 fix: hide donation links for paying customers by tdurieux · Pull Request #922 · tdurieux/anonymous_github · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"core.min.js": "core.4a77c8ac41.min.js",
"vendor.min.js": "vendor.553866ebed.min.js",
"vendor.min.js": "vendor.3116e4efe4.min.js",
"mermaid.min.js": "mermaid.a7356d5ed1.min.js",
"all.min.css": "all.e9dc695558.min.css",
"markdown.min.js": "markdown.6c8dfb7b1d.min.js",
Expand Down
4 changes: 2 additions & 2 deletions public/partials/header.htm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<nav class="navbar navbar-expand-lg" :class="{&#x27;navbar-dark&#x27;: isDarkMode}">
<a class="navbar-brand" href="/">Anonymous <em>GitHub</em></a>
<a class="nav-support" href="https://ko-fi.com/tdurieux" target="_blank" rel="noopener" title="Donate on Ko-fi to help cover hosting costs" aria-label="Donate on Ko-fi to help cover hosting costs">
<a v-if="headerShowSupport" class="nav-support" href="https://ko-fi.com/tdurieux" target="_blank" rel="noopener" title="Donate on Ko-fi to help cover hosting costs" aria-label="Donate on Ko-fi to help cover hosting costs">
<svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-heart"></use></svg>
<span class="nav-support-label">Support</span>
</a>
Expand Down Expand Up @@ -103,7 +103,7 @@ <h6 class="dropdown-header">Signed in as @{{ user?.username }}</h6>
<i class="fab fa-github" aria-hidden="true"></i>
<span>Source code</span>
</a>
<a class="dropdown-item" href="https://ko-fi.com/tdurieux" target="_blank" rel="noopener">
<a v-if="headerShowSupport" class="dropdown-item" href="https://ko-fi.com/tdurieux" target="_blank" rel="noopener">
<svg class="ui-icon" aria-hidden="true"><use href="#ui-icon-heart"></use></svg>
<span>Support the project</span>
</a>
Expand Down
4 changes: 4 additions & 0 deletions public/script/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ function previewTabKeydown(event) {
export const mainController = function (state, http, location, timeout) {
state.previewTabKeydown = previewTabKeydown;
state.headerCanUpgrade = false;
state.headerShowSupport = false;
state.headerBillingPending = ["success", "portal"].includes(new URLSearchParams(window.location.search).get("billing"));
const updateHeaderBilling = billing => {
state.headerShowSupport = !(billing?.grants || []).some(g => ["active", "paid", "past_due"].includes(g.status) && new Date(g.until).getTime() > Date.now());
const subscribed = (billing?.grants || []).some(g => ["author_monthly", "author_annual"].includes(g.planId) && ["active", "paid", "past_due"].includes(g.status) && new Date(g.until).getTime() > Date.now());
state.headerCanUpgrade = !!billing?.enabled && billing.checkoutEnabled !== false && !subscribed && (billing.plans || []).some(p => ["author_monthly", "author_annual"].includes(p.id));
};
Expand Down Expand Up @@ -192,6 +194,7 @@ export const mainController = function (state, http, location, timeout) {
(res) => {
if (res) state.user = res.data;
if (state.user?.username) readBilling(http).then(res => updateHeaderBilling(res.data)).catch(() => {});
else state.headerShowSupport = true;
if (state.user?.emailNotificationsEnabled && state.user.showEmailPrompt && !state.user.notificationEmail) {
emailPromptFocus = document.activeElement;
state.emailPromptOpen = true;
Expand All @@ -205,6 +208,7 @@ export const mainController = function (state, http, location, timeout) {
},
() => {
state.user = null;
state.headerShowSupport = true;
}
);
}
Expand Down
14 changes: 7 additions & 7 deletions public/script/vendor.min.js

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions test/vue-ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,52 @@ describe("Vue 3 UI", function () {
expect(ui.errors).to.deep.equal([]);
});

for (const scenario of [
{ name: "signed-out visitors", user: null, enabled: true, grants: [], visible: true },
{ name: "free accounts with billing enabled", enabled: true, grants: [], visible: true },
{ name: "free accounts with billing disabled", enabled: false, grants: [], visible: true },
...["author_monthly", "author_annual", "author_pass", "conference"].map(planId => ({
name: planId + " customers", enabled: true, grants: [{ planId, status: "paid", until: "2099-01-01" }], visible: false,
})),
{ name: "canceled subscriptions with remaining access", enabled: true, grants: [{ status: "active", cancelAtPeriodEnd: true, until: "2099-01-01" }], visible: false },
{ name: "past-due subscriptions with remaining access", enabled: true, grants: [{ status: "past_due", until: "2099-01-01" }], visible: false },
{ name: "expired customers", enabled: true, grants: [{ status: "paid", until: "2000-01-01" }], visible: true },
{ name: "revoked customers", enabled: true, grants: [{ status: "revoked", until: "2099-01-01" }], visible: true },
]) {
it("sets header donation visibility for " + scenario.name, async () => {
ui = await browser("/faq", {
"/api/user": scenario.user === null ? null : { username: "owner" },
"/api/billing/": { enabled: scenario.enabled, grants: scenario.grants, plans: [] },
});
await delay(100);
expect(!!ui.window.document.querySelector(".nav-support")).to.equal(scenario.visible);
const menuLink = ui.window.document.querySelector('.user-menu a[href="https://ko-fi.com/tdurieux"]');
expect(!!menuLink).to.equal(scenario.visible && scenario.user !== null);
expect(ui.errors).to.deep.equal([]);
});
}

it("waits for billing before showing donation links and reacts to paid access changes", async () => {
let resolveBilling;
const billing = new Promise(resolve => { resolveBilling = resolve; });
ui = await browser("/faq", {
"/api/user": { username: "owner" },
"/api/billing/": () => billing,
});
expect(ui.window.document.querySelector(".nav-support")).to.equal(null);
resolveBilling({ enabled: true, grants: [], plans: [] });
await delay(100);
expect(ui.window.document.querySelector(".nav-support")).not.to.equal(null);
ui.app.state.emit("billing:updated", { enabled: true, grants: [{ status: "paid", until: "2099-01-01" }] });
await delay(30);
expect(ui.window.document.querySelector(".nav-support")).to.equal(null);
expect(ui.window.document.querySelector('.user-menu a[href="https://ko-fi.com/tdurieux"]')).to.equal(null);
ui.app.state.emit("billing:updated", { enabled: true, grants: [] });
await delay(30);
expect(ui.window.document.querySelector(".nav-support")).not.to.equal(null);
expect(ui.errors).to.deep.equal([]);
});

it("opens the plan comparison from the global header on another page", async () => {
ui = await browser("/dashboard", {
"/api/user": { username: "author" },
Expand Down
Loading
0