Skip to content

Instantly share code, notes, and snippets.

@JeffTomlinson
Created August 3, 2015 15:59
Show Gist options
  • Save JeffTomlinson/62b13369cb671710b793 to your computer and use it in GitHub Desktop.
Save JeffTomlinson/62b13369cb671710b793 to your computer and use it in GitHub Desktop.
Template.breweryForm.helpers({
canCreateBrewery: function () {
// This is the part that seems weird.
var clientResult = Meteor.apply('canCreateBrewery', [], {returnStubValue: true}, function(err, serverResult) {
// If this is indeed the way this should be done, I'd like to
// update the template when the server result is returned.
});
return clientResult;
}
});
<template name="breweryForm">
<h2>Add Brewery</h2>
{{#if canCreateBrewery}}
{{#autoForm collection="Breweries" id="createBrewery" type="method" meteormethod="createBrewery"}}
{{> afQuickField name='name'}}
<button type="submit" class="btn btn-primary">Add</button>
{{/autoForm}}
{{/if}}
</template>
// Add methods for Breweries collections.
Meteor.methods({
createBrewery: function (doc) {
// Make sure the user has permissions.
if (Meteor.call('canCreateBrewery', doc)) {
// Create the brewery.
Breweries.insert({
name: doc.name
});
return true;
}
throw new Meteor.Error(403, 'Not authorized to create breweries.');
},
canCreateBrewery: function () {
if (!Meteor.userId()) {
return false;
}
if (Roles.userIsInRole(Meteor.user(), ['create-content'])) {
return true;
}
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment