Created
September 27, 2012 16:13
-
-
Save dallonf/3794879 to your computer and use it in GitHub Desktop.
Managing groups with events
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
// departments has string parentId, string name | |
// On GET /departments | |
if (this.parentId) { | |
// Recursively build an array of parents | |
dpd.departments.get({id: parentId, $limitRecursion: 64}, function(parentDep) { | |
if (parentDep) { | |
this.parents = [parentDep.name]; | |
if (parentDep.parents) { | |
this.parents = parentDep.parents.concat(this.parents); | |
} | |
} | |
}); | |
} |
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
// files has string departmentName | |
// On GET /files | |
if (!me || me.allDepartments.indexOf(this.departmentName) === -1) { | |
cancel("Your department is not allowed to view this file!", 401); | |
} |
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
// users has string departmentId, array allDepartments | |
// On Validate /users | |
dpd.departments.get({id: departmentId}, function(department) { | |
// Store all departments on the user for easier querying | |
this.allDepartments = department.parents || []; | |
this.allDepartments.push(department.name); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment