Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
r03ert0 authored Jun 13, 2020
2 parents 1c644fc + 7ee7571 commit c7e3cb2
Show file tree
Hide file tree
Showing 288 changed files with 5,099 additions and 108,663 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"indent": "off",
"indent": ["error", 2],
"indent-legacy": "off",
"init-declarations": "off",
"jsx-quotes": "error",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ test/*.png
.vscode
access.log
package-lock.json
app/controller/api/tmp
46 changes: 23 additions & 23 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ const app = express();
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
if (process.env.NODE_ENV !== 'production') {
app.use(require('morgan')('dev'));
app.use(require('morgan')('dev'));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));


/* setup DB */
var checkAnyoneUser = function () {

/* check that the 'anyone' user exists. Insert it if it doesn't */
db.queryUser({username: 'anyone'})
/* check that the 'anyone' user exists. Insert it if it doesn't */
db.queryUser({username: 'anyone'})
.then((res) => {
console.log('"anyone" user correctly configured.', res);
console.log('"anyone" user correctly configured.', res);
})
.catch((err) => {
console.log('"anyone" user absent: adding one.', err);
const anyone = {
username: 'anyone',
nickname: 'anyone',
name: 'Any User',
joined: (new Date()).toJSON()
};
db.addUser(anyone);
console.log('"anyone" user absent: adding one.', err);
const anyone = {
username: 'anyone',
nickname: 'anyone',
name: 'Any User',
joined: (new Date()).toJSON()
};
db.addUser(anyone);
});
};

const db = require('./db/db')(null, checkAnyoneUser);
app.db = db;

Expand All @@ -49,21 +49,21 @@ require('./routes/routes')(app);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
console.log('ERROR: File not found', req.url);
var err = new Error('Not Found', req);
err.status = 404;
next(err);
console.log('ERROR: File not found', req.url);
var err = new Error('Not Found', req);
err.status = 404;
next(err);
});

// error handler
app.use(function(err, req, res) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
// render the error page
res.status(err.status || 500);
res.render('error');
});


Expand Down
5 changes: 1 addition & 4 deletions app/controller/api/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const app = express()
function buildFileID({source, slice}) {
return `${source}&slice=${slice}`;
}

// app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.urlencoded({ extended: true }))

