Skip to content

Commit

Permalink
Merge branch 'develop' into develop-airbyte
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlynchRNA committed Oct 1, 2024
2 parents ebe3415 + 3ab2177 commit 30a3eb1
Show file tree
Hide file tree
Showing 11 changed files with 686 additions and 605 deletions.
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webapp-next",
"version": "1.11.0",
"version": "1.12.0",
"description": "",
"main": "server.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/controllers/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export async function modelAddApi(req, res, next) {
return dynamicResponse(req, res, 400, { error: validationError });
}

if (!stripePlan || !pricingMatrix[stripePlan].llmModels.includes(type)) {
return dynamicResponse(req, res, 403, { error: 'This model is not avialable on this plan' });
}

const configValidations = Object.entries(ModelTypeRequirements[type])
.filter((en: any) => en[1].optional !== true)
.map(en => ({ field: en[0], validation: { notEmpty: true } }));
Expand Down
26 changes: 11 additions & 15 deletions webapp/src/lib/middleware/auth/checkresourceslug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import debug from 'debug';

const log = debug('webapp:middleware:auth:checkresourceslug');

function getAllowedSlugs(orgs) {
return orgs.reduce((acc, org) => {
if (org?.teams?.length > 0) {
acc = acc.concat(org.teams.map(t => t.id.toString()));
}
return acc;
}, []);
}

export async function checkResourceSlug(req, res, next) {
if (
!req.params?.resourceSlug ||
Expand All @@ -17,12 +26,7 @@ export async function checkResourceSlug(req, res, next) {
) {
return dynamicResponse(req, res, 302, { redirect: '/welcome?noaccess=true' });
}
const allowedSlugs = res.locals.account.orgs.reduce((acc, org) => {
if (org?.teams?.length > 0) {
acc = acc.concat(org.teams.map(t => t.id.toString()));
}
return acc;
}, []);
const allowedSlugs = getAllowedSlugs(res.locals.account.orgs);
if (!allowedSlugs.includes(req.params.resourceSlug.toString())) {
return dynamicResponse(req, res, 302, { redirect: '/welcome?noaccess=true' });
}
Expand Down Expand Up @@ -59,12 +63,7 @@ export async function checkResourceSlugQuery(req, res, next) {
return next();
}

const allowedSlugs = res.locals.account.orgs.reduce((acc, org) => {
if (org?.teams?.length > 0) {
acc = acc.concat(org.teams.map(t => t.id.toString()));
}
return acc;
}, []);
const allowedSlugs = getAllowedSlugs(res.locals.account.orgs);
if (req.query?.resourceSlug && !allowedSlugs.includes(req.query.resourceSlug.toString())) {
return res.status(403).send({ error: 'No permission' });
}
Expand Down Expand Up @@ -100,7 +99,6 @@ export async function setDefaultOrgAndTeam(req, res, next) {

const { currentOrg, currentTeam } = res?.locals?.account || {};
if (!currentOrg) {
// return res.status(403).send({ error: 'No current organization available' });
log('No current organization available');
req.session.destroy();
return dynamicResponse(req, res, 302, {
Expand All @@ -110,9 +108,7 @@ export async function setDefaultOrgAndTeam(req, res, next) {
//TODO: cache in redis
const foundOrg = await getOrgById(currentOrg);
if (!foundOrg) {
// return res.status(403).send({ error: 'No permission' });
log('No permission, sending to welcome');
// req.session.destroy();
return dynamicResponse(req, res, 302, { redirect: '/welcome?noaccess=true' });
}
foundOrg['id'] = foundOrg._id;
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/lib/struct/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export enum CollectionName {
Toolrevisions = 'toolrevisions',
Verifications = 'verifications',
ShareLinks = 'sharelinks',
APIKeys = 'apikeys'
APIKeys = 'apikeys',
Checkpoints = 'checkpoints'
}
55 changes: 5 additions & 50 deletions webapp/src/migrations/1.11.0.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,9 @@
import Permission from '@permission';
import debug from 'debug';
import { Binary, ObjectId } from 'mongodb';
import { TeamRoles } from 'permissions/roles';

const log = debug('webapp:migration:1.10.0');
import { CollectionName } from 'lib/struct/db';
const log = debug('webapp:migration:1.11.0');

export default async function (db) {
log('unsetting all account level perms');
const blankPermission = new Permission();
await db.collection('accounts').updateMany(
{},
{
$set: {
permissions: new Binary(blankPermission.array)
}
}
);

log('setting all accounts team permissions to be TEAM_MEMBER');
const accounts = await db.collection('accounts').find().toArray();

const teamMemberPermission = new Binary(new Permission(TeamRoles.TEAM_MEMBER.base64).array);

const bulkWrites = [];

for (const account of accounts) {
if (!account.orgs || account.orgs.length === 0) continue;

for (const org of account.orgs) {
if (!org.teams || org.teams.length === 0) continue;

for (const team of org.teams) {
bulkWrites.push({
updateOne: {
filter: { _id: new ObjectId(team.id) },
update: {
$set: {
[`permissions.${account._id}`]: teamMemberPermission
}
}
}
});
}
}
}

if (bulkWrites.length > 0) {
log('executing bulk write for teams');
await db.collection('teams').bulkWrite(bulkWrites);
} else {
log('no teams to update');
}
log('add indexes to checkpoints collection');
await db.collection(CollectionName.Checkpoints).createIndex({ checkpoint_id: 1 });
await db.collection(CollectionName.Checkpoints).createIndex({ thread_id: 1 });
}
Loading

0 comments on commit 30a3eb1

Please sign in to comment.