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

221 xhn dev #222

Open
wants to merge 50 commits into
base: migration-to-v17
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
240aac6
create anchor-web-route.js and add 3 general purpose views
ltann Sep 14, 2020
3be1f6e
add pre handlers for each routes in anchor-web-route.js
ltann Sep 15, 2020
6b9151f
add anchor-web-route.js routes into routeMap and routes into anchor-m…
ltann Sep 16, 2020
8dac082
change route /create/{collectionName} key name in anchor-model.js rou…
ltann Sep 17, 2020
54adf0a
include default scope property and check for routes in anchor-web-rou…
ltann Sep 20, 2020
e37714e
Add template for default table view and updated AnchorModel and ancho…
asadeg02 Sep 24, 2020
d5b678e
Resolve merge conflicts
asadeg02 Sep 24, 2020
73e53b9
Add option for setting the default visibility of default table view d…
asadeg02 Sep 24, 2020
a5e0033
Fix the bug inside default table view route
asadeg02 Sep 24, 2020
a5ec349
Add validation for table view outputDataFields
asadeg02 Sep 29, 2020
34aa969
secure column options above user roles in tokens tableview
ltann Oct 1, 2020
675f638
Merge remote-tracking branch 'origin/221-XHN-dev' into 221-XHN-dev
ltann Oct 1, 2020
4b26cf9
modify comparison roles check to compare for existence rather than by…
ltann Oct 4, 2020
c6c1afe
add scopeCheck handler with explicit string role comparison
ltann Oct 4, 2020
7b81c7f
include scopeCheck pre handler on all routes in anchor-web-route.js
ltann Oct 4, 2020
1dfca2a
Add primary code for default crearte view
asadeg02 Oct 7, 2020
d105441
Add new files
asadeg02 Oct 7, 2020
2ce168e
Display the secondary collection in the table on the UI when a user l…
ltann Oct 12, 2020
2f7b8dd
fix scope configuration of routes api
ltann Oct 13, 2020
a3c5c24
directly add unconfigurable routes with no scope into second table in…
ltann Oct 13, 2020
02a9cc1
fix display of secondary collection in the table on the UI
ltann Oct 18, 2020
757e069
Add parser for form fields json schemas
asadeg02 Oct 27, 2020
4dd16f1
Add parser file
asadeg02 Oct 27, 2020
6700c8f
Fix hard coded Create button onclick handler. Extend concat.js functi…
ltann Oct 28, 2020
0d0896b
Clean up default script for create view
asadeg02 Oct 29, 2020
be5572a
Mergework on remote
asadeg02 Oct 29, 2020
5cb6e9e
Remove hard coded string from create url in default template for tabl…
asadeg02 Oct 29, 2020
863a47e
Resovle merge conflicts
asadeg02 Oct 29, 2020
7b25935
Replce hard coded token string with {{collectionName}} in scripts for…
asadeg02 Oct 29, 2020
103f418
Create anchor-default-script.js for Edit and Delete button in table v…
ltann Oct 30, 2020
10e272d
Configure default table view data format (Boolean -> badge view, Date…
ltann Nov 3, 2020
3d62198
Add parser for converting joi to json and integrate that with create …
asadeg02 Nov 5, 2020
0e49f4d
Initialized tableView property in collections
ltann Nov 5, 2020
b9b57d2
Merge remote-tracking branch 'origin/221-XHN-dev' into 221-XHN-dev
ltann Nov 5, 2020
ff9da74
Implement default edit view work flow
asadeg02 Nov 9, 2020
91647d2
Comment out the /{collectionName} routes in route folder for all the …
ltann Nov 13, 2020
8781445
Merge remote-tracking branch 'origin/221-XHN-dev' into 221-XHN-dev
ltann Nov 15, 2020
696f003
Resolve conflicts and fix linting issues
asadeg02 Nov 19, 2020
e31f80d
Fix the bug in anchor web route
asadeg02 Nov 19, 2020
ad63458
fix bug in tableView for undefined/empty column data
ltann Nov 19, 2020
c62b22a
initialized createView and create payload for all collections
ltann Nov 19, 2020
9fc6e22
fix bug in tokens checkbox createView
ltann Nov 19, 2020
0893b08
Fix bug in route for default table view
asadeg02 Nov 21, 2020
852512d
Initialized editView and update payload for all collections.
ltann Nov 30, 2020
4d5984d
Fix issues regarding routescopes
asadeg02 Dec 3, 2020
0035823
dealt with case when createSchema is null, include collection schema …
ltann Dec 4, 2020
7432a0e
update createSchema to either contain specific collection schema or t…
ltann Dec 4, 2020
5957d59
Resolve conflicts
asadeg02 Jan 13, 2021
6b45205
Refactor first-time-setup script
asadeg02 Jan 13, 2021
99b49d2
Fix the bug for authentication in index and login routes
asadeg02 Jun 13, 2022
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
158 changes: 52 additions & 106 deletions first-time-setup.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,76 @@
'use strict';
const Async = require('async');
const Config = require('./config');
const Joi = require('joi');
const MongoModels = require('hicsail-mongo-models');
const AnchorModels = require('./server/anchor/anchor-model');
const Mongodb = require('mongodb');
const Promptly = require('promptly');
const User = require('./server/models/user');
const PasswordComplexity = require('joi-password-complexity');

Async.auto({
mongodbUri: (done) => {

const options = {
default: 'mongodb://localhost:27017/anchor'
};
const main = async function () {

Promptly.prompt(`MongoDB URI: (${options.default})`, options, done);
},
testMongo: ['mongodbUri', (results, done) => {
const options = {
default: 'mongodb://localhost:27017/anchor'
};
const mongodbUri = await Promptly.prompt(`MongoDB URI: (${options.default})`, options);

Mongodb.MongoClient.connect(results.mongodbUri, {}, (err, db) => {

if (err) {
console.error('Failed to connect to Mongodb.');
return done(err);
}
const testMongo = await Mongodb.MongoClient.connect(mongodbUri, {});

db.close();
done(null, true);
});
}],
rootEmail: ['testMongo', (results, done) => {

Promptly.prompt('Root user email:', done);
}],
rootPassword: ['rootEmail', (results, done) => {

Promptly.password('Root user password:', done);
}],
rootPasswordCheck: ['rootPassword', (results, done) => {

const complexityOptions = Config.get('/passwordComplexity');
Joi.validate(results.rootPassword, new PasswordComplexity(complexityOptions),done);
}],
setupRootUser: ['rootPassword', (results, done) => {

Async.auto({
connect: function (done) {

MongoModels.connect(results.mongodbUri, {}, done);
},
rootUser: ['connect', (dbResults, done) => {

User.findOne({ username: 'root' }, done);
}],
rootUserCheck: ['rootUser', (dbResults, done) => {

if (results.rootUser) {
return done(Error('Root User already exists'));
}
done();
}],
userEmail:['rootUserCheck', function (dbResults, done) {

User.findOne({ email: results.rootEmail }, done);
}],
emailCheck:['userEmail', function (dbResults, done) {

console.log(dbResults.userEmail);
if (dbResults.userEmail) {
done(Error('Email is in use'));
}
else {
done();
}
}],
user: ['emailCheck', function (dbResults, done) {

Async.auto({
passwordHash: function (done) {

User.generatePasswordHash(results.rootPassword,done);
}
}, (err, passResults) => {

if (err) {
return done(err);
}
if (!testMongo) {
console.error('Failed to connect to Mongodb.');
}

const document = {
_id: User.ObjectId('000000000000000000000000'),
isActive: true,
username: 'root',
name: 'Root',
password: passResults.passwordHash.hash,
email: results.rootEmail.toLowerCase(),
roles: {
root: true
},
timeCreated: new Date()
};
const rootEmail = await Promptly.prompt('Root user email:');

User.insertOne(document, (err, docs) => {
const rootPassword = await Promptly.password('Root user password:');
const complexityOptions = Config.get('/passwordComplexity');
Joi.validate(rootPassword, new PasswordComplexity(complexityOptions));

done(err, docs && docs[0]);
});
});
}]
}, (err, dbResults) => {

if (err) {
console.error('Failed to setup root user.');
return done(err);
}
console.log(mongodbUri);
const connection = { 'uri': mongodbUri, 'db': 'anchor' };
await AnchorModels.connect(connection, {});

done(null, true);
});
}]
}, (err, results) => {
const rootUser = await User.findOne({ username: 'root' });

if (err) {
console.error('Setup failed.');
console.error(err);
if (rootUser) {
console.error(Error('Root User already exists'));
return process.exit(1);
}

const userEmail = await User.findOne({ email: rootEmail });
// replaces emailCheck
if (userEmail) {
console.err(Error('Email is in use'));
}
const passwordHash = await User.generatePasswordHash(rootPassword);
const document = {
_id: User.ObjectId('000000000000000000000000'),
isActive: true,
username: 'root',
name: 'Root',
password: passwordHash.hash,
email: rootEmail.toLowerCase(),
roles: {
root: true
},
timeCreated: new Date()
};
await User.insertOne(document);
console.log('Setup complete.');
process.exit(0);
});

/*
* if (err) {
* console.error('Setup failed.');
* console.error(err);
* return process.exit(1);
* }
*
* console.log('Setup complete.');
* process.exit(0);
*/
};
main();
3 changes: 3 additions & 0 deletions manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const manifest = {
{
plugin: './server/anchor/anchor-api'
},
{
plugin: './server/anchor/anchor-web-route'
},
{
plugin: './server/anchor/hapi-anchor-api'
},
Expand Down
80 changes: 76 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"node": "8.x.x"
},
"dependencies": {
"@hapi/joi": "^17.1.1",
"adm-zip": "0.4.x",
"archiver": "2.x.x",
"async": "2.x.x",
Expand All @@ -46,6 +47,7 @@
"hoek": "5.x.x",
"inert": "^5.1.0",
"joi": "13.x.x",
"joi-json": "^4.0.0",
"joi-password-complexity": "2.x.x",
"jsonwebtoken": "8.x.x",
"lout": "10.x.x",
Expand Down
Loading