Created
August 3, 2015 15:59
-
-
Save JeffTomlinson/62b13369cb671710b793 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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; | |
} | |
}); |
This file contains hidden or 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
<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> |
This file contains hidden or 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
// 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