Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #318 set username when retrieving project from storage #320

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
});
});
Loading