/**
Expand Down Expand Up @@ -107,8 +105,7 @@ describe('controller/api/index.js', () => {
returnFoundAnnotation = true,
updateAnnotation = sinon.stub().resolves(),
findAnnotations = sinon.stub().callsFake(() => Promise.resolve( returnFoundAnnotation ? annoationInDb : {Regions: []} )),
queryProject = sinon.stub().callsFake(() => Promise.resolve(queryPublicProject ? publicProject : privateProject))

queryProject = sinon.stub().callsFake(() => Promise.resolve(queryPublicProject ? publicProject : privateProject))

before(() => {
app.db = {
Expand Down
69 changes: 39 additions & 30 deletions app/controller/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@ router.get('/', async function (req, res) {
const project = (req.query.project) || '';
console.log(`current project: ${project}`);

// project owner and project users
const result = await req.app.db.queryProject({shortname: project});
const owner = result
&& result.owner;
const users = result
&& result.collaborators
&& result.collaborators.list
&& result.collaborators.list.map((u)=>u.username);
console.log(`project owner: ${owner}, users: ${users}`);

// check if user is among the allowed project's users
userIndex = [...users, owner].indexOf(user);
if(userIndex<0) {
res.status(403).send(`User ${user} not part of project ${project}`);
if(project) {
// project owner and project users
const result = await req.app.db.queryProject({shortname: project});
const owner = result
&& result.owner;
const users = result
&& result.collaborators
&& result.collaborators.list
&& result.collaborators.list.map((u)=>u.username) || [];
console.log(`project owner: ${owner}, users: ${users}`);

return;
// check if user is among the allowed project's users
userIndex = [...users, owner].indexOf(user);
if(userIndex<0) {
res.status(403).send(`User ${user} not part of project ${project}`);

return;
}
}

const query = {
Expand All @@ -51,7 +53,12 @@ router.get('/', async function (req, res) {
};
console.log("api get query", query);

const annotations = await req.app.db.findAnnotations(query);
let annotations;
try {
annotations = await req.app.db.findAnnotations(query);
} catch(err) {
throw new Error(err);
}

res.status(200).send(annotations);
});
Expand All @@ -72,21 +79,23 @@ const saveFromGUI = async function (req, res) {
console.log(`current project: ${project}`);

// project owner and project users
const result = await req.app.db.queryProject({shortname: project});
const owner = result
&& result.owner;
const users = result
&& result.collaborators
&& result.collaborators.list
&& result.collaborators.list.map((u)=>u.username);
console.log(`project owner: ${owner}, users: ${users}`);

// check if user is among the allowed project's users
userIndex = [...users, owner].indexOf(user);
if(userIndex<0) {
if(project) {
const result = await req.app.db.queryProject({shortname: project});
const owner = result
&& result.owner;
const users = result
&& result.collaborators
&& result.collaborators.list
&& result.collaborators.list.map((u)=>u.username);
console.log(`project owner: ${owner}, users: ${users}`);

// check if user is among the allowed project's users
userIndex = [...users, owner].indexOf(user);
if(userIndex<0) {
res.status(403).send(`User ${user} not part of project ${project}`);

return;
}
}

req.app.db.updateAnnotation({
Expand All @@ -96,8 +105,8 @@ const saveFromGUI = async function (req, res) {
Hash,
annotation
})
.then(() => res.status(200).send())
.catch((e) => res.status(500).send({err:JSON.stringify(e)}));
.then(() => res.status(200).send())
.catch((e) => res.status(500).send({err:JSON.stringify(e)}));
};

/**
Expand Down
88 changes: 43 additions & 45 deletions app/db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ module.exports = function(overwriteMongoPath, callback) {
return reject(new Error('db connection not healthy'));
}
db.get('user').update({
username : user.username
username: user.username
}, {
$set : user
$set: user
})
.then(() => resolve(user))
.catch(reject);
Expand Down Expand Up @@ -189,13 +189,12 @@ module.exports = function(overwriteMongoPath, callback) {
if (!checkHealth()) {
return reject(new Error('db connection not healthy'));
}
console.log('updateProject:', project);
delete project._id;
db.get('projects').update(
{ shortname : project.shortname },
project
{ shortname: project.shortname },
{ $set: project }
)
.then((o) => {
console.log('updateProject', o);
resolve(o);
})
.catch(reject);
Expand Down Expand Up @@ -245,37 +244,37 @@ module.exports = function(overwriteMongoPath, callback) {
return reject(new Error('db connection not healthy'));
}
db.get('projects').find(pagination)
.then((projects) => {
if(projects) {
resolve(projects);
} else {
reject({message: 'error find all projects', result: projects});
}
})
.catch((e) => reject(e));
.then((projects) => {
if(projects) {
resolve(projects);
} else {
reject({message: 'error find all projects', result: projects});
}
})
.catch((e) => reject(e));
});

/* query user projects */
const queryUserProjects = (requestedUser) => new Promise((resolve, reject) => {
if (!checkHealth()) {
return reject(new Error('db connection not healthy'));
}
db.get('projects').find({
$or: [
{owner: requestedUser},
{"collaborators.list": {$elemMatch:{userID: requestedUser}}}
],
backup: {$exists: false}
if (!checkHealth()) {
return reject(new Error('db connection not healthy'));
}
db.get('projects').find({
$or: [
{owner: requestedUser},
{"collaborators.list": {$elemMatch:{userID: requestedUser}}}
],
backup: {$exists: false}
})
// @todo the results should be access filtered
.then((projects) => {
if(projects) {
resolve(projects);
} else {
reject({message: 'error find all projects', result: projects});
}
})
// @todo the results should be access filtered
.then((projects) => {
if(projects) {
resolve(projects);
} else {
reject({message: 'error find all projects', result: projects});
}
})
.catch(reject);
.catch(reject);
});

/* search users */
Expand Down Expand Up @@ -303,21 +302,20 @@ module.exports = function(overwriteMongoPath, callback) {
.catch(reject);
});

db
.then(() => {
connected = true;
db.then(() => {
connected = true;

console.log('connected successfully');
console.log('connected successfully');

if(typeof callback !== 'undefined') {
return callback();
}
})
.catch((e) => {
// retry (?)
connected = false;
console.log('connection error', e);
});
if(typeof callback !== 'undefined') {
return callback();
}
})
.catch((e) => {
// retry (?)
connected = false;
console.log('connection error', e);
});

return {
addUser,
Expand Down
26 changes: 0 additions & 26 deletions app/public/css/data-style.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
html,body {
margin:0px;
background-color: #333;
}
* {
font-family: sans-serif;
font-size:1rem;
}
#header {
height:48px;
}
Expand All @@ -27,10 +19,8 @@ html,body {
font-weight: lighter;
}
#menu {
float:right;
margin-right: 10px;
display: inline-block;
font: 16px/24px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif;
}
#MyLogin {
display:inline-block;
Expand All @@ -56,22 +46,6 @@ html,body {
z-index:1;
}

#paperjs-container
{
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
z-index:2;
pointer-events: none;
}

#paperjs-container canvas
{
/* pointer-events: */
}

#colorSelector,
#colorSelector *
{
Expand Down
3 changes: 1 addition & 2 deletions app/public/css/index-style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
html, #menu, #footer {
background-color: #111;
background-color: #222;
}
#footer {
display: block;
Expand Down Expand Up @@ -27,7 +27,6 @@ html, #menu, #footer {
margin-top:0;
width: 100%;
display: inline-block;
font: 16px/24px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Verdana, sans-serif;
transition: top .5s, opacity .5s;
-moz-transition: top .5s, opacity .5s;
-webkit-transition: top .5s, opacity .5s;
Expand Down
Loading

0 comments on commit c7e3cb2

Please sign in to comment.