Skip to content

Commit

Permalink
[WIP] init Updating blockList for portal labels
Browse files Browse the repository at this point in the history
[WIP] init Updating blockList for portal labels
  • Loading branch information
rushirajnenuji committed Jul 2, 2020
1 parent 7dece55 commit 2e4c8dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/js/models/AppModel.js
Expand Up @@ -920,7 +920,7 @@ define(['jquery', 'underscore', 'backbone'],
* The list of portals labels that no one should be able to create portals with
* @type {string[]}
*/
portalLabelBlacklist: [
portalLabelBlockList: [
"Dataone",
'urn:node:CN', 'CN', 'cn',
'urn:node:CNUNM1', 'CNUNM1', 'cn-unm-1',
Expand Down
16 changes: 8 additions & 8 deletions src/js/models/CollectionModel.js
Expand Up @@ -42,7 +42,7 @@ define(["jquery",
name: null,
label: null,
originalLabel: null,
labelBlacklist: ["new"],
labelBlockList: ["new"],
description: null,
formatId: "https://purl.dataone.org/collections-1.0.0",
formatType: "METADATA",
Expand Down Expand Up @@ -77,10 +77,10 @@ define(["jquery",
//Create a Filters collection to store the definition filters
this.set("definitionFilters", new Filters());

// Update the blacklist with the node/repository labels
var nodeBlackList = MetacatUI.appModel.get("portalLabelBlacklist");
if (nodeBlackList !== undefined && Array.isArray(nodeBlackList)) {
this.set("labelBlacklist", this.get("labelBlacklist").concat(nodeBlackList));
// Update the blocklist with the node/repository labels
var nodeBlockList = MetacatUI.appModel.get("portalLabelBlockList");
if (nodeBlockList !== undefined && Array.isArray(nodeBlockList)) {
this.set("labelBlockList", this.get("labelBlockList").concat(nodeBlockList));
}

//When this Collection has been saved, re-save the collection definition
Expand Down Expand Up @@ -600,9 +600,9 @@ define(["jquery",
}

// If the label is a restricted string
var blacklist = this.get("labelBlacklist");
if( blacklist && Array.isArray(blacklist) ){
if(blacklist.includes(label)){
var blockList = this.get("labelBlockList");
if( blocklist && Array.isArray(blockList) ){
if(blockList.includes(label)){
return "This URL is already taken, please try something else";
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/js/models/portals/PortalModel.js
Expand Up @@ -1280,7 +1280,7 @@ define(["jquery",

/**
* Queries the Solr discovery index for other Portal objects with this same label.
* Also, checks for the existing black list for repository labels
* Also, checks for the existing block list for repository labels
* If at least one other Portal has the same label, then it is not available.
* @param {string} label - The label to query for
*/
Expand All @@ -1299,13 +1299,13 @@ define(["jquery",

var model = this;

// Convert the black list to lower case for case insensitive match
var lowerCaseBlackList = this.get("labelBlacklist").map(function(value) {
// Convert the block list to lower case for case insensitive match
var lowerCaseBlockList = this.get("labelBlockList").map(function(value) {
return value.toLowerCase();
});

// Check the existing blacklist before making a Solr call
if (lowerCaseBlackList.indexOf(label.toLowerCase()) > -1) {
// Check the existing blockList before making a Solr call
if (lowerCaseBlockList.indexOf(label.toLowerCase()) > -1) {
model.trigger("labelTaken");
return
}
Expand All @@ -1322,10 +1322,10 @@ define(["jquery",
},
success: function(response){
if( response.response.numFound > 0 ){
//Add this label to the blacklist so we don't have to query for it later
var blacklist = model.get("labelBlacklist");
if( Array.isArray(blacklist) ){
blacklist.push(label);
//Add this label to the blockList so we don't have to query for it later
var blockList = model.get("labelBlockList");
if( Array.isArray(blockList) ){
blockList.push(label);
}

model.trigger("labelTaken");
Expand Down

0 comments on commit 2e4c8dc

Please sign in to comment.