Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
plausible-analytics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
varac-projects
plausible-analytics
Commits
8719865a
Commit
8719865a
authored
3 years ago
by
Uku Taht
Browse files
Options
Downloads
Patches
Plain Diff
Redirect user when they've already upgraded
parent
ed9e1d9d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/plausible_web/controllers/billing_controller.ex
+13
-10
13 additions, 10 deletions
lib/plausible_web/controllers/billing_controller.ex
test/plausible_web/controllers/billing_controller_test.exs
+10
-0
10 additions, 0 deletions
test/plausible_web/controllers/billing_controller_test.exs
with
23 additions
and
10 deletions
lib/plausible_web/controllers/billing_controller.ex
+
13
−
10
View file @
8719865a
...
...
@@ -31,19 +31,22 @@ defmodule PlausibleWeb.BillingController do
def
upgrade_enterprise_plan
(
conn
,
%{
"plan_id"
=>
plan_id
})
do
user
=
conn
.
assigns
[
:current_user
]
subscription
=
user
.
subscription
plan
=
Repo
.
get_by
(
Plausible
.
Billing
.
EnterprisePlan
,
user_id:
user
.
id
,
id:
plan_id
)
if
plan
do
usage
=
Plausible
.
Billing
.
usage
(
conn
.
assigns
[
:current_user
])
cond
do
plan
&&
subscription
&&
plan
.
paddle_plan_id
==
subscription
.
paddle_plan_id
->
redirect
(
conn
,
to:
Routes
.
billing_path
(
conn
,
:change_plan_form
))
render
(
conn
,
"upgrade_to_plan.html"
,
usage:
usage
,
user:
user
,
plan:
plan
,
layout:
{
PlausibleWeb
.
LayoutView
,
"focus.html"
}
)
else
render_error
(
conn
,
404
)
plan
->
render
(
conn
,
"upgrade_to_plan.html"
,
user:
user
,
plan:
plan
,
layout:
{
PlausibleWeb
.
LayoutView
,
"focus.html"
}
)
true
->
render_error
(
conn
,
404
)
end
end
...
...
This diff is collapsed.
Click to expand it.
test/plausible_web/controllers/billing_controller_test.exs
+
10
−
0
View file @
8719865a
...
...
@@ -40,6 +40,16 @@ defmodule PlausibleWeb.BillingControllerTest do
assert
html_response
(
conn
,
200
)
=~
"Upgrade your free trial"
assert
html_response
(
conn
,
200
)
=~
"enterprise plan"
end
test
"redirects to change-plan page if user is already subscribed to the given enterprise plan"
,
%{
conn:
conn
,
user:
user
}
do
plan
=
insert
(
:enterprise_plan
,
user:
user
)
insert
(
:subscription
,
paddle_plan_id:
plan
.
paddle_plan_id
,
user:
user
)
conn
=
get
(
conn
,
"/billing/upgrade/enterprise/
#{
plan
.
id
}
"
)
assert
redirected_to
(
conn
)
==
"/billing/change-plan"
end
end
describe
"GET /change-plan"
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment