Skip to content

Instantly share code, notes, and snippets.

@ferclaverino
Last active December 24, 2015 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferclaverino/6763408 to your computer and use it in GitHub Desktop.
Save ferclaverino/6763408 to your computer and use it in GitHub Desktop.
var Authorization = function(anUserId) {
var userId = anUserId;
this.authorizeForInstitution = function(institution) {
if (isResponsable(institution)) {
$("[auth~='responsable-institucion']").show();
}
};
var isResponsable = function(institution) {
var isResponsable = false;
console.log(userId)
for (var i = 0; i < institution.admins.length; i++) {
if (institution.admins[i].id == userId) {
isResponsable = true;
}
}
return isResponsable;
}
};
<a href="instituciones/{{id}}/suscripciones" auth="responsable-institucion">Suscripciones pendientes</a>
<a href="instituciones/{{id}}/addActivity" auth="responsable-institucion">Agregar actividad</a>
<a href="instituciones/{{id}}/addOwner?isAdmin=true" auth="responsable-institucion">Nuevo responsable</a>
<a href="instituciones/">Ver Todas</a>
var authorization = new Authorization({{ app.security.token.user.id }});
$("document").ready(function() {
institucionQuery.getById({{id}}, function(institucion) {
//...
authorization.authorizeForInstitution(institucion);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment