Skip to content

Instantly share code, notes, and snippets.

@dallonf
Created September 27, 2012 16:13
Show Gist options
  • Save dallonf/3794879 to your computer and use it in GitHub Desktop.
Save dallonf/3794879 to your computer and use it in GitHub Desktop.
Managing groups with events
// 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);
}
}
});
}
// 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);
}
// 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