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

uxess

v0.4.1

Published

Generic authorization module for role-based handling of ui elements

Downloads

11

Readme

uXess

Generic authorization module for role-based handling of ui elements


  1. Introduction
  2. Installation
  3. Usage
  4. Minimal Working Example
  5. Development
  6. Contribution
  7. Changelog
  8. License

Introduction

The only dependencies are AngularJS and the animation module ngAnimate.

Tested against v1.4.7 but other versions should work.

Installation

For installation use the Node Package Manager:

$ npm install --save uxess

or clone the repository:

$ git clone https://github.com/felixheck/uXess

Usage

Integration

Include uXess and ngAnimate into your application:

<!DOCTYPE html>
<html ng-app="yourApp">
<head>
	...
</head>
<body>
	...

	<script src="../uxess.min.js"></script>
	<script src="../angular-animate.min.js"></script>
</body>
</html>

Declare a dependency on the uXess module:

angular.module('yourApp', [
	'uxs'
]);

Set a new wildcard symbol

In the config block:

angular.module('yourApp')
	.config(function(uxsWildcardHandlerProvider) {
		uxsWildcardHandlerProvider.setWildcard('?');
	});

After initialisation, for example in a controller:

angular.module('yourApp').controller('FooCtrl', function(uxsWildcardHandler) {
	this.init = function() {
		uxsWildcardHandler.setWildcard('?');
	};
});

Set default authorization type

In the config block:

angular.module('yourApp')
	.config(function(uxsAuthTypeHandlerProvider) {
		uxsAuthTypeHandlerProvider.setDefaultAuthType('all');
	});

After initialisation, for example in a controller:

angular.module('yourApp').controller('FooCtrl', function(uxsAuthTypeHandler) {
	this.init = function() {
		uxsAuthTypeHandler.setDefaultAuthType('all');
	};
});

Set permits

Before AngularJS bootstrapping:

angular.element(document).ready(function() {
	$.get('api/v1/user', function(res) {
		angular.module('yourApp').config(function(uxsPermitHandlerProvider) {
			uxsPermitHandlerProvider.setPermits(res.permits);
		});

		angular.bootstrap(document, ['yourApp']);
  });
});

In the run block:

angular.module('yourApp')
	.run(function($http, uxsPermitHandler) {
		$http.get('/api/v1/user').then(function(res) {
	    uxsPermitHandler.setPermits(res.permits);
	  });
	});

After initialisation, for example in a controller:

angular.module('yourApp').controller('FooCtrl', function(uxsPermitHandler) {
	this.init = function() {
		uxsPermitHandler.setPermits('admin');
	};
});

Directives

Make use of static permit and the default authorization type:

<button uxs-if="admin"></button>

Make use of static permits and the none authorization type:

<button uxs-if="admin, user" uxs-type="none"></button>

Make use of the scope and the all authorization type:

<button uxs-if="FooCtrl.permits" uxs-type="all"></button>

Make use of an expression and the any authorization type:

<button uxs-if="{{ FooCtrl.permits }}" uxs-type="any"></button>

Make use of the wildcard symbol, to check if user has any role:

<button uxs-if="*"></button>

##Public API

uxsAccessHandler

uxsAccessHandler.isPermitted

/**
 * @description
 * Check if UI element is accessible for user
 *
 * @param {(Array.<?string> | string)} permits Permits to be searched for
 * @param {string} authType Required auth type
 * @returns {boolean} UI element is accessible
 */

uxsAccessHandler.hasPermits

/**
 * @description
 * Check if any permits are included in `data.permits`of `uxsPermitHandler`
 *
 * @returns {boolean} Any permit is set
 */

uxsAccessHandler.hasAllPermits

/**
 * @description
 * Check if all passed permits are included in `data.permits` of `uxsPermitHandler`
 *
 * @param {(Array.<?string> | string)} permits Permits to be searched for
 * @returns {boolean} All passed permits are set
 */

uxsAccessHandler.hasAnyPermits

/**
 * @description
 * Check if any of passed permits is included in `data.permits` of `uxsPermitHandler`
 *
 * @param {(Array.<?string> | string)} permits Permits to be searched for
 * @returns {boolean} Any of passed permits is set
 */

uxsAccessHandler.hasNonePermits

/**
 * @description
 * Check if none of passed permits is included in `data.permits` of `uxsPermitHandler`
 *
 * @param {(Array.<?string> | string)} permits Permits to be searched for
 * @returns {boolean} None of passed permits is set
 */

uxsAuthTypeHandler

uxsAuthTypeHandler.setDefaultAuthType

/**
 * @description
 * Set `_data.defaultAuthType`
 *
 * @param {string} authType Auth type to be set
 */

uxsAuthTypeHandler.getDefaultAuthType

/**
 * @description
 * Set `_data.defaultAuthType`
 *
 * @returns {string} `_data.defaultAuthType`
 */

uxsAuthTypeHandler.isAuthType

/**
 * @description
 * Check if passed auth type is valid
 *
 * @param {string} authType Auth type to be checked
 * @returns {boolean} Auth type is valid
 */

uxsAuthTypeHandler.parseAuthType

/**
 * @description
 * Parse passed auth type
 *
 * @param {string} authType Auth type to be parsed
 * @returns {string} Parsed auth type
 */

uxsPermitHandler

uxsPermitHandler.setPermits

/**
 * @description
 * Set `_data.permits`
 *
 * @fires `uxsPermitsChanged`
 *
 * @param {(Array.<?string> | string)} permits Permits to be set
 */

uxsPermitHandler.getPermits

/**
 * @description
 * Get `_data.permits`
 *
 * @returns {Array.<?string>} `_data.permits`
 */

uxsPermitHandler.parsePermits

/**
 * @description
 * Parse permits to list of trimmed and transformed ones
 *
 * @param {(Array.<?string> | string)} permits Permits to be parsed
 * @returns {Array.<?string>} List of permits
 */

uxsWildcardHandler

uxsWildcardHandler.setWildcard

/**
 * @description
 * Set `_data.wildcard`
 *
 * @param {string} wildcard Wildcard to be set
 */

uxsWildcardHandler.getWildcard

/**
 * @description
 * Get `_data.wildcard`
 *
 * @returns {Array.<?string>} `_data.permits`
 */

uxsWildcardHandler.parseWildcard

/**
 * @description
 * Parse wildcard to string
 *
 * @param {string} wildcard Wildcard to be parsed
 * @returns {string} Parsed wildcard
 */

Minimal Working Example

To run a demo or rather a minimal working example, use:

$ npm install
$ npm run sample

It is possible to set the permits by checking the checkboxes.

Development

First you have to install all dependencies:

$ npm install

Testing

To execute all unit tests, use:

$ npm test

To execute end-to-end tests, use:

$ npm run http
$ npm run selenium
$ npm run test:e2e

To open the coverage information of the unit tests, use:

$ npm run coverage

Distributing

To build the distributional files, use:

$ npm run build

or make use of the file watcher:

$ npm start

Contribution

Fork this repository and push in your ideas.

Do not forget to add corresponding tests.

Changelog

License

The MIT License

Copyright (c) 2016 Felix Heck

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.