Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow admin member of team plan using free plan account to use api #307

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
SMTP_MESSAGE_MAX_SIZE: ${{ secrets.SMTP_MESSAGE_MAX_SIZE }}
DKIM_PRIVATE_KEY_VALUE: ${{ secrets.DKIM_PRIVATE_KEY_VALUE }}
AXE_SILENT: ${{ secrets.AXE_SILENT }}
AXE_SHOW_META: ${{ secrets.AXE_SILENT }}
AXE_SHOW_META: ${{ secrets.AXE_SHOW_META }}
AXE_SHOW_STACK: ${{ secrets.AXE_SHOW_STACK }}
TXT_ENCRYPTION_KEY: ${{ secrets.TXT_ENCRYPTION_KEY }}
HELPER_ENCRYPTION_KEY: ${{ secrets.HELPER_ENCRYPTION_KEY }}
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/api/v1/enforce-paid-plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ async function enforcePaidPlan(ctx, next) {
if (!ctx.isAuthenticated())
return ctx.throw(Boom.unauthorized(ctx.translateError('LOGIN_REQUIRED')));

// if the user is a member of a team plan and in the admin group, continue
if (ctx.state?.domain?.group === 'admin' && ctx.state?.domain?.plan === 'team')
return next();

if (ctx.state.user.plan === 'free')
return ctx.throw(
Boom.paymentRequired(
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/web/my-account/ensure-upgraded-plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ function ensureUpgradedPlan(ctx, next) {
)
return next();

if (!ctx.state.domain && ctx.state.user.plan !== 'free') return next();
if (
(!ctx.state.domain && ctx.state.user.plan !== 'free') ||
ctx.state?.domain?.plan === 'team'
)
return next();

const redirectTo = ctx.state.domain
? ctx.state.l(
Expand Down
10 changes: 9 additions & 1 deletion routes/api/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ router
policies.ensureApiToken,
policies.checkVerifiedEmail,
web.myAccount.ensureNotBanned,
api.v1.enforcePaidPlan,
web.myAccount.ensurePaidToDate,
(ctx, next) => {
//
Expand Down Expand Up @@ -200,23 +199,27 @@ router
'/domains',
web.myAccount.validateDomain,
rateLimit(50, 'create domain'),
api.v1.enforcePaidPlan,
web.myAccount.createDomain,
api.v1.domains.retrieve
)
.get(
'/domains/:domain_id',
web.myAccount.retrieveDomain,
api.v1.enforcePaidPlan,
api.v1.domains.retrieve
)
.get(
'/domains/:domain_id/verify-records',
web.myAccount.retrieveDomain,
api.v1.enforcePaidPlan,
web.myAccount.verifyRecords
)
.put(
'/domains/:domain_id',
web.myAccount.retrieveDomain,
web.myAccount.ensureDomainAdmin,
api.v1.enforcePaidPlan,
web.myAccount.ensureUpgradedPlan,
web.myAccount.updateDomain,
web.myAccount.retrieveDomains,
Expand All @@ -226,6 +229,7 @@ router
'/domains/:domain_id',
web.myAccount.retrieveDomain,
web.myAccount.ensureDomainAdmin,
api.v1.enforcePaidPlan,
web.myAccount.removeDomain,
web.myAccount.retrieveDomains,
api.v1.domains.retrieve
Expand All @@ -238,6 +242,7 @@ router
web.myAccount.retrieveDomain,
web.myAccount.ensureDomainAdmin,
web.myAccount.ensureTeamPlan,
api.v1.enforcePaidPlan,
web.myAccount.ensureUpgradedPlan,
rateLimit(10, 'create invite'),
web.myAccount.createInvite,
Expand All @@ -250,6 +255,7 @@ router
web.myAccount.retrieveDomain,
web.myAccount.ensureDomainAdmin,
web.myAccount.ensureTeamPlan,
api.v1.enforcePaidPlan,
web.myAccount.ensureUpgradedPlan,
web.myAccount.removeInvite,
web.myAccount.retrieveDomains,
Expand All @@ -264,6 +270,7 @@ router
web.myAccount.ensureDomainAdmin,
web.myAccount.ensureTeamPlan,
web.myAccount.ensureUpgradedPlan,
api.v1.enforcePaidPlan,
web.myAccount.retrieveAliases,
web.myAccount.updateMember,
web.myAccount.retrieveDomains,
Expand All @@ -276,6 +283,7 @@ router
web.myAccount.ensureDomainAdmin,
web.myAccount.ensureTeamPlan,
web.myAccount.ensureUpgradedPlan,
api.v1.enforcePaidPlan,
web.myAccount.retrieveAliases,
web.myAccount.removeMember,
web.myAccount.retrieveDomains,
Expand Down
Loading