From ef474d95dbbe32c34f03f8317ac298a439e72d3f Mon Sep 17 00:00:00 2001 From: Robbie Wagner Date: Fri, 25 Apr 2025 17:22:18 -0400 Subject: [PATCH 1/2] Update badges, ensure pnpm 10 --- .github/workflows/ci.yml | 6 ++ .github/workflows/push-dist.yml | 2 + README.md | 97 ++++++++++++++++----------------- 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35e4727..480c103 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 + with: + version: 10 - uses: actions/setup-node@v4 with: node-version: 18 @@ -39,6 +41,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 + with: + version: 10 - uses: actions/setup-node@v4 with: node-version: 18 @@ -72,6 +76,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 + with: + version: 10 - uses: actions/setup-node@v4 with: node-version: 18 diff --git a/.github/workflows/push-dist.yml b/.github/workflows/push-dist.yml index 3e4cc36..96b9000 100644 --- a/.github/workflows/push-dist.yml +++ b/.github/workflows/push-dist.yml @@ -20,6 +20,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 + with: + version: 10 - uses: actions/setup-node@v4 with: node-version: 18 diff --git a/README.md b/README.md index 5cb250d..0393ce5 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,20 @@ # Ember-can -

- - - + + + - - Ember Observer - + + Ember Observer + - - Travis CI Status - +[![CI](https://github.com/minutebase/ember-can/actions/workflows/ci.yml/badge.svg)](https://github.com/minutebase/ember-can/actions/workflows/ci.yml) - - - -

+ + + -___ +--- Simple authorisation addon for Ember. @@ -45,6 +41,7 @@ Resolver = extendResolver(Resolver); Without this update, the app will encounter an error where it cannot find your abilities. After these changes your app file should look something like: + ```js import Application from '@ember/application'; import Resolver from 'ember-resolver'; @@ -61,18 +58,17 @@ export default class App extends Application { loadInitializers(App, config.modulePrefix); ``` - ## Compatibility -* Ember.js v4.12 or above -* Embroider or ember-auto-import v2 +- Ember.js v4.12 or above +- Embroider or ember-auto-import v2 ## Quick Example You want to conditionally allow creating a new blog post: ```hbs -{{#if (can "create post")}} +{{#if (can 'create post')}} Type post content here... {{else}} You can't write a new post! @@ -152,8 +148,9 @@ export default class CreatePostComponent extends Component { The `can` helper is meant to be used with `{{if}}` and `{{unless}}` to protect a block (but can be used anywhere in the template). ```hbs -{{can "doSth in myModel" model extraProperties}} +{{can 'doSth in myModel' model extraProperties}} ``` + - `"doSth in myModel" ` - The first parameter is a string which is used to find the ability class call the appropriate property (see [Looking up abilities](#looking-up-abilities)). - `model` - The second parameter is an optional model object which will be given to the ability to check permissions. @@ -164,8 +161,9 @@ The `can` helper is meant to be used with `{{if}}` and `{{unless}}` to protect a automatically update accordingly.** #### Example + ```hbs -{{#if (can "edit post" post)}} +{{#if (can 'edit post' post)}} ... {{else}} ... @@ -176,7 +174,7 @@ As it's a sub-expression, you can use it anywhere a helper can be used. For example to give a div a class based on an ability you can use an inline if: ```hbs -
+
``` @@ -186,10 +184,9 @@ For example to give a div a class based on an ability you can use an inline if: Cannot helper is a negation of `can` helper with the same API. ```hbs -{{cannot "doSth in myModel" model extraProperties}} +{{cannot 'doSth in myModel' model extraProperties}} ``` - ## Abilities An ability class protects an individual model which is available in the ability as `model`. @@ -229,7 +226,7 @@ You can do this in the helpers, for example this will set the `model` to `projec but also `member` as a bound property. ```hbs -{{#if (can "remove member from project" project member=member)}} +{{#if (can 'remove member from project' project member=member)}} ... {{/if}} ``` @@ -255,20 +252,20 @@ Then for the ability name we remove some basic stopwords (of, for in) at the end For example: -| String | property | resource | pod | -|-----------------------------|--------------------|-------------------------|--------------------------------| -| write post | `canWrite` | `/abilities/post.js` | `app/pods/post/ability.js` | -| manage members in project | `canManageMembers` | `/abilities/project.js`| `app/pods/project/ability.js` | -| view profile for user | `canViewProfile` | `/abilities/user.js` | `app/pods/user/ability.js` | +| String | property | resource | pod | +| ------------------------- | ------------------ | ----------------------- | ----------------------------- | +| write post | `canWrite` | `/abilities/post.js` | `app/pods/post/ability.js` | +| manage members in project | `canManageMembers` | `/abilities/project.js` | `app/pods/project/ability.js` | +| view profile for user | `canViewProfile` | `/abilities/user.js` | `app/pods/user/ability.js` | Current stopwords which are ignored are: -* for -* from -* in -* of -* to -* on +- for +- from +- in +- of +- to +- on ## Custom Ability Lookup @@ -289,7 +286,7 @@ export default class AbilitiesService extends Service { let [abilityName, propertyName] = str.split('.'); return { propertyName, abilityName }; } -}; +} ``` You can also modify the property prefix by overriding `parseProperty` in our ability file: @@ -326,7 +323,7 @@ The ability classes will now have access to `session` which can then be used to ## Components & computed properties -In a component, you may want to expose abilities as computed properties +In a component, you may want to expose abilities as computed properties so that you can bind to them in your templates. ```js @@ -351,7 +348,7 @@ export default class MyComponent extends Component { ## Accessing abilities within an Ember engine -If you're using [engines](http://ember-engines.com/) and you want to access an *ability* within it, you will need it to be present in your Engine’s namespace. This is accomplished by doing what is called a "re-export": +If you're using [engines](http://ember-engines.com/) and you want to access an _ability_ within it, you will need it to be present in your Engine’s namespace. This is accomplished by doing what is called a "re-export": ```javascript //my-engine/addon/abilities/foo-bar.js @@ -383,26 +380,26 @@ stub the service following [the official EmberJS guide](https://guides.emberjs.c ### Installation -* `git clone https://github.com/minutebase/ember-can.git` -* `cd ember-can` -* `npm install` +- `git clone https://github.com/minutebase/ember-can.git` +- `cd ember-can` +- `npm install` ### Linting -* `npm run lint:hbs` -* `npm run lint:js` -* `npm run lint:js -- --fix` +- `npm run lint:hbs` +- `npm run lint:js` +- `npm run lint:js -- --fix` ### Running tests -* `ember test` – Runs the test suite on the current Ember version -* `ember test --server` – Runs the test suite in "watch mode" -* `ember try:each` – Runs the test suite against multiple Ember versions +- `ember test` – Runs the test suite on the current Ember version +- `ember test --server` – Runs the test suite in "watch mode" +- `ember try:each` – Runs the test suite against multiple Ember versions ### Running the dummy application -* `ember serve` -* Visit the dummy application at [http://localhost:4200](http://localhost:4200). +- `ember serve` +- Visit the dummy application at [http://localhost:4200](http://localhost:4200). For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). From 32a487654b88d145e238879fc1fa701cbf5f578e Mon Sep 17 00:00:00 2001 From: Robbie Wagner Date: Fri, 25 Apr 2025 17:25:18 -0400 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 0393ce5..0bb7bbe 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,6 @@ [![CI](https://github.com/minutebase/ember-can/actions/workflows/ci.yml/badge.svg)](https://github.com/minutebase/ember-can/actions/workflows/ci.yml) - - - - --- Simple authorisation addon for Ember.