Skip to content

Commit

Permalink
Fixes #318 set username when retrieving project from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Meijer committed Oct 10, 2023
1 parent 2476c23 commit b1eb8bb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/server/storage/safestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ SafeStorage.prototype.createProject = function (data, callback) {
})
.then(function (dbProject) {
var project = new UserProject(dbProject, self, self.logger, self.gmeConfig);
project.setUser(data.username);
deferred.resolve(project);
})
.catch(function (err) {
Expand Down Expand Up @@ -505,6 +506,7 @@ SafeStorage.prototype.duplicateProject = function (data, callback) {
})
.then(function (dbProject) {
var project = new UserProject(dbProject, self, self.logger, self.gmeConfig);
project.setUser(data.username);
deferred.resolve(project);
})
.catch(function (err) {
Expand Down Expand Up @@ -1319,6 +1321,7 @@ SafeStorage.prototype.openProject = function (data, callback) {
self._getProject(data)
.then(function (dbProject) {
userProject = new UserProject(dbProject, self, self.logger, self.gmeConfig);
userProject.setUser(data.username);
deferred.resolve(userProject);
})
.catch(function (err) {
Expand Down
59 changes: 59 additions & 0 deletions test/issue/webgme-engine_318.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*eslint-env node, mocha*/
/**
* @author pmeijer / https://github.com/pmeijer
*/

var testFixture = require('../_globals.js');

describe('UserProject_Auth', function () {
'use strict';
const gmeConfig = testFixture.getGmeConfig();
gmeConfig.authentication.enable = true;
const logger = testFixture.logger.fork('core.intrapersist');
const expect = testFixture.expect;
const projectName = 'UserProject_Auth';
let gmeAuth;
let projectId;
let storage;

before(async function () {
gmeAuth = await testFixture.clearDBAndGetGMEAuth(gmeConfig, null);
storage = testFixture.getMemoryStorage(logger, gmeConfig, gmeAuth);
await storage.openDatabase();
const { project, commitHash, projectId: projectId_ } = await testFixture.importProject(storage, {
projectSeed: './seeds/EmptyProject.webgmex',
username: 'admin',
ownerId: 'admin',
projectName: projectName,
gmeConfig: gmeConfig,
logger: logger
});

projectId = projectId_;

project.createTag('tag', commitHash);
});

after(async function () {
gmeAuth && await gmeAuth.unload();
storage && await storage.closeDatabase();
});

it('should pass on username at OpenProject', async function () {
const project = await storage.openProject({ username: 'admin', projectId });
const tags = await project.getTags();
expect(Object.keys(tags)).to.deep.equal(['tag']);
});

it('should pass on username at CreateProject', async function () {
const project = await storage.createProject({ username: 'admin', projectName: 'newProject' });
const tags = await project.getTags();
expect(Object.keys(tags)).to.deep.equal([]);
});

it('should pass on username at DuplicateProject', async function () {
const project = await storage.duplicateProject({ username: 'admin', projectName: 'newProjectDup', projectId });
const tags = await project.getTags();
expect(Object.keys(tags)).to.deep.equal(['tag']);
});
});

0 comments on commit b1eb8bb

Please sign in to comment.