Remove plan limitations entirely

This commit is contained in:
Mathias Wagner
2024-07-21 12:28:17 +02:00
parent dc6add0760
commit f250defbc4
9 changed files with 4 additions and 74 deletions

View File

@ -1,7 +1,6 @@
import { checkProjectAccess } from "@controller/projects";
import { IKeyRole } from "@models/AccessKey";
import { Group, IGroup } from "@models/Group";
import { planLimits } from "../limits/plans";
import { Permission } from "@models/Permission";
import { convertIdsToPermissions } from "@controller/permission";
@ -36,9 +35,6 @@ export const createGroup = async (userId: string, projectId: string, configurati
const access = await checkProjectAccess(IKeyRole.MANAGE)(userId, projectId);
if ("code" in access) return access;
const count = await Group.countDocuments({ projectId: String(access._id) });
if (count >= planLimits[access.plan].GROUPS) return { code: 95, message: "You have exceeded the group limit" };
const group = await Group.findOne({ projectId: String(access._id), name: configuration.name });
if (group !== null) return { code: 4008, message: "The provided group name is already in use" };

View File

@ -1,6 +1,5 @@
import { checkProjectAccess } from "@controller/projects";
import { AccessKey, IKeyRole } from "@models/AccessKey";
import { planLimits } from "../limits/plans";
export const listKeys = async (userId: string, projectId: string) => {
const access = await checkProjectAccess(IKeyRole.VIEW)(userId, projectId);
@ -15,9 +14,6 @@ export const createKey = async (userId: string, projectId: string, configuration
const access = await checkProjectAccess(IKeyRole.MANAGE)(userId, projectId);
if ("code" in access) return access;
const count = await AccessKey.countDocuments({ projectId: String(access._id) });
if (count >= planLimits[access.plan].KEYS) return { code: 95, message: "You have exceeded the key limit" };
const key = await AccessKey.create({ ...configuration, projectId });
return { token: key.token };

View File

@ -1,7 +1,6 @@
import { checkProjectAccess } from "@controller/projects";
import { IKeyRole } from "@models/AccessKey";
import { ILicense, License } from "@models/License";
import { planLimits } from "../limits/plans";
import { Permission } from "@models/Permission";
import { IProject } from "@models/Project";
import { Group } from "@models/Group";
@ -98,9 +97,6 @@ export const createLicense = async (userId: string, projectId: string, config: I
const access = await checkProjectAccess(IKeyRole.MANAGE)(userId, projectId);
if ("code" in access) return access;
const count = await License.countDocuments({ projectId: String(access._id) });
if (count >= planLimits[access.plan].LICENSES) return { code: 95, message: "You have exceeded the license limit" };
if (!config.key) config.key = replaceLicenseDefaults(access.defaults.licenseKey);
if (!config.maxUses) config.maxUses = access.defaults.maxUses;
if (!config.groups) config.groups = access.defaults.groups;

View File

@ -4,7 +4,6 @@ import { IMember, Member } from "@models/Member";
import { Account } from "@models/Account";
import { sendMail } from "@utils/email";
import { getSimpleAccountObjectById } from "@controller/account";
import { planLimits } from "../limits/plans";
export const sendInvitationMail = async (email: string, username: string, projectName: string) => {
sendMail({
@ -38,9 +37,6 @@ export const inviteMember = async (userId: string, projectId: string, configurat
allowInvites: true,
}, { email: configuration.user, verified: true, allowInvites: true }]);
const count = await Member.countDocuments({ projectId: String(access._id) });
if (count >= planLimits[access.plan].MEMBERS) return { code: 95, message: "You have exceeded the member limit" };
if (account === null) return { code: 1002, message: "The provided account does not exist or disabled invites" };
if (String(account._id) === userId) return { code: 1005, message: "You cannot invite yourself" };

View File

@ -1,7 +1,6 @@
import { checkProjectAccess } from "@controller/projects";
import { IKeyRole } from "@models/AccessKey";
import { ILicenseMetaType, IMetaData, MetaData } from "@models/MetaData";
import { planLimits } from "../limits/plans";
export const isValidMetaType = (type: string, value: string) => {
if (type === ILicenseMetaType.TEXT) return true;
@ -51,9 +50,6 @@ export const createMetaData = async (userId: string, projectId: string, config:
const access = await checkProjectAccess(IKeyRole.MANAGE)(userId, projectId);
if ("code" in access) return access;
const count = await MetaData.countDocuments({ projectId: String(access._id) });
if (count >= planLimits[access.plan].META) return { code: 95, message: "You have exceeded the meta item limit" };
const meta = await MetaData.findOne({ projectId: String(access._id), name: config.name });
if (meta !== null) return { code: 8003, message: "The provided meta item name is already in use" };

View File

@ -1,7 +1,6 @@
import { checkProjectAccess } from "@controller/projects";
import { IKeyRole } from "@models/AccessKey";
import { Permission } from "@models/Permission";
import { planLimits } from "../limits/plans";
export const convertIdsToPermissions = async (projectId: string, permissions: string[]) => {
const permissionsDb = await Permission.find({ projectId: projectId, _id: { $in: permissions } });
@ -34,9 +33,6 @@ export const createPermission = async (userId: string, projectId: string, config
const permission = await Permission.findOne({ projectId: String(access._id), permission: configuration.permission });
if (permission !== null) return { code: 4008, message: "The provided permission name is already in use" };
const count = await Permission.countDocuments({ projectId: String(access._id) });
if (count >= planLimits[access.plan].PERMISSIONS) return { code: 95, message: "You have exceeded the permission limit" };
await Permission.create({ ...configuration, projectId });
return {};
@ -46,9 +42,6 @@ export const deletePermission = async (userId: string, projectId: string, permis
const access = await checkProjectAccess(IKeyRole.MANAGE)(userId, projectId);
if ("code" in access) return access;
const count = await Permission.countDocuments({ projectId: String(access._id) });
if (count >= planLimits[access.plan].PERMISSIONS) return { code: 95, message: "You have exceeded the permission limit" };
const permission = await Permission.findOne({ projectId: String(access._id), permission: permissionName });
if (permission === null) return { code: 4009, message: "The provided permission does not exist" };

View File

@ -1,9 +1,8 @@
import { IProject, IProjectPlan, Project } from "@models/Project";
import { IProject, Project } from "@models/Project";
import { Types } from "mongoose";
import crypto from "crypto";
import { AccessKey, IKeyRole } from "@models/AccessKey";
import { Member } from "@models/Member";
import { planLimits } from "../limits/plans";
import { License } from "@models/License";
import { Permission } from "@models/Permission";
import { Group } from "@models/Group";
@ -54,13 +53,9 @@ export const getProject = async (projectId: string, userId: string) => {
};
export const createProject = async (name: string, userId: string) => {
const count = await Project.countDocuments({ creatorId: userId,
plan: IProjectPlan.PERSONAL });
if (count > planLimits["account"].FREE_PROJECTS) return { code: 95, message: "You have exceeded the free project limit" };
if (count > 100) return { code: 95, message: "You have exceeded the project limit" };
await Project.create({ name, creatorId: userId });
return {};
};
export const deleteProject = async (id: string, userId: string) => {

View File

@ -1,29 +0,0 @@
export const planLimits = {
account: {
FREE_PROJECTS: 5,
},
personal: {
LICENSES: 100,
MEMBERS: 1,
GROUPS: 3,
KEYS: 1,
META: 3,
PERMISSIONS: 10
},
plus: {
LICENSES: 5000,
MEMBERS: 10,
GROUPS: 15,
KEYS: 10,
META: 10,
PERMISSIONS: 50
},
pro: {
LICENSES: 50000,
MEMBERS: 20,
GROUPS: 40,
KEYS: 20,
META: 20,
PERMISSIONS: 100
}
}

View File

@ -1,10 +1,6 @@
import { model, ObjectId, Schema } from "mongoose";
import crypto from "crypto";
export enum IProjectPlan {
PERSONAL = "personal", PLUS = "plus", PRO = "pro"
}
export interface IProjectDefaults {
licenseKey: string,
groups: string[],
@ -18,8 +14,7 @@ export interface IProject {
name: string,
creatorId: ObjectId,
validationKey: string,
defaults: IProjectDefaults,
plan: IProjectPlan
defaults: IProjectDefaults
}
const ProjectSchema = new Schema<IProject>({
@ -38,10 +33,6 @@ const ProjectSchema = new Schema<IProject>({
defaults: {
type: Object,
default: { licenseKey: "NNUN-UUNN-UNAU-NAAN", groups: [], expirationDate: new Date(0), permissions: [], maxUses: -1 },
},
plan: {
type: String,
default: IProjectPlan.PERSONAL
}
});