npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-unauthorized

v0.3.0

Published

Ember Mixins for handling unauthorized access to application content

Downloads

13

Readme

Ember-Unauthorized

Build Status Ember Observer Score Dependency Status Code Climate Codacy Badge

Ember Mixins for handling unauthorized access to application content

View Demo

Usage

Ember-Unauthorized currently provides two mixins: access and route-access. The former provides the base implementation of this addon, with the latter providing route-specific code such as transitioning to an unauthorized route. The examples below will use the route-access mixin, but you can customize your experience by using access directly or creating more mixins for different scenarios. We welcome contributions if you think you have a common use-case!

With Feature Flags

This addon has been optimized for use with Ember-Feature-Flags:

// routes/user-list.js
import Ember from 'ember';
import RouteAccessMixin from 'ember-unauthorized/mixins/route-access';

export default Ember.Route.extend(RouteAccessMixin, {
    requiredFeatures: ['userList']
});

If you are using a customized key name to access your feature flags, import the mixin into your app and set featuresKey:

// mixins/route-access.js
import Ember from 'ember';
import RouteAccessMixin from 'ember-unauthorized/mixins/route-access';

export default Ember.Mixin.create(RouteAccessMixin, {
    featuresKey: 'featureFlags'
});

Then import RouteAccessMixin from 'my-app-name/mixins/route-access'; instead of taking it directly from the addon.

It is also easy to use other feature flag implementations. Simply override isFeatureDisabled:

// mixins/route-access.js
import Ember from 'ember';
import RouteAccessMixin from 'ember-unauthorized/mixins/route-access';

export default Ember.Mixin.create(RouteAccessMixin, {
    isFeatureDisabled(key) {
        return this.get('featureService').hasFeature(key); // Insert custom implementation here
    }
});

Custom Authorization

Sometimes access to routes isn't solely determined by feature flags, such as through user role access control. To address this, Ember-Unauthorized allows you to optionally implement an authorize method that returns true if the content is authorized for the user.

// route/admin.js
import Ember from 'ember';
import RouteAccessMixin from 'ember-unauthorized/mixins/route-access';

export default Ember.Route.extend(RouteAccessMixin, {
    authorize() {
        return this.get('user').isAdmin(); // Your custom authorization code
    }
});

Routes

The route-access mixin defines some default behavior for accessing unauthorized routes. When a user's authorization fails, the mixin will automatically transition them to the unauthorized route. If your application uses a different route for this behavior, it can be customized via unauthorizedRoute:

// route/foo.js
import Ember from 'ember';
import RouteAccessMixin from 'ember-unauthorized/mixins/route-access';

export default Ember.Route.extend(RouteAccessMixin, {
    requiredFeatures: ['foo'],
    unauthorizedRoute: 'error'
});

Furthermore, if you do not want a transition to take place or need to add additional behavior, override the unauthorized method:

// route/foo.js
import Ember from 'ember';
import RouteAccessMixin from 'ember-unauthorized/mixins/route-access';

export default Ember.Route.extend(RouteAccessMixin, {
    requiredFeatures: ['foo'],
    unauthorized() {
        this.notifications.send('You are not authorized to view this content'); // Custom behavior goes here
    }
});

Contributing

This section outlines the details of collaborating on this Ember addon.

Installation

  • git clone this repository
  • cd ember-unauthorized
  • npm install
  • bower install

Running The Demo Application

Running Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit https://ember-cli.com/.