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

#1452 Remove unused columns from projects #1565

Merged
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
51 changes: 6 additions & 45 deletions app/model/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const roles = require('./roles')
const projectSchema = joi.object().keys({
name: joi.string(),
url: joi.string(),
description: joi.string().optional(),
is_private: joi.boolean(),
external_id: joi.string().optional(),
});
Expand Down Expand Up @@ -61,7 +60,7 @@ var Projects = {
},

listAll: function(callback) {
var q = "SELECT project_id as id, name, url, description, is_private, is_enabled \n"+
var q = "SELECT project_id as id, name, url, is_private \n"+
"FROM projects";

queryHandler(q, callback);
Expand Down Expand Up @@ -100,11 +99,7 @@ var Projects = {
whereExp.push("1 = 1");
}
if(query.hasOwnProperty('q')) {
whereExp.push("(p.name LIKE '%"+query.q+"%' OR p.description LIKE '%"+query.q+"%')");
}
if(query.hasOwnProperty('featured')) {
selectExtra += 'featured, image, '
whereExp.push("p.featured = 1 OR p.featured = 2");
whereExp.push("(p.name LIKE '%"+query.q+"%')");
}

if(!whereExp.length) {
Expand All @@ -117,10 +112,7 @@ var Projects = {

if(!query.basicInfo){
selectExtra += " p.citizen_scientist_enabled, \n"+
" p.pattern_matching_enabled, \n"+
" p.reports_enabled, \n"+
" p.is_partner, \n"+
" p.cnn_enabled \n";
" p.is_partner \n";
} else {
selectExtra += "p.project_id as id \n";
}
Expand Down Expand Up @@ -220,7 +212,7 @@ var Projects = {
const result = sites.map(s => {
return {
...s,
utcOffset: fileHelper.formattedTzOffsetFromTimezoneName(s.timezone)
utcOffset: fileHelper.formattedTzOffsetFromTimezoneName(s.timezone ? s.timezone : 'UTC')
}
})
return result
Expand Down Expand Up @@ -286,18 +278,14 @@ var Projects = {
* @param {Object} project
* @param {String} project.name
* @param {String} project.url
* @param {String} project.description
* @param {Number} project.owner_id - creator id
* @param {Number} project.project_type_id
* @param {Boolean} project.is_private
*/
create: async function(project, owner_id, db) {
var schema = joi.object().keys({
name: joi.string(),
url: joi.string(),
description: joi.string().optional(),
external_id: joi.string().optional(),
project_type_id: joi.number(),
is_private: joi.boolean()
});

Expand All @@ -311,13 +299,6 @@ var Projects = {
}

project = result.value;

project.storage_usage = 0;
project.processing_usage = 0;
project.pattern_matching_enabled = 1;
project.aed_enabled = 1;
project.clustering_enabled = 1;
project.reports_enabled = 1;
project.public_templates_enabled = 0;

let createdConnection = false;
Expand Down Expand Up @@ -363,12 +344,7 @@ var Projects = {
* @param {Number} project.project_id
* @param {String} project.name
* @param {String} project.url
* @param {String} project.description
* @param {Number} project.project_type_id
* @param {Boolean} project.is_private
* @param {Boolean} project.is_enabled
* @param {Number} project.storage_usage
* @param {Number} project.processing_usage
* @param {Function} callback(err, projectId)
*
* @return {Promise} resolved after the update.
Expand All @@ -379,18 +355,8 @@ var Projects = {
project_id: joi.number().required(),
name: joi.string(),
url: joi.string(),
description: joi.string().allow(null, '').optional(),
project_type_id: joi.number(),
is_private: [joi.number().valid(0,1), joi.boolean()],
is_enabled: [joi.number().valid(0,1), joi.boolean()],
storage_usage: joi.number().allow(null),
processing_usage: joi.number().allow(null),
citizen_scientist_enabled: [joi.number().valid(0,1), joi.boolean()],
pattern_matching_enabled: [joi.number().valid(0,1), joi.boolean()],
cnn_enabled: [joi.number().valid(0,1), joi.boolean()],
aed_enabled: [joi.number().valid(0,1), joi.boolean()],
clustering_enabled: [joi.number().valid(0,1), joi.boolean()],
reports_enabled: [joi.number().valid(0,1), joi.boolean()],
public_templates_enabled: [joi.number().valid(0,1), joi.boolean()]
};
return q.ninvoke(joi, 'validate', project, schema).then(function(projectInfo){
Expand Down Expand Up @@ -1162,7 +1128,7 @@ var Projects = {
createInCoreAPI: async function(project, idToken) {
const body = {
name: project.name,
description: project.description,
description: '',
is_public: !project.is_private,
external_id: project.project_id
}
Expand Down Expand Up @@ -1216,7 +1182,6 @@ var Projects = {
updateInCoreAPI: async function(data, idToken) {
let body = {}
data.name !== undefined && (body.name = data.name)
data.description !== undefined && (body.description = data.description)
data.is_private !== undefined && (body.is_public = !data.is_private)
const options = {
method: 'PATCH',
Expand Down Expand Up @@ -1286,14 +1251,12 @@ var Projects = {
* Creates a project with given data
* @param {*} data
* @param {string} data.name
* @param {string} data.description
* @param {string} data.url
* @param {boolean} data.is_private
* @param {integer} userId
*/
createProject: async function (data, userId, connection) {
const projectData = {
project_type_id: 1,
...data
}
await q.ninvoke(joi, 'validate', projectData, projectSchema, {
Expand Down Expand Up @@ -1364,9 +1327,7 @@ var Projects = {
const projectData = {
is_private: true,
name: `${user.firstname} ${user.lastname}'s project`,
url: this.getPersonalProjectUrl(user),
description: `${user.firstname}'s personal project`,
project_type_id: 1
url: this.getPersonalProjectUrl(user)
};
await q.ninvoke(joi, 'validate', projectData, projectSchema, {
stripUnknown: true,
Expand Down
6 changes: 1 addition & 5 deletions app/model/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var Users = {
let selectExtra = '';
let joinExtra = '';

selectExtra = "p.project_id AS id, name, url, lat, lon, description, is_private, is_enabled, u.login AS `owner`";
selectExtra = "p.project_id AS id, name, url, lat, lon, description, is_private, u.login AS `owner`";

joinExtra = "JOIN user_project_role AS upr ON (p.project_id = upr.project_id and upr.role_id = 4) \n"+
"JOIN user_project_role AS upr2 ON (p.project_id = upr2.project_id) \n"+
Expand All @@ -198,10 +198,6 @@ var Users = {
if(query.hasOwnProperty('q')) {
whereExp.push("p.name LIKE '%"+query.q+"%' OR p.description LIKE '%"+query.q+"%'");
}
if(query.hasOwnProperty('featured')) {
selectExtra += ', featured, image'
whereExp.push("p.featured = 1 OR p.featured = 2");
}
if (query.hasOwnProperty('publicTemplates')) {
whereExp.push('p.deleted_at IS NULL');
}
Expand Down
9 changes: 0 additions & 9 deletions app/routes/citizen-scientist.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ router.get('/:projecturl?/', function(req, res, next) {

var project = rows[0];

if(!project.is_enabled) {
return res.render('project_disabled', {
project: project,
user: req.session.user
});
}


if(project.plan_period && project.plan_activated) {
project.plan_due = new Date(project.plan_activated);
project.plan_due.setFullYear(project.plan_due.getFullYear() + project.plan_period);
Expand All @@ -102,7 +94,6 @@ router.get('/:projecturl?/', function(req, res, next) {
authorized: true,
public: !project.is_private,
features:{
pattern_matching: !!project.pattern_matching_enabled,
citizen_scientist: !!project.citizen_scientist_enabled,
},
super: !!req.session.user.isSuper,
Expand Down
7 changes: 2 additions & 5 deletions app/routes/data-api/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ router.post('/projects', verifyToken(), hasRole(['appUser', 'rfcxUser']), async
try {
const converter = new Converter(req.body, {});
converter.convert('name').toString();
converter.convert('description').optional().toString();
converter.convert('is_private').toBoolean().default(true);
converter.convert('external_id').toString();
const params = await converter.validate();
const user = await model.users.ensureUserExistFromAuth0(req.user);
const url = await model.projects.findUniqueUrl(params.name, params.external_id, user.user_id)
const { name, description, is_private, external_id } = params
const projectId = await model.projects.createProject({ name, description, is_private, external_id, url }, user.user_id);
const { name, is_private, external_id } = params
const projectId = await model.projects.createProject({ name, is_private, external_id, url }, user.user_id);
const project = await model.projects.find({ id: projectId }).get(0);
res.status(201).json(project);
} catch (e) {
Expand All @@ -34,7 +33,6 @@ router.patch('/projects/:externalId', verifyToken(), hasRole(['appUser', 'rfcxUs
const user = await model.users.ensureUserExistFromAuth0(req.user);
const converter = new Converter(req.body, {});
converter.convert('name').optional().toString();
converter.convert('description').optional().toString();
converter.convert('url').optional().toString();

const params = await converter.validate();
Expand All @@ -49,7 +47,6 @@ router.patch('/projects/:externalId', verifyToken(), hasRole(['appUser', 'rfcxUs
project_id: project.project_id,
name: params.name !== undefined ? params.name : project.name,
url: params.url !== undefined ? params.url : project.url,
description: params.description !== undefined ? params.description : project.description,
is_private: project.is_private,
})
res.sendStatus(200);
Expand Down
2 changes: 0 additions & 2 deletions app/routes/data-api/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ router.post('/create-project', function(req, res, next) {
})
]).then(function() {
console.log('project:', project);
// assign project_type_id to normal type
project.project_type_id = 1;

return model.projects.createProjectInArbimonAndCoreAPI(project, req.session.user.id, req.session.idToken).then(function (projectId) {
res.json({
Expand Down
1 change: 0 additions & 1 deletion app/routes/data-api/project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ router.post('/:projectUrl/info/update', function(req, res, next) {
project_id: joi.number().required(),
name: joi.string(),
url: joi.string(),
description: joi.string().allow(null, '').optional(),
is_private: joi.number(),
public_templates_enabled: joi.number(),
};
Expand Down
10 changes: 0 additions & 10 deletions app/routes/data-api/project/pattern_matchings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ let cachedData = {
counts: { }
};

// global project.pattern_matching_enabled check
router.use(function(req, res, next) {
if(!req.project.pattern_matching_enabled) {
return res.status(401).json({ error: "Pattern matching features are not enabled for your project." });
}

next();
});


/** Return a list of all the pattern matchings in a project.
*/
router.get('/', function(req, res, next) {
Expand Down
2 changes: 0 additions & 2 deletions app/routes/data-api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ router.get('/projectlist', function(req, res, next) {
user_id: req.session.user.id,
publicTemplates: publicTemplates,
...req.query.q && { q: req.query.q },
...req.query.featured && { featured: req.query.featured }
}, function(err, rows) {
if(err) return next(err);
res.json(rows);
Expand All @@ -32,7 +31,6 @@ router.get('/projectlist', function(req, res, next) {
...includeLocation && { include_location: true },
publicTemplates: publicTemplates,
...req.query.q && { q: req.query.q },
...req.query.featured && type !== 'my' && { featured: req.query.featured }
}, function(err, rows) {
if(err) return next(err);
res.json(rows);
Expand Down
11 changes: 0 additions & 11 deletions app/routes/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ router.get('/:projecturl?/', function(req, res, next) {

var project = rows[0];

if(!project.is_enabled) {
return res.render('project_disabled', {
project: project,
user: req.session.user
});
}
const userRole = await model.users.getProjectRole(req.session.user.id, project.project_id)
model.users.getPermissions(req.session.user.id, project.project_id, function(err, rows) {
var permissionsMap = rows.reduce(function(_, p) {
Expand Down Expand Up @@ -116,12 +110,7 @@ router.get('/:projecturl?/', function(req, res, next) {
authorized: true,
public: !project.is_private,
features:{
pattern_matching: !!project.pattern_matching_enabled,
cnn: !!project.cnn_enabled,
citizen_scientist: !!project.citizen_scientist_enabled,
aed: !!project.aed_enabled,
clustering: !!project.clustering_enabled,
reports_enabled: !!project.reports_enabled,
public_templates_enabled: !!project.public_templates_enabled,
},
super: !!req.session.user.isSuper,
Expand Down
9 changes: 0 additions & 9 deletions app/routes/visualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ router.get('/:projecturl?/', function(req, res, next) {

var project = rows[0];

if(!project.is_enabled) {
return res.render('project_disabled', {
project: project,
user: req.session.user
});
}


if(project.plan_period && project.plan_activated) {
project.plan_due = new Date(project.plan_activated);
project.plan_due.setFullYear(project.plan_due.getFullYear() + project.plan_period);
Expand All @@ -103,7 +95,6 @@ router.get('/:projecturl?/', function(req, res, next) {
authorized: true,
public: !project.is_private,
features:{
pattern_matching: !!project.pattern_matching_enabled,
citizen_scientist: !!project.citizen_scientist_enabled,
},
super: !!req.session.user.isSuper,
Expand Down
36 changes: 0 additions & 36 deletions assets/app/admin/projects/list-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,12 @@ <h4>
ng-model="controller.project.processing_limit">
</div>
<label>Features</label>
<div class="form-group">
<label>Pattern Matching:</label>
<div class="btn-group">
<a2-switch ng-model="controller.project.pattern_matching_enabled" />
</div>
</div>
<div class="form-group">
<label>Convolutional Neural Networks:</label>
<div class="btn-group">
<a2-switch ng-model="controller.project.cnn_enabled" />
</div>
</div>
<div class="form-group">
<label>Audio Event Detection:</label>
<div class="btn-group">
<a2-switch
ng-model="controller.project.aed_enabled"
ng-change="controller.handleAedToggle()"
/>
</div>
</div>
<div class="form-group">
<label>Clustering:</label>
<div class="btn-group">
<a2-switch
ng-model="controller.project.clustering_enabled"
disabled="!controller.project.aed_enabled"
/>
</div>
</div>
<div class="form-group">
<label>Citizen Scientist:</label>
<div class="btn-group">
<a2-switch ng-model="controller.project.citizen_scientist_enabled" />
</div>
</div>
<div class="form-group">
<label>Insights:</label>
<div class="btn-group">
<a2-switch ng-model="controller.project.reports_enabled" />
</div>
</div>
<button class="btn btn-primary"
ng-click="controller.save()">
<i class="fa fa-floppy-o"></i> Save
Expand Down
2 changes: 0 additions & 2 deletions assets/app/admin/projects/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<ui-select-match placeholder="Select a Project">
{{ $select.selected.name }}
<i class="fa" ng-class="$select.selected.is_private ? 'fa-lock' :'fa-globe'"></i>
<small ng-hide="$select.selected.is_enabled"><i>disabled</i></small>
</ui-select-match>
<ui-select-choices repeat="project in controller.projects | filter:$select.search">
{{ project.name }}
<i class="fa" ng-class="project.is_private ? 'fa-lock' :'fa-globe'"></i>
<small ng-hide="project.is_enabled"><i>disabled</i></small>
</ui-select-choices>
</ui-select>
<ui-view name="detail"></ui-view>
Expand Down
Loading
Loading