Skip to content

Commit

Permalink
fix(authentication): getTeam checks not working correctly
Browse files Browse the repository at this point in the history
fix(database): temporary patch for schema cloning on view creation
  • Loading branch information
kkopanidis committed Jun 16, 2023
1 parent ba7f1fd commit c0ef200
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
23 changes: 15 additions & 8 deletions modules/authentication/src/handlers/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,24 @@ export class TeamsHandler implements IAuthenticationStrategy {
async getTeam(call: ParsedRouterRequest): Promise<UnparsedRouterResponse> {
const { user } = call.request.context;
const { teamId, populate } = call.request.params;
const relations = await this.grpcSdk.authorization!.findRelation({
const allowed = await this.grpcSdk.authorization?.can({
subject: 'User:' + user._id,
actions: ['read'],
resource: 'Team:' + teamId,
skip: 0,
limit: 1,
});
if (!relations || relations.relations.length === 0) {
throw new GrpcError(
status.PERMISSION_DENIED,
'User does not have permission to view team',
);
if (!allowed || !allowed.allow) {
const relations = await this.grpcSdk.authorization!.findRelation({
subject: 'User:' + user._id,
resource: 'Team:' + teamId,
skip: 0,
limit: 1,
});
if (!relations || relations.relations.length === 0) {
throw new GrpcError(
status.PERMISSION_DENIED,
'User does not have permission to view team',
);
}
}
const team: Team | null = await Team.getInstance().findOne(
{ _id: teamId },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ export class MongooseSchema extends SchemaAdapter<Model<any>> {
} else {
(schema as _ConduitSchema).collectionName = schema.name; //restore collectionName
}
const mongooseSchema = new Schema(schema.fields as Indexable, {
...schema.modelOptions,
const mongooseSchema = new Schema(cloneDeep(schema.fields as Indexable), {
...cloneDeep(schema.modelOptions),
...(isView
? {
autoCreate: false,
autoIndex: false,
}
: {}),
});
this.model = mongoose.model(schema.name, mongooseSchema);
this.model = mongoose.model(cloneDeep(schema.name), mongooseSchema);
}

parseStringToQuery(
Expand Down
4 changes: 3 additions & 1 deletion modules/database/src/adapters/mongoose-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
return;
}
const model = this.models[modelName];
const newSchema = JSON.parse(JSON.stringify(model.schema));
let newSchema = model.schema;
//@ts-ignore
newSchema.name = viewName;
//@ts-ignore
newSchema.collectionName = viewName;
const viewModel = new MongooseSchema(
this.grpcSdk,
Expand Down

0 comments on commit c0ef200

Please sign in to comment.