Merge pull request #469 from padloc/feature/directory-sync-billing

Allow hiding/disable directory sync feature via provisioning layer
This commit is contained in:
Martin Kleinschrodt 2022-06-10 09:30:02 +02:00 committed by GitHub
commit ea05def083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 6 deletions

View File

@ -18,6 +18,7 @@ import { customElement, property } from "lit/decorators.js";
import { css, html, LitElement } from "lit";
import { ProvisioningStatus } from "@padloc/core/src/provisioning";
import "./rich-content";
import "./button";
@customElement("pl-org-dashboard")
export class OrgDashboard extends Routing(StateMixin(LitElement)) {

View File

@ -15,6 +15,7 @@ import "./drawer";
import { ToggleButton } from "./toggle-button";
import { setClipboard } from "../lib/clipboard";
import { live } from "lit/directives/live.js";
import { checkFeatureDisabled } from "../lib/provisioning";
@customElement("pl-org-settings")
export class OrgSettingsView extends Routing(StateMixin(LitElement)) {
@ -121,6 +122,11 @@ export class OrgSettingsView extends Routing(StateMixin(LitElement)) {
}
private async _enableDirectorySync() {
if (checkFeatureDisabled(app.getOrgFeatures(this._org!).directorySync, this._org!.isOwner(app.account!))) {
this.requestUpdate();
return;
}
const confirmed = await confirm(
$l(
"Do you want to enable Directory Sync via SCIM for this organization? You will be given a unique URL to provide to your Active Directory or LDAP server for synchronizing and provisioning members."
@ -129,6 +135,7 @@ export class OrgSettingsView extends Routing(StateMixin(LitElement)) {
);
if (!confirmed) {
this.requestUpdate();
return;
}
@ -227,6 +234,12 @@ export class OrgSettingsView extends Routing(StateMixin(LitElement)) {
const scimUrl = (syncEnabled && org.directory.scim?.url) || "";
const scimSecretToken = (syncEnabled && org.directory.scim?.secretToken) || "";
const feature = app.getOrgFeatures(org).directorySync;
if (feature.hidden && !syncEnabled) {
return;
}
return html`
<div class="vertical spacing layout fill-horizontally">
<section class="margined box">

View File

@ -109,6 +109,9 @@ export class OrgFeatures extends Serializable {
@AsSerializable(OrgFeature)
securityReport: OrgFeature = new OrgFeature();
@AsSerializable(OrgFeature)
directorySync: OrgFeature = new OrgFeature();
}
export class AccountProvisioning extends Storable {

View File

@ -718,6 +718,7 @@ export class Controller extends API {
accountId: account.id,
email: account.email,
status: OrgMemberStatus.Provisioned,
role: OrgRole.Owner,
}),
];
org.created = new Date();

View File

@ -154,6 +154,7 @@ export class StripeProvisioner extends BasicProvisioner {
"Security Report",
"Unlimited Vaults",
"Unlimited Groups",
"Directory Sync / Automatic Provisioning",
],
disabledFeatures: [],
},
@ -367,7 +368,7 @@ export class StripeProvisioner extends BasicProvisioner {
return {
type: "html",
content: html`
<div style="max-width: ${15 * tiers.length}em">
<div style="max-width: ${Math.max(15 * tiers.length, 30)}em">
<h1 class="text-centering">${title}</h1>
<div class="margined text-centering">${message}</div>
${!allowUpdate
@ -478,9 +479,33 @@ export class StripeProvisioner extends BasicProvisioner {
private async _getOrgFeatures(customer: Stripe.Customer, tier: Tier, quota: OrgQuota, org?: Org | null) {
const features = new OrgFeatures();
if (tier === Tier.Family) {
features.addGroup.hidden = true;
features.addGroup.disabled = true;
switch (tier) {
case Tier.Family:
features.addGroup.hidden = true;
features.addGroup.disabled = true;
features.directorySync.hidden = true;
features.directorySync.disabled = true;
break;
case Tier.Team:
features.directorySync.hidden = false;
features.directorySync.disabled = true;
features.directorySync.message = await this._getUpgradeMessage(
customer,
[Tier.Business],
"Upgrade Required",
"Directory sync is not available for this plan. Please ugrade to the Business plan to continue!",
false,
"Directory Sync"
);
features.directorySync.messageOwner = await this._getUpgradeMessage(
customer,
[Tier.Business],
"Upgrade Required",
"Directory sync is not available for this plan. Please ugrade to the Business plan to continue!",
true,
"Directory Sync"
);
break;
}
if (org) {
@ -490,14 +515,14 @@ export class StripeProvisioner extends BasicProvisioner {
customer,
[Tier.Team, Tier.Business],
"Upgrade Required",
"You have reached the maximum number of orginization members for this plan. Please upgrade to the next tier to add more!",
"You have reached the maximum number of organization members for this plan. Please upgrade to the next tier to add more!",
false
);
features.addMember.messageOwner = await this._getUpgradeMessage(
customer,
[Tier.Team, Tier.Business],
"Upgrade Required",
"You have reached the maximum number of orginization members for this plan. Please upgrade to the next tier to add more!",
"You have reached the maximum number of organization members for this plan. Please upgrade to the next tier to add more!",
true
);
} else if (quota.members !== -1 && org?.members.length >= quota.members) {