Skip to content

Instantly share code, notes, and snippets.

@Imperat
Created February 24, 2019 16:36
Show Gist options
  • Save Imperat/9749d89f4caec2cefab9fe11b05e379e to your computer and use it in GitHub Desktop.
Save Imperat/9749d89f4caec2cefab9fe11b05e379e to your computer and use it in GitHub Desktop.
<script>
export default {
name: 'permission-control',
props: ['permission-name'],
render() {
// EDITABLE case. Don't change anything and just render control as is.
if (userHasPermission(this.permissionName, EDITABLE)) {
return this.$slots.default[0];
}
// If user has no EDITABLE permission, but he has 'VISIBLE',
// let's change "disabled" prop value to the true
if (userHasPermission(this.permissionName, VISIBLE)) {
this.$slots.default[0].componentOptions.propsData.disabled = true;
return this.$slots.default[0];
}
// User has permission for nothing! Let's don't show him anything!
return null;
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment