-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create initial policies and abilities files
- Loading branch information
1 parent
70acc43
commit 2c0b82a
Showing
5 changed files
with
146 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{{ | ||
exports({ to: app.makePath('app/abilities/main.ts') }) | ||
}}} | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Bouncer abilities | ||
|-------------------------------------------------------------------------- | ||
| | ||
| You may export multiple abilities from this file and pre-register them | ||
| when creating the Bouncer instance. | ||
| | ||
| Pre-registered policies and abilities can be referenced as a string by their | ||
| name. Also they are must if want to perform authorization inside Edge | ||
| templates. | ||
| | ||
*/ | ||
|
||
import { Bouncer } from '@adonisjs/bouncer' | ||
|
||
/** | ||
* Delete the following ability to start from | ||
* scratch | ||
*/ | ||
export const editUser = Bouncer.ability(() => { | ||
return true | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{{ | ||
exports({ to: app.policiesPath('main.ts') }) | ||
}}} | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Bouncer policies | ||
|-------------------------------------------------------------------------- | ||
| | ||
| You may define a collection of policies inside this file and pre-register | ||
| them when creating a new bouncer instance. | ||
| | ||
| Pre-registered policies and abilities can be referenced as a string by their | ||
| name. Also they are must if want to perform authorization inside Edge | ||
| templates. | ||
| | ||
*/ | ||
|
||
export const policies = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* @adonisjs/session | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { test } from '@japa/runner' | ||
import { fileURLToPath } from 'node:url' | ||
import { IgnitorFactory } from '@adonisjs/core/factories' | ||
import Configure from '@adonisjs/core/commands/configure' | ||
|
||
import { stubsRoot } from '../index.js' | ||
const BASE_URL = new URL('./tmp/', import.meta.url) | ||
|
||
test.group('Configure', (group) => { | ||
group.each.setup(({ context }) => { | ||
context.fs.baseUrl = BASE_URL | ||
context.fs.basePath = fileURLToPath(BASE_URL) | ||
}) | ||
|
||
test('register provider and publish stubs', async ({ fs, assert }) => { | ||
const ignitor = new IgnitorFactory() | ||
.withCoreProviders() | ||
.withCoreConfig() | ||
.create(BASE_URL, { | ||
importer: (filePath) => { | ||
if (filePath.startsWith('./') || filePath.startsWith('../')) { | ||
return import(new URL(filePath, BASE_URL).href) | ||
} | ||
|
||
return import(filePath) | ||
}, | ||
}) | ||
|
||
await fs.createJson('tsconfig.json', {}) | ||
await fs.create('start/kernel.ts', `router.use([])`) | ||
await fs.create('adonisrc.ts', `export default defineConfig({}) {}`) | ||
|
||
const app = ignitor.createApp('web') | ||
await app.init() | ||
await app.boot() | ||
|
||
const ace = await app.container.make('ace') | ||
const command = await ace.create(Configure, ['../../index.js']) | ||
await command.exec() | ||
|
||
const stubsManager = await app.stubs.create() | ||
const abilitiesStub = await stubsManager | ||
.build('abilities.stub', { source: stubsRoot }) | ||
.then((stub) => stub.prepare({})) | ||
|
||
const policiesStub = await stubsManager | ||
.build('policies.stub', { source: stubsRoot }) | ||
.then((stub) => stub.prepare({})) | ||
|
||
await assert.fileContains('adonisrc.ts', '@adonisjs/bouncer/bouncer_provider') | ||
await assert.fileContains('app/abilities/main.ts', abilitiesStub.contents) | ||
await assert.fileContains('app/policies/main.ts', policiesStub.contents) | ||
await assert.fileContains( | ||
'app/middleware/initialize_bouncer_middleware.ts', | ||
`export default class InitializeBouncerMiddleware {` | ||
) | ||
}).disableTimeout() | ||
}) |