How to use the ember-can/computed.ability function in ember-can

To help you get started, we’ve selected a few ember-can examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hummingbird-me / hummingbird-client / app / abilities / group.js View on Github external
import { Ability } from 'ember-can';
import { ability } from 'ember-can/computed';
import { get, computed } from '@ember/object';

const hasPermission = permission => (
  computed('membership.permissions.@each.hasDirtyAttributes', function() {
    return this._isGroupMember() && get(this, 'membership').hasPermission(permission);
  }).readOnly()
);

export default Ability.extend({
  membership: null,
  postAbility: ability('post', 'post'),
  commentAbility: ability('comment', 'comment'),

  canViewDashboard: computed('membership', function() {
    const isMember = this._isGroupMember();
    return isMember && (get(get(this, 'membership'), 'permissions.length') > 0);
  }).readOnly(),

  canManageEverything: hasPermission('owner'),
  canManageMembers: hasPermission('members'),
  canManageLeaders: hasPermission('leaders'),
  canManageSettings: hasPermission('community'),
  canManageReports: hasPermission('content'),
  canManageTickets: hasPermission('tickets'),

  canWritePost: computed('model', 'membership', function() {
    // If this is a restricted group, then posting is limited to leaders
github hummingbird-me / hummingbird-client / app / abilities / group.js View on Github external
import { Ability } from 'ember-can';
import { ability } from 'ember-can/computed';
import { get, computed } from '@ember/object';

const hasPermission = permission => (
  computed('membership.permissions.@each.hasDirtyAttributes', function() {
    return this._isGroupMember() && get(this, 'membership').hasPermission(permission);
  }).readOnly()
);

export default Ability.extend({
  membership: null,
  postAbility: ability('post', 'post'),
  commentAbility: ability('comment', 'comment'),

  canViewDashboard: computed('membership', function() {
    const isMember = this._isGroupMember();
    return isMember && (get(get(this, 'membership'), 'permissions.length') > 0);
  }).readOnly(),

  canManageEverything: hasPermission('owner'),
  canManageMembers: hasPermission('members'),
  canManageLeaders: hasPermission('leaders'),
  canManageSettings: hasPermission('community'),
  canManageReports: hasPermission('content'),
  canManageTickets: hasPermission('tickets'),

  canWritePost: computed('model', 'membership', function() {
    // If this is a restricted group, then posting is limited to leaders
    const group = get(this, 'model');
github code-corps / code-corps-ember / app / components / project-user-role-modal.js View on Github external
import { alias, and } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { ability } from 'ember-can/computed';

export default Component.extend({
  classNames: ['project-user-role-modal-container'],
  tagName: 'span',

  currentUser: service(),

  projectUser: null,
  save: null,
  selectedRole: null,
  showModal: false,

  ability: ability('project'),
  canManage: alias('ability.canManage'),
  demotionDisabled: and('canManage', 'isSelf'),
  user: alias('currentUser.user'),

  isSelf: computed('projectUser', 'user', function() {
    return get(this, 'projectUser.user.id') === get(this, 'user.id');
  }),

  init() {
    this._super(...arguments);
    let role = get(this, 'projectUser.role');
    set(this, 'selectedRole', role);
  }
});

ember-can

Simple authorization addon for Ember apps

MIT
Latest version published 25 days ago

Package Health Score

77 / 100
Full package analysis