Skip to content

Commit

Permalink
Merge pull request #259 from tnc-ca-geo/unregister-camera-fix
Browse files Browse the repository at this point in the history
Fix unregister camera permissions issue
  • Loading branch information
nathanielrindlaub authored Aug 31, 2024
2 parents a46003d + 52ff687 commit 74ff0d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/api/db/models/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ProjectModel } from './Project.js';
import { BaseAuthedModel, MethodParams, roleCheck, idMatch } from './utils.js';
import { Context } from '../../handler.js';
import type * as gql from '../../../@types/graphql.js';
import { ProjectSchema } from '../schemas/Project.js';
import Project, { ProjectSchema } from '../schemas/Project.js';

const ObjectId = mongoose.Types.ObjectId;

Expand Down Expand Up @@ -188,6 +188,7 @@ export class CameraModel {
if (defaultProjReg) defaultProjReg.active = true;
else {
cam.projRegistrations.push({
_id: new ObjectId(),
projectId: 'default_project',
active: true,
});
Expand All @@ -197,7 +198,10 @@ export class CameraModel {

// make sure there's a Project.cameraConfig record for this camera
// in the default_project and create one if not
let [defaultProj] = await ProjectModel.getProjects({ _ids: ['default_project'] }, context);
let defaultProj = await Project.findOne({ _id: 'default_project' });
if (!defaultProj) {
throw new CameraRegistrationError('Could not find default project');
}

let addedNewCamConfig = false;
const camConfig = defaultProj.cameraConfigs.find((cc) => idMatch(cc._id, input.cameraId));
Expand Down
3 changes: 2 additions & 1 deletion src/api/db/models/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ export class ProjectModel {
try {
return await retry(
async () => {
const [project] = await ProjectModel.getProjects({ _ids: [projectId] }, context);
let project = await Project.findOne({ _id: projectId });
if (!project) throw new NotFoundError('Project not found');
console.log('originalProject: ', project);

const newCamConfig = {
Expand Down

0 comments on commit 74ff0d8

Please sign in to comment.