How to use the ember-can.Ability.extend 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 minutebase / ember-can / tests / dummy / app / abilities / post.js View on Github external
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
import { Ability } from 'ember-can';

export default Ability.extend({
  session: service('session'),

  model: null,

  author: null,

  canWrite: computed("session.isAuthenticated", function() {
    return this.get("session.isAuthenticated");
  }),

  canEdit: computed("model.author", "session.isAuthenticated", function() {
    return this.get("session.isAuthenticated") && this.get("model.author") === this.get("session.user");
  }),

  canChangeAuthor: computed("model.author", "author.id", function() {
    return this.get("author") && this.get("model") && parseInt(this.get("author.id"), null) !== this.get("model.author");
github minutebase / ember-can / tests / dummy / app / abilities / default.js View on Github external
import { Ability } from 'ember-can';

export default Ability.extend({
  isLoggedIn: function() {
    return this.session.get("isAuthenticated");
  }.checks("write post"),

  isAuthor: function(post) {
    return post.get("author") === this.session.get("user");
  }.checks("edit post")
});
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'),
github ilios / frontend / app / abilities / learner-groups.js View on Github external
import Ember from 'ember';
import { Ability } from 'ember-can';

const { inject, computed } = Ember;
const { service } = inject;
const { alias } = computed;

export default Ability.extend({
  currentUser: service(),
  canView: alias('currentUser.canViewLearnerGroups'),
  canEdit: alias('currentUser.canEditLearnerGroups'),
});
github code-corps / code-corps-ember / app / abilities / organization.js View on Github external
import { alias } from '@ember/object/computed';
import { get, computed } from '@ember/object';
import { inject as service } from '@ember/service';
import { Ability } from 'ember-can';

export default Ability.extend({
  currentUser: service(),

  canManage: computed('organization.owner.id', 'currentUser.user.id', function() {
    return get(this, 'organization.owner.id') === get(this, 'currentUser.user.id');
  }),

  organization: alias('model')
});
github code-corps / code-corps-ember / app / abilities / project.js View on Github external
import { alias, equal, or } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { Ability } from 'ember-can';
import projectMember from 'code-corps-ember/macros/project-member';

/**
 * Ability object used to determine what the current user can do with a project
 *
 * @module  Ability
 * @extends EmberCan.Ability
 */
export default Ability.extend({
  currentUser: service(),

  /**
   * An `ember-can` ability.
   *
   * Indicates if the current user can manage a project.
   * Returns true if the user is the owner of the project.
   * @type {Boolean}
   */
  canAdminister: or('{userIsAdmin,userIsOwner}'),

  /**
   * An `ember-can` ability.
   *
   * Indicates if the current user can manage a project.
   * Returns true if the user is the owner of the project.
github hummingbird-me / hummingbird-client / app / abilities / user.js View on Github external
import { Ability } from 'ember-can';
import { get, computed } from '@ember/object';

export default Ability.extend({
  canEdit: computed('session.hasUser', 'model', function() {
    if (!get(this, 'session.hasUser')) { return false; }
    const isOwner = get(this, 'session').isCurrentUser(get(this, 'model'));
    const isAdmin = get(this, 'session.account').hasRole('admin', get(this, 'model'));
    return isOwner || isAdmin;
  }).readOnly()
});
github hummingbird-me / hummingbird-client / app / abilities / post.js View on Github external
import { Ability } from 'ember-can';
import { get, computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';

export default Ability.extend({
  canWrite: readOnly('session.hasUser'),

  canEdit: computed('session.hasUser', 'model.user', function() {
    if (!get(this, 'session.hasUser')) { return false; }
    const isOwner = get(this, 'session').isCurrentUser(get(this, 'model.user'));
    const isAdmin = get(this, 'session.account').hasRole('admin', get(this, 'model'));
    return isOwner || isAdmin;
  }).readOnly()
});
github hummingbird-me / hummingbird-client / app / abilities / library-entry.js View on Github external
import { Ability } from 'ember-can';
import { get, computed } from '@ember/object';

export default Ability.extend({
  /**
   * Determines if the sessioned user is the owner of the library entry.
   *    (can "edit library-entry" )
   *
   * @returns {Boolean}
   */
  canEdit: computed('session.hasUser', 'model', 'user', function() {
    if (!get(this, 'session.hasUser')) { return false; }
    const user = get(this, 'user') || get(this, 'model.user') || get(this, 'model');
    return get(this, 'session').isCurrentUser(user);
  }).readOnly()
});
github ilios / frontend / app / abilities / instructor-groups.js View on Github external
import Ember from 'ember';
import { Ability } from 'ember-can';

const { inject, computed } = Ember;
const { service } = inject;
const { alias } = computed;

export default Ability.extend({
  currentUser: service(),
  canView: alias('currentUser.canViewInstructorGroups'),
  canEdit: alias('currentUser.canEditInstructorGroups'),
});

ember-can

Simple authorization addon for Ember apps

MIT
Latest version published 1 month ago

Package Health Score

75 / 100
Full package analysis