mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-17 10:45:58 +00:00
feat: go greppy
This commit is contained in:
@@ -63,7 +63,7 @@ export const additionalPrivilegeServiceFactory = ({
|
||||
[dbActorField]: data.actorId,
|
||||
[scope.key]: scope.value
|
||||
});
|
||||
if (existingSlug) throw new BadRequestError({ message: `Additional privilege with name ${data.name} exist` });
|
||||
if (existingSlug) throw new BadRequestError({ message: `Additional privilege with name ${data.name} exists` });
|
||||
|
||||
validateHandlebarTemplate("Additional Privilege Create", JSON.stringify(data.permissions || []), {
|
||||
allowedExpressions: (val) => val.includes("identity.")
|
||||
@@ -115,12 +115,12 @@ export const additionalPrivilegeServiceFactory = ({
|
||||
const dbActorField = dto.selector.actorType === ActorType.IDENTITY ? "actorIdentityId" : "actorUserId";
|
||||
|
||||
const existingPrivilege = await additionalPrivilegeDAL.findOne({
|
||||
id: dto.selector.id,
|
||||
[dbActorField]: dto.selector.actorId,
|
||||
id: dto.selector.id,
|
||||
[scope.key]: scope.value
|
||||
});
|
||||
if (!existingPrivilege)
|
||||
throw new NotFoundError({ message: `Additional privilege with name ${data.name} doesn't exist` });
|
||||
throw new NotFoundError({ message: `Additional privilege with id ${dto.selector.id} doesn't exist` });
|
||||
|
||||
validateHandlebarTemplate("Additional Privilege Create", JSON.stringify(data.permissions || []), {
|
||||
allowedExpressions: (val) => val.includes("identity.")
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { AccessScope } from "@app/db/schemas";
|
||||
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
||||
import { NotFoundError } from "@app/lib/errors";
|
||||
|
||||
import { TAdditionalPrivilegeDALFactory } from "../additional-privilege/additional-privilege-dal";
|
||||
import { TMembershipDALFactory } from "../membership/membership-dal";
|
||||
import { TProjectDALFactory } from "../project/project-dal";
|
||||
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
||||
|
||||
type TConvertorServiceFactoryDep = {
|
||||
projectDAL: Pick<TProjectDALFactory, "findOne">;
|
||||
@@ -105,7 +105,7 @@ export const convertorServiceFactory = ({
|
||||
projectId
|
||||
});
|
||||
if (!privilege) {
|
||||
throw new NotFoundError({ message: `Privilege with slug ${privilegeName} not found` });
|
||||
throw new NotFoundError({ message: `Privilege with name ${privilegeName} not found` });
|
||||
}
|
||||
|
||||
return { privilegeId: privilege.id, privilege };
|
||||
|
||||
@@ -54,7 +54,7 @@ export const externalMigrationServiceFactory = ({
|
||||
actorAuthMethod,
|
||||
actorOrgId
|
||||
);
|
||||
if (hasRole(OrgMembershipRole.Admin)) {
|
||||
if (!hasRole(OrgMembershipRole.Admin)) {
|
||||
throw new ForbiddenRequestError({ message: "Only admins can import data" });
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ export const externalMigrationServiceFactory = ({
|
||||
actorOrgId
|
||||
);
|
||||
|
||||
if (hasRole(OrgMembershipRole.Admin)) {
|
||||
if (!hasRole(OrgMembershipRole.Admin)) {
|
||||
throw new ForbiddenRequestError({ message: "Only admins can import data" });
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ export const externalMigrationServiceFactory = ({
|
||||
actorOrgId
|
||||
);
|
||||
|
||||
if (hasRole(OrgMembershipRole.Admin)) {
|
||||
if (!hasRole(OrgMembershipRole.Admin)) {
|
||||
throw new ForbiddenRequestError({ message: "Only admins can check custom migration status" });
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ export const groupProjectDALFactory = (db: TDbClient) => {
|
||||
db.ref("id").as("groupId").withSchema(TableName.Groups),
|
||||
db.ref("name").as("groupName").withSchema(TableName.Groups),
|
||||
db.ref("slug").as("groupSlug").withSchema(TableName.Groups),
|
||||
db.ref("id").withSchema(TableName.Membership),
|
||||
db.ref("role").withSchema(TableName.MembershipRole),
|
||||
db.ref("id").withSchema(TableName.MembershipRole).as("membershipRoleId"),
|
||||
db.ref("customRoleId").withSchema(TableName.MembershipRole),
|
||||
|
||||
@@ -257,7 +257,7 @@ export const identityOidcAuthServiceFactory = ({
|
||||
identityId
|
||||
});
|
||||
if (!identityMembershipOrg) {
|
||||
if (!identityMembershipOrg) throw new NotFoundError({ message: `Failed to find identity with ID ${identityId}` });
|
||||
throw new NotFoundError({ message: `Failed to find identity with ID ${identityId}` });
|
||||
}
|
||||
if (identityMembershipOrg.identity.authMethods.includes(IdentityAuthMethod.OIDC_AUTH)) {
|
||||
throw new BadRequestError({
|
||||
|
||||
@@ -429,7 +429,7 @@ export const identityProjectDALFactory = (db: TDbClient) => {
|
||||
.join(TableName.Identity, `${TableName.Membership}.actorIdentityId`, `${TableName.Identity}.id`)
|
||||
.where((qb) => {
|
||||
if (filter.identityId) {
|
||||
void qb.where("identityId", filter.identityId);
|
||||
void qb.where(`${TableName.Membership}.actorIdentityId`, filter.identityId);
|
||||
}
|
||||
|
||||
if (filter.search) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
|
||||
type TIdentityProjectServiceFactoryDep = {
|
||||
identityProjectDAL: TIdentityProjectDALFactory;
|
||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "getProjectPermissionByRoles">;
|
||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||
membershipIdentityDAL: TMembershipIdentityDALFactory;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import { TIdentityAccessTokenJwtPayload } from "../identity-access-token/identit
|
||||
import { TKmsServiceFactory } from "../kms/kms-service";
|
||||
import { KmsDataKey } from "../kms/kms-types";
|
||||
import { TMembershipIdentityDALFactory } from "../membership-identity/membership-identity-dal";
|
||||
import { TOrgDALFactory } from "../org/org-dal";
|
||||
import { validateIdentityUpdateForSuperAdminPrivileges } from "../super-admin/super-admin-fns";
|
||||
import { TIdentityTlsCertAuthDALFactory } from "./identity-tls-cert-auth-dal";
|
||||
import { TIdentityTlsCertAuthServiceFactory } from "./identity-tls-cert-auth-types";
|
||||
@@ -35,7 +34,6 @@ type TIdentityTlsCertAuthServiceFactoryDep = {
|
||||
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
||||
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
|
||||
orgDAL: Pick<TOrgDALFactory, "findById">;
|
||||
};
|
||||
|
||||
const parseSubjectDetails = (data: string) => {
|
||||
@@ -53,8 +51,7 @@ export const identityTlsCertAuthServiceFactory = ({
|
||||
membershipIdentityDAL,
|
||||
licenseService,
|
||||
permissionService,
|
||||
kmsService,
|
||||
orgDAL
|
||||
kmsService
|
||||
}: TIdentityTlsCertAuthServiceFactoryDep): TIdentityTlsCertAuthServiceFactory => {
|
||||
const login: TIdentityTlsCertAuthServiceFactory["login"] = async ({ identityId, clientCertificate }) => {
|
||||
const identityTlsCertAuth = await identityTlsCertAuthDAL.findOne({ identityId });
|
||||
@@ -411,7 +408,7 @@ export const identityTlsCertAuthServiceFactory = ({
|
||||
);
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
|
||||
|
||||
const { permission: rolePermission } = await permissionService.getOrgPermission(
|
||||
const { permission: rolePermission, memberships } = await permissionService.getOrgPermission(
|
||||
ActorType.IDENTITY,
|
||||
identityMembershipOrg.identity.id,
|
||||
identityMembershipOrg.scopeOrgId,
|
||||
@@ -419,7 +416,7 @@ export const identityTlsCertAuthServiceFactory = ({
|
||||
actorOrgId
|
||||
);
|
||||
|
||||
const { shouldUseNewPrivilegeSystem } = await orgDAL.findById(identityMembershipOrg.scopeOrgId);
|
||||
const shouldUseNewPrivilegeSystem = Boolean(memberships?.[0]?.shouldUseNewPrivilegeSystem);
|
||||
const permissionBoundary = validatePrivilegeChangeOperation(
|
||||
shouldUseNewPrivilegeSystem,
|
||||
OrgPermissionIdentityActions.RevokeAuth,
|
||||
|
||||
@@ -404,7 +404,7 @@ export const identityOrgDALFactory = (db: TDbClient) => {
|
||||
.leftJoin(TableName.Role, `${TableName.MembershipRole}.customRoleId`, `${TableName.Role}.id`)
|
||||
.orderBy(
|
||||
orderBy === OrgIdentityOrderBy.Role
|
||||
? `${TableName.Membership}.${orderBy}`
|
||||
? `${TableName.MembershipRole}.${orderBy}`
|
||||
: `${TableName.Identity}.${orderBy}`,
|
||||
orderDirection
|
||||
)
|
||||
|
||||
@@ -45,8 +45,7 @@ export const membershipGroupDALFactory = (db: TDbClient) => {
|
||||
} else if (scopeData.scope === AccessScope.Namespace) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Namespace)
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId)
|
||||
.whereNull(`${TableName.Membership}.scopeNamespaceId`);
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId);
|
||||
} else if (scopeData.scope === AccessScope.Project) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Project)
|
||||
@@ -148,8 +147,7 @@ export const membershipGroupDALFactory = (db: TDbClient) => {
|
||||
} else if (scopeData.scope === AccessScope.Namespace) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Namespace)
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId)
|
||||
.whereNull(`${TableName.Membership}.scopeNamespaceId`);
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId);
|
||||
} else if (scopeData.scope === AccessScope.Project) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Project)
|
||||
|
||||
@@ -57,7 +57,7 @@ export const membershipGroupServiceFactory = ({
|
||||
const hasNoPermanentRole = data.roles.every((el) => el.isTemporary);
|
||||
if (hasNoPermanentRole) {
|
||||
throw new BadRequestError({
|
||||
message: "Group must have atleast one permanent role"
|
||||
message: "Group must have at least one permanent role"
|
||||
});
|
||||
}
|
||||
const isInvalidTemporaryRole = data.roles.some((el) => {
|
||||
@@ -151,7 +151,7 @@ export const membershipGroupServiceFactory = ({
|
||||
const hasNoPermanentRole = data.roles.every((el) => el.isTemporary);
|
||||
if (hasNoPermanentRole) {
|
||||
throw new BadRequestError({
|
||||
message: "Group must have atleast one permanent role"
|
||||
message: "Group must have at least one permanent role"
|
||||
});
|
||||
}
|
||||
const isInvalidTemporaryRole = data.roles.some((el) => {
|
||||
|
||||
@@ -84,7 +84,7 @@ export const newOrgMembershipGroupFactory = ({
|
||||
|
||||
const onDeleteMembershipGroupGuard: TMembershipGroupScopeFactory["onDeleteMembershipGroupGuard"] = async () => {
|
||||
throw new BadRequestError({
|
||||
message: "Organization membership cannot be created for organization scoped group"
|
||||
message: "Organization membership cannot be deleted for organization scoped group"
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ export const newProjectMembershipGroupFactory = ({
|
||||
if (!permissionBoundary.isValid)
|
||||
throw new PermissionBoundaryError({
|
||||
message: constructPermissionErrorMessage(
|
||||
"Failed to create group project membership",
|
||||
"Failed to update group project membership",
|
||||
shouldUseNewPrivilegeSystem,
|
||||
ProjectPermissionGroupActions.GrantPrivileges,
|
||||
ProjectPermissionSub.Groups
|
||||
|
||||
@@ -52,8 +52,7 @@ export const membershipIdentityDALFactory = (db: TDbClient) => {
|
||||
} else if (scopeData.scope === AccessScope.Namespace) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Namespace)
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId)
|
||||
.whereNull(`${TableName.Membership}.scopeNamespaceId`);
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId);
|
||||
} else if (scopeData.scope === AccessScope.Project) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Project)
|
||||
@@ -236,8 +235,7 @@ export const membershipIdentityDALFactory = (db: TDbClient) => {
|
||||
} else if (scopeData.scope === AccessScope.Namespace) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Namespace)
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId)
|
||||
.whereNull(`${TableName.Membership}.scopeNamespaceId`);
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId);
|
||||
} else if (scopeData.scope === AccessScope.Project) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Project)
|
||||
|
||||
@@ -63,7 +63,7 @@ export const membershipIdentityServiceFactory = ({
|
||||
const hasNoPermanentRole = data.roles.every((el) => el.isTemporary);
|
||||
if (hasNoPermanentRole) {
|
||||
throw new BadRequestError({
|
||||
message: "Identity must have atleast one permanent role"
|
||||
message: "Identity must have at least one permanent role"
|
||||
});
|
||||
}
|
||||
const isInvalidTemporaryRole = data.roles.some((el) => {
|
||||
@@ -157,7 +157,7 @@ export const membershipIdentityServiceFactory = ({
|
||||
const hasNoPermanentRole = data.roles.every((el) => el.isTemporary);
|
||||
if (hasNoPermanentRole) {
|
||||
throw new BadRequestError({
|
||||
message: "Identity must have atleast one permanent role"
|
||||
message: "Identity must have at least one permanent role"
|
||||
});
|
||||
}
|
||||
const isInvalidTemporaryRole = data.roles.some((el) => {
|
||||
|
||||
+6
-6
@@ -24,31 +24,31 @@ export const newNamespaceMembershipIdentityFactory = (
|
||||
};
|
||||
|
||||
const isCustomRole: TMembershipIdentityScopeFactory["isCustomRole"] = () => {
|
||||
throw new InternalServerError({ message: "Namespace membership user isCustomRole not implemented" });
|
||||
throw new InternalServerError({ message: "Namespace membership identity isCustomRole not implemented" });
|
||||
};
|
||||
|
||||
const onCreateMembershipIdentityGuard: TMembershipIdentityScopeFactory["onCreateMembershipIdentityGuard"] =
|
||||
async () => {
|
||||
throw new InternalServerError({ message: "Namespace membership user create not implemented" });
|
||||
throw new InternalServerError({ message: "Namespace membership identity create not implemented" });
|
||||
};
|
||||
|
||||
const onUpdateMembershipIdentityGuard: TMembershipIdentityScopeFactory["onUpdateMembershipIdentityGuard"] =
|
||||
async () => {
|
||||
throw new InternalServerError({ message: "Namespace membership user update not implemented" });
|
||||
throw new InternalServerError({ message: "Namespace membership identity update not implemented" });
|
||||
};
|
||||
|
||||
const onDeleteMembershipIdentityGuard: TMembershipIdentityScopeFactory["onDeleteMembershipIdentityGuard"] =
|
||||
async () => {
|
||||
throw new InternalServerError({ message: "Namespace membership user delete not implemented" });
|
||||
throw new InternalServerError({ message: "Namespace membership identity delete not implemented" });
|
||||
};
|
||||
|
||||
const onListMembershipIdentityGuard: TMembershipIdentityScopeFactory["onListMembershipIdentityGuard"] = async () => {
|
||||
throw new InternalServerError({ message: "Namespace membership user list not implemented" });
|
||||
throw new InternalServerError({ message: "Namespace membership identity list not implemented" });
|
||||
};
|
||||
|
||||
const onGetMembershipIdentityByIdentityIdGuard: TMembershipIdentityScopeFactory["onGetMembershipIdentityByIdentityIdGuard"] =
|
||||
async () => {
|
||||
throw new InternalServerError({ message: "Namespace membership user get by user id not implemented" });
|
||||
throw new InternalServerError({ message: "Namespace membership identity get by identity id not implemented" });
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -74,7 +74,7 @@ export const newOrgMembershipIdentityFactory = ({
|
||||
if (!permissionBoundary.isValid)
|
||||
throw new PermissionBoundaryError({
|
||||
message: constructPermissionErrorMessage(
|
||||
"Failed to create identity org membership",
|
||||
"Failed to update identity org membership",
|
||||
shouldUseNewPrivilegeSystem,
|
||||
OrgPermissionIdentityActions.GrantPrivileges,
|
||||
OrgPermissionSubjects.Identity
|
||||
@@ -88,7 +88,7 @@ export const newOrgMembershipIdentityFactory = ({
|
||||
const onDeleteMembershipIdentityGuard: TMembershipIdentityScopeFactory["onDeleteMembershipIdentityGuard"] =
|
||||
async () => {
|
||||
throw new BadRequestError({
|
||||
message: "Organization membership cannot be created for organization scoped identity"
|
||||
message: "Organization membership cannot be deleted for organization scoped identity"
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ export const newProjectMembershipIdentityFactory = ({
|
||||
if (!permissionBoundary.isValid)
|
||||
throw new PermissionBoundaryError({
|
||||
message: constructPermissionErrorMessage(
|
||||
"Failed to create identity project membership",
|
||||
"Failed to update identity project membership",
|
||||
shouldUseNewPrivilegeSystem,
|
||||
ProjectPermissionIdentityActions.GrantPrivileges,
|
||||
ProjectPermissionSub.Identity
|
||||
|
||||
@@ -51,8 +51,7 @@ export const membershipUserDALFactory = (db: TDbClient) => {
|
||||
} else if (scopeData.scope === AccessScope.Namespace) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Namespace)
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId)
|
||||
.whereNull(`${TableName.Membership}.scopeNamespaceId`);
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId);
|
||||
} else if (scopeData.scope === AccessScope.Project) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Project)
|
||||
@@ -168,8 +167,7 @@ export const membershipUserDALFactory = (db: TDbClient) => {
|
||||
} else if (scopeData.scope === AccessScope.Namespace) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Namespace)
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId)
|
||||
.whereNull(`${TableName.Membership}.scopeNamespaceId`);
|
||||
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId);
|
||||
} else if (scopeData.scope === AccessScope.Project) {
|
||||
void qb
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Project)
|
||||
@@ -192,7 +190,7 @@ export const membershipUserDALFactory = (db: TDbClient) => {
|
||||
case "role":
|
||||
return [`${TableName.Role}.slug`, `${TableName.MembershipRole}.role`];
|
||||
case "username":
|
||||
return `${TableName.Users}.name`;
|
||||
return `${TableName.Users}.username`;
|
||||
default:
|
||||
throw new BadRequestError({ message: `Invalid ${String(attr)} provided` });
|
||||
}
|
||||
|
||||
@@ -131,13 +131,13 @@ export const membershipUserServiceFactory = ({
|
||||
|
||||
existingUsers.push(inviteeUser);
|
||||
const inviteeUserId = inviteeUser?.id;
|
||||
const existingEncrytionKey = await userDAL.findUserEncKeyByUserId(inviteeUserId, tx);
|
||||
const existingEncryptionKey = await userDAL.findUserEncKeyByUserId(inviteeUserId, tx);
|
||||
|
||||
// when user is missing the encrytion keys
|
||||
// this could happen either if user doesn't exist or user didn't find step 3 of generating the encryption keys of srp
|
||||
// So what we do is we generate a random secure password and then encrypt it with a random pub-private key
|
||||
// Then when user sign in (as login is not possible as isAccepted is false) we rencrypt the private key with the user password
|
||||
if (!inviteeUser || (inviteeUser && !inviteeUser?.isAccepted && !existingEncrytionKey)) {
|
||||
if (!inviteeUser || (inviteeUser && !inviteeUser?.isAccepted && !existingEncryptionKey)) {
|
||||
await userDAL.createUserEncryption(
|
||||
{
|
||||
userId: inviteeUserId,
|
||||
@@ -159,7 +159,7 @@ export const membershipUserServiceFactory = ({
|
||||
const hasNoPermanentRole = data.roles.every((el) => el.isTemporary);
|
||||
if (hasNoPermanentRole) {
|
||||
throw new BadRequestError({
|
||||
message: "User must have atleast one permanent role"
|
||||
message: "User must have at least one permanent role"
|
||||
});
|
||||
}
|
||||
const isInvalidTemporaryRole = data.roles.some((el) => {
|
||||
@@ -284,7 +284,7 @@ export const membershipUserServiceFactory = ({
|
||||
const hasNoPermanentRole = data.roles.every((el) => el.isTemporary);
|
||||
if (hasNoPermanentRole) {
|
||||
throw new BadRequestError({
|
||||
message: "User must have atleast one permanent role"
|
||||
message: "User must have at least one permanent role"
|
||||
});
|
||||
}
|
||||
const isInvalidTemporaryRole = data.roles.some((el) => {
|
||||
|
||||
@@ -15,6 +15,7 @@ export const orgMembershipDALFactory = (db: TDbClient) => {
|
||||
.whereNotNull(`${TableName.Membership}.actorUserId`)
|
||||
.join(TableName.Users, `${TableName.Membership}.actorUserId`, `${TableName.Users}.id`)
|
||||
.join(TableName.MembershipRole, `${TableName.Membership}.id`, `${TableName.MembershipRole}.membershipId`)
|
||||
.leftJoin(TableName.Role, `${TableName.Role}.id`, `${TableName.MembershipRole}.customRoleId`)
|
||||
.leftJoin<TUserEncryptionKeys>(
|
||||
TableName.UserEncryptionKey,
|
||||
`${TableName.UserEncryptionKey}.userId`,
|
||||
@@ -31,6 +32,7 @@ export const orgMembershipDALFactory = (db: TDbClient) => {
|
||||
db.ref("scopeOrgId").withSchema(TableName.Membership).as("orgId"),
|
||||
db.ref("role").withSchema(TableName.MembershipRole),
|
||||
db.ref("customRoleId").withSchema(TableName.MembershipRole).as("roleId"),
|
||||
db.ref("slug").withSchema(TableName.Role).as("customRoleSlug"),
|
||||
db.ref("status").withSchema(TableName.Membership),
|
||||
db.ref("isActive").withSchema(TableName.Membership),
|
||||
db.ref("lastLoginAuthMethod").withSchema(TableName.Membership),
|
||||
@@ -56,6 +58,7 @@ export const orgMembershipDALFactory = (db: TDbClient) => {
|
||||
parentMapper: ({
|
||||
email,
|
||||
isEmailVerified,
|
||||
customRoleSlug,
|
||||
username,
|
||||
firstName,
|
||||
lastName,
|
||||
@@ -75,6 +78,7 @@ export const orgMembershipDALFactory = (db: TDbClient) => {
|
||||
orgId,
|
||||
id,
|
||||
role,
|
||||
customRoleSlug,
|
||||
status,
|
||||
isActive,
|
||||
inviteEmail,
|
||||
|
||||
@@ -646,7 +646,7 @@ export const orgDALFactory = (db: TDbClient) => {
|
||||
.replicaNode()(TableName.Membership)
|
||||
.where({ actorIdentityId: identityId })
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Organization)
|
||||
.whereNotNull(`${TableName.Membership}.actorUserId`)
|
||||
.whereNotNull(`${TableName.Membership}.actorIdentityId`)
|
||||
.join(TableName.MembershipRole, `${TableName.Membership}.id`, `${TableName.MembershipRole}.membershipId`)
|
||||
.join(TableName.Organization, `${TableName.Membership}.scopeOrgId`, `${TableName.Organization}.id`)
|
||||
.select(db.ref("id").withSchema(TableName.Organization).as("id"))
|
||||
|
||||
@@ -35,11 +35,11 @@ export const projectKeyDALFactory = (db: TDbClient) => {
|
||||
const findAllProjectUserPubKeys = async (projectId: string, tx?: Knex) => {
|
||||
try {
|
||||
const pubKeys = await (tx || db.replicaNode())(TableName.Membership)
|
||||
.where(`${TableName.Membership}.scopeProjectId` as "projectId", projectId)
|
||||
.where(`${TableName.Membership}.scopeProjectId` as "scopeProjectId", projectId)
|
||||
.where(`${TableName.Membership}.scope`, AccessScope.Project)
|
||||
.join(TableName.Users, `${TableName.Membership}.actorUserId`, `${TableName.Users}.id`)
|
||||
.join(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`)
|
||||
.select("userId", "publicKey");
|
||||
.select(db.ref("userId").withSchema(TableName.Users), "publicKey");
|
||||
return pubKeys;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find all workspace pub keys" });
|
||||
|
||||
@@ -42,12 +42,7 @@ export const projectMembershipDALFactory = (db: TDbClient) => {
|
||||
.select("role")
|
||||
.from(TableName.MembershipRole)
|
||||
.leftJoin(TableName.Role, `${TableName.Role}.id`, `${TableName.MembershipRole}.customRoleId`)
|
||||
.whereRaw("??.?? = ??.??", [
|
||||
TableName.MembershipRole,
|
||||
"projectMembershipId",
|
||||
TableName.Membership,
|
||||
"id"
|
||||
])
|
||||
.whereRaw("??.?? = ??.??", [TableName.MembershipRole, "membershipId", TableName.Membership, "id"])
|
||||
.where((subQb) => {
|
||||
void subQb
|
||||
.whereIn(`${TableName.MembershipRole}.role`, filter.roles as string[])
|
||||
|
||||
@@ -31,7 +31,6 @@ export const projectDALFactory = (db: TDbClient) => {
|
||||
.where(`${TableName.Membership}.actorIdentityId`, identityId)
|
||||
.join(TableName.Project, `${TableName.Membership}.scopeProjectId`, `${TableName.Project}.id`)
|
||||
.where(`${TableName.Project}.orgId`, orgId)
|
||||
.join(TableName.Project, `${TableName.Membership}.scopeProjectId`, `${TableName.Project}.id`)
|
||||
.andWhere((qb) => {
|
||||
if (projectType) {
|
||||
void qb.where(`${TableName.Project}.type`, projectType);
|
||||
|
||||
@@ -72,7 +72,7 @@ export const roleServiceFactory = ({
|
||||
slug: data.slug,
|
||||
[scope.key]: scope.value
|
||||
});
|
||||
if (existingRole) throw new NotFoundError({ message: `Role with ${data.slug} exist` });
|
||||
if (existingRole) throw new NotFoundError({ message: `Role with ${data.slug} exists` });
|
||||
|
||||
validateHandlebarTemplate("Role Creation", JSON.stringify(data.permissions || []), {
|
||||
allowedExpressions: (val) => val.includes("identity.")
|
||||
@@ -108,7 +108,7 @@ export const roleServiceFactory = ({
|
||||
[scope.key]: scope.value
|
||||
});
|
||||
if (existingSlug && existingRole.id !== existingSlug.id)
|
||||
throw new BadRequestError({ message: `Role with ${data.slug} not found` });
|
||||
throw new BadRequestError({ message: `Role with ${data.slug} already exists` });
|
||||
}
|
||||
|
||||
validateHandlebarTemplate("Role Update", JSON.stringify(data.permissions || []), {
|
||||
|
||||
@@ -597,7 +597,7 @@ export const superAdminServiceFactory = ({
|
||||
{
|
||||
actorIdentityId: newIdentity.id,
|
||||
scopeOrgId: organization.id,
|
||||
scope: AccessScope.Project
|
||||
scope: AccessScope.Organization
|
||||
},
|
||||
tx
|
||||
);
|
||||
@@ -947,6 +947,9 @@ export const superAdminServiceFactory = ({
|
||||
}
|
||||
|
||||
const membershipRole = await membershipRoleDAL.findOne({ membershipId });
|
||||
if (!membershipRole) {
|
||||
throw new NotFoundError({ name: "Membership Role", message: "Membership role not found" });
|
||||
}
|
||||
const [organizationMembership] = await membershipUserDAL.delete({
|
||||
scopeOrgId: organizationId,
|
||||
scope: AccessScope.Organization,
|
||||
|
||||
Reference in New Issue
Block a user