Refactoring
This commit is contained in:
parent
916c911ac7
commit
48ab72fb14
|
@ -996,29 +996,21 @@ Common.Utils.UserInfoParser = new(function() {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _getParsedGroups = function(username) {
|
||||||
|
if (parse && username) {
|
||||||
|
var idx = username.indexOf(separator),
|
||||||
|
groups = (idx>-1) ? username.substring(0, idx).split(',') : [];
|
||||||
|
for (var i=0; i<groups.length; i++)
|
||||||
|
groups[i] = groups[i].trim();
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setParser: function(value) {
|
setParser: function(value) {
|
||||||
parse = !!value;
|
parse = !!value;
|
||||||
},
|
},
|
||||||
|
|
||||||
getSeparator: function() {
|
|
||||||
return separator;
|
|
||||||
},
|
|
||||||
|
|
||||||
getParsedName: function(username) {
|
|
||||||
return (parse && username) ? username.substring(username.indexOf(separator)+1) : username;
|
|
||||||
},
|
|
||||||
|
|
||||||
getParsedGroups: function(username) {
|
|
||||||
if (parse && username) {
|
|
||||||
var idx = username.indexOf(separator),
|
|
||||||
groups = (idx>-1) ? username.substring(0, idx).split(',') : [];
|
|
||||||
for (var i=0; i<groups.length; i++)
|
|
||||||
groups[i] = groups[i].trim();
|
|
||||||
return groups;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
setCurrentName: function(name) {
|
setCurrentName: function(name) {
|
||||||
username = name;
|
username = name;
|
||||||
_reviewPermissions && this.setReviewPermissions(null, _reviewPermissions); // old version of review permissions
|
_reviewPermissions && this.setReviewPermissions(null, _reviewPermissions); // old version of review permissions
|
||||||
|
@ -1028,13 +1020,21 @@ Common.Utils.UserInfoParser = new(function() {
|
||||||
return username;
|
return username;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getSeparator: function() {
|
||||||
|
return separator;
|
||||||
|
},
|
||||||
|
|
||||||
|
getParsedName: function(username) {
|
||||||
|
return (parse && username) ? username.substring(username.indexOf(separator)+1) : username;
|
||||||
|
},
|
||||||
|
|
||||||
setReviewPermissions: function(groups, permissions) {
|
setReviewPermissions: function(groups, permissions) {
|
||||||
if (groups) {
|
if (groups) {
|
||||||
if (typeof groups == 'object' && groups.length>0)
|
if (typeof groups == 'object' && groups.length>0)
|
||||||
reviewGroups = groups;
|
reviewGroups = groups;
|
||||||
} else if (permissions) { // old version of review permissions
|
} else if (permissions) { // old version of review permissions
|
||||||
var arr = [],
|
var arr = [],
|
||||||
arrgroups = this.getParsedGroups(username);
|
arrgroups = _getParsedGroups(username);
|
||||||
arrgroups && arrgroups.forEach(function(group) {
|
arrgroups && arrgroups.forEach(function(group) {
|
||||||
var item = permissions[group.trim()];
|
var item = permissions[group.trim()];
|
||||||
item && (arr = arr.concat(item));
|
item && (arr = arr.concat(item));
|
||||||
|
@ -1057,7 +1057,7 @@ Common.Utils.UserInfoParser = new(function() {
|
||||||
canEditReview: function(username) {
|
canEditReview: function(username) {
|
||||||
if (!parse || !reviewGroups) return true;
|
if (!parse || !reviewGroups) return true;
|
||||||
|
|
||||||
var groups = this.getParsedGroups(username);
|
var groups = _getParsedGroups(username);
|
||||||
groups && (groups.length==0) && (groups = [""]);
|
groups && (groups.length==0) && (groups = [""]);
|
||||||
return _intersection(reviewGroups, groups);
|
return _intersection(reviewGroups, groups);
|
||||||
},
|
},
|
||||||
|
@ -1065,7 +1065,7 @@ Common.Utils.UserInfoParser = new(function() {
|
||||||
canViewComment: function(username) {
|
canViewComment: function(username) {
|
||||||
if (!parse || !commentGroups) return true;
|
if (!parse || !commentGroups) return true;
|
||||||
|
|
||||||
var groups = this.getParsedGroups(username);
|
var groups = _getParsedGroups(username);
|
||||||
groups && (groups.length==0) && (groups = [""]);
|
groups && (groups.length==0) && (groups = [""]);
|
||||||
return _intersection(commentGroups.view, groups);
|
return _intersection(commentGroups.view, groups);
|
||||||
},
|
},
|
||||||
|
@ -1073,7 +1073,7 @@ Common.Utils.UserInfoParser = new(function() {
|
||||||
canEditComment: function(username) {
|
canEditComment: function(username) {
|
||||||
if (!parse || !commentGroups) return true;
|
if (!parse || !commentGroups) return true;
|
||||||
|
|
||||||
var groups = this.getParsedGroups(username);
|
var groups = _getParsedGroups(username);
|
||||||
groups && (groups.length==0) && (groups = [""]);
|
groups && (groups.length==0) && (groups = [""]);
|
||||||
return _intersection(commentGroups.edit, groups);
|
return _intersection(commentGroups.edit, groups);
|
||||||
},
|
},
|
||||||
|
@ -1081,7 +1081,7 @@ Common.Utils.UserInfoParser = new(function() {
|
||||||
canDeleteComment: function(username) {
|
canDeleteComment: function(username) {
|
||||||
if (!parse || !commentGroups) return true;
|
if (!parse || !commentGroups) return true;
|
||||||
|
|
||||||
var groups = this.getParsedGroups(username);
|
var groups = _getParsedGroups(username);
|
||||||
groups && (groups.length==0) && (groups = [""]);
|
groups && (groups.length==0) && (groups = [""]);
|
||||||
return _intersection(commentGroups.remove, groups);
|
return _intersection(commentGroups.remove, groups);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue