Skip to content

Commit 8569d07

Browse files
committed
Add License Policy support
* Add licensePolicy model * Add initial jstree license policy icons and colors Addresses: #215 Signed-off-by: Steven Esser <[email protected]>
1 parent 5097990 commit 8569d07

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

assets/app/css/main.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,22 @@ div.dataTables_scrollHead th:first-child {
399399
.fa_custom_nr {
400400
color: #1697af;
401401
}
402+
403+
.fa_custom_approved {
404+
color: #008000;
405+
}
406+
407+
.fa_custom_prohibited {
408+
color: #c83025;
409+
}
410+
411+
.fa_custom_recommended {
412+
color: #002FFF;
413+
}
414+
415+
.fa_custom_restricted {
416+
color: #FFcc33;
417+
}
402418
/*---------------------------------------
403419
Split.js
404420
-----------------------------------------*/

assets/app/js/controllers/jsTree.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,25 @@ class JsTree extends Controller {
9696
},
9797
'packageFile': {
9898
'icon': 'fa fa-file fa_custom_package'
99+
},
100+
'approvedLicense': {
101+
'icon': 'fa fa-check-circle fa_custom_approved'
102+
},
103+
'prohibitedLicense': {
104+
'icon': 'fa fa-ban fa_custom_prohibited'
105+
},
106+
'recommendedLicense': {
107+
'icon': 'fa fa-thumbs-up fa_custom_recommended'
108+
},
109+
'restrictedLicense': {
110+
'icon': 'fa fa-exclamation-triangle fa_custom_restricted'
99111
}
100112
},
101113
'plugins': ['types', 'sort', 'contextmenu', 'wholerow'],
102114
// TODO: must fix sorting with these new types
103115
'sort': function (a, b) {
104116
const dir_types = ['directory', 'analyzedDir', 'naDir', 'ocDir', 'nrDir', 'packageDir'];
105-
const file_types = ['file', 'analyzedFile', 'naFile', 'ocFile', 'ocDir', 'pacakgeFile'];
117+
const file_types = ['file', 'analyzedFile', 'naFile', 'ocFile', 'ocDir', 'pacakgeFile', 'approvedLicense', 'prohibitedLicense', 'recommendedLicense', 'restrictedLicense'];
106118

107119
const a1 = this.get_node(a);
108120
const b1 = this.get_node(b);

assets/app/js/models/database.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const headerModel = require('./header');
1818
const fileModel = require('./file');
1919
const licenseModel = require('./license');
2020
const licenseExpressionModel = require('./licenseExpression');
21+
const licensePolicyModel = require('./licensePolicy');
2122
const copyrightModel = require('./copyright');
2223
const packageModel = require('./package');
2324
const emailModel = require('./email');
@@ -31,6 +32,7 @@ module.exports = function(sequelize, DataTypes) {
3132
this.File = fileModel(sequelize, DataTypes);
3233
this.License = licenseModel(sequelize, DataTypes);
3334
this.LicenseExpression = licenseExpressionModel(sequelize, DataTypes);
35+
this.LicensePolicy = licensePolicyModel(sequelize, DataTypes);
3436
this.Copyright = copyrightModel(sequelize, DataTypes);
3537
this.Package = packageModel(sequelize, DataTypes);
3638
this.Email = emailModel(sequelize, DataTypes);
@@ -43,6 +45,7 @@ module.exports = function(sequelize, DataTypes) {
4345
this.Header.hasMany(this.File);
4446
this.File.hasMany(this.License);
4547
this.File.hasMany(this.LicenseExpression);
48+
this.File.hasMany(this.LicensePolicy);
4649
this.File.hasMany(this.Copyright);
4750
this.File.hasMany(this.Package);
4851
this.File.hasMany(this.Email);
@@ -53,6 +56,7 @@ module.exports = function(sequelize, DataTypes) {
5356
this.fileIncludes = [
5457
{ model: this.License, separate: true },
5558
{ model: this.LicenseExpression, separate: true },
59+
{ model: this.LicensePolicy, separate: true },
5660
{ model: this.Copyright, separate: true },
5761
{ model: this.Package, separate: true },
5862
{ model: this.Email, separate: true },
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
#
3+
# Copyright (c) 2019 nexB Inc. and others. All rights reserved.
4+
# https://nexb.com and https://github.com/nexB/scancode-workbench/
5+
# The ScanCode Workbench software is licensed under the Apache License version 2.0.
6+
# ScanCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
*/
16+
17+
module.exports = function(sequelize, DataTypes) {
18+
return sequelize.define(
19+
'license_policy',
20+
{
21+
license_key: DataTypes.STRING,
22+
label: DataTypes.STRING,
23+
color_code: DataTypes.STRING,
24+
icon: DataTypes.STRING
25+
},
26+
{
27+
timestamps: false
28+
});
29+
};

assets/app/js/workbenchDB.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,16 @@ class WorkbenchDB {
172172
.then((concs) => concs.map((conc) => conc.fileId));
173173
const pkgPromise = this.db.Package.findAll({attributes: ['fileId']})
174174
.then((pkgs) => pkgs.map((pkg) => pkg.fileId));
175-
176-
return Promise.all([analyzedPromise, NAPromise, OCPromise, NRPromise, pkgPromise]).then((promises) => this.sync
175+
const approvedPromise = this.db.LicensePolicy.findAll({where: {label: 'Approved License'}, attributes: ['fileId']})
176+
.then((policies) => policies.map((policy) => policy.fileId));
177+
const prohibitedPromise = this.db.LicensePolicy.findAll({where: {label: 'Prohibited License'}, attributes: ['fileId']})
178+
.then((policies) => policies.map((policy) => policy.fileId));
179+
const recommendedPromise = this.db.LicensePolicy.findAll({where: {label: 'Recommended License'}, attributes: ['fileId']})
180+
.then((policies) => policies.map((policy) => policy.fileId));
181+
const restrictedPromise = this.db.LicensePolicy.findAll({where: {label: 'Restricted License'}, attributes: ['fileId']})
182+
.then((policies) => policies.map((policy) => policy.fileId));
183+
184+
return Promise.all([analyzedPromise, NAPromise, OCPromise, NRPromise, pkgPromise, approvedPromise, prohibitedPromise, recommendedPromise, restrictedPromise]).then((promises) => this.sync
177185
.then((db) => db.File.findAll(query))
178186
.then((files) => {
179187
return files.map((file) => {
@@ -196,6 +204,10 @@ class WorkbenchDB {
196204
const oc = promises[2];
197205
const nr = promises[3];
198206
const packages = promises[4];
207+
const approvedPolicies = promises[5];
208+
const prohibitedPolicies = promises[6];
209+
const recommendedPolicies = promises[7];
210+
const restrictedPolicies = promises[8];
199211

200212
if (analyzed.includes(file.id)) {
201213
if (file.type === 'file') {
@@ -227,6 +239,14 @@ class WorkbenchDB {
227239
} else if (file.type === 'directory') {
228240
type = 'packageDir';
229241
}
242+
} else if (approvedPolicies.includes(file.id)) {
243+
type = 'approvedLicense';
244+
} else if (prohibitedPolicies.includes(file.id)) {
245+
type = 'prohibitedLicense';
246+
} else if (recommendedPolicies.includes(file.id)) {
247+
type = 'recommendedLicense';
248+
} else if (restrictedPolicies.includes(file.id)) {
249+
type = 'restrictedLicense';
230250
} else {
231251
type = file.type;
232252
}
@@ -372,6 +392,7 @@ class WorkbenchDB {
372392
return this.db.File.bulkCreate(files, options)
373393
.then(() => this.db.License.bulkCreate(this._addExtraFields(files, 'licenses'), options))
374394
.then(() => this.db.LicenseExpression.bulkCreate(this._addExtraFields(files, 'license_expressions'), options))
395+
.then(() => this.db.LicensePolicy.bulkCreate(this._addExtraFields(files, 'license_policy'), options))
375396
.then(() => this.db.Copyright.bulkCreate(this._addExtraFields(files, 'copyrights'), options))
376397
.then(() => this.db.Package.bulkCreate(this._addExtraFields(files, 'packages'), options))
377398
.then(() => this.db.Email.bulkCreate(this._addExtraFields(files, 'emails'), options))
@@ -388,6 +409,8 @@ class WorkbenchDB {
388409
return $.map(files, (file) => {
389410
if (attribute === 'copyrights') {
390411
return this._getNewCopyrights(file);
412+
} else if (attribute === 'license_policy') {
413+
return this._getLicensePolicy(file);
391414
}
392415
return $.map(file[attribute] || [], (value) => {
393416
if (attribute === 'license_expressions') {
@@ -402,6 +425,15 @@ class WorkbenchDB {
402425
});
403426
}
404427

428+
_getLicensePolicy(file) {
429+
if ($.isEmptyObject(file.license_policy)) {
430+
return;
431+
}
432+
const license_policy = file.license_policy;
433+
license_policy.fileId = file.id;
434+
return license_policy;
435+
}
436+
405437
_getNewCopyrights(file) {
406438
const statements = file.copyrights;
407439
const holders = file.holders;

0 commit comments

Comments
 (0)