forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature/chat locker 6 #9
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e3fda68
Modified 'room' template to display a banner
41397d6
Merge branch 'master' into feature/chat-locker-6
e347465
Converted js to coffeescript
da1a639
Fixed obtaining system country code setting
a71aa08
Removed default permission. Now return empty list if none found.
e12566e
Merge branch 'master' into feature/chat-locker-6
67364fd
Alternate css for security-banner
rwakida 4b6e17a
Use jquery to get actual height instead of hard 26
24fdb81
Merge pull request #10 from sscpac/feature/chat-locker-6.1
14ab971
Variables for classification colors
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ jquery | |
less | ||
meteor-platform | ||
reactive-var | ||
reactive-dict | ||
service-configuration | ||
|
||
chrismbeckett:toastr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
Jedis = this.Jedis || {}; | ||
// Class for managing user/resource permissions. | ||
// Structure: Hash of arrays of AccessPermission objects (see Schemas.AccessPermission), keyed by "type", which will be | ||
// one of the following: | ||
// classification | ||
// SAP | ||
// SCI | ||
// Release Caveat | ||
// Example: | ||
// { | ||
// "classification": ["TS", "S", "C", "U"], | ||
// "SAP: [ | ||
// { "_id" : "107", "trigraph" : "QUE", "label" : "Quesadilla", "type" : "SAP" }, | ||
// { "_id" : "108", "trigraph" : "HAB", "label" : "Habanero", "type" : "SAP" } | ||
// ] | ||
// } | ||
// | ||
|
||
// Construct an AccessPermission object from a list of access ids. | ||
Jedis.AccessPermission = function(ids) { | ||
if (!(this instanceof arguments.callee)) { | ||
// We were called without `new' operator. | ||
return new arguments.callee(arguments); | ||
} | ||
// Allow any of the supported input types to be passed as scalar. | ||
if (!_.isArray(ids)) { | ||
ids = [ids]; | ||
} | ||
// Now we have array, but of what? String id or Schema.AccessPermission objects? | ||
// Assumption: Whichever it is, list should be homogeneous. | ||
if (!ids.length) { | ||
// Empty object | ||
return this; | ||
} | ||
// Ensure we have a list of objects for grouping stage. | ||
var perms = typeof ids[0] === 'object' | ||
? ids | ||
: AccessPermissions.find({_id: {$in : ids}}).fetch(); | ||
|
||
// Group by types. | ||
perms.reduce(function(o, perm) { | ||
var type = perm.type; | ||
o[type] = o[type] || []; | ||
o[type].push(perm); | ||
return o; | ||
}, this); | ||
}; | ||
// | ||
Jedis.AccessPermission.prototype.resourceClassifications = function() { | ||
var classInfo = { selected:null, higher:[], lower:[] }; | ||
var classifications = Jedis.accessManager.getClassifications(); | ||
var classificationIds = _.pluck(classifications, '_id'); | ||
// Get the classification from the access permissions | ||
var resourceClassificationIds = _.filter(_.pluck(this.classification,'_id'), function(id) { | ||
return _.contains(classificationIds ,id); | ||
}); | ||
if (resourceClassificationIds.length > 1) { | ||
console.warn('Resource permissions has more then one classifications' + resourceClassificationIds.length ) | ||
} | ||
var resourceClassificationId = resourceClassificationIds[0]; | ||
_.each(classifications, function(element, index, list) { | ||
var cid = element._id; | ||
if (cid === resourceClassificationId) { | ||
classInfo.selected = cid; | ||
} else if ( ! classInfo.selected) { | ||
classInfo.higher.push(cid); | ||
} else { | ||
classInfo.lower.push(cid); | ||
} | ||
}); | ||
return classInfo; | ||
}; | ||
// Return a flat list of ids whose types are in the provided list (default all) | ||
// Design Intent: The object instance maintains the full access permission object, but in some scenarios (e.g., calls to | ||
// external validation service), we may need only the ids, possibly only the ids for specific types. | ||
Jedis.AccessPermission.prototype.getPermissionIds = function(types) { | ||
var self = this; | ||
if (typeof types === 'string') { | ||
types = [types]; | ||
} | ||
// Default (no types specified) means all types defined for this instance. | ||
types = types || _.keys(self); | ||
return types.reduce(function(acc, type) { | ||
return self[type] ? acc.concat(_.pluck(self[type], '_id')) : acc; | ||
}, []); | ||
}; | ||
|
||
// Return true iff invocant has sufficient permissions to access input resource. | ||
// TODO - Consider pros/cons with strategy vs instance method approach. First let's implement it all within the class. | ||
Jedis.AccessPermission.prototype.canAccessResource = function(resPerms) { | ||
var andTypes = ['SCI', 'SAP', 'classification'], | ||
orTypes = ['Release Caveat']; | ||
//console.log("canAccessResource: user perms: ", this.toString()); | ||
//console.log("canAccessResource: resource perms: ", resPerms.toString()); | ||
|
||
var userIds = this.getPermissionIds(andTypes); | ||
// Note: The following will short-circuit on failure. | ||
var fail = | ||
// AND logic | ||
resPerms.getPermissionIds(andTypes).some(function(resId) { | ||
return userIds.indexOf(resId) === -1; | ||
}); | ||
if (!fail) { | ||
// OR logic | ||
var resIds = resPerms.getPermissionIds(orTypes); | ||
userIds = this.getPermissionIds(orTypes); | ||
if (resIds.length) { | ||
fail = resIds.every(function(resId) { | ||
return userIds.indexOf(resId) === -1; | ||
}); | ||
} | ||
} | ||
//console.log("canAccessResource says: ", fail ? "fail" : "pass"); | ||
return !fail; | ||
}; | ||
|
||
// Convert hash of lists keyed by type to flat list. | ||
Jedis.AccessPermission.prototype.toArray = function() { | ||
return _.values(this).reduce(function(acc, perms) { | ||
return acc.concat(perms); | ||
}, []); | ||
}; | ||
|
||
// --- Debug/Test methods --- | ||
// Add permission object(s) represented by input id(s). | ||
Jedis.AccessPermission.prototype.addAccessIds = function(ids) { | ||
ids = _.isArray(ids) ? ids : [ids]; | ||
// Lookup input ids and add corresponding objects under applicable keys (if not already there). | ||
_.pairs( | ||
_.groupBy( | ||
AccessPermissions.find({_id: {$in: ids}}).fetch(), | ||
function(perm) { return perm.type })) | ||
// Iterate [type, perm_ary] pairs. | ||
.forEach(function(pair) { | ||
var type = pair[0], perms = pair[1]; | ||
this[type] = this[type] || []; | ||
// Merge the (unique) new access objects. | ||
this[type] = _.uniq(this[type].concat(perms), | ||
function(perm) { return perm._id }) | ||
}, this); | ||
}; | ||
|
||
// Remove permission object(s) represented by input id(s). | ||
Jedis.AccessPermission.prototype.removeAccessIds = function(ids) { | ||
ids = _.isArray(ids) ? ids : [ids]; | ||
// Remove access objects (from under their respective keys) whose id is found in input list. | ||
// Iterate access types (object's own enumerable properties) | ||
// Idiosyncrasy: Underscore docs say mapObject, but map is actually overloaded. | ||
_.map(this, function(perms, type) { | ||
this[type] = perms.filter(function(perm) { return ids.indexOf(perm._id) === -1 }); | ||
}, this); | ||
}; | ||
|
||
Jedis.AccessPermission.prototype.toString = function() { | ||
return JSON.stringify(this, undefined, 4); | ||
}; | ||
|
||
// vim:ts=4:sw=4:tw=120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Meteor.methods | ||
getSecurityBanner: (permissionIds) -> | ||
if not Meteor.userId() | ||
throw new Meteor.Error('invalid-user', "[methods] getSecurityBanner -> Invalid user") | ||
|
||
banner = {} | ||
|
||
perms = new Jedis.AccessPermission permissionIds | ||
.toArray(); | ||
|
||
systemCountryCode = Jedis.accessManager.getPermissions(Jedis.settings.get('public').system.countryCode) | ||
|
||
if systemCountryCode.length is 0 | ||
console.log 'System country not found. Defaulting to USA' | ||
systemCountryCode = _id: '300', trigraph: 'USA', label: 'United States', type: 'Release Caveat' | ||
else | ||
systemCountryCode = systemCountryCode[0]; | ||
|
||
|
||
|
||
# Obtain classification, add to banner. If none, default: 'UNCLASSIFIED' | ||
classification = _.chain perms | ||
.filter (perm) -> return perm.type is 'classification' | ||
# there should only be a single classification label | ||
.first() | ||
# if no classification then default to unclassified | ||
.value() || _id : 'U', label : 'UNCLASSIFIED' | ||
|
||
|
||
# get all sci and sap labels, sort separately by trigraph | ||
# join trigraphs separated by ' / '' | ||
sciLabels = _.chain perms | ||
.filter (perm) -> return perm.type is 'SCI' | ||
.pluck 'trigraph' | ||
.sort() | ||
.value() | ||
sapLabels = _.chain perms | ||
.filter (perm) -> return perm.type is 'SAP' | ||
.pluck 'trigraph' | ||
.sort() | ||
.value() | ||
sciSapLabels = _.flatten [sciLabels, sapLabels] | ||
.join ' / ' | ||
|
||
|
||
# get all rel-to countries, add to banner with ', ' separator | ||
# if none specified (or only 'USA'), default to 'NOFORN' | ||
reltoLabels = _.chain perms | ||
.filter (perm) -> return perm.type is 'Release Caveat' | ||
# exclude system country code because we prepend later as first country | ||
.reject (perm) -> return perm._id is systemCountryCode._id | ||
.pluck 'trigraph' | ||
.sort() | ||
.value() | ||
# if still contains entries, hard-code system country code at front else 'NOFORN' | ||
reltoLabels.splice(0, 0, ( if reltoLabels.length > 0 then 'REL TO ' + systemCountryCode.trigraph else 'NOFORN')) | ||
reltoLabels = reltoLabels.join ', ' | ||
|
||
|
||
# stitch everything together | ||
banner.classificationId = classification._id | ||
banner.text = _.compact [classification.label.toUpperCase(), sciSapLabels, reltoLabels] | ||
.join ' // ' | ||
|
||
return banner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ Meteor.publish 'room', (rid) -> | |
cl: 1 | ||
u: 1 | ||
usernames: 1 | ||
accessPermissions: 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can create variables for these in _variables.less and reference them here. Then we can reuse them in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean variables for the colors? Like, say, "@unclassified-color"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